/* AES_CreateContext * * create a new context for Rijndael operations */ AESContext * AES_CreateContext(const unsigned char *key, const unsigned char *iv, int mode, int encrypt, unsigned int keysize, unsigned int blocksize) { AESContext *cx = AES_AllocateContext(); if (cx) { SECStatus rv = AES_InitContext(cx, key, keysize, iv, mode, encrypt, blocksize); if (rv != SECSuccess) { AES_DestroyContext(cx, PR_TRUE); cx = NULL; } } return cx; }
SECStatus AESKeyWrap_InitContext(AESKeyWrapContext *cx, const unsigned char *key, unsigned int keylen, const unsigned char *iv, int x1, unsigned int encrypt, unsigned int x2) { SECStatus rv = SECFailure; if (!cx) { PORT_SetError(SEC_ERROR_INVALID_ARGS); return SECFailure; } if (iv) { memcpy(cx->iv, iv, sizeof cx->iv); } else { memset(cx->iv, 0xA6, sizeof cx->iv); } rv = AES_InitContext(&cx->aescx, key, keylen, NULL, NSS_AES, encrypt, AES_BLOCK_SIZE); return rv; }