diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2021-04-26 14:55:46 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-04-26 14:55:46 +0200 |
| commit | 03ab2a90bbd5970fabe50fcd510730e5e088b923 (patch) | |
| tree | b475efaeda2020b16a7dc9884ae2090b8e9f8d64 | |
| parent | 166363f47d74a73a0a3ad1ebbb5aae00752ab8f7 (diff) | |
| download | busybox-w32-03ab2a90bbd5970fabe50fcd510730e5e088b923.tar.gz busybox-w32-03ab2a90bbd5970fabe50fcd510730e5e088b923.tar.bz2 busybox-w32-03ab2a90bbd5970fabe50fcd510730e5e088b923.zip | |
tls: simplify array manipulations in sp_256_ecc_mulmod_10
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | networking/tls_sp_c32.c | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/networking/tls_sp_c32.c b/networking/tls_sp_c32.c index 87d44d5e0..d3bb36a39 100644 --- a/networking/tls_sp_c32.c +++ b/networking/tls_sp_c32.c | |||
| @@ -788,29 +788,25 @@ static void sp_256_proj_point_add_10(sp_point* r, sp_point* p, sp_point* q, | |||
| 788 | * r Resulting point. | 788 | * r Resulting point. |
| 789 | * g Point to multiply. | 789 | * g Point to multiply. |
| 790 | * k Scalar to multiply by. | 790 | * k Scalar to multiply by. |
| 791 | * map Indicates whether to convert result to affine. | ||
| 791 | */ | 792 | */ |
| 792 | static void sp_256_ecc_mulmod_10(sp_point* r, const sp_point* g, const sp_digit* k /*, int map*/) | 793 | static void sp_256_ecc_mulmod_10(sp_point* r, const sp_point* g, const sp_digit* k /*, int map*/) |
| 793 | { | 794 | { |
| 794 | enum { map = 1 }; /* we always convert result to affine coordinates */ | 795 | enum { map = 1 }; /* we always convert result to affine coordinates */ |
| 795 | sp_point td[3]; | 796 | sp_point t[3]; |
| 796 | sp_point* t[3]; | ||
| 797 | sp_digit tmp[2 * 10 * 5]; | 797 | sp_digit tmp[2 * 10 * 5]; |
| 798 | sp_digit n; | 798 | sp_digit n; |
| 799 | int i; | 799 | int i; |
| 800 | int c, y; | 800 | int c, y; |
| 801 | 801 | ||
| 802 | memset(td, 0, sizeof(td)); | 802 | memset(t, 0, sizeof(t)); |
| 803 | |||
| 804 | t[0] = &td[0]; | ||
| 805 | t[1] = &td[1]; | ||
| 806 | t[2] = &td[2]; | ||
| 807 | 803 | ||
| 808 | /* t[0] = {0, 0, 1} * norm */ | 804 | /* t[0] = {0, 0, 1} * norm */ |
| 809 | t[0]->infinity = 1; | 805 | t[0].infinity = 1; |
| 810 | /* t[1] = {g->x, g->y, g->z} * norm */ | 806 | /* t[1] = {g->x, g->y, g->z} * norm */ |
| 811 | sp_256_mod_mul_norm_10(t[1]->x, g->x); | 807 | sp_256_mod_mul_norm_10(t[1].x, g->x); |
| 812 | sp_256_mod_mul_norm_10(t[1]->y, g->y); | 808 | sp_256_mod_mul_norm_10(t[1].y, g->y); |
| 813 | sp_256_mod_mul_norm_10(t[1]->z, g->z); | 809 | sp_256_mod_mul_norm_10(t[1].z, g->z); |
| 814 | 810 | ||
| 815 | i = 9; | 811 | i = 9; |
| 816 | c = 22; | 812 | c = 22; |
| @@ -827,19 +823,21 @@ static void sp_256_ecc_mulmod_10(sp_point* r, const sp_point* g, const sp_digit* | |||
| 827 | y = (n >> 25) & 1; | 823 | y = (n >> 25) & 1; |
| 828 | n <<= 1; | 824 | n <<= 1; |
| 829 | 825 | ||
| 830 | sp_256_proj_point_add_10(t[y^1], t[0], t[1], tmp); | 826 | //FIXME: what's "tmp" and why do we pass it down? |
| 831 | memcpy(t[2], t[y], sizeof(sp_point)); | 827 | //is it scratch space for "sensitive" data, to be memset(0) after we are done? |
| 832 | sp_256_proj_point_dbl_10(t[2], t[2], tmp); | 828 | sp_256_proj_point_add_10(&t[y^1], &t[0], &t[1], tmp); |
| 833 | memcpy(t[y], t[2], sizeof(sp_point)); | 829 | memcpy(&t[2], &t[y], sizeof(sp_point)); |
| 830 | sp_256_proj_point_dbl_10(&t[2], &t[2], tmp); | ||
| 831 | memcpy(&t[y], &t[2], sizeof(sp_point)); | ||
| 834 | } | 832 | } |
| 835 | 833 | ||
| 836 | if (map) | 834 | if (map) |
| 837 | sp_256_map_10(r, t[0], tmp); | 835 | sp_256_map_10(r, &t[0], tmp); |
| 838 | else | 836 | else |
| 839 | memcpy(r, t[0], sizeof(sp_point)); | 837 | memcpy(r, &t[0], sizeof(sp_point)); |
| 840 | 838 | ||
| 841 | memset(tmp, 0, sizeof(tmp)); //paranoia | 839 | memset(tmp, 0, sizeof(tmp)); //paranoia |
| 842 | memset(td, 0, sizeof(td)); //paranoia | 840 | memset(t, 0, sizeof(t)); //paranoia |
| 843 | } | 841 | } |
| 844 | 842 | ||
| 845 | /* Multiply the base point of P256 by the scalar and return the result. | 843 | /* Multiply the base point of P256 by the scalar and return the result. |
| @@ -847,6 +845,7 @@ static void sp_256_ecc_mulmod_10(sp_point* r, const sp_point* g, const sp_digit* | |||
| 847 | * | 845 | * |
| 848 | * r Resulting point. | 846 | * r Resulting point. |
| 849 | * k Scalar to multiply by. | 847 | * k Scalar to multiply by. |
| 848 | * map Indicates whether to convert result to affine. | ||
| 850 | */ | 849 | */ |
| 851 | static void sp_256_ecc_mulmod_base_10(sp_point* r, sp_digit* k /*, int map*/) | 850 | static void sp_256_ecc_mulmod_base_10(sp_point* r, sp_digit* k /*, int map*/) |
| 852 | { | 851 | { |
