diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-01-19 15:51:00 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-01-19 15:51:00 +0100 |
commit | 6b1b004845ebec194c4d4868d3deb57f22711b19 (patch) | |
tree | 291b2cf65b5537a184369eabec0089420ed63930 | |
parent | 1bfc4b85a7915210936edc62ecf0d01a17751222 (diff) | |
download | busybox-w32-6b1b004845ebec194c4d4868d3deb57f22711b19.tar.gz busybox-w32-6b1b004845ebec194c4d4868d3deb57f22711b19.tar.bz2 busybox-w32-6b1b004845ebec194c4d4868d3deb57f22711b19.zip |
tls: commented out psPool_t use
function old new delta
psAesEncrypt 159 162 +3
der_binary_to_pstm 42 40 -2
xwrite_and_hash 437 434 -3
xread_tls_block 446 443 -3
pstm_div_2d 449 444 -5
psAesDecrypt 179 174 -5
pstm_init_size 52 45 -7
pstm_init 46 39 -7
pstm_to_unsigned_bin 165 157 -8
tls_main 1265 1256 -9
pstm_mulmod 132 123 -9
pstm_mod 125 116 -9
pstm_init_copy 93 84 -9
psAesInitKey 840 825 -15
send_client_key_exchange 362 342 -20
psAesInit 103 80 -23
psRsaEncryptPub 429 403 -26
psAesDecryptBlock 1211 1184 -27
psAesEncryptBlock 1223 1193 -30
pstm_exptmod 1582 1524 -58
pstm_div 1557 1472 -85
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/20 up/down: 3/-360) Total: -357 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | networking/tls.h | 3 | ||||
-rw-r--r-- | networking/tls_aes.c | 60 | ||||
-rw-r--r-- | networking/tls_pstm.c | 27 | ||||
-rw-r--r-- | networking/tls_pstm.h | 47 | ||||
-rw-r--r-- | networking/tls_pstm_montgomery_reduce.c | 6 | ||||
-rw-r--r-- | networking/tls_pstm_mul_comba.c | 10 | ||||
-rw-r--r-- | networking/tls_pstm_sqr_comba.c | 10 | ||||
-rw-r--r-- | networking/tls_rsa.c | 20 | ||||
-rw-r--r-- | networking/tls_rsa.h | 4 | ||||
-rw-r--r-- | networking/tls_symmetric.h | 4 |
10 files changed, 122 insertions, 69 deletions
diff --git a/networking/tls.h b/networking/tls.h index 5a0cb67e9..5e6b346e2 100644 --- a/networking/tls.h +++ b/networking/tls.h | |||
@@ -66,8 +66,7 @@ typedef int32_t int32; | |||
66 | typedef uint16_t uint16; | 66 | typedef uint16_t uint16; |
67 | typedef int16_t int16; | 67 | typedef int16_t int16; |
68 | 68 | ||
69 | //FIXME | 69 | //typedef char psPool_t; |
70 | typedef char psPool_t; | ||
71 | 70 | ||
72 | //#ifdef PS_PUBKEY_OPTIMIZE_FOR_SMALLER_RAM | 71 | //#ifdef PS_PUBKEY_OPTIMIZE_FOR_SMALLER_RAM |
73 | #define PS_EXPTMOD_WINSIZE 3 | 72 | #define PS_EXPTMOD_WINSIZE 3 |
diff --git a/networking/tls_aes.c b/networking/tls_aes.c index 661bd8272..6c3c39373 100644 --- a/networking/tls_aes.c +++ b/networking/tls_aes.c | |||
@@ -6,7 +6,7 @@ | |||
6 | #include "tls.h" | 6 | #include "tls.h" |
7 | 7 | ||
8 | /* The file is taken almost verbatim from matrixssl-3-7-2b-open/crypto/symmetric/. | 8 | /* The file is taken almost verbatim from matrixssl-3-7-2b-open/crypto/symmetric/. |
9 | * Changes are flagged with ///bbox | 9 | * Changes are flagged with //bbox |
10 | */ | 10 | */ |
11 | 11 | ||
12 | /** | 12 | /** |
@@ -43,7 +43,7 @@ | |||
43 | */ | 43 | */ |
44 | /******************************************************************************/ | 44 | /******************************************************************************/ |
45 | 45 | ||
46 | ///vda | 46 | //bbox |
47 | //#include "../cryptoApi.h" | 47 | //#include "../cryptoApi.h" |
48 | 48 | ||
49 | #ifdef USE_AES | 49 | #ifdef USE_AES |
@@ -1084,10 +1084,11 @@ int32 psAesInit(psCipherContext_t *ctx, unsigned char *IV, | |||
1084 | { | 1084 | { |
1085 | int32 x, err; | 1085 | int32 x, err; |
1086 | 1086 | ||
1087 | if (IV == NULL || key == NULL || ctx == NULL) { | 1087 | //bbox |
1088 | psTraceCrypto("psAesInit arg fail\n"); | 1088 | // if (IV == NULL || key == NULL || ctx == NULL) { |
1089 | return PS_ARG_FAIL; | 1089 | // psTraceCrypto("psAesInit arg fail\n"); |
1090 | } | 1090 | // return PS_ARG_FAIL; |
1091 | // } | ||
1091 | memset(ctx, 0x0, sizeof(psCipherContext_t)); | 1092 | memset(ctx, 0x0, sizeof(psCipherContext_t)); |
1092 | /* | 1093 | /* |
1093 | setup cipher | 1094 | setup cipher |
@@ -1112,10 +1113,13 @@ int32 psAesEncrypt(psCipherContext_t *ctx, unsigned char *pt, | |||
1112 | uint32 i; | 1113 | uint32 i; |
1113 | unsigned char tmp[MAXBLOCKSIZE]; | 1114 | unsigned char tmp[MAXBLOCKSIZE]; |
1114 | 1115 | ||
1115 | if (pt == NULL || ct == NULL || ctx == NULL || (len & 0x7) != 0) { | 1116 | //bbox |
1116 | psTraceCrypto("Bad parameters to psAesEncrypt\n"); | 1117 | // if (pt == NULL || ct == NULL || ctx == NULL || (len & 0x7) != 0) { |
1117 | return PS_ARG_FAIL; | 1118 | // psTraceCrypto("Bad parameters to psAesEncrypt\n"); |
1118 | } | 1119 | // return PS_ARG_FAIL; |
1120 | // } | ||
1121 | if ((len & 0x7) != 0) | ||
1122 | bb_error_msg_and_die("AES len:%d", len); | ||
1119 | 1123 | ||
1120 | /* | 1124 | /* |
1121 | is blocklen valid? | 1125 | is blocklen valid? |
@@ -1159,10 +1163,13 @@ int32 psAesDecrypt(psCipherContext_t *ctx, unsigned char *ct, | |||
1159 | uint32 i; | 1163 | uint32 i; |
1160 | unsigned char tmp[MAXBLOCKSIZE], tmp2[MAXBLOCKSIZE]; | 1164 | unsigned char tmp[MAXBLOCKSIZE], tmp2[MAXBLOCKSIZE]; |
1161 | 1165 | ||
1162 | if (pt == NULL || ct == NULL || ctx == NULL || (len & 0x7) != 0) { | 1166 | //bbox |
1163 | psTraceCrypto("Bad parameters to psAesDecrypt\n"); | 1167 | // if (pt == NULL || ct == NULL || ctx == NULL || (len & 0x7) != 0) { |
1164 | return PS_ARG_FAIL; | 1168 | // psTraceCrypto("Bad parameters to psAesDecrypt\n"); |
1165 | } | 1169 | // return PS_ARG_FAIL; |
1170 | // } | ||
1171 | if ((len & 0x7) != 0) | ||
1172 | bb_error_msg_and_die("AES len:%d", len); | ||
1166 | 1173 | ||
1167 | /* | 1174 | /* |
1168 | is blocklen valid? | 1175 | is blocklen valid? |
@@ -1221,14 +1228,15 @@ int32 psAesInitKey(const unsigned char *key, uint32 keylen, psAesKey_t *skey) | |||
1221 | int32 i, j; | 1228 | int32 i, j; |
1222 | uint32 temp, *rk, *rrk; | 1229 | uint32 temp, *rk, *rrk; |
1223 | 1230 | ||
1224 | if (key == NULL || skey == NULL) { | 1231 | //bbox |
1225 | psTraceCrypto("Bad args to psAesInitKey\n"); | 1232 | // if (key == NULL || skey == NULL) { |
1226 | return PS_ARG_FAIL; | 1233 | // psTraceCrypto("Bad args to psAesInitKey\n"); |
1227 | } | 1234 | // return PS_ARG_FAIL; |
1235 | // } | ||
1228 | 1236 | ||
1229 | if (keylen != 16 && keylen != 24 && keylen != 32) { | 1237 | if (keylen != 16 && keylen != 24 && keylen != 32) { |
1230 | psTraceCrypto("Invalid AES key length\n"); | 1238 | psTraceCrypto("Invalid AES key length\n"); |
1231 | ///bbox return CRYPT_INVALID_KEYSIZE; | 1239 | //bbox return CRYPT_INVALID_KEYSIZE; |
1232 | //unreachable anyway | 1240 | //unreachable anyway |
1233 | return PS_ARG_FAIL; | 1241 | return PS_ARG_FAIL; |
1234 | } | 1242 | } |
@@ -1398,9 +1406,10 @@ void psAesEncryptBlock(const unsigned char *pt, unsigned char *ct, | |||
1398 | uint32 s0, s1, s2, s3, t0, t1, t2, t3, *rk; | 1406 | uint32 s0, s1, s2, s3, t0, t1, t2, t3, *rk; |
1399 | int32 Nr, r; | 1407 | int32 Nr, r; |
1400 | 1408 | ||
1401 | if (pt == NULL || ct == NULL || skey == NULL) { | 1409 | //bbox |
1402 | return; | 1410 | // if (pt == NULL || ct == NULL || skey == NULL) { |
1403 | } | 1411 | // return; |
1412 | // } | ||
1404 | 1413 | ||
1405 | Nr = skey->Nr; | 1414 | Nr = skey->Nr; |
1406 | rk = skey->eK; | 1415 | rk = skey->eK; |
@@ -1562,9 +1571,10 @@ void psAesDecryptBlock(const unsigned char *ct, unsigned char *pt, | |||
1562 | uint32 s0, s1, s2, s3, t0, t1, t2, t3, *rk; | 1571 | uint32 s0, s1, s2, s3, t0, t1, t2, t3, *rk; |
1563 | int32 Nr, r; | 1572 | int32 Nr, r; |
1564 | 1573 | ||
1565 | if (pt == NULL || ct == NULL || skey == NULL) { | 1574 | //bbox |
1566 | return; | 1575 | // if (pt == NULL || ct == NULL || skey == NULL) { |
1567 | } | 1576 | // return; |
1577 | // } | ||
1568 | 1578 | ||
1569 | Nr = skey->Nr; | 1579 | Nr = skey->Nr; |
1570 | rk = skey->dK; | 1580 | rk = skey->dK; |
diff --git a/networking/tls_pstm.c b/networking/tls_pstm.c index f802baa15..acd800307 100644 --- a/networking/tls_pstm.c +++ b/networking/tls_pstm.c | |||
@@ -6,7 +6,7 @@ | |||
6 | #include "tls.h" | 6 | #include "tls.h" |
7 | 7 | ||
8 | /* The file is taken almost verbatim from matrixssl-3-7-2b-open/crypto/math/. | 8 | /* The file is taken almost verbatim from matrixssl-3-7-2b-open/crypto/math/. |
9 | * Changes are flagged with ///bbox | 9 | * Changes are flagged with //bbox |
10 | */ | 10 | */ |
11 | 11 | ||
12 | /** | 12 | /** |
@@ -43,7 +43,7 @@ | |||
43 | */ | 43 | */ |
44 | /******************************************************************************/ | 44 | /******************************************************************************/ |
45 | 45 | ||
46 | ///bbox | 46 | //bbox |
47 | //#include "../cryptoApi.h" | 47 | //#include "../cryptoApi.h" |
48 | #ifndef DISABLE_PSTM | 48 | #ifndef DISABLE_PSTM |
49 | 49 | ||
@@ -55,21 +55,21 @@ static int32 pstm_mul_2d(pstm_int *a, int16 b, pstm_int *c); | |||
55 | */ | 55 | */ |
56 | int32 pstm_init_size(psPool_t *pool, pstm_int * a, uint32 size) | 56 | int32 pstm_init_size(psPool_t *pool, pstm_int * a, uint32 size) |
57 | { | 57 | { |
58 | ///bbox | 58 | //bbox |
59 | // uint16 x; | 59 | // uint16 x; |
60 | 60 | ||
61 | /* | 61 | /* |
62 | alloc mem | 62 | alloc mem |
63 | */ | 63 | */ |
64 | a->dp = xzalloc(sizeof (pstm_digit) * size);///bbox | 64 | a->dp = xzalloc(sizeof (pstm_digit) * size);//bbox |
65 | a->pool = pool; | 65 | //bbox a->pool = pool; |
66 | a->used = 0; | 66 | a->used = 0; |
67 | a->alloc = (int16)size; | 67 | a->alloc = (int16)size; |
68 | a->sign = PSTM_ZPOS; | 68 | a->sign = PSTM_ZPOS; |
69 | /* | 69 | /* |
70 | zero the digits | 70 | zero the digits |
71 | */ | 71 | */ |
72 | ///bbox | 72 | //bbox |
73 | // for (x = 0; x < size; x++) { | 73 | // for (x = 0; x < size; x++) { |
74 | // a->dp[x] = 0; | 74 | // a->dp[x] = 0; |
75 | // } | 75 | // } |
@@ -82,16 +82,16 @@ int32 pstm_init_size(psPool_t *pool, pstm_int * a, uint32 size) | |||
82 | */ | 82 | */ |
83 | int32 pstm_init(psPool_t *pool, pstm_int * a) | 83 | int32 pstm_init(psPool_t *pool, pstm_int * a) |
84 | { | 84 | { |
85 | ///bbox | 85 | //bbox |
86 | // int32 i; | 86 | // int32 i; |
87 | /* | 87 | /* |
88 | allocate memory required and clear it | 88 | allocate memory required and clear it |
89 | */ | 89 | */ |
90 | a->dp = xzalloc(sizeof (pstm_digit) * PSTM_DEFAULT_INIT);///bbox | 90 | a->dp = xzalloc(sizeof (pstm_digit) * PSTM_DEFAULT_INIT);//bbox |
91 | /* | 91 | /* |
92 | set the digits to zero | 92 | set the digits to zero |
93 | */ | 93 | */ |
94 | ///bbox | 94 | //bbox |
95 | // for (i = 0; i < PSTM_DEFAULT_INIT; i++) { | 95 | // for (i = 0; i < PSTM_DEFAULT_INIT; i++) { |
96 | // a->dp[i] = 0; | 96 | // a->dp[i] = 0; |
97 | // } | 97 | // } |
@@ -99,7 +99,7 @@ int32 pstm_init(psPool_t *pool, pstm_int * a) | |||
99 | set the used to zero, allocated digits to the default precision and sign | 99 | set the used to zero, allocated digits to the default precision and sign |
100 | to positive | 100 | to positive |
101 | */ | 101 | */ |
102 | a->pool = pool; | 102 | //bbox a->pool = pool; |
103 | a->used = 0; | 103 | a->used = 0; |
104 | a->alloc = PSTM_DEFAULT_INIT; | 104 | a->alloc = PSTM_DEFAULT_INIT; |
105 | a->sign = PSTM_ZPOS; | 105 | a->sign = PSTM_ZPOS; |
@@ -126,7 +126,7 @@ int32 pstm_grow(pstm_int * a, int16 size) | |||
126 | We store the return in a temporary variable in case the operation | 126 | We store the return in a temporary variable in case the operation |
127 | failed we don't want to overwrite the dp member of a. | 127 | failed we don't want to overwrite the dp member of a. |
128 | */ | 128 | */ |
129 | tmp = xrealloc(a->dp, sizeof (pstm_digit) * size);///bbox | 129 | tmp = xrealloc(a->dp, sizeof (pstm_digit) * size);//bbox |
130 | /* | 130 | /* |
131 | reallocation succeeded so set a->dp | 131 | reallocation succeeded so set a->dp |
132 | */ | 132 | */ |
@@ -1622,7 +1622,7 @@ int32 pstm_exptmod(psPool_t *pool, pstm_int *G, pstm_int *X, pstm_int *P, | |||
1622 | Pre-allocated digit. Used for mul, sqr, AND reduce | 1622 | Pre-allocated digit. Used for mul, sqr, AND reduce |
1623 | */ | 1623 | */ |
1624 | paDlen = ((M[1].used + 3) * 2) * sizeof(pstm_digit); | 1624 | paDlen = ((M[1].used + 3) * 2) * sizeof(pstm_digit); |
1625 | paD = xzalloc(paDlen);///bbox | 1625 | paD = xzalloc(paDlen);//bbox |
1626 | /* | 1626 | /* |
1627 | compute the value at M[1<<(winsize-1)] by squaring M[1] (winsize-1) times | 1627 | compute the value at M[1<<(winsize-1)] by squaring M[1] (winsize-1) times |
1628 | */ | 1628 | */ |
@@ -1941,6 +1941,9 @@ int32 pstm_cmp_d(pstm_int *a, pstm_digit b) | |||
1941 | in cases where dQ > dP. The values must be switched and a new qP must be | 1941 | in cases where dQ > dP. The values must be switched and a new qP must be |
1942 | calculated using this function | 1942 | calculated using this function |
1943 | */ | 1943 | */ |
1944 | //bbox: pool unused | ||
1945 | #define pstm_invmod_slow(pool, a, b, c) \ | ||
1946 | pstm_invmod_slow( a, b, c) | ||
1944 | static int32 pstm_invmod_slow(psPool_t *pool, pstm_int * a, pstm_int * b, | 1947 | static int32 pstm_invmod_slow(psPool_t *pool, pstm_int * a, pstm_int * b, |
1945 | pstm_int * c) | 1948 | pstm_int * c) |
1946 | { | 1949 | { |
diff --git a/networking/tls_pstm.h b/networking/tls_pstm.h index de03e3f92..3a0fd8ce6 100644 --- a/networking/tls_pstm.h +++ b/networking/tls_pstm.h | |||
@@ -4,7 +4,7 @@ | |||
4 | * Licensed under GPLv2, see file LICENSE in this source tree. | 4 | * Licensed under GPLv2, see file LICENSE in this source tree. |
5 | */ | 5 | */ |
6 | /* The file is taken almost verbatim from matrixssl-3-7-2b-open/crypto/math/. | 6 | /* The file is taken almost verbatim from matrixssl-3-7-2b-open/crypto/math/. |
7 | * Changes are flagged with ///bbox | 7 | * Changes are flagged with //bbox |
8 | */ | 8 | */ |
9 | 9 | ||
10 | /** | 10 | /** |
@@ -124,7 +124,7 @@ | |||
124 | typedef struct { | 124 | typedef struct { |
125 | int16 used, alloc, sign; | 125 | int16 used, alloc, sign; |
126 | pstm_digit *dp; | 126 | pstm_digit *dp; |
127 | psPool_t *pool; | 127 | //bbox psPool_t *pool; |
128 | } pstm_int; | 128 | } pstm_int; |
129 | 129 | ||
130 | /******************************************************************************/ | 130 | /******************************************************************************/ |
@@ -140,15 +140,27 @@ extern void pstm_set(pstm_int *a, pstm_digit b); | |||
140 | 140 | ||
141 | extern void pstm_zero(pstm_int * a); | 141 | extern void pstm_zero(pstm_int * a); |
142 | 142 | ||
143 | //bbox: pool unused | ||
144 | #define pstm_init(pool, a) \ | ||
145 | pstm_init( a) | ||
143 | extern int32 pstm_init(psPool_t *pool, pstm_int * a); | 146 | extern int32 pstm_init(psPool_t *pool, pstm_int * a); |
144 | 147 | ||
148 | //bbox: pool unused | ||
149 | #define pstm_init_size(pool, a, size) \ | ||
150 | pstm_init_size( a, size) | ||
145 | extern int32 pstm_init_size(psPool_t *pool, pstm_int * a, uint32 size); | 151 | extern int32 pstm_init_size(psPool_t *pool, pstm_int * a, uint32 size); |
146 | 152 | ||
153 | //bbox: pool unused | ||
154 | #define pstm_init_copy(pool, a, b, toSqr) \ | ||
155 | pstm_init_copy( a, b, toSqr) | ||
147 | extern int32 pstm_init_copy(psPool_t *pool, pstm_int * a, pstm_int * b, | 156 | extern int32 pstm_init_copy(psPool_t *pool, pstm_int * a, pstm_int * b, |
148 | int16 toSqr); | 157 | int16 toSqr); |
149 | 158 | ||
150 | extern int16 pstm_count_bits (pstm_int * a); | 159 | extern int16 pstm_count_bits (pstm_int * a); |
151 | 160 | ||
161 | //bbox: pool unused | ||
162 | #define pstm_init_for_read_unsigned_bin(pool, a, len) \ | ||
163 | pstm_init_for_read_unsigned_bin( a, len) | ||
152 | extern int32 pstm_init_for_read_unsigned_bin(psPool_t *pool, pstm_int *a, | 164 | extern int32 pstm_init_for_read_unsigned_bin(psPool_t *pool, pstm_int *a, |
153 | uint32 len); | 165 | uint32 len); |
154 | 166 | ||
@@ -178,9 +190,15 @@ extern void pstm_rshd(pstm_int *a, int16 x); | |||
178 | 190 | ||
179 | extern int32 pstm_lshd(pstm_int * a, int16 b); | 191 | extern int32 pstm_lshd(pstm_int * a, int16 b); |
180 | 192 | ||
193 | //bbox: pool unused | ||
194 | #define pstm_div(pool, a, b, c, d) \ | ||
195 | pstm_div( a, b, c, d) | ||
181 | extern int32 pstm_div(psPool_t *pool, pstm_int *a, pstm_int *b, pstm_int *c, | 196 | extern int32 pstm_div(psPool_t *pool, pstm_int *a, pstm_int *b, pstm_int *c, |
182 | pstm_int *d); | 197 | pstm_int *d); |
183 | 198 | ||
199 | //bbox: pool unused | ||
200 | #define pstm_div_2d(pool, a, b, c, d) \ | ||
201 | pstm_div_2d( a, b, c, d) | ||
184 | extern int32 pstm_div_2d(psPool_t *pool, pstm_int *a, int16 b, pstm_int *c, | 202 | extern int32 pstm_div_2d(psPool_t *pool, pstm_int *a, int16 b, pstm_int *c, |
185 | pstm_int *d); | 203 | pstm_int *d); |
186 | 204 | ||
@@ -190,15 +208,27 @@ extern int32 s_pstm_sub(pstm_int *a, pstm_int *b, pstm_int *c); | |||
190 | 208 | ||
191 | extern int32 pstm_sub(pstm_int *a, pstm_int *b, pstm_int *c); | 209 | extern int32 pstm_sub(pstm_int *a, pstm_int *b, pstm_int *c); |
192 | 210 | ||
211 | //bbox: pool unused | ||
212 | #define pstm_sub_d(pool, a, b, c) \ | ||
213 | pstm_sub_d( a, b, c) | ||
193 | extern int32 pstm_sub_d(psPool_t *pool, pstm_int *a, pstm_digit b, pstm_int *c); | 214 | extern int32 pstm_sub_d(psPool_t *pool, pstm_int *a, pstm_digit b, pstm_int *c); |
194 | 215 | ||
195 | extern int32 pstm_mul_2(pstm_int * a, pstm_int * b); | 216 | extern int32 pstm_mul_2(pstm_int * a, pstm_int * b); |
196 | 217 | ||
218 | //bbox: pool unused | ||
219 | #define pstm_mod(pool, a, b, c) \ | ||
220 | pstm_mod( a, b, c) | ||
197 | extern int32 pstm_mod(psPool_t *pool, pstm_int *a, pstm_int *b, pstm_int *c); | 221 | extern int32 pstm_mod(psPool_t *pool, pstm_int *a, pstm_int *b, pstm_int *c); |
198 | 222 | ||
223 | //bbox: pool unused | ||
224 | #define pstm_mulmod(pool, a, b, c, d) \ | ||
225 | pstm_mulmod( a, b, c, d) | ||
199 | extern int32 pstm_mulmod(psPool_t *pool, pstm_int *a, pstm_int *b, pstm_int *c, | 226 | extern int32 pstm_mulmod(psPool_t *pool, pstm_int *a, pstm_int *b, pstm_int *c, |
200 | pstm_int *d); | 227 | pstm_int *d); |
201 | 228 | ||
229 | //bbox: pool unused | ||
230 | #define pstm_exptmod(pool, G, X, P, Y) \ | ||
231 | pstm_exptmod( G, X, P, Y) | ||
202 | extern int32 pstm_exptmod(psPool_t *pool, pstm_int *G, pstm_int *X, pstm_int *P, | 232 | extern int32 pstm_exptmod(psPool_t *pool, pstm_int *G, pstm_int *X, pstm_int *P, |
203 | pstm_int *Y); | 233 | pstm_int *Y); |
204 | 234 | ||
@@ -206,15 +236,21 @@ extern int32 pstm_2expt(pstm_int *a, int16 b); | |||
206 | 236 | ||
207 | extern int32 pstm_add(pstm_int *a, pstm_int *b, pstm_int *c); | 237 | extern int32 pstm_add(pstm_int *a, pstm_int *b, pstm_int *c); |
208 | 238 | ||
239 | //bbox: pool unused | ||
240 | #define pstm_to_unsigned_bin(pool, a, b) \ | ||
241 | pstm_to_unsigned_bin( a, b) | ||
209 | extern int32 pstm_to_unsigned_bin(psPool_t *pool, pstm_int *a, | 242 | extern int32 pstm_to_unsigned_bin(psPool_t *pool, pstm_int *a, |
210 | unsigned char *b); | 243 | unsigned char *b); |
211 | 244 | ||
245 | //bbox: pool unused | ||
246 | #define pstm_to_unsigned_bin_nr(pool, a, b) \ | ||
247 | pstm_to_unsigned_bin_nr( a, b) | ||
212 | extern int32 pstm_to_unsigned_bin_nr(psPool_t *pool, pstm_int *a, | 248 | extern int32 pstm_to_unsigned_bin_nr(psPool_t *pool, pstm_int *a, |
213 | unsigned char *b); | 249 | unsigned char *b); |
214 | 250 | ||
215 | extern int32 pstm_montgomery_setup(pstm_int *a, pstm_digit *rho); | 251 | extern int32 pstm_montgomery_setup(pstm_int *a, pstm_digit *rho); |
216 | 252 | ||
217 | ///bbox: pool unused | 253 | //bbox: pool unused |
218 | #define pstm_montgomery_reduce(pool, a, m, mp, paD, paDlen) \ | 254 | #define pstm_montgomery_reduce(pool, a, m, mp, paD, paDlen) \ |
219 | pstm_montgomery_reduce( a, m, mp, paD, paDlen) | 255 | pstm_montgomery_reduce( a, m, mp, paD, paDlen) |
220 | extern int32 pstm_montgomery_reduce(psPool_t *pool, pstm_int *a, pstm_int *m, | 256 | extern int32 pstm_montgomery_reduce(psPool_t *pool, pstm_int *a, pstm_int *m, |
@@ -225,7 +261,7 @@ extern int32 pstm_montgomery_reduce(psPool_t *pool, pstm_int *a, pstm_int *m, | |||
225 | extern int32 pstm_mul_comba(psPool_t *pool, pstm_int *A, pstm_int *B, | 261 | extern int32 pstm_mul_comba(psPool_t *pool, pstm_int *A, pstm_int *B, |
226 | pstm_int *C, pstm_digit *paD, uint32 paDlen); | 262 | pstm_int *C, pstm_digit *paD, uint32 paDlen); |
227 | 263 | ||
228 | ///bbox: pool unused | 264 | //bbox: pool unused |
229 | #define pstm_sqr_comba(pool, A, B, paD, paDlen) \ | 265 | #define pstm_sqr_comba(pool, A, B, paD, paDlen) \ |
230 | pstm_sqr_comba( A, B, paD, paDlen) | 266 | pstm_sqr_comba( A, B, paD, paDlen) |
231 | extern int32 pstm_sqr_comba(psPool_t *pool, pstm_int *A, pstm_int *B, | 267 | extern int32 pstm_sqr_comba(psPool_t *pool, pstm_int *A, pstm_int *B, |
@@ -237,6 +273,9 @@ extern int32 pstm_montgomery_calc_normalization(pstm_int *a, pstm_int *b); | |||
237 | 273 | ||
238 | extern int32 pstm_mul_d(pstm_int *a, pstm_digit b, pstm_int *c); | 274 | extern int32 pstm_mul_d(pstm_int *a, pstm_digit b, pstm_int *c); |
239 | 275 | ||
276 | //bbox: pool unused | ||
277 | #define pstm_invmod(pool, a, b, c) \ | ||
278 | pstm_invmod( a, b, c) | ||
240 | extern int32 pstm_invmod(psPool_t *pool, pstm_int * a, pstm_int * b, | 279 | extern int32 pstm_invmod(psPool_t *pool, pstm_int * a, pstm_int * b, |
241 | pstm_int * c); | 280 | pstm_int * c); |
242 | 281 | ||
diff --git a/networking/tls_pstm_montgomery_reduce.c b/networking/tls_pstm_montgomery_reduce.c index e9ae81c53..dc2fe0a48 100644 --- a/networking/tls_pstm_montgomery_reduce.c +++ b/networking/tls_pstm_montgomery_reduce.c | |||
@@ -6,7 +6,7 @@ | |||
6 | #include "tls.h" | 6 | #include "tls.h" |
7 | 7 | ||
8 | /* The file is taken almost verbatim from matrixssl-3-7-2b-open/crypto/math/. | 8 | /* The file is taken almost verbatim from matrixssl-3-7-2b-open/crypto/math/. |
9 | * Changes are flagged with ///bbox | 9 | * Changes are flagged with //bbox |
10 | */ | 10 | */ |
11 | 11 | ||
12 | /** | 12 | /** |
@@ -43,7 +43,7 @@ | |||
43 | */ | 43 | */ |
44 | /******************************************************************************/ | 44 | /******************************************************************************/ |
45 | 45 | ||
46 | ///bbox | 46 | //bbox |
47 | //#include "../cryptoApi.h" | 47 | //#include "../cryptoApi.h" |
48 | #ifndef DISABLE_PSTM | 48 | #ifndef DISABLE_PSTM |
49 | 49 | ||
@@ -357,7 +357,7 @@ int32 pstm_montgomery_reduce(psPool_t *pool, pstm_int *a, pstm_int *m, | |||
357 | c = paD; | 357 | c = paD; |
358 | memset(c, 0x0, paDlen); | 358 | memset(c, 0x0, paDlen); |
359 | } else { | 359 | } else { |
360 | c = xzalloc(2*pa+1);///bbox | 360 | c = xzalloc(2*pa+1);//bbox |
361 | } | 361 | } |
362 | /* copy the input */ | 362 | /* copy the input */ |
363 | oldused = a->used; | 363 | oldused = a->used; |
diff --git a/networking/tls_pstm_mul_comba.c b/networking/tls_pstm_mul_comba.c index 7967231df..47cbb9618 100644 --- a/networking/tls_pstm_mul_comba.c +++ b/networking/tls_pstm_mul_comba.c | |||
@@ -6,7 +6,7 @@ | |||
6 | #include "tls.h" | 6 | #include "tls.h" |
7 | 7 | ||
8 | /* The file is taken almost verbatim from matrixssl-3-7-2b-open/crypto/math/. | 8 | /* The file is taken almost verbatim from matrixssl-3-7-2b-open/crypto/math/. |
9 | * Changes are flagged with ///bbox | 9 | * Changes are flagged with //bbox |
10 | */ | 10 | */ |
11 | 11 | ||
12 | /** | 12 | /** |
@@ -43,7 +43,7 @@ | |||
43 | */ | 43 | */ |
44 | /******************************************************************************/ | 44 | /******************************************************************************/ |
45 | 45 | ||
46 | ///bbox | 46 | //bbox |
47 | //#include "../cryptoApi.h" | 47 | //#include "../cryptoApi.h" |
48 | #ifndef DISABLE_PSTM | 48 | #ifndef DISABLE_PSTM |
49 | 49 | ||
@@ -222,7 +222,7 @@ asm( \ | |||
222 | 222 | ||
223 | /******************************************************************************/ | 223 | /******************************************************************************/ |
224 | /* generic PxQ multiplier */ | 224 | /* generic PxQ multiplier */ |
225 | ///bbox: pool unused | 225 | //bbox: pool unused |
226 | #define pstm_mul_comba_gen(pool, A, B, C, paD, paDlen) \ | 226 | #define pstm_mul_comba_gen(pool, A, B, C, paD, paDlen) \ |
227 | pstm_mul_comba_gen( A, B, C, paD, paDlen) | 227 | pstm_mul_comba_gen( A, B, C, paD, paDlen) |
228 | static int32 pstm_mul_comba_gen(psPool_t *pool, pstm_int *A, pstm_int *B, | 228 | static int32 pstm_mul_comba_gen(psPool_t *pool, pstm_int *A, pstm_int *B, |
@@ -250,13 +250,13 @@ static int32 pstm_mul_comba_gen(psPool_t *pool, pstm_int *A, pstm_int *B, | |||
250 | if (paD != NULL) { | 250 | if (paD != NULL) { |
251 | if (paDlen < (sizeof(pstm_digit) * pa)) { | 251 | if (paDlen < (sizeof(pstm_digit) * pa)) { |
252 | paDfail = 1; /* have a paD but it's not large enough */ | 252 | paDfail = 1; /* have a paD but it's not large enough */ |
253 | dst = xzalloc(sizeof(pstm_digit) * pa);///bbox | 253 | dst = xzalloc(sizeof(pstm_digit) * pa);//bbox |
254 | } else { | 254 | } else { |
255 | dst = paD; | 255 | dst = paD; |
256 | memset(dst, 0x0, paDlen); | 256 | memset(dst, 0x0, paDlen); |
257 | } | 257 | } |
258 | } else { | 258 | } else { |
259 | dst = xzalloc(sizeof(pstm_digit) * pa);///bbox | 259 | dst = xzalloc(sizeof(pstm_digit) * pa);//bbox |
260 | } | 260 | } |
261 | 261 | ||
262 | for (ix = 0; ix < pa; ix++) { | 262 | for (ix = 0; ix < pa; ix++) { |
diff --git a/networking/tls_pstm_sqr_comba.c b/networking/tls_pstm_sqr_comba.c index 378e0647b..36cb9ea97 100644 --- a/networking/tls_pstm_sqr_comba.c +++ b/networking/tls_pstm_sqr_comba.c | |||
@@ -6,7 +6,7 @@ | |||
6 | #include "tls.h" | 6 | #include "tls.h" |
7 | 7 | ||
8 | /* The file is taken almost verbatim from matrixssl-3-7-2b-open/crypto/math/. | 8 | /* The file is taken almost verbatim from matrixssl-3-7-2b-open/crypto/math/. |
9 | * Changes are flagged with ///bbox | 9 | * Changes are flagged with //bbox |
10 | */ | 10 | */ |
11 | 11 | ||
12 | /** | 12 | /** |
@@ -43,7 +43,7 @@ | |||
43 | */ | 43 | */ |
44 | /******************************************************************************/ | 44 | /******************************************************************************/ |
45 | 45 | ||
46 | ///bbox | 46 | //bbox |
47 | //#include "../cryptoApi.h" | 47 | //#include "../cryptoApi.h" |
48 | #ifndef DISABLE_PSTM | 48 | #ifndef DISABLE_PSTM |
49 | 49 | ||
@@ -439,7 +439,7 @@ asm( \ | |||
439 | /* | 439 | /* |
440 | Non-unrolled comba squarer | 440 | Non-unrolled comba squarer |
441 | */ | 441 | */ |
442 | ///bbox: pool unused | 442 | //bbox: pool unused |
443 | #define pstm_sqr_comba_gen(pool, A, B, paD, paDlen) \ | 443 | #define pstm_sqr_comba_gen(pool, A, B, paD, paDlen) \ |
444 | pstm_sqr_comba_gen( A, B, paD, paDlen) | 444 | pstm_sqr_comba_gen( A, B, paD, paDlen) |
445 | static int32 pstm_sqr_comba_gen(psPool_t *pool, pstm_int *A, pstm_int *B, | 445 | static int32 pstm_sqr_comba_gen(psPool_t *pool, pstm_int *A, pstm_int *B, |
@@ -470,13 +470,13 @@ static int32 pstm_sqr_comba_gen(psPool_t *pool, pstm_int *A, pstm_int *B, | |||
470 | if (paD != NULL) { | 470 | if (paD != NULL) { |
471 | if (paDlen < (sizeof(pstm_digit) * pa)) { | 471 | if (paDlen < (sizeof(pstm_digit) * pa)) { |
472 | paDfail = 1; /* have a paD, but it's not big enough */ | 472 | paDfail = 1; /* have a paD, but it's not big enough */ |
473 | dst = xzalloc(sizeof(pstm_digit) * pa);///bbox | 473 | dst = xzalloc(sizeof(pstm_digit) * pa);//bbox |
474 | } else { | 474 | } else { |
475 | dst = paD; | 475 | dst = paD; |
476 | memset(dst, 0x0, paDlen); | 476 | memset(dst, 0x0, paDlen); |
477 | } | 477 | } |
478 | } else { | 478 | } else { |
479 | dst = xzalloc(sizeof(pstm_digit) * pa);///bbox | 479 | dst = xzalloc(sizeof(pstm_digit) * pa);//bbox |
480 | } | 480 | } |
481 | 481 | ||
482 | for (ix = 0; ix < pa; ix++) { | 482 | for (ix = 0; ix < pa; ix++) { |
diff --git a/networking/tls_rsa.c b/networking/tls_rsa.c index df711865c..60c54248e 100644 --- a/networking/tls_rsa.c +++ b/networking/tls_rsa.c | |||
@@ -8,12 +8,12 @@ | |||
8 | /* The code below is taken from parts of | 8 | /* The code below is taken from parts of |
9 | * matrixssl-3-7-2b-open/crypto/pubkey/pkcs.c | 9 | * matrixssl-3-7-2b-open/crypto/pubkey/pkcs.c |
10 | * matrixssl-3-7-2b-open/crypto/pubkey/rsa.c | 10 | * matrixssl-3-7-2b-open/crypto/pubkey/rsa.c |
11 | * and (so far) almost not modified. Changes are flagged with ///bbox | 11 | * and (so far) almost not modified. Changes are flagged with //bbox |
12 | */ | 12 | */ |
13 | 13 | ||
14 | #define pkcs1Pad(in, inlen, out, outlen, cryptType, userPtr) \ | 14 | #define pkcs1Pad(in, inlen, out, outlen, cryptType, userPtr) \ |
15 | pkcs1Pad(in, inlen, out, outlen, cryptType) | 15 | pkcs1Pad(in, inlen, out, outlen, cryptType) |
16 | static ///bbox | 16 | static //bbox |
17 | int32 pkcs1Pad(unsigned char *in, uint32 inlen, unsigned char *out, | 17 | int32 pkcs1Pad(unsigned char *in, uint32 inlen, unsigned char *out, |
18 | uint32 outlen, int32 cryptType, void *userPtr) | 18 | uint32 outlen, int32 cryptType, void *userPtr) |
19 | { | 19 | { |
@@ -57,8 +57,8 @@ int32 pkcs1Pad(unsigned char *in, uint32 inlen, unsigned char *out, | |||
57 | } | 57 | } |
58 | 58 | ||
59 | #define psRsaCrypt(pool, in, inlen, out, outlen, key, type, data) \ | 59 | #define psRsaCrypt(pool, in, inlen, out, outlen, key, type, data) \ |
60 | psRsaCrypt(pool, in, inlen, out, outlen, key, type) | 60 | psRsaCrypt( in, inlen, out, outlen, key, type) |
61 | static ///bbox | 61 | static //bbox |
62 | int32 psRsaCrypt(psPool_t *pool, const unsigned char *in, uint32 inlen, | 62 | int32 psRsaCrypt(psPool_t *pool, const unsigned char *in, uint32 inlen, |
63 | unsigned char *out, uint32 *outlen, psRsaKey_t *key, int32 type, | 63 | unsigned char *out, uint32 *outlen, psRsaKey_t *key, int32 type, |
64 | void *data) | 64 | void *data) |
@@ -67,10 +67,11 @@ int32 psRsaCrypt(psPool_t *pool, const unsigned char *in, uint32 inlen, | |||
67 | int32 res; | 67 | int32 res; |
68 | uint32 x; | 68 | uint32 x; |
69 | 69 | ||
70 | if (in == NULL || out == NULL || outlen == NULL || key == NULL) { | 70 | //bbox |
71 | psTraceCrypto("NULL parameter error in psRsaCrypt\n"); | 71 | // if (in == NULL || out == NULL || outlen == NULL || key == NULL) { |
72 | return PS_ARG_FAIL; | 72 | // psTraceCrypto("NULL parameter error in psRsaCrypt\n"); |
73 | } | 73 | // return PS_ARG_FAIL; |
74 | // } | ||
74 | 75 | ||
75 | tmp.dp = tmpa.dp = tmpb.dp = NULL; | 76 | tmp.dp = tmpa.dp = tmpb.dp = NULL; |
76 | 77 | ||
@@ -187,7 +188,8 @@ int32 psRsaEncryptPub(psPool_t *pool, psRsaKey_t *key, | |||
187 | 188 | ||
188 | size = key->size; | 189 | size = key->size; |
189 | if (outlen < size) { | 190 | if (outlen < size) { |
190 | psTraceCrypto("Error on bad outlen parameter to psRsaEncryptPub: outlen:%d < size:%d", outlen, size); | 191 | //bbox psTraceCrypto("Error on bad outlen parameter to psRsaEncryptPub\n"); |
192 | bb_error_msg_and_die("RSA crypt outlen:%d < size:%d", outlen, size); | ||
191 | return PS_ARG_FAIL; | 193 | return PS_ARG_FAIL; |
192 | } | 194 | } |
193 | 195 | ||
diff --git a/networking/tls_rsa.h b/networking/tls_rsa.h index 93f469e83..c464ed552 100644 --- a/networking/tls_rsa.h +++ b/networking/tls_rsa.h | |||
@@ -10,11 +10,11 @@ typedef struct { | |||
10 | pstm_int e, d, N, qP, dP, dQ, p, q; | 10 | pstm_int e, d, N, qP, dP, dQ, p, q; |
11 | uint32 size; /* Size of the key in bytes */ | 11 | uint32 size; /* Size of the key in bytes */ |
12 | int32 optimized; /* 1 for optimized */ | 12 | int32 optimized; /* 1 for optimized */ |
13 | psPool_t *pool; | 13 | //bbox psPool_t *pool; |
14 | } psRsaKey_t; | 14 | } psRsaKey_t; |
15 | 15 | ||
16 | #define psRsaEncryptPub(pool, key, in, inlen, out, outlen, data) \ | 16 | #define psRsaEncryptPub(pool, key, in, inlen, out, outlen, data) \ |
17 | psRsaEncryptPub(pool, key, in, inlen, out, outlen) | 17 | psRsaEncryptPub( key, in, inlen, out, outlen) |
18 | int32 psRsaEncryptPub(psPool_t *pool, psRsaKey_t *key, | 18 | int32 psRsaEncryptPub(psPool_t *pool, psRsaKey_t *key, |
19 | unsigned char *in, uint32 inlen, | 19 | unsigned char *in, uint32 inlen, |
20 | unsigned char *out, uint32 outlen, void *data); | 20 | unsigned char *out, uint32 outlen, void *data); |
diff --git a/networking/tls_symmetric.h b/networking/tls_symmetric.h index 712ee600c..b6b55c78c 100644 --- a/networking/tls_symmetric.h +++ b/networking/tls_symmetric.h | |||
@@ -6,7 +6,7 @@ | |||
6 | 6 | ||
7 | 7 | ||
8 | /* The part below is a section of matrixssl-3-7-2b-open/crypto/cryptolib.h | 8 | /* The part below is a section of matrixssl-3-7-2b-open/crypto/cryptolib.h |
9 | * Changes are flagged with ///bbox | 9 | * Changes are flagged with //bbox |
10 | * TODO: | 10 | * TODO: |
11 | * Take a look at "roll %%cl" part... rotates by constant use fewer registers, | 11 | * Take a look at "roll %%cl" part... rotates by constant use fewer registers, |
12 | * and on many Intel CPUs rotates by %cl are slower: they take 2 cycles, not 1. | 12 | * and on many Intel CPUs rotates by %cl are slower: they take 2 cycles, not 1. |
@@ -299,7 +299,7 @@ x = (((uint64)((y)[0] & 255))<<56)|(((uint64)((y)[1] & 255))<<48)| \ | |||
299 | 299 | ||
300 | 300 | ||
301 | /* The part below is taken almost verbatim from matrixssl-3-7-2b-open/crypto/symmetric/. | 301 | /* The part below is taken almost verbatim from matrixssl-3-7-2b-open/crypto/symmetric/. |
302 | * Changes are flagged with ///bbox | 302 | * Changes are flagged with //bbox |
303 | */ | 303 | */ |
304 | 304 | ||
305 | /** | 305 | /** |