Mercurial > trustbridge > nss-cmake-static
annotate nss/lib/freebl/rsapkcs.c @ 0:1e5118fa0cb1
This is NSS with a Cmake Buildsyste
To compile a static NSS library for Windows we've used the
Chromium-NSS fork and added a Cmake buildsystem to compile
it statically for Windows. See README.chromium for chromium
changes and README.trustbridge for our modifications.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Mon, 28 Jul 2014 10:47:06 +0200 |
parents | |
children |
rev | line source |
---|---|
0
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
4 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
5 /* |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
6 * RSA PKCS#1 v2.1 (RFC 3447) operations |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
7 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
8 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
9 #ifdef FREEBL_NO_DEPEND |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
10 #include "stubs.h" |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
11 #endif |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
12 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
13 #include "secerr.h" |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
14 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
15 #include "blapi.h" |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
16 #include "secitem.h" |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
17 #include "blapii.h" |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
18 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
19 #define RSA_BLOCK_MIN_PAD_LEN 8 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
20 #define RSA_BLOCK_FIRST_OCTET 0x00 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
21 #define RSA_BLOCK_PRIVATE_PAD_OCTET 0xff |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
22 #define RSA_BLOCK_AFTER_PAD_OCTET 0x00 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
23 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
24 /* |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
25 * RSA block types |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
26 * |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
27 * The values of RSA_BlockPrivate and RSA_BlockPublic are fixed. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
28 * The value of RSA_BlockRaw isn't fixed by definition, but we are keeping |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
29 * the value that NSS has been using in the past. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
30 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
31 typedef enum { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
32 RSA_BlockPrivate = 1, /* pad for a private-key operation */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
33 RSA_BlockPublic = 2, /* pad for a public-key operation */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
34 RSA_BlockRaw = 4 /* simply justify the block appropriately */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
35 } RSA_BlockType; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
36 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
37 /* Needed for RSA-PSS functions */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
38 static const unsigned char eightZeros[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
39 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
40 /* Constant time comparison of a single byte. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
41 * Returns 1 iff a == b, otherwise returns 0. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
42 * Note: For ranges of bytes, use constantTimeCompare. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
43 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
44 static unsigned char constantTimeEQ8(unsigned char a, unsigned char b) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
45 unsigned char c = ~((a - b) | (b - a)); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
46 c >>= 7; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
47 return c; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
48 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
49 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
50 /* Constant time comparison of a range of bytes. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
51 * Returns 1 iff len bytes of a are identical to len bytes of b, otherwise |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
52 * returns 0. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
53 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
54 static unsigned char constantTimeCompare(const unsigned char *a, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
55 const unsigned char *b, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
56 unsigned int len) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
57 unsigned char tmp = 0; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
58 unsigned int i; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
59 for (i = 0; i < len; ++i, ++a, ++b) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
60 tmp |= *a ^ *b; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
61 return constantTimeEQ8(0x00, tmp); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
62 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
63 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
64 /* Constant time conditional. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
65 * Returns a if c is 1, or b if c is 0. The result is undefined if c is |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
66 * not 0 or 1. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
67 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
68 static unsigned int constantTimeCondition(unsigned int c, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
69 unsigned int a, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
70 unsigned int b) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
71 { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
72 return (~(c - 1) & a) | ((c - 1) & b); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
73 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
74 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
75 static unsigned int |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
76 rsa_modulusLen(SECItem * modulus) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
77 { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
78 unsigned char byteZero = modulus->data[0]; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
79 unsigned int modLen = modulus->len - !byteZero; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
80 return modLen; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
81 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
82 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
83 /* |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
84 * Format one block of data for public/private key encryption using |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
85 * the rules defined in PKCS #1. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
86 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
87 static unsigned char * |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
88 rsa_FormatOneBlock(unsigned modulusLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
89 RSA_BlockType blockType, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
90 SECItem * data) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
91 { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
92 unsigned char *block; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
93 unsigned char *bp; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
94 int padLen; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
95 int i, j; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
96 SECStatus rv; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
97 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
98 block = (unsigned char *) PORT_Alloc(modulusLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
99 if (block == NULL) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
100 return NULL; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
101 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
102 bp = block; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
103 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
104 /* |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
105 * All RSA blocks start with two octets: |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
106 * 0x00 || BlockType |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
107 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
108 *bp++ = RSA_BLOCK_FIRST_OCTET; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
109 *bp++ = (unsigned char) blockType; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
110 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
111 switch (blockType) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
112 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
113 /* |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
114 * Blocks intended for private-key operation. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
115 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
116 case RSA_BlockPrivate: /* preferred method */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
117 /* |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
118 * 0x00 || BT || Pad || 0x00 || ActualData |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
119 * 1 1 padLen 1 data->len |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
120 * Pad is either all 0x00 or all 0xff bytes, depending on blockType. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
121 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
122 padLen = modulusLen - data->len - 3; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
123 PORT_Assert(padLen >= RSA_BLOCK_MIN_PAD_LEN); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
124 if (padLen < RSA_BLOCK_MIN_PAD_LEN) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
125 PORT_Free(block); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
126 return NULL; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
127 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
128 PORT_Memset(bp, RSA_BLOCK_PRIVATE_PAD_OCTET, padLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
129 bp += padLen; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
130 *bp++ = RSA_BLOCK_AFTER_PAD_OCTET; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
131 PORT_Memcpy(bp, data->data, data->len); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
132 break; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
133 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
134 /* |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
135 * Blocks intended for public-key operation. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
136 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
137 case RSA_BlockPublic: |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
138 /* |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
139 * 0x00 || BT || Pad || 0x00 || ActualData |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
140 * 1 1 padLen 1 data->len |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
141 * Pad is all non-zero random bytes. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
142 * |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
143 * Build the block left to right. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
144 * Fill the entire block from Pad to the end with random bytes. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
145 * Use the bytes after Pad as a supply of extra random bytes from |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
146 * which to find replacements for the zero bytes in Pad. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
147 * If we need more than that, refill the bytes after Pad with |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
148 * new random bytes as necessary. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
149 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
150 padLen = modulusLen - (data->len + 3); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
151 PORT_Assert(padLen >= RSA_BLOCK_MIN_PAD_LEN); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
152 if (padLen < RSA_BLOCK_MIN_PAD_LEN) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
153 PORT_Free(block); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
154 return NULL; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
155 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
156 j = modulusLen - 2; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
157 rv = RNG_GenerateGlobalRandomBytes(bp, j); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
158 if (rv == SECSuccess) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
159 for (i = 0; i < padLen; ) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
160 unsigned char repl; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
161 /* Pad with non-zero random data. */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
162 if (bp[i] != RSA_BLOCK_AFTER_PAD_OCTET) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
163 ++i; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
164 continue; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
165 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
166 if (j <= padLen) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
167 rv = RNG_GenerateGlobalRandomBytes(bp + padLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
168 modulusLen - (2 + padLen)); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
169 if (rv != SECSuccess) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
170 break; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
171 j = modulusLen - 2; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
172 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
173 do { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
174 repl = bp[--j]; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
175 } while (repl == RSA_BLOCK_AFTER_PAD_OCTET && j > padLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
176 if (repl != RSA_BLOCK_AFTER_PAD_OCTET) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
177 bp[i++] = repl; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
178 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
179 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
180 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
181 if (rv != SECSuccess) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
182 PORT_Free(block); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
183 PORT_SetError(SEC_ERROR_LIBRARY_FAILURE); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
184 return NULL; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
185 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
186 bp += padLen; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
187 *bp++ = RSA_BLOCK_AFTER_PAD_OCTET; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
188 PORT_Memcpy(bp, data->data, data->len); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
189 break; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
190 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
191 default: |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
192 PORT_Assert(0); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
193 PORT_Free(block); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
194 return NULL; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
195 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
196 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
197 return block; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
198 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
199 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
200 static SECStatus |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
201 rsa_FormatBlock(SECItem * result, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
202 unsigned modulusLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
203 RSA_BlockType blockType, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
204 SECItem * data) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
205 { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
206 switch (blockType) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
207 case RSA_BlockPrivate: |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
208 case RSA_BlockPublic: |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
209 /* |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
210 * 0x00 || BT || Pad || 0x00 || ActualData |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
211 * |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
212 * The "3" below is the first octet + the second octet + the 0x00 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
213 * octet that always comes just before the ActualData. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
214 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
215 PORT_Assert(data->len <= (modulusLen - (3 + RSA_BLOCK_MIN_PAD_LEN))); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
216 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
217 result->data = rsa_FormatOneBlock(modulusLen, blockType, data); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
218 if (result->data == NULL) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
219 result->len = 0; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
220 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
221 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
222 result->len = modulusLen; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
223 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
224 break; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
225 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
226 case RSA_BlockRaw: |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
227 /* |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
228 * Pad || ActualData |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
229 * Pad is zeros. The application is responsible for recovering |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
230 * the actual data. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
231 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
232 if (data->len > modulusLen ) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
233 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
234 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
235 result->data = (unsigned char*)PORT_ZAlloc(modulusLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
236 result->len = modulusLen; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
237 PORT_Memcpy(result->data + (modulusLen - data->len), |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
238 data->data, data->len); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
239 break; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
240 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
241 default: |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
242 PORT_Assert(0); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
243 result->data = NULL; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
244 result->len = 0; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
245 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
246 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
247 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
248 return SECSuccess; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
249 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
250 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
251 /* |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
252 * Mask generation function MGF1 as defined in PKCS #1 v2.1 / RFC 3447. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
253 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
254 static SECStatus |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
255 MGF1(HASH_HashType hashAlg, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
256 unsigned char * mask, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
257 unsigned int maskLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
258 const unsigned char * mgfSeed, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
259 unsigned int mgfSeedLen) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
260 { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
261 unsigned int digestLen; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
262 PRUint32 counter; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
263 PRUint32 rounds; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
264 unsigned char * tempHash; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
265 unsigned char * temp; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
266 const SECHashObject * hash; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
267 void * hashContext; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
268 unsigned char C[4]; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
269 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
270 hash = HASH_GetRawHashObject(hashAlg); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
271 if (hash == NULL) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
272 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
273 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
274 hashContext = (*hash->create)(); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
275 rounds = (maskLen + hash->length - 1) / hash->length; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
276 for (counter = 0; counter < rounds; counter++) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
277 C[0] = (unsigned char)((counter >> 24) & 0xff); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
278 C[1] = (unsigned char)((counter >> 16) & 0xff); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
279 C[2] = (unsigned char)((counter >> 8) & 0xff); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
280 C[3] = (unsigned char)(counter & 0xff); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
281 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
282 /* This could be optimized when the clone functions in |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
283 * rawhash.c are implemented. */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
284 (*hash->begin)(hashContext); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
285 (*hash->update)(hashContext, mgfSeed, mgfSeedLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
286 (*hash->update)(hashContext, C, sizeof C); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
287 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
288 tempHash = mask + counter * hash->length; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
289 if (counter != (rounds - 1)) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
290 (*hash->end)(hashContext, tempHash, &digestLen, hash->length); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
291 } else { /* we're in the last round and need to cut the hash */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
292 temp = (unsigned char *)PORT_Alloc(hash->length); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
293 (*hash->end)(hashContext, temp, &digestLen, hash->length); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
294 PORT_Memcpy(tempHash, temp, maskLen - counter * hash->length); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
295 PORT_Free(temp); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
296 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
297 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
298 (*hash->destroy)(hashContext, PR_TRUE); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
299 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
300 return SECSuccess; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
301 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
302 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
303 /* XXX Doesn't set error code */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
304 SECStatus |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
305 RSA_SignRaw(RSAPrivateKey * key, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
306 unsigned char * output, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
307 unsigned int * outputLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
308 unsigned int maxOutputLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
309 const unsigned char * data, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
310 unsigned int dataLen) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
311 { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
312 SECStatus rv = SECSuccess; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
313 unsigned int modulusLen = rsa_modulusLen(&key->modulus); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
314 SECItem formatted; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
315 SECItem unformatted; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
316 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
317 if (maxOutputLen < modulusLen) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
318 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
319 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
320 unformatted.len = dataLen; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
321 unformatted.data = (unsigned char*)data; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
322 formatted.data = NULL; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
323 rv = rsa_FormatBlock(&formatted, modulusLen, RSA_BlockRaw, &unformatted); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
324 if (rv != SECSuccess) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
325 goto done; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
326 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
327 rv = RSA_PrivateKeyOpDoubleChecked(key, output, formatted.data); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
328 *outputLen = modulusLen; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
329 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
330 done: |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
331 if (formatted.data != NULL) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
332 PORT_ZFree(formatted.data, modulusLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
333 return rv; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
334 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
335 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
336 /* XXX Doesn't set error code */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
337 SECStatus |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
338 RSA_CheckSignRaw(RSAPublicKey * key, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
339 const unsigned char * sig, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
340 unsigned int sigLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
341 const unsigned char * hash, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
342 unsigned int hashLen) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
343 { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
344 SECStatus rv; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
345 unsigned int modulusLen = rsa_modulusLen(&key->modulus); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
346 unsigned char * buffer; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
347 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
348 if (sigLen != modulusLen) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
349 goto failure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
350 if (hashLen > modulusLen) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
351 goto failure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
352 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
353 buffer = (unsigned char *)PORT_Alloc(modulusLen + 1); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
354 if (!buffer) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
355 goto failure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
356 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
357 rv = RSA_PublicKeyOp(key, buffer, sig); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
358 if (rv != SECSuccess) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
359 goto loser; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
360 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
361 /* |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
362 * make sure we get the same results |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
363 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
364 /* XXX(rsleevi): Constant time */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
365 /* NOTE: should we verify the leading zeros? */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
366 if (PORT_Memcmp(buffer + (modulusLen - hashLen), hash, hashLen) != 0) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
367 goto loser; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
368 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
369 PORT_Free(buffer); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
370 return SECSuccess; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
371 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
372 loser: |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
373 PORT_Free(buffer); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
374 failure: |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
375 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
376 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
377 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
378 /* XXX Doesn't set error code */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
379 SECStatus |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
380 RSA_CheckSignRecoverRaw(RSAPublicKey * key, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
381 unsigned char * data, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
382 unsigned int * dataLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
383 unsigned int maxDataLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
384 const unsigned char * sig, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
385 unsigned int sigLen) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
386 { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
387 SECStatus rv; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
388 unsigned int modulusLen = rsa_modulusLen(&key->modulus); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
389 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
390 if (sigLen != modulusLen) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
391 goto failure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
392 if (maxDataLen < modulusLen) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
393 goto failure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
394 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
395 rv = RSA_PublicKeyOp(key, data, sig); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
396 if (rv != SECSuccess) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
397 goto failure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
398 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
399 *dataLen = modulusLen; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
400 return SECSuccess; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
401 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
402 failure: |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
403 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
404 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
405 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
406 /* XXX Doesn't set error code */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
407 SECStatus |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
408 RSA_EncryptRaw(RSAPublicKey * key, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
409 unsigned char * output, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
410 unsigned int * outputLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
411 unsigned int maxOutputLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
412 const unsigned char * input, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
413 unsigned int inputLen) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
414 { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
415 SECStatus rv; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
416 unsigned int modulusLen = rsa_modulusLen(&key->modulus); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
417 SECItem formatted; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
418 SECItem unformatted; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
419 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
420 formatted.data = NULL; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
421 if (maxOutputLen < modulusLen) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
422 goto failure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
423 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
424 unformatted.len = inputLen; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
425 unformatted.data = (unsigned char*)input; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
426 formatted.data = NULL; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
427 rv = rsa_FormatBlock(&formatted, modulusLen, RSA_BlockRaw, &unformatted); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
428 if (rv != SECSuccess) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
429 goto failure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
430 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
431 rv = RSA_PublicKeyOp(key, output, formatted.data); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
432 if (rv != SECSuccess) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
433 goto failure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
434 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
435 PORT_ZFree(formatted.data, modulusLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
436 *outputLen = modulusLen; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
437 return SECSuccess; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
438 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
439 failure: |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
440 if (formatted.data != NULL) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
441 PORT_ZFree(formatted.data, modulusLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
442 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
443 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
444 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
445 /* XXX Doesn't set error code */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
446 SECStatus |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
447 RSA_DecryptRaw(RSAPrivateKey * key, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
448 unsigned char * output, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
449 unsigned int * outputLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
450 unsigned int maxOutputLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
451 const unsigned char * input, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
452 unsigned int inputLen) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
453 { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
454 SECStatus rv; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
455 unsigned int modulusLen = rsa_modulusLen(&key->modulus); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
456 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
457 if (modulusLen > maxOutputLen) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
458 goto failure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
459 if (inputLen != modulusLen) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
460 goto failure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
461 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
462 rv = RSA_PrivateKeyOp(key, output, input); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
463 if (rv != SECSuccess) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
464 goto failure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
465 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
466 *outputLen = modulusLen; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
467 return SECSuccess; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
468 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
469 failure: |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
470 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
471 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
472 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
473 /* |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
474 * Decodes an EME-OAEP encoded block, validating the encoding in constant |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
475 * time. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
476 * Described in RFC 3447, section 7.1.2. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
477 * input contains the encoded block, after decryption. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
478 * label is the optional value L that was associated with the message. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
479 * On success, the original message and message length will be stored in |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
480 * output and outputLen. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
481 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
482 static SECStatus |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
483 eme_oaep_decode(unsigned char * output, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
484 unsigned int * outputLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
485 unsigned int maxOutputLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
486 const unsigned char * input, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
487 unsigned int inputLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
488 HASH_HashType hashAlg, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
489 HASH_HashType maskHashAlg, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
490 const unsigned char * label, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
491 unsigned int labelLen) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
492 { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
493 const SECHashObject * hash; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
494 void * hashContext; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
495 SECStatus rv = SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
496 unsigned char labelHash[HASH_LENGTH_MAX]; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
497 unsigned int i; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
498 unsigned int maskLen; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
499 unsigned int paddingOffset; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
500 unsigned char * mask = NULL; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
501 unsigned char * tmpOutput = NULL; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
502 unsigned char isGood; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
503 unsigned char foundPaddingEnd; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
504 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
505 hash = HASH_GetRawHashObject(hashAlg); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
506 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
507 /* 1.c */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
508 if (inputLen < (hash->length * 2) + 2) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
509 PORT_SetError(SEC_ERROR_INPUT_LEN); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
510 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
511 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
512 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
513 /* Step 3.a - Generate lHash */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
514 hashContext = (*hash->create)(); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
515 if (hashContext == NULL) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
516 PORT_SetError(SEC_ERROR_NO_MEMORY); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
517 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
518 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
519 (*hash->begin)(hashContext); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
520 if (labelLen > 0) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
521 (*hash->update)(hashContext, label, labelLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
522 (*hash->end)(hashContext, labelHash, &i, sizeof(labelHash)); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
523 (*hash->destroy)(hashContext, PR_TRUE); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
524 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
525 tmpOutput = (unsigned char*)PORT_Alloc(inputLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
526 if (tmpOutput == NULL) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
527 PORT_SetError(SEC_ERROR_NO_MEMORY); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
528 goto done; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
529 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
530 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
531 maskLen = inputLen - hash->length - 1; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
532 mask = (unsigned char*)PORT_Alloc(maskLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
533 if (mask == NULL) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
534 PORT_SetError(SEC_ERROR_NO_MEMORY); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
535 goto done; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
536 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
537 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
538 PORT_Memcpy(tmpOutput, input, inputLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
539 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
540 /* 3.c - Generate seedMask */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
541 MGF1(maskHashAlg, mask, hash->length, &tmpOutput[1 + hash->length], |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
542 inputLen - hash->length - 1); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
543 /* 3.d - Unmask seed */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
544 for (i = 0; i < hash->length; ++i) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
545 tmpOutput[1 + i] ^= mask[i]; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
546 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
547 /* 3.e - Generate dbMask */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
548 MGF1(maskHashAlg, mask, maskLen, &tmpOutput[1], hash->length); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
549 /* 3.f - Unmask DB */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
550 for (i = 0; i < maskLen; ++i) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
551 tmpOutput[1 + hash->length + i] ^= mask[i]; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
552 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
553 /* 3.g - Compare Y, lHash, and PS in constant time |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
554 * Warning: This code is timing dependent and must not disclose which of |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
555 * these were invalid. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
556 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
557 paddingOffset = 0; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
558 isGood = 1; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
559 foundPaddingEnd = 0; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
560 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
561 /* Compare Y */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
562 isGood &= constantTimeEQ8(0x00, tmpOutput[0]); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
563 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
564 /* Compare lHash and lHash' */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
565 isGood &= constantTimeCompare(&labelHash[0], |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
566 &tmpOutput[1 + hash->length], |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
567 hash->length); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
568 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
569 /* Compare that the padding is zero or more zero octets, followed by a |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
570 * 0x01 octet */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
571 for (i = 1 + (hash->length * 2); i < inputLen; ++i) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
572 unsigned char isZero = constantTimeEQ8(0x00, tmpOutput[i]); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
573 unsigned char isOne = constantTimeEQ8(0x01, tmpOutput[i]); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
574 /* non-constant time equivalent: |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
575 * if (tmpOutput[i] == 0x01 && !foundPaddingEnd) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
576 * paddingOffset = i; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
577 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
578 paddingOffset = constantTimeCondition(isOne & ~foundPaddingEnd, i, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
579 paddingOffset); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
580 /* non-constant time equivalent: |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
581 * if (tmpOutput[i] == 0x01) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
582 * foundPaddingEnd = true; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
583 * |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
584 * Note: This may yield false positives, as it will be set whenever |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
585 * a 0x01 byte is encountered. If there was bad padding (eg: |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
586 * 0x03 0x02 0x01), foundPaddingEnd will still be set to true, and |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
587 * paddingOffset will still be set to 2. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
588 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
589 foundPaddingEnd = constantTimeCondition(isOne, 1, foundPaddingEnd); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
590 /* non-constant time equivalent: |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
591 * if (tmpOutput[i] != 0x00 && tmpOutput[i] != 0x01 && |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
592 * !foundPaddingEnd) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
593 * isGood = false; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
594 * } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
595 * |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
596 * Note: This may yield false positives, as a message (and padding) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
597 * that is entirely zeros will result in isGood still being true. Thus |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
598 * it's necessary to check foundPaddingEnd is positive below. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
599 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
600 isGood = constantTimeCondition(~foundPaddingEnd & ~isZero, 0, isGood); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
601 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
602 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
603 /* While both isGood and foundPaddingEnd may have false positives, they |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
604 * cannot BOTH have false positives. If both are not true, then an invalid |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
605 * message was received. Note, this comparison must still be done in constant |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
606 * time so as not to leak either condition. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
607 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
608 if (!(isGood & foundPaddingEnd)) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
609 PORT_SetError(SEC_ERROR_BAD_DATA); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
610 goto done; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
611 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
612 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
613 /* End timing dependent code */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
614 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
615 ++paddingOffset; /* Skip the 0x01 following the end of PS */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
616 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
617 *outputLen = inputLen - paddingOffset; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
618 if (*outputLen > maxOutputLen) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
619 PORT_SetError(SEC_ERROR_OUTPUT_LEN); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
620 goto done; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
621 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
622 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
623 if (*outputLen) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
624 PORT_Memcpy(output, &tmpOutput[paddingOffset], *outputLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
625 rv = SECSuccess; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
626 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
627 done: |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
628 if (mask) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
629 PORT_ZFree(mask, maskLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
630 if (tmpOutput) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
631 PORT_ZFree(tmpOutput, inputLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
632 return rv; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
633 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
634 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
635 /* |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
636 * Generate an EME-OAEP encoded block for encryption |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
637 * Described in RFC 3447, section 7.1.1 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
638 * We use input instead of M for the message to be encrypted |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
639 * label is the optional value L to be associated with the message. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
640 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
641 static SECStatus |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
642 eme_oaep_encode(unsigned char * em, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
643 unsigned int emLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
644 const unsigned char * input, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
645 unsigned int inputLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
646 HASH_HashType hashAlg, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
647 HASH_HashType maskHashAlg, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
648 const unsigned char * label, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
649 unsigned int labelLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
650 const unsigned char * seed, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
651 unsigned int seedLen) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
652 { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
653 const SECHashObject * hash; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
654 void * hashContext; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
655 SECStatus rv; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
656 unsigned char * mask; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
657 unsigned int reservedLen; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
658 unsigned int dbMaskLen; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
659 unsigned int i; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
660 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
661 hash = HASH_GetRawHashObject(hashAlg); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
662 PORT_Assert(seed == NULL || seedLen == hash->length); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
663 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
664 /* Step 1.b */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
665 reservedLen = (2 * hash->length) + 2; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
666 if (emLen < reservedLen || inputLen > (emLen - reservedLen)) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
667 PORT_SetError(SEC_ERROR_INPUT_LEN); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
668 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
669 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
670 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
671 /* |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
672 * From RFC 3447, Section 7.1 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
673 * +----------+---------+-------+ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
674 * DB = | lHash | PS | M | |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
675 * +----------+---------+-------+ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
676 * | |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
677 * +----------+ V |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
678 * | seed |--> MGF ---> xor |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
679 * +----------+ | |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
680 * | | |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
681 * +--+ V | |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
682 * |00| xor <----- MGF <-----| |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
683 * +--+ | | |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
684 * | | | |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
685 * V V V |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
686 * +--+----------+----------------------------+ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
687 * EM = |00|maskedSeed| maskedDB | |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
688 * +--+----------+----------------------------+ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
689 * |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
690 * We use mask to hold the result of the MGF functions, and all other |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
691 * values are generated in their final resting place. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
692 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
693 *em = 0x00; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
694 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
695 /* Step 2.a - Generate lHash */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
696 hashContext = (*hash->create)(); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
697 if (hashContext == NULL) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
698 PORT_SetError(SEC_ERROR_NO_MEMORY); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
699 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
700 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
701 (*hash->begin)(hashContext); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
702 if (labelLen > 0) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
703 (*hash->update)(hashContext, label, labelLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
704 (*hash->end)(hashContext, &em[1 + hash->length], &i, hash->length); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
705 (*hash->destroy)(hashContext, PR_TRUE); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
706 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
707 /* Step 2.b - Generate PS */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
708 if (emLen - reservedLen - inputLen > 0) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
709 PORT_Memset(em + 1 + (hash->length * 2), 0x00, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
710 emLen - reservedLen - inputLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
711 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
712 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
713 /* Step 2.c. - Generate DB |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
714 * DB = lHash || PS || 0x01 || M |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
715 * Note that PS and lHash have already been placed into em at their |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
716 * appropriate offsets. This just copies M into place |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
717 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
718 em[emLen - inputLen - 1] = 0x01; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
719 if (inputLen) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
720 PORT_Memcpy(em + emLen - inputLen, input, inputLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
721 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
722 if (seed == NULL) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
723 /* Step 2.d - Generate seed */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
724 rv = RNG_GenerateGlobalRandomBytes(em + 1, hash->length); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
725 if (rv != SECSuccess) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
726 return rv; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
727 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
728 } else { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
729 /* For Known Answer Tests, copy the supplied seed. */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
730 PORT_Memcpy(em + 1, seed, seedLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
731 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
732 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
733 /* Step 2.e - Generate dbMask*/ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
734 dbMaskLen = emLen - hash->length - 1; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
735 mask = (unsigned char*)PORT_Alloc(dbMaskLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
736 if (mask == NULL) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
737 PORT_SetError(SEC_ERROR_NO_MEMORY); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
738 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
739 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
740 MGF1(maskHashAlg, mask, dbMaskLen, em + 1, hash->length); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
741 /* Step 2.f - Compute maskedDB*/ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
742 for (i = 0; i < dbMaskLen; ++i) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
743 em[1 + hash->length + i] ^= mask[i]; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
744 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
745 /* Step 2.g - Generate seedMask */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
746 MGF1(maskHashAlg, mask, hash->length, &em[1 + hash->length], dbMaskLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
747 /* Step 2.h - Compute maskedSeed */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
748 for (i = 0; i < hash->length; ++i) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
749 em[1 + i] ^= mask[i]; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
750 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
751 PORT_ZFree(mask, dbMaskLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
752 return SECSuccess; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
753 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
754 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
755 SECStatus |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
756 RSA_EncryptOAEP(RSAPublicKey * key, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
757 HASH_HashType hashAlg, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
758 HASH_HashType maskHashAlg, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
759 const unsigned char * label, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
760 unsigned int labelLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
761 const unsigned char * seed, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
762 unsigned int seedLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
763 unsigned char * output, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
764 unsigned int * outputLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
765 unsigned int maxOutputLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
766 const unsigned char * input, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
767 unsigned int inputLen) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
768 { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
769 SECStatus rv = SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
770 unsigned int modulusLen = rsa_modulusLen(&key->modulus); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
771 unsigned char * oaepEncoded = NULL; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
772 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
773 if (maxOutputLen < modulusLen) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
774 PORT_SetError(SEC_ERROR_OUTPUT_LEN); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
775 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
776 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
777 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
778 if ((hashAlg == HASH_AlgNULL) || (maskHashAlg == HASH_AlgNULL)) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
779 PORT_SetError(SEC_ERROR_INVALID_ALGORITHM); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
780 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
781 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
782 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
783 if ((labelLen == 0 && label != NULL) || |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
784 (labelLen > 0 && label == NULL)) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
785 PORT_SetError(SEC_ERROR_INVALID_ALGORITHM); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
786 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
787 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
788 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
789 oaepEncoded = (unsigned char *)PORT_Alloc(modulusLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
790 if (oaepEncoded == NULL) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
791 PORT_SetError(SEC_ERROR_NO_MEMORY); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
792 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
793 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
794 rv = eme_oaep_encode(oaepEncoded, modulusLen, input, inputLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
795 hashAlg, maskHashAlg, label, labelLen, seed, seedLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
796 if (rv != SECSuccess) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
797 goto done; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
798 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
799 rv = RSA_PublicKeyOp(key, output, oaepEncoded); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
800 if (rv != SECSuccess) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
801 goto done; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
802 *outputLen = modulusLen; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
803 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
804 done: |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
805 PORT_Free(oaepEncoded); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
806 return rv; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
807 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
808 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
809 SECStatus |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
810 RSA_DecryptOAEP(RSAPrivateKey * key, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
811 HASH_HashType hashAlg, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
812 HASH_HashType maskHashAlg, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
813 const unsigned char * label, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
814 unsigned int labelLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
815 unsigned char * output, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
816 unsigned int * outputLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
817 unsigned int maxOutputLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
818 const unsigned char * input, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
819 unsigned int inputLen) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
820 { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
821 SECStatus rv = SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
822 unsigned int modulusLen = rsa_modulusLen(&key->modulus); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
823 unsigned char * oaepEncoded = NULL; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
824 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
825 if ((hashAlg == HASH_AlgNULL) || (maskHashAlg == HASH_AlgNULL)) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
826 PORT_SetError(SEC_ERROR_INVALID_ALGORITHM); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
827 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
828 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
829 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
830 if (inputLen != modulusLen) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
831 PORT_SetError(SEC_ERROR_INPUT_LEN); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
832 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
833 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
834 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
835 if ((labelLen == 0 && label != NULL) || |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
836 (labelLen > 0 && label == NULL)) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
837 PORT_SetError(SEC_ERROR_INVALID_ALGORITHM); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
838 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
839 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
840 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
841 oaepEncoded = (unsigned char *)PORT_Alloc(modulusLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
842 if (oaepEncoded == NULL) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
843 PORT_SetError(SEC_ERROR_NO_MEMORY); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
844 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
845 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
846 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
847 rv = RSA_PrivateKeyOpDoubleChecked(key, oaepEncoded, input); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
848 if (rv != SECSuccess) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
849 goto done; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
850 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
851 rv = eme_oaep_decode(output, outputLen, maxOutputLen, oaepEncoded, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
852 modulusLen, hashAlg, maskHashAlg, label, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
853 labelLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
854 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
855 done: |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
856 if (oaepEncoded) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
857 PORT_ZFree(oaepEncoded, modulusLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
858 return rv; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
859 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
860 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
861 /* XXX Doesn't set error code */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
862 SECStatus |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
863 RSA_EncryptBlock(RSAPublicKey * key, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
864 unsigned char * output, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
865 unsigned int * outputLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
866 unsigned int maxOutputLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
867 const unsigned char * input, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
868 unsigned int inputLen) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
869 { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
870 SECStatus rv; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
871 unsigned int modulusLen = rsa_modulusLen(&key->modulus); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
872 SECItem formatted; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
873 SECItem unformatted; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
874 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
875 formatted.data = NULL; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
876 if (maxOutputLen < modulusLen) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
877 goto failure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
878 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
879 unformatted.len = inputLen; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
880 unformatted.data = (unsigned char*)input; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
881 formatted.data = NULL; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
882 rv = rsa_FormatBlock(&formatted, modulusLen, RSA_BlockPublic, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
883 &unformatted); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
884 if (rv != SECSuccess) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
885 goto failure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
886 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
887 rv = RSA_PublicKeyOp(key, output, formatted.data); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
888 if (rv != SECSuccess) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
889 goto failure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
890 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
891 PORT_ZFree(formatted.data, modulusLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
892 *outputLen = modulusLen; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
893 return SECSuccess; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
894 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
895 failure: |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
896 if (formatted.data != NULL) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
897 PORT_ZFree(formatted.data, modulusLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
898 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
899 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
900 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
901 /* XXX Doesn't set error code */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
902 SECStatus |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
903 RSA_DecryptBlock(RSAPrivateKey * key, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
904 unsigned char * output, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
905 unsigned int * outputLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
906 unsigned int maxOutputLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
907 const unsigned char * input, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
908 unsigned int inputLen) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
909 { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
910 SECStatus rv; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
911 unsigned int modulusLen = rsa_modulusLen(&key->modulus); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
912 unsigned int i; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
913 unsigned char * buffer; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
914 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
915 if (inputLen != modulusLen) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
916 goto failure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
917 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
918 buffer = (unsigned char *)PORT_Alloc(modulusLen + 1); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
919 if (!buffer) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
920 goto failure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
921 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
922 rv = RSA_PrivateKeyOp(key, buffer, input); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
923 if (rv != SECSuccess) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
924 goto loser; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
925 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
926 /* XXX(rsleevi): Constant time */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
927 if (buffer[0] != RSA_BLOCK_FIRST_OCTET || |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
928 buffer[1] != (unsigned char)RSA_BlockPublic) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
929 goto loser; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
930 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
931 *outputLen = 0; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
932 for (i = 2; i < modulusLen; i++) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
933 if (buffer[i] == RSA_BLOCK_AFTER_PAD_OCTET) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
934 *outputLen = modulusLen - i - 1; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
935 break; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
936 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
937 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
938 if (*outputLen == 0) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
939 goto loser; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
940 if (*outputLen > maxOutputLen) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
941 goto loser; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
942 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
943 PORT_Memcpy(output, buffer + modulusLen - *outputLen, *outputLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
944 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
945 PORT_Free(buffer); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
946 return SECSuccess; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
947 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
948 loser: |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
949 PORT_Free(buffer); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
950 failure: |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
951 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
952 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
953 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
954 /* |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
955 * Encode a RSA-PSS signature. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
956 * Described in RFC 3447, section 9.1.1. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
957 * We use mHash instead of M as input. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
958 * emBits from the RFC is just modBits - 1, see section 8.1.1. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
959 * We only support MGF1 as the MGF. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
960 * |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
961 * NOTE: this code assumes modBits is a multiple of 8. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
962 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
963 static SECStatus |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
964 emsa_pss_encode(unsigned char * em, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
965 unsigned int emLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
966 const unsigned char * mHash, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
967 HASH_HashType hashAlg, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
968 HASH_HashType maskHashAlg, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
969 const unsigned char * salt, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
970 unsigned int saltLen) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
971 { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
972 const SECHashObject * hash; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
973 void * hash_context; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
974 unsigned char * dbMask; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
975 unsigned int dbMaskLen; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
976 unsigned int i; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
977 SECStatus rv; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
978 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
979 hash = HASH_GetRawHashObject(hashAlg); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
980 dbMaskLen = emLen - hash->length - 1; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
981 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
982 /* Step 3 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
983 if (emLen < hash->length + saltLen + 2) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
984 PORT_SetError(SEC_ERROR_OUTPUT_LEN); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
985 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
986 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
987 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
988 /* Step 4 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
989 if (salt == NULL) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
990 rv = RNG_GenerateGlobalRandomBytes(&em[dbMaskLen - saltLen], saltLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
991 if (rv != SECSuccess) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
992 return rv; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
993 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
994 } else { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
995 PORT_Memcpy(&em[dbMaskLen - saltLen], salt, saltLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
996 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
997 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
998 /* Step 5 + 6 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
999 /* Compute H and store it at its final location &em[dbMaskLen]. */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1000 hash_context = (*hash->create)(); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1001 if (hash_context == NULL) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1002 PORT_SetError(SEC_ERROR_NO_MEMORY); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1003 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1004 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1005 (*hash->begin)(hash_context); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1006 (*hash->update)(hash_context, eightZeros, 8); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1007 (*hash->update)(hash_context, mHash, hash->length); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1008 (*hash->update)(hash_context, &em[dbMaskLen - saltLen], saltLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1009 (*hash->end)(hash_context, &em[dbMaskLen], &i, hash->length); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1010 (*hash->destroy)(hash_context, PR_TRUE); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1011 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1012 /* Step 7 + 8 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1013 PORT_Memset(em, 0, dbMaskLen - saltLen - 1); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1014 em[dbMaskLen - saltLen - 1] = 0x01; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1015 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1016 /* Step 9 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1017 dbMask = (unsigned char *)PORT_Alloc(dbMaskLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1018 if (dbMask == NULL) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1019 PORT_SetError(SEC_ERROR_NO_MEMORY); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1020 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1021 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1022 MGF1(maskHashAlg, dbMask, dbMaskLen, &em[dbMaskLen], hash->length); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1023 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1024 /* Step 10 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1025 for (i = 0; i < dbMaskLen; i++) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1026 em[i] ^= dbMask[i]; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1027 PORT_Free(dbMask); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1028 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1029 /* Step 11 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1030 em[0] &= 0x7f; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1031 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1032 /* Step 12 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1033 em[emLen - 1] = 0xbc; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1034 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1035 return SECSuccess; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1036 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1037 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1038 /* |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1039 * Verify a RSA-PSS signature. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1040 * Described in RFC 3447, section 9.1.2. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1041 * We use mHash instead of M as input. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1042 * emBits from the RFC is just modBits - 1, see section 8.1.2. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1043 * We only support MGF1 as the MGF. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1044 * |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1045 * NOTE: this code assumes modBits is a multiple of 8. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1046 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1047 static SECStatus |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1048 emsa_pss_verify(const unsigned char * mHash, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1049 const unsigned char * em, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1050 unsigned int emLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1051 HASH_HashType hashAlg, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1052 HASH_HashType maskHashAlg, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1053 unsigned int saltLen) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1054 { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1055 const SECHashObject * hash; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1056 void * hash_context; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1057 unsigned char * db; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1058 unsigned char * H_; /* H' from the RFC */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1059 unsigned int i; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1060 unsigned int dbMaskLen; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1061 SECStatus rv; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1062 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1063 hash = HASH_GetRawHashObject(hashAlg); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1064 dbMaskLen = emLen - hash->length - 1; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1065 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1066 /* Step 3 + 4 + 6 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1067 if ((emLen < (hash->length + saltLen + 2)) || |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1068 (em[emLen - 1] != 0xbc) || |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1069 ((em[0] & 0x80) != 0)) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1070 PORT_SetError(SEC_ERROR_BAD_SIGNATURE); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1071 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1072 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1073 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1074 /* Step 7 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1075 db = (unsigned char *)PORT_Alloc(dbMaskLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1076 if (db == NULL) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1077 PORT_SetError(SEC_ERROR_NO_MEMORY); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1078 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1079 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1080 /* &em[dbMaskLen] points to H, used as mgfSeed */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1081 MGF1(maskHashAlg, db, dbMaskLen, &em[dbMaskLen], hash->length); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1082 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1083 /* Step 8 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1084 for (i = 0; i < dbMaskLen; i++) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1085 db[i] ^= em[i]; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1086 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1087 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1088 /* Step 9 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1089 db[0] &= 0x7f; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1090 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1091 /* Step 10 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1092 for (i = 0; i < (dbMaskLen - saltLen - 1); i++) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1093 if (db[i] != 0) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1094 PORT_Free(db); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1095 PORT_SetError(SEC_ERROR_BAD_SIGNATURE); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1096 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1097 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1098 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1099 if (db[dbMaskLen - saltLen - 1] != 0x01) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1100 PORT_Free(db); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1101 PORT_SetError(SEC_ERROR_BAD_SIGNATURE); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1102 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1103 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1104 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1105 /* Step 12 + 13 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1106 H_ = (unsigned char *)PORT_Alloc(hash->length); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1107 if (H_ == NULL) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1108 PORT_Free(db); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1109 PORT_SetError(SEC_ERROR_NO_MEMORY); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1110 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1111 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1112 hash_context = (*hash->create)(); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1113 if (hash_context == NULL) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1114 PORT_Free(db); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1115 PORT_Free(H_); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1116 PORT_SetError(SEC_ERROR_NO_MEMORY); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1117 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1118 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1119 (*hash->begin)(hash_context); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1120 (*hash->update)(hash_context, eightZeros, 8); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1121 (*hash->update)(hash_context, mHash, hash->length); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1122 (*hash->update)(hash_context, &db[dbMaskLen - saltLen], saltLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1123 (*hash->end)(hash_context, H_, &i, hash->length); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1124 (*hash->destroy)(hash_context, PR_TRUE); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1125 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1126 PORT_Free(db); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1127 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1128 /* Step 14 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1129 if (PORT_Memcmp(H_, &em[dbMaskLen], hash->length) != 0) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1130 PORT_SetError(SEC_ERROR_BAD_SIGNATURE); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1131 rv = SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1132 } else { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1133 rv = SECSuccess; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1134 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1135 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1136 PORT_Free(H_); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1137 return rv; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1138 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1139 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1140 SECStatus |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1141 RSA_SignPSS(RSAPrivateKey * key, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1142 HASH_HashType hashAlg, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1143 HASH_HashType maskHashAlg, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1144 const unsigned char * salt, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1145 unsigned int saltLength, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1146 unsigned char * output, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1147 unsigned int * outputLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1148 unsigned int maxOutputLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1149 const unsigned char * input, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1150 unsigned int inputLen) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1151 { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1152 SECStatus rv = SECSuccess; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1153 unsigned int modulusLen = rsa_modulusLen(&key->modulus); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1154 unsigned char *pssEncoded = NULL; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1155 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1156 if (maxOutputLen < modulusLen) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1157 PORT_SetError(SEC_ERROR_OUTPUT_LEN); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1158 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1159 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1160 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1161 if ((hashAlg == HASH_AlgNULL) || (maskHashAlg == HASH_AlgNULL)) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1162 PORT_SetError(SEC_ERROR_INVALID_ALGORITHM); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1163 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1164 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1165 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1166 pssEncoded = (unsigned char *)PORT_Alloc(modulusLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1167 if (pssEncoded == NULL) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1168 PORT_SetError(SEC_ERROR_NO_MEMORY); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1169 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1170 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1171 rv = emsa_pss_encode(pssEncoded, modulusLen, input, hashAlg, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1172 maskHashAlg, salt, saltLength); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1173 if (rv != SECSuccess) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1174 goto done; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1175 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1176 rv = RSA_PrivateKeyOpDoubleChecked(key, output, pssEncoded); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1177 *outputLen = modulusLen; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1178 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1179 done: |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1180 PORT_Free(pssEncoded); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1181 return rv; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1182 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1183 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1184 SECStatus |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1185 RSA_CheckSignPSS(RSAPublicKey * key, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1186 HASH_HashType hashAlg, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1187 HASH_HashType maskHashAlg, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1188 unsigned int saltLength, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1189 const unsigned char * sig, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1190 unsigned int sigLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1191 const unsigned char * hash, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1192 unsigned int hashLen) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1193 { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1194 SECStatus rv; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1195 unsigned int modulusLen = rsa_modulusLen(&key->modulus); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1196 unsigned char * buffer; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1197 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1198 if (sigLen != modulusLen) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1199 PORT_SetError(SEC_ERROR_BAD_SIGNATURE); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1200 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1201 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1202 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1203 if ((hashAlg == HASH_AlgNULL) || (maskHashAlg == HASH_AlgNULL)) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1204 PORT_SetError(SEC_ERROR_INVALID_ALGORITHM); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1205 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1206 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1207 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1208 buffer = (unsigned char *)PORT_Alloc(modulusLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1209 if (!buffer) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1210 PORT_SetError(SEC_ERROR_NO_MEMORY); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1211 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1212 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1213 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1214 rv = RSA_PublicKeyOp(key, buffer, sig); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1215 if (rv != SECSuccess) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1216 PORT_Free(buffer); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1217 PORT_SetError(SEC_ERROR_BAD_SIGNATURE); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1218 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1219 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1220 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1221 rv = emsa_pss_verify(hash, buffer, modulusLen, hashAlg, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1222 maskHashAlg, saltLength); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1223 PORT_Free(buffer); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1224 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1225 return rv; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1226 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1227 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1228 /* XXX Doesn't set error code */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1229 SECStatus |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1230 RSA_Sign(RSAPrivateKey * key, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1231 unsigned char * output, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1232 unsigned int * outputLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1233 unsigned int maxOutputLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1234 const unsigned char * input, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1235 unsigned int inputLen) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1236 { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1237 SECStatus rv = SECSuccess; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1238 unsigned int modulusLen = rsa_modulusLen(&key->modulus); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1239 SECItem formatted; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1240 SECItem unformatted; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1241 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1242 if (maxOutputLen < modulusLen) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1243 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1244 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1245 unformatted.len = inputLen; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1246 unformatted.data = (unsigned char*)input; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1247 formatted.data = NULL; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1248 rv = rsa_FormatBlock(&formatted, modulusLen, RSA_BlockPrivate, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1249 &unformatted); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1250 if (rv != SECSuccess) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1251 goto done; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1252 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1253 rv = RSA_PrivateKeyOpDoubleChecked(key, output, formatted.data); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1254 *outputLen = modulusLen; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1255 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1256 goto done; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1257 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1258 done: |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1259 if (formatted.data != NULL) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1260 PORT_ZFree(formatted.data, modulusLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1261 return rv; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1262 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1263 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1264 /* XXX Doesn't set error code */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1265 SECStatus |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1266 RSA_CheckSign(RSAPublicKey * key, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1267 const unsigned char * sig, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1268 unsigned int sigLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1269 const unsigned char * data, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1270 unsigned int dataLen) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1271 { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1272 SECStatus rv; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1273 unsigned int modulusLen = rsa_modulusLen(&key->modulus); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1274 unsigned int i; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1275 unsigned char * buffer; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1276 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1277 if (sigLen != modulusLen) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1278 goto failure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1279 /* |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1280 * 0x00 || BT || Pad || 0x00 || ActualData |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1281 * |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1282 * The "3" below is the first octet + the second octet + the 0x00 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1283 * octet that always comes just before the ActualData. |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1284 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1285 if (dataLen > modulusLen - (3 + RSA_BLOCK_MIN_PAD_LEN)) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1286 goto failure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1287 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1288 buffer = (unsigned char *)PORT_Alloc(modulusLen + 1); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1289 if (!buffer) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1290 goto failure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1291 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1292 rv = RSA_PublicKeyOp(key, buffer, sig); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1293 if (rv != SECSuccess) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1294 goto loser; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1295 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1296 /* |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1297 * check the padding that was used |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1298 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1299 if (buffer[0] != RSA_BLOCK_FIRST_OCTET || |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1300 buffer[1] != (unsigned char)RSA_BlockPrivate) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1301 goto loser; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1302 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1303 for (i = 2; i < modulusLen - dataLen - 1; i++) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1304 if (buffer[i] != RSA_BLOCK_PRIVATE_PAD_OCTET) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1305 goto loser; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1306 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1307 if (buffer[i] != RSA_BLOCK_AFTER_PAD_OCTET) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1308 goto loser; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1309 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1310 /* |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1311 * make sure we get the same results |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1312 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1313 if (PORT_Memcmp(buffer + modulusLen - dataLen, data, dataLen) != 0) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1314 goto loser; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1315 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1316 PORT_Free(buffer); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1317 return SECSuccess; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1318 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1319 loser: |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1320 PORT_Free(buffer); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1321 failure: |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1322 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1323 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1324 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1325 /* XXX Doesn't set error code */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1326 SECStatus |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1327 RSA_CheckSignRecover(RSAPublicKey * key, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1328 unsigned char * output, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1329 unsigned int * outputLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1330 unsigned int maxOutputLen, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1331 const unsigned char * sig, |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1332 unsigned int sigLen) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1333 { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1334 SECStatus rv; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1335 unsigned int modulusLen = rsa_modulusLen(&key->modulus); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1336 unsigned int i; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1337 unsigned char * buffer; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1338 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1339 if (sigLen != modulusLen) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1340 goto failure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1341 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1342 buffer = (unsigned char *)PORT_Alloc(modulusLen + 1); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1343 if (!buffer) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1344 goto failure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1345 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1346 rv = RSA_PublicKeyOp(key, buffer, sig); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1347 if (rv != SECSuccess) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1348 goto loser; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1349 *outputLen = 0; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1350 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1351 /* |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1352 * check the padding that was used |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1353 */ |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1354 if (buffer[0] != RSA_BLOCK_FIRST_OCTET || |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1355 buffer[1] != (unsigned char)RSA_BlockPrivate) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1356 goto loser; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1357 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1358 for (i = 2; i < modulusLen; i++) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1359 if (buffer[i] == RSA_BLOCK_AFTER_PAD_OCTET) { |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1360 *outputLen = modulusLen - i - 1; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1361 break; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1362 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1363 if (buffer[i] != RSA_BLOCK_PRIVATE_PAD_OCTET) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1364 goto loser; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1365 } |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1366 if (*outputLen == 0) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1367 goto loser; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1368 if (*outputLen > maxOutputLen) |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1369 goto loser; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1370 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1371 PORT_Memcpy(output, buffer + modulusLen - *outputLen, *outputLen); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1372 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1373 PORT_Free(buffer); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1374 return SECSuccess; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1375 |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1376 loser: |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1377 PORT_Free(buffer); |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1378 failure: |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1379 return SECFailure; |
1e5118fa0cb1
This is NSS with a Cmake Buildsyste
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1380 } |