Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(424)

Side by Side Diff: nss/lib/freebl/ctr.c

Issue 214183004: Implement AES in different modes of operation, using AES-NI and (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/nss.git@master
Patch Set: Remove an assertion. ctr->cipher doesn't set *outlen. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « nss/lib/freebl/ctr.h ('k') | nss/lib/freebl/intel-aes.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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)
180 {
181 unsigned int fullblocks;
182 unsigned int tmp;
183 SECStatus rv;
184
185 if (maxout < inlen) {
186 *outlen = inlen;
187 PORT_SetError(SEC_ERROR_OUTPUT_LEN);
188 return SECFailure;
189 }
190 *outlen = 0;
191 if (ctr->bufPtr != blocksize) {
192 unsigned int needed = PR_MIN(blocksize-ctr->bufPtr, inlen);
193 ctr_xor(outbuf, inbuf, ctr->buffer+ctr->bufPtr, needed);
194 ctr->bufPtr += needed;
195 outbuf += needed;
196 inbuf += needed;
197 *outlen += needed;
198 inlen -= needed;
199 if (inlen == 0) {
200 return SECSuccess;
201 }
202 PORT_Assert(ctr->bufPtr == blocksize);
203 }
204
205 intel_aes_ctr_worker(((AESContext*)(ctr->context))->Nr)(
206 ctr, outbuf, outlen, maxout, inbuf, inlen, blocksize);
207 /* XXX intel_aes_ctr_worker should set *outlen. */
208 PORT_Assert(*outlen == 0);
209 fullblocks = (inlen/blocksize)*blocksize;
210 *outlen += fullblocks;
211 outbuf += fullblocks;
212 inbuf += fullblocks;
213 inlen -= fullblocks;
214
215 if (inlen == 0) {
216 return SECSuccess;
217 }
218 rv = (*ctr->cipher)(ctr->context, ctr->buffer, &tmp, blocksize,
219 ctr->counter, blocksize, blocksize);
220 ctr_GetNextCtr(ctr->counter, ctr->counterBits, blocksize);
221 if (rv != SECSuccess) {
222 return SECFailure;
223 }
224 ctr_xor(outbuf, inbuf, ctr->buffer, inlen);
225 ctr->bufPtr = inlen;
226 *outlen += inlen;
227 return SECSuccess;
228 }
229 #endif
OLDNEW
« no previous file with comments | « nss/lib/freebl/ctr.h ('k') | nss/lib/freebl/intel-aes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698