OLD | NEW |
---|---|
1 /* This Source Code Form is subject to the terms of the Mozilla Public | 1 /* This Source Code Form is subject to the terms of the Mozilla Public |
2 * License, v. 2.0. If a copy of the MPL was not distributed with this | 2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | 4 |
5 #ifdef FREEBL_NO_DEPEND | 5 #ifdef FREEBL_NO_DEPEND |
6 #include "stubs.h" | 6 #include "stubs.h" |
7 #endif | 7 #endif |
8 #include "prtypes.h" | 8 #include "prtypes.h" |
9 #include "blapit.h" | 9 #include "blapit.h" |
10 #include "blapii.h" | 10 #include "blapii.h" |
11 #include "ctr.h" | 11 #include "ctr.h" |
12 #include "pkcs11t.h" | 12 #include "pkcs11t.h" |
13 #include "secerr.h" | 13 #include "secerr.h" |
14 | 14 |
15 #ifdef USE_HW_AES | |
16 #include "intel-aes.h" | |
17 #include "rijndael.h" | |
18 #endif | |
19 | |
15 SECStatus | 20 SECStatus |
16 CTR_InitContext(CTRContext *ctr, void *context, freeblCipherFunc cipher, | 21 CTR_InitContext(CTRContext *ctr, void *context, freeblCipherFunc cipher, |
17 const unsigned char *param, unsigned int blocksize) | 22 const unsigned char *param, unsigned int blocksize) |
18 { | 23 { |
19 const CK_AES_CTR_PARAMS *ctrParams = (const CK_AES_CTR_PARAMS *)param; | 24 const CK_AES_CTR_PARAMS *ctrParams = (const CK_AES_CTR_PARAMS *)param; |
20 | 25 |
21 if (ctrParams->ulCounterBits == 0 || | 26 if (ctrParams->ulCounterBits == 0 || |
22 ctrParams->ulCounterBits > blocksize * PR_BITS_PER_BYTE) { | 27 ctrParams->ulCounterBits > blocksize * PR_BITS_PER_BYTE) { |
23 PORT_SetError(SEC_ERROR_INVALID_ARGS); | 28 PORT_SetError(SEC_ERROR_INVALID_ARGS); |
24 return SECFailure; | 29 return SECFailure; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 ctr->counter, blocksize, blocksize); | 163 ctr->counter, blocksize, blocksize); |
159 ctr_GetNextCtr(ctr->counter, ctr->counterBits, blocksize); | 164 ctr_GetNextCtr(ctr->counter, ctr->counterBits, blocksize); |
160 if (rv != SECSuccess) { | 165 if (rv != SECSuccess) { |
161 return SECFailure; | 166 return SECFailure; |
162 } | 167 } |
163 ctr_xor(outbuf, inbuf, ctr->buffer, inlen); | 168 ctr_xor(outbuf, inbuf, ctr->buffer, inlen); |
164 ctr->bufPtr = inlen; | 169 ctr->bufPtr = inlen; |
165 *outlen += inlen; | 170 *outlen += inlen; |
166 return SECSuccess; | 171 return SECSuccess; |
167 } | 172 } |
173 | |
174 #if defined(USE_HW_AES) && defined(_MSC_VER) | |
175 SECStatus | |
176 CTR_Update_HW_AES(CTRContext *ctr, unsigned char *outbuf, | |
177 unsigned int *outlen, unsigned int maxout, | |
178 const unsigned char *inbuf, unsigned int inlen, | |
179 unsigned int blocksize) | |
Ryan Sleevi
2014/04/23 19:53:34
Alignment?
wtc
2014/04/24 01:04:10
Done. I will also align the parameters of the othe
| |
180 { | |
181 unsigned int tmp; | |
182 SECStatus rv; | |
183 | |
184 if (maxout < inlen) { | |
185 *outlen = inlen; | |
186 PORT_SetError(SEC_ERROR_OUTPUT_LEN); | |
187 return SECFailure; | |
188 } | |
189 *outlen = 0; | |
190 if (ctr->bufPtr != blocksize) { | |
191 unsigned int needed = PR_MIN(blocksize-ctr->bufPtr, inlen); | |
192 ctr_xor(outbuf, inbuf, ctr->buffer+ctr->bufPtr, needed); | |
Ryan Sleevi
2014/04/23 19:53:34
spaces here between ctr->buffer and ctr->bufPtr?
wtc
2014/04/24 01:04:10
I will fix this in the NSS upstream.
| |
193 ctr->bufPtr += needed; | |
194 outbuf += needed; | |
195 inbuf += needed; | |
196 *outlen += needed; | |
197 inlen -= needed; | |
198 if (inlen == 0) { | |
199 return SECSuccess; | |
200 } | |
201 PORT_Assert(ctr->bufPtr == blocksize); | |
202 } | |
203 | |
204 intel_aes_ctr_worker(((AESContext*)(ctr->context))->Nr)( | |
205 ctr, outbuf, outlen, maxout, inbuf, inlen, blocksize); | |
206 *outlen += inlen & (-16); | |
207 outbuf += inlen & (-16); | |
208 inbuf += inlen & (-16); | |
209 inlen &= 16 - 1; | |
Ryan Sleevi
2014/04/23 19:53:34
This style surprises me, if only because it seems
wtc
2014/04/24 01:04:10
Done. This code also assumes |blocksize| is 16. I
| |
210 | |
211 if (inlen == 0) { | |
212 return SECSuccess; | |
213 } | |
214 rv = (*ctr->cipher)(ctr->context, ctr->buffer, &tmp, blocksize, | |
Ryan Sleevi
2014/04/23 19:53:34
Should we add a PORT_Assert that tmp == blocksize?
wtc
2014/04/24 01:04:10
Done.
| |
215 ctr->counter, blocksize, blocksize); | |
216 ctr_GetNextCtr(ctr->counter, ctr->counterBits, blocksize); | |
Ryan Sleevi
2014/04/23 19:53:34
Why does this happen before the rv check?
wtc
2014/04/24 01:04:10
I don't really know. Perhaps the author wanted to
| |
217 if (rv != SECSuccess) { | |
218 return SECFailure; | |
219 } | |
220 ctr_xor(outbuf, inbuf, ctr->buffer, inlen); | |
221 ctr->bufPtr = inlen; | |
222 *outlen += inlen; | |
223 return SECSuccess; | |
224 } | |
225 #endif | |
OLD | NEW |