| Index: nss/lib/freebl/ctr.c
|
| diff --git a/nss/lib/freebl/ctr.c b/nss/lib/freebl/ctr.c
|
| index 3a2f1a6b82b7818e6052e400a387ac76ec57848e..d8527602111ff746f5f41aaacf6dd8430e61ece6 100644
|
| --- a/nss/lib/freebl/ctr.c
|
| +++ b/nss/lib/freebl/ctr.c
|
| @@ -12,6 +12,11 @@
|
| #include "pkcs11t.h"
|
| #include "secerr.h"
|
|
|
| +#ifdef USE_HW_AES
|
| +#include "intel-aes.h"
|
| +#include "rijndael.h"
|
| +#endif
|
| +
|
| SECStatus
|
| CTR_InitContext(CTRContext *ctr, void *context, freeblCipherFunc cipher,
|
| const unsigned char *param, unsigned int blocksize)
|
| @@ -165,3 +170,60 @@ CTR_Update(CTRContext *ctr, unsigned char *outbuf,
|
| *outlen += inlen;
|
| return SECSuccess;
|
| }
|
| +
|
| +#if defined(USE_HW_AES) && defined(_MSC_VER)
|
| +SECStatus
|
| +CTR_Update_HW_AES(CTRContext *ctr, unsigned char *outbuf,
|
| + unsigned int *outlen, unsigned int maxout,
|
| + const unsigned char *inbuf, unsigned int inlen,
|
| + unsigned int blocksize)
|
| +{
|
| + unsigned int fullblocks;
|
| + unsigned int tmp;
|
| + SECStatus rv;
|
| +
|
| + if (maxout < inlen) {
|
| + *outlen = inlen;
|
| + PORT_SetError(SEC_ERROR_OUTPUT_LEN);
|
| + return SECFailure;
|
| + }
|
| + *outlen = 0;
|
| + if (ctr->bufPtr != blocksize) {
|
| + unsigned int needed = PR_MIN(blocksize-ctr->bufPtr, inlen);
|
| + ctr_xor(outbuf, inbuf, ctr->buffer+ctr->bufPtr, needed);
|
| + ctr->bufPtr += needed;
|
| + outbuf += needed;
|
| + inbuf += needed;
|
| + *outlen += needed;
|
| + inlen -= needed;
|
| + if (inlen == 0) {
|
| + return SECSuccess;
|
| + }
|
| + PORT_Assert(ctr->bufPtr == blocksize);
|
| + }
|
| +
|
| + intel_aes_ctr_worker(((AESContext*)(ctr->context))->Nr)(
|
| + ctr, outbuf, outlen, maxout, inbuf, inlen, blocksize);
|
| + /* XXX intel_aes_ctr_worker should set *outlen. */
|
| + PORT_Assert(*outlen == 0);
|
| + fullblocks = (inlen/blocksize)*blocksize;
|
| + *outlen += fullblocks;
|
| + outbuf += fullblocks;
|
| + inbuf += fullblocks;
|
| + inlen -= fullblocks;
|
| +
|
| + if (inlen == 0) {
|
| + return SECSuccess;
|
| + }
|
| + rv = (*ctr->cipher)(ctr->context, ctr->buffer, &tmp, blocksize,
|
| + ctr->counter, blocksize, blocksize);
|
| + ctr_GetNextCtr(ctr->counter, ctr->counterBits, blocksize);
|
| + if (rv != SECSuccess) {
|
| + return SECFailure;
|
| + }
|
| + ctr_xor(outbuf, inbuf, ctr->buffer, inlen);
|
| + ctr->bufPtr = inlen;
|
| + *outlen += inlen;
|
| + return SECSuccess;
|
| +}
|
| +#endif
|
|
|