aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2021-10-05 13:47:42 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2021-10-05 13:50:11 +0200
commit137864f559e7eff1f929958d3999359c7070ed91 (patch)
tree369d1c465bbdc3030061c777ab7fd68ed41bfe26
parent389329efbed15122bb3fba59e9919d870301eb93 (diff)
downloadbusybox-w32-137864f559e7eff1f929958d3999359c7070ed91.tar.gz
busybox-w32-137864f559e7eff1f929958d3999359c7070ed91.tar.bz2
busybox-w32-137864f559e7eff1f929958d3999359c7070ed91.zip
tls: add debugging scaffolding to P256 code
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/tls_sp_c32.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/networking/tls_sp_c32.c b/networking/tls_sp_c32.c
index f4902f7f3..5b4c7e97c 100644
--- a/networking/tls_sp_c32.c
+++ b/networking/tls_sp_c32.c
@@ -136,6 +136,53 @@ static void sp_256_from_bin_10(sp_digit* r, const uint8_t* a)
136 } 136 }
137} 137}
138 138
139#if SP_DEBUG
140static void dump_256(const char *fmt, const sp_digit* cr)
141{
142 sp_digit* r = (sp_digit*)cr;
143 uint8_t b32[32];
144 sp_256_to_bin_10(r, b32);
145 dump_hex(fmt, b32, 32);
146}
147static void dump_512(const char *fmt, const sp_digit* cr)
148{
149 sp_digit* r = (sp_digit*)cr;
150 uint8_t a[64];
151 int i, j, s, b;
152
153 /* sp_512_norm_10: */
154 for (i = 0; i < 19; i++) {
155 r[i+1] += r[i] >> 26;
156 r[i] &= 0x3ffffff;
157 }
158 /* sp_512_to_bin_10: */
159 s = 0;
160 j = 512 / 8 - 1;
161 a[j] = 0;
162 for (i = 0; i < 20 && j >= 0; i++) {
163 b = 0;
164 a[j--] |= r[i] << s; b += 8 - s;
165 if (j < 0)
166 break;
167 while (b < 26) {
168 a[j--] = r[i] >> b; b += 8;
169 if (j < 0)
170 break;
171 }
172 s = 8 - (b - 26);
173 if (j >= 0)
174 a[j] = 0;
175 if (s != 0)
176 j++;
177 }
178
179 dump_hex(fmt, a, 64);
180}
181#else
182# define dump_256(...) ((void)0)
183# define dump_512(...) ((void)0)
184#endif
185
139/* Convert a point of big-endian 32-byte x,y pair to type sp_point. */ 186/* Convert a point of big-endian 32-byte x,y pair to type sp_point. */
140static void sp_256_point_from_bin2x32(sp_point* p, const uint8_t *bin2x32) 187static void sp_256_point_from_bin2x32(sp_point* p, const uint8_t *bin2x32)
141{ 188{
@@ -743,6 +790,9 @@ static void sp_256_ecc_mulmod_10(sp_point* r, const sp_point* g, const sp_digit*
743 sp_256_mod_mul_norm_10(t[1].x, g->x); 790 sp_256_mod_mul_norm_10(t[1].x, g->x);
744 sp_256_mod_mul_norm_10(t[1].y, g->y); 791 sp_256_mod_mul_norm_10(t[1].y, g->y);
745 sp_256_mod_mul_norm_10(t[1].z, g->z); 792 sp_256_mod_mul_norm_10(t[1].z, g->z);
793 dump_512("t[1].x %s\n", t[1].x);
794 dump_512("t[1].y %s\n", t[1].y);
795 dump_512("t[1].z %s\n", t[1].z);
746 796
747 i = 9; 797 i = 9;
748 c = 22; 798 c = 22;
@@ -875,7 +925,10 @@ static void sp_ecc_make_key_256(sp_digit privkey[10], uint8_t *pubkey)
875 sp_point point[1]; 925 sp_point point[1];
876 926
877 sp_256_ecc_gen_k_10(privkey); 927 sp_256_ecc_gen_k_10(privkey);
928 dump_256("privkey %s\n", privkey);
878 sp_256_ecc_mulmod_base_10(point, privkey); 929 sp_256_ecc_mulmod_base_10(point, privkey);
930 dump_512("point->x %s\n", point->x);
931 dump_512("point->y %s\n", point->y);
879 sp_256_to_bin_10(point->x, pubkey); 932 sp_256_to_bin_10(point->x, pubkey);
880 sp_256_to_bin_10(point->y, pubkey + 32); 933 sp_256_to_bin_10(point->y, pubkey + 32);
881 934