diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2021-11-28 12:55:20 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-11-28 12:55:20 +0100 |
commit | 832626227ea3798403159080532f763a37273a91 (patch) | |
tree | 7459de384856350c34c570fca9270f6679cc0011 | |
parent | 00b5051cd25ef7e42ac62637ba16b70d3ac1014a (diff) | |
download | busybox-w32-832626227ea3798403159080532f763a37273a91.tar.gz busybox-w32-832626227ea3798403159080532f763a37273a91.tar.bz2 busybox-w32-832626227ea3798403159080532f763a37273a91.zip |
tls: P256: add comment on logic in sp_512to256_mont_reduce_8, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | networking/tls_sp_c32.c | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/networking/tls_sp_c32.c b/networking/tls_sp_c32.c index 9bd5c6832..eb6cc2431 100644 --- a/networking/tls_sp_c32.c +++ b/networking/tls_sp_c32.c | |||
@@ -850,6 +850,20 @@ static int sp_256_mul_add_8(sp_digit* r /*, const sp_digit* a, sp_digit b*/) | |||
850 | * a Double-wide number to reduce. Clobbered. | 850 | * a Double-wide number to reduce. Clobbered. |
851 | * m The single precision number representing the modulus. | 851 | * m The single precision number representing the modulus. |
852 | * mp The digit representing the negative inverse of m mod 2^n. | 852 | * mp The digit representing the negative inverse of m mod 2^n. |
853 | * | ||
854 | * Montgomery reduction on multiprecision integers: | ||
855 | * Montgomery reduction requires products modulo R. | ||
856 | * When R is a power of B [in our case R=2^128, B=2^32], there is a variant | ||
857 | * of Montgomery reduction which requires products only of machine word sized | ||
858 | * integers. T is stored as an little-endian word array a[0..n]. The algorithm | ||
859 | * reduces it one word at a time. First an appropriate multiple of modulus | ||
860 | * is added to make T divisible by B. [In our case, it is p256_mp_mod * a[0].] | ||
861 | * Then a multiple of modulus is added to make T divisible by B^2. | ||
862 | * [In our case, it is (p256_mp_mod * a[1]) << 32.] | ||
863 | * And so on. Eventually T is divisible by R, and after division by R | ||
864 | * the algorithm is in the same place as the usual Montgomery reduction was. | ||
865 | * | ||
866 | * TODO: Can conditionally use 64-bit (if bit-little-endian arch) logic? | ||
853 | */ | 867 | */ |
854 | static void sp_512to256_mont_reduce_8(sp_digit* r, sp_digit* a/*, const sp_digit* m, sp_digit mp*/) | 868 | static void sp_512to256_mont_reduce_8(sp_digit* r, sp_digit* a/*, const sp_digit* m, sp_digit mp*/) |
855 | { | 869 | { |
@@ -941,15 +955,6 @@ static void sp_256_mont_sqr_8(sp_digit* r, const sp_digit* a | |||
941 | * r Inverse result. Must not coincide with a. | 955 | * r Inverse result. Must not coincide with a. |
942 | * a Number to invert. | 956 | * a Number to invert. |
943 | */ | 957 | */ |
944 | #if 0 | ||
945 | //p256_mod - 2: | ||
946 | //ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff ffffffff - 2 | ||
947 | //Bit pattern: | ||
948 | //2 2 2 2 2 2 2 1...1 | ||
949 | //5 5 4 3 2 1 0 9...0 9...1 | ||
950 | //543210987654321098765432109876543210987654321098765432109876543210...09876543210...09876543210 | ||
951 | //111111111111111111111111111111110000000000000000000000000000000100...00000111111...11111111101 | ||
952 | #endif | ||
953 | static void sp_256_mont_inv_8(sp_digit* r, sp_digit* a) | 958 | static void sp_256_mont_inv_8(sp_digit* r, sp_digit* a) |
954 | { | 959 | { |
955 | int i; | 960 | int i; |
@@ -957,7 +962,15 @@ static void sp_256_mont_inv_8(sp_digit* r, sp_digit* a) | |||
957 | memcpy(r, a, sizeof(sp_digit) * 8); | 962 | memcpy(r, a, sizeof(sp_digit) * 8); |
958 | for (i = 254; i >= 0; i--) { | 963 | for (i = 254; i >= 0; i--) { |
959 | sp_256_mont_sqr_8(r, r /*, p256_mod, p256_mp_mod*/); | 964 | sp_256_mont_sqr_8(r, r /*, p256_mod, p256_mp_mod*/); |
960 | /*if (p256_mod_2[i / 32] & ((sp_digit)1 << (i % 32)))*/ | 965 | /* p256_mod - 2: |
966 | * ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff ffffffff - 2 | ||
967 | * Bit pattern: | ||
968 | * 2 2 2 2 2 2 2 1...1 | ||
969 | * 5 5 4 3 2 1 0 9...0 9...1 | ||
970 | * 543210987654321098765432109876543210987654321098765432109876543210...09876543210...09876543210 | ||
971 | * 111111111111111111111111111111110000000000000000000000000000000100...00000111111...11111111101 | ||
972 | */ | ||
973 | /*if (p256_mod_minus_2[i / 32] & ((sp_digit)1 << (i % 32)))*/ | ||
961 | if (i >= 224 || i == 192 || (i <= 95 && i != 1)) | 974 | if (i >= 224 || i == 192 || (i <= 95 && i != 1)) |
962 | sp_256_mont_mul_8(r, r, a /*, p256_mod, p256_mp_mod*/); | 975 | sp_256_mont_mul_8(r, r, a /*, p256_mod, p256_mp_mod*/); |
963 | } | 976 | } |