OLD | NEW |
1 /* This Source Code Form is subject to the terms of the Mozilla Public | 1 /* This Source Code Form is subject to the terms of the Mozilla Public |
2 * License, v. 2.0. If a copy of the MPL was not distributed with this | 2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | 4 |
5 /* | 5 /* |
6 * RSA PKCS#1 v2.1 (RFC 3447) operations | 6 * RSA PKCS#1 v2.1 (RFC 3447) operations |
7 */ | 7 */ |
8 | 8 |
9 #ifdef FREEBL_NO_DEPEND | 9 #ifdef FREEBL_NO_DEPEND |
10 #include "stubs.h" | 10 #include "stubs.h" |
11 #endif | 11 #endif |
12 | 12 |
13 #include "secerr.h" | 13 #include "secerr.h" |
14 | 14 |
15 #include "blapi.h" | 15 #include "blapi.h" |
16 #include "secitem.h" | 16 #include "secitem.h" |
17 #include "blapii.h" | 17 #include "blapii.h" |
18 | 18 |
19 #define RSA_BLOCK_MIN_PAD_LEN 8 | 19 #define RSA_BLOCK_MIN_PAD_LEN 8 |
20 #define RSA_BLOCK_FIRST_OCTET 0x00 | 20 #define RSA_BLOCK_FIRST_OCTET 0x00 |
21 #define RSA_BLOCK_PRIVATE_PAD_OCTET 0xff | 21 #define RSA_BLOCK_PRIVATE_PAD_OCTET 0xff |
22 #define RSA_BLOCK_AFTER_PAD_OCTET 0x00 | 22 #define RSA_BLOCK_AFTER_PAD_OCTET 0x00 |
23 | 23 |
24 /* | 24 /* |
25 * RSA block types | 25 * RSA block types |
26 * | 26 * |
27 * The actual values are important -- they are fixed, *not* arbitrary. | 27 * The values of RSA_BlockPrivate and RSA_BlockPublic are fixed. |
28 * The explicit value assignments are not needed (because C would give | 28 * The value of RSA_BlockRaw isn't fixed by definition, but we are keeping |
29 * us those same values anyway) but are included as a reminder... | 29 * the value that NSS has been using in the past. |
30 */ | 30 */ |
31 typedef enum { | 31 typedef enum { |
32 RSA_BlockUnused = 0, /* unused */ | |
33 RSA_BlockPrivate = 1, /* pad for a private-key operation */ | 32 RSA_BlockPrivate = 1, /* pad for a private-key operation */ |
34 RSA_BlockPublic = 2, /* pad for a public-key operation */ | 33 RSA_BlockPublic = 2, /* pad for a public-key operation */ |
35 RSA_BlockRaw = 4, /* simply justify the block appropriately */ | 34 RSA_BlockRaw = 4 /* simply justify the block appropriately */ |
36 RSA_BlockTotal | |
37 } RSA_BlockType; | 35 } RSA_BlockType; |
38 | 36 |
39 /* Needed for RSA-PSS functions */ | 37 /* Needed for RSA-PSS functions */ |
40 static const unsigned char eightZeros[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; | 38 static const unsigned char eightZeros[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; |
41 | 39 |
42 /* Constant time comparison of a single byte. | 40 /* Constant time comparison of a single byte. |
43 * Returns 1 iff a == b, otherwise returns 0. | 41 * Returns 1 iff a == b, otherwise returns 0. |
44 * Note: For ranges of bytes, use constantTimeCompare. | 42 * Note: For ranges of bytes, use constantTimeCompare. |
45 */ | 43 */ |
46 static unsigned char constantTimeEQ8(unsigned char a, unsigned char b) { | 44 static unsigned char constantTimeEQ8(unsigned char a, unsigned char b) { |
(...skipping 1326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1373 PORT_Memcpy(output, buffer + modulusLen - *outputLen, *outputLen); | 1371 PORT_Memcpy(output, buffer + modulusLen - *outputLen, *outputLen); |
1374 | 1372 |
1375 PORT_Free(buffer); | 1373 PORT_Free(buffer); |
1376 return SECSuccess; | 1374 return SECSuccess; |
1377 | 1375 |
1378 loser: | 1376 loser: |
1379 PORT_Free(buffer); | 1377 PORT_Free(buffer); |
1380 failure: | 1378 failure: |
1381 return SECFailure; | 1379 return SECFailure; |
1382 } | 1380 } |
OLD | NEW |