diff options
author | wolfbeast <mcwerewolf@wolfbeast.com> | 2020-01-02 21:06:40 +0100 |
---|---|---|
committer | wolfbeast <mcwerewolf@wolfbeast.com> | 2020-01-02 21:06:40 +0100 |
commit | f4a12fc67689a830e9da1c87fd11afe5bc09deb3 (patch) | |
tree | 211ae0cd022a6c11b0026ecc7761a550c584583c /security/nss/lib/freebl/rijndael.c | |
parent | f7d30133221896638f7bf4f66c504255c4b14f48 (diff) | |
download | UXP-f4a12fc67689a830e9da1c87fd11afe5bc09deb3.tar UXP-f4a12fc67689a830e9da1c87fd11afe5bc09deb3.tar.gz UXP-f4a12fc67689a830e9da1c87fd11afe5bc09deb3.tar.lz UXP-f4a12fc67689a830e9da1c87fd11afe5bc09deb3.tar.xz UXP-f4a12fc67689a830e9da1c87fd11afe5bc09deb3.zip |
Issue #1338 - Part 2: Update NSS to 3.48-RTM
Diffstat (limited to 'security/nss/lib/freebl/rijndael.c')
-rw-r--r-- | security/nss/lib/freebl/rijndael.c | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/security/nss/lib/freebl/rijndael.c b/security/nss/lib/freebl/rijndael.c index 5de27de9c..fbf229aa5 100644 --- a/security/nss/lib/freebl/rijndael.c +++ b/security/nss/lib/freebl/rijndael.c @@ -20,9 +20,19 @@ #include "gcm.h" #include "mpi.h" +#if (!defined(IS_LITTLE_ENDIAN) && !defined(NSS_X86_OR_X64)) || \ + (defined(__arm__) && !defined(__ARM_NEON) && !defined(__ARM_NEON__)) +// not test yet on big endian platform of arm +#undef USE_HW_AES +#endif + #ifdef USE_HW_AES +#ifdef NSS_X86_OR_X64 #include "intel-aes.h" +#else +#include "aes-armv8.h" #endif +#endif /* USE_HW_AES */ #ifdef INTEL_GCM #include "intel-gcm.h" #endif /* INTEL_GCM */ @@ -321,7 +331,7 @@ rijndael_key_expansion7(AESContext *cx, const unsigned char *key, unsigned int N PRUint32 *W; PRUint32 *pW; PRUint32 tmp; - W = cx->expandedKey; + W = cx->k.expandedKey; /* 1. the first Nk words contain the cipher key */ memcpy(W, key, Nk * 4); i = Nk; @@ -353,7 +363,7 @@ rijndael_key_expansion(AESContext *cx, const unsigned char *key, unsigned int Nk rijndael_key_expansion7(cx, key, Nk); return; } - W = cx->expandedKey; + W = cx->k.expandedKey; /* The first Nk words contain the input cipher key */ memcpy(W, key, Nk * 4); i = Nk; @@ -430,7 +440,7 @@ rijndael_invkey_expansion(AESContext *cx, const unsigned char *key, unsigned int /* ... but has the additional step of InvMixColumn, * excepting the first and last round keys. */ - roundkeyw = cx->expandedKey + cx->Nb; + roundkeyw = cx->k.expandedKey + cx->Nb; for (r = 1; r < cx->Nr; ++r) { /* each key word, roundkeyw, represents a column in the key * matrix. Each column is multiplied by the InvMixColumn matrix. @@ -528,7 +538,7 @@ rijndael_encryptBlock128(AESContext *cx, pOut = (unsigned char *)output; } #endif - roundkeyw = cx->expandedKey; + roundkeyw = cx->k.expandedKey; /* Step 1: Add Round Key 0 to initial state */ COLUMN_0(state) = *((PRUint32 *)(pIn)) ^ *roundkeyw++; COLUMN_1(state) = *((PRUint32 *)(pIn + 4)) ^ *roundkeyw++; @@ -623,7 +633,7 @@ rijndael_decryptBlock128(AESContext *cx, pOut = (unsigned char *)output; } #endif - roundkeyw = cx->expandedKey + cx->Nb * cx->Nr + 3; + roundkeyw = cx->k.expandedKey + cx->Nb * cx->Nr + 3; /* reverse the final key addition */ COLUMN_3(state) = *((PRUint32 *)(pIn + 12)) ^ *roundkeyw--; COLUMN_2(state) = *((PRUint32 *)(pIn + 8)) ^ *roundkeyw--; @@ -847,7 +857,11 @@ aes_InitContext(AESContext *cx, const unsigned char *key, unsigned int keysize, PORT_SetError(SEC_ERROR_INVALID_ARGS); return SECFailure; } - use_hw_aes = aesni_support() && (keysize % 8) == 0; +#if defined(NSS_X86_OR_X64) || defined(USE_HW_AES) + use_hw_aes = (aesni_support() || arm_aes_support()) && (keysize % 8) == 0; +#else + use_hw_aes = PR_FALSE; +#endif /* Nb = (block size in bits) / 32 */ cx->Nb = AES_BLOCK_SIZE / 4; /* Nk = (key size in bits) / 32 */ @@ -860,7 +874,7 @@ aes_InitContext(AESContext *cx, const unsigned char *key, unsigned int keysize, #ifdef USE_HW_AES if (use_hw_aes) { cx->worker = (freeblCipherFunc) - intel_aes_cbc_worker(encrypt, keysize); + native_aes_cbc_worker(encrypt, keysize); } else #endif { @@ -872,7 +886,7 @@ aes_InitContext(AESContext *cx, const unsigned char *key, unsigned int keysize, #ifdef USE_HW_AES if (use_hw_aes) { cx->worker = (freeblCipherFunc) - intel_aes_ecb_worker(encrypt, keysize); + native_aes_ecb_worker(encrypt, keysize); } else #endif { @@ -888,7 +902,7 @@ aes_InitContext(AESContext *cx, const unsigned char *key, unsigned int keysize, } #ifdef USE_HW_AES if (use_hw_aes) { - intel_aes_init(encrypt, keysize); + native_aes_init(encrypt, keysize); } else #endif { @@ -1032,13 +1046,19 @@ AES_CreateContext(const unsigned char *key, const unsigned char *iv, void AES_DestroyContext(AESContext *cx, PRBool freeit) { + void *mem = cx->mem; if (cx->worker_cx && cx->destroy) { (*cx->destroy)(cx->worker_cx, PR_TRUE); cx->worker_cx = NULL; cx->destroy = NULL; } + PORT_Memset(cx, 0, sizeof(AESContext)); if (freeit) { - PORT_Free(cx->mem); + PORT_Free(mem); + } else { + /* if we are not freeing the context, restore mem, We may get called + * again to actually free the context */ + cx->mem = mem; } } |