summaryrefslogtreecommitdiffstats
path: root/security/nss/lib/freebl/intel-gcm-wrap.c
diff options
context:
space:
mode:
authorKevin Jacobs <kjacobs@mozilla.com>2019-10-24 16:47:28 +0200
committerwolfbeast <mcwerewolf@wolfbeast.com>2019-10-24 16:47:28 +0200
commitc525bb791873ecdcce59c0da4ceafc8f5f557b2f (patch)
treef35f574e4213bd9a0cfaafbc8c283d7653ac063d /security/nss/lib/freebl/intel-gcm-wrap.c
parentedfba06ce39f155f9394381d4f445a0c986bac77 (diff)
downloadUXP-c525bb791873ecdcce59c0da4ceafc8f5f557b2f.tar
UXP-c525bb791873ecdcce59c0da4ceafc8f5f557b2f.tar.gz
UXP-c525bb791873ecdcce59c0da4ceafc8f5f557b2f.tar.lz
UXP-c525bb791873ecdcce59c0da4ceafc8f5f557b2f.tar.xz
UXP-c525bb791873ecdcce59c0da4ceafc8f5f557b2f.zip
Add length checks for cryptographic primitives
This rollup patch adds additional length checks around cryptographic primitives.
Diffstat (limited to 'security/nss/lib/freebl/intel-gcm-wrap.c')
-rw-r--r--security/nss/lib/freebl/intel-gcm-wrap.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/security/nss/lib/freebl/intel-gcm-wrap.c b/security/nss/lib/freebl/intel-gcm-wrap.c
index 37a1af765..f69bc7c7a 100644
--- a/security/nss/lib/freebl/intel-gcm-wrap.c
+++ b/security/nss/lib/freebl/intel-gcm-wrap.c
@@ -62,6 +62,12 @@ intel_AES_GCM_CreateContext(void *context,
PORT_SetError(SEC_ERROR_INVALID_ARGS);
return NULL;
}
+ // Limit AADLen in accordance with SP800-38D
+ if (sizeof(AAD_whole_len) >= 8 && AAD_whole_len > (1ULL << 61) - 1) {
+ PORT_SetError(SEC_ERROR_INPUT_LEN);
+ return NULL;
+ }
+
gcm = PORT_ZNew(intel_AES_GCMContext);
if (gcm == NULL) {
return NULL;
@@ -159,6 +165,14 @@ intel_AES_GCM_EncryptUpdate(intel_AES_GCMContext *gcm,
unsigned char T[AES_BLOCK_SIZE];
unsigned int j;
+ // GCM has a 16 octet block, with a 32-bit block counter
+ // Limit in accordance with SP800-38D
+ if (sizeof(inlen) > 4 &&
+ inlen >= ((1ULL << 32) - 2) * AES_BLOCK_SIZE) {
+ PORT_SetError(SEC_ERROR_INPUT_LEN);
+ return SECFailure;
+ }
+
tagBytes = (gcm->tagBits + (PR_BITS_PER_BYTE - 1)) / PR_BITS_PER_BYTE;
if (UINT_MAX - inlen < tagBytes) {
PORT_SetError(SEC_ERROR_INPUT_LEN);
@@ -216,6 +230,14 @@ intel_AES_GCM_DecryptUpdate(intel_AES_GCMContext *gcm,
inlen -= tagBytes;
intag = inbuf + inlen;
+ // GCM has a 16 octet block, with a 32-bit block counter
+ // Limit in accordance with SP800-38D
+ if (sizeof(inlen) > 4 &&
+ inlen >= ((1ULL << 32) - 2) * AES_BLOCK_SIZE) {
+ PORT_SetError(SEC_ERROR_INPUT_LEN);
+ return SECFailure;
+ }
+
if (maxout < inlen) {
*outlen = inlen;
PORT_SetError(SEC_ERROR_OUTPUT_LEN);