|
|
cae166 |
diff -up ./lib/softoken/kbkdf.c.kdf_update ./lib/softoken/kbkdf.c
|
|
|
cae166 |
--- ./lib/softoken/kbkdf.c.kdf_update 2019-11-27 16:48:01.864135431 -0800
|
|
|
cae166 |
+++ ./lib/softoken/kbkdf.c 2019-11-27 16:48:51.779661708 -0800
|
|
|
cae166 |
@@ -160,6 +160,9 @@ static CK_RV kbkdf_ValidateParameter(CK_
|
|
|
cae166 |
/* There is no additional data to validate for byte arrays; we can
|
|
|
cae166 |
* only assume the context is of the correct size. */
|
|
|
cae166 |
break;
|
|
|
cae166 |
+ default:
|
|
|
cae166 |
+ /* don't allow unknown types */
|
|
|
cae166 |
+ return CKR_MECHANISM_PARAM_INVALID;
|
|
|
cae166 |
}
|
|
|
cae166 |
|
|
|
cae166 |
return CKR_OK;
|
|
|
cae166 |
@@ -250,14 +253,16 @@ static CK_RV kbkdf_ValidateParameters(CK
|
|
|
cae166 |
return CKR_MECHANISM_PARAM_INVALID;
|
|
|
cae166 |
}
|
|
|
cae166 |
|
|
|
cae166 |
- /* Count that we have a parameter of this type. */
|
|
|
cae166 |
- param_type_count[params->pDataParams[offset].type] += 1;
|
|
|
cae166 |
-
|
|
|
cae166 |
/* Validate this parameter has acceptable values. */
|
|
|
cae166 |
ret = kbkdf_ValidateParameter(mech, params->pDataParams + offset);
|
|
|
cae166 |
if (ret != CKR_OK) {
|
|
|
cae166 |
- return CKR_MECHANISM_PARAM_INVALID;
|
|
|
cae166 |
+ return ret;
|
|
|
cae166 |
}
|
|
|
cae166 |
+ /* Count that we have a parameter of this type. */
|
|
|
cae166 |
+ /* Do this after we've validated the param to make sure we don't
|
|
|
cae166 |
+ * overflow our array */
|
|
|
cae166 |
+ PORT_Assert(params->pDataParams[offset].type < sizeof(param_type_count)/sizeof(param_type_count[0]));
|
|
|
cae166 |
+ param_type_count[params->pDataParams[offset].type] += 1;
|
|
|
cae166 |
}
|
|
|
cae166 |
|
|
|
cae166 |
if (mech == CKM_SP800_108_COUNTER_KDF || mech == CKM_NSS_SP800_108_COUNTER_KDF_DERIVE_DATA) {
|
|
|
cae166 |
@@ -306,18 +311,20 @@ static CK_RV kbkdf_ValidateParameters(CK
|
|
|
cae166 |
/* [ section: parameter helpers ] */
|
|
|
cae166 |
|
|
|
cae166 |
static void kbkdf_EncodeInteger(uint64_t integer, CK_ULONG num_bits, CK_BBOOL littleEndian, CK_BYTE_PTR output, CK_ULONG_PTR output_len) {
|
|
|
cae166 |
- uint64_t reordered;
|
|
|
cae166 |
+ CK_ULONG num_bytes = num_bits/8;
|
|
|
cae166 |
+ CK_ULONG i;
|
|
|
cae166 |
if (output_len) {
|
|
|
cae166 |
- *output_len = (num_bits / 8);
|
|
|
cae166 |
+ *output_len = num_bytes;
|
|
|
cae166 |
}
|
|
|
cae166 |
|
|
|
cae166 |
if (littleEndian == CK_TRUE) {
|
|
|
cae166 |
- reordered = htole64(integer);
|
|
|
cae166 |
- memcpy(output, &reordered, num_bits/8);
|
|
|
cae166 |
+ for (i=0; i < num_bytes; i++) {
|
|
|
cae166 |
+ output[i] = (integer >> i*8) & 0xff;
|
|
|
cae166 |
+ }
|
|
|
cae166 |
} else {
|
|
|
cae166 |
- reordered = htobe64(integer);
|
|
|
cae166 |
- reordered = reordered >> (64 - num_bits);
|
|
|
cae166 |
- memcpy(output, &reordered, (num_bits/8));
|
|
|
cae166 |
+ for (i=num_bytes; i > 0; i--) {
|
|
|
cae166 |
+ output[num_bytes-i] = (integer >> (i-1)*8) & 0xff;
|
|
|
cae166 |
+ }
|
|
|
cae166 |
}
|
|
|
cae166 |
}
|
|
|
cae166 |
|