|
|
285d04 |
diff --git a/lib/freebl/config.mk b/lib/freebl/config.mk
|
|
|
285d04 |
--- a/lib/freebl/config.mk
|
|
|
285d04 |
+++ b/lib/freebl/config.mk
|
|
|
285d04 |
@@ -85,9 +85,13 @@ EXTRA_SHARED_LIBS += \
|
|
|
285d04 |
$(NULL)
|
|
|
285d04 |
endif
|
|
|
285d04 |
endif
|
|
|
285d04 |
|
|
|
285d04 |
ifeq ($(OS_ARCH), Darwin)
|
|
|
285d04 |
EXTRA_SHARED_LIBS += -dylib_file @executable_path/libplc4.dylib:$(DIST)/lib/libplc4.dylib -dylib_file @executable_path/libplds4.dylib:$(DIST)/lib/libplds4.dylib
|
|
|
285d04 |
endif
|
|
|
285d04 |
|
|
|
285d04 |
+ifdef NSS_FIPS_140_3
|
|
|
285d04 |
+DEFINES += -DNSS_FIPS_140_3
|
|
|
285d04 |
endif
|
|
|
285d04 |
+
|
|
|
285d04 |
+endif
|
|
|
285d04 |
diff --git a/lib/freebl/unix_urandom.c b/lib/freebl/unix_urandom.c
|
|
|
285d04 |
--- a/lib/freebl/unix_urandom.c
|
|
|
285d04 |
+++ b/lib/freebl/unix_urandom.c
|
|
|
285d04 |
@@ -20,53 +20,110 @@ RNG_SystemInfoForRNG(void)
|
|
|
285d04 |
if (!numBytes) {
|
|
|
285d04 |
/* error is set */
|
|
|
285d04 |
return;
|
|
|
285d04 |
}
|
|
|
285d04 |
RNG_RandomUpdate(bytes, numBytes);
|
|
|
285d04 |
PORT_Memset(bytes, 0, sizeof bytes);
|
|
|
285d04 |
}
|
|
|
285d04 |
|
|
|
285d04 |
+#ifdef NSS_FIPS_140_3
|
|
|
285d04 |
+#include <sys/random.h>
|
|
|
285d04 |
+#include "prinit.h"
|
|
|
285d04 |
+
|
|
|
285d04 |
+static int rng_grndFlags= 0;
|
|
|
285d04 |
+static PRCallOnceType rng_KernelFips;
|
|
|
285d04 |
+
|
|
|
285d04 |
+static PRStatus
|
|
|
285d04 |
+rng_getKernelFips()
|
|
|
285d04 |
+{
|
|
|
285d04 |
+#ifdef LINUX
|
|
|
285d04 |
+ FILE *f;
|
|
|
285d04 |
+ char d;
|
|
|
285d04 |
+ size_t size;
|
|
|
285d04 |
+
|
|
|
285d04 |
+ f = fopen("/proc/sys/crypto/fips_enabled", "r");
|
|
|
285d04 |
+ if (!f)
|
|
|
285d04 |
+ return PR_FAILURE;
|
|
|
285d04 |
+
|
|
|
285d04 |
+ size = fread(&d, 1, 1, f);
|
|
|
285d04 |
+ fclose(f);
|
|
|
285d04 |
+ if (size != 1)
|
|
|
285d04 |
+ return PR_SUCCESS;
|
|
|
285d04 |
+ if (d != '1')
|
|
|
285d04 |
+ return PR_SUCCESS;
|
|
|
285d04 |
+ /* if the kernel is in FIPS mode, set the GRND_RANDOM flag */
|
|
|
285d04 |
+ rng_grndFlags = GRND_RANDOM;
|
|
|
285d04 |
+#endif /* LINUX */
|
|
|
285d04 |
+ return PR_SUCCESS;
|
|
|
285d04 |
+}
|
|
|
285d04 |
+#endif
|
|
|
285d04 |
+
|
|
|
285d04 |
size_t
|
|
|
285d04 |
RNG_SystemRNG(void *dest, size_t maxLen)
|
|
|
285d04 |
{
|
|
|
285d04 |
+ size_t fileBytes = 0;
|
|
|
285d04 |
+ unsigned char *buffer = dest;
|
|
|
285d04 |
+#ifndef NSS_FIPS_140_3
|
|
|
285d04 |
int fd;
|
|
|
285d04 |
int bytes;
|
|
|
285d04 |
- size_t fileBytes = 0;
|
|
|
285d04 |
- unsigned char *buffer = dest;
|
|
|
285d04 |
+#else
|
|
|
285d04 |
+ PR_CallOnce(&rng_KernelFips, rng_getKernelFips);
|
|
|
285d04 |
+#endif
|
|
|
285d04 |
|
|
|
285d04 |
#if defined(__OpenBSD__) || (defined(__FreeBSD__) && __FreeBSD_version >= 1200000) || (defined(LINUX) && defined(__GLIBC__) && ((__GLIBC__ > 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 25))))
|
|
|
285d04 |
int result;
|
|
|
285d04 |
-
|
|
|
285d04 |
while (fileBytes < maxLen) {
|
|
|
285d04 |
size_t getBytes = maxLen - fileBytes;
|
|
|
285d04 |
if (getBytes > GETENTROPY_MAX_BYTES) {
|
|
|
285d04 |
getBytes = GETENTROPY_MAX_BYTES;
|
|
|
285d04 |
}
|
|
|
285d04 |
+#ifdef NSS_FIPS_140_3
|
|
|
285d04 |
+ /* FIP 140-3 requires full kernel reseeding for chained entropy sources
|
|
|
285d04 |
+ * so we need to use getrandom with GRND_RANDOM.
|
|
|
285d04 |
+ * getrandom returns -1 on failure, otherwise returns
|
|
|
285d04 |
+ * the number of bytes, which can be less than getBytes */
|
|
|
285d04 |
+ result = getrandom(buffer, getBytes, rng_grndFlags);
|
|
|
285d04 |
+ if (result < 0) {
|
|
|
285d04 |
+ break;
|
|
|
285d04 |
+ }
|
|
|
285d04 |
+ fileBytes += result;
|
|
|
285d04 |
+ buffer += result;
|
|
|
285d04 |
+#else
|
|
|
285d04 |
+ /* get entropy returns 0 on success and always return
|
|
|
285d04 |
+ * getBytes on success */
|
|
|
285d04 |
result = getentropy(buffer, getBytes);
|
|
|
285d04 |
if (result == 0) { /* success */
|
|
|
285d04 |
fileBytes += getBytes;
|
|
|
285d04 |
buffer += getBytes;
|
|
|
285d04 |
} else {
|
|
|
285d04 |
break;
|
|
|
285d04 |
}
|
|
|
285d04 |
+#endif
|
|
|
285d04 |
}
|
|
|
285d04 |
if (fileBytes == maxLen) { /* success */
|
|
|
285d04 |
return maxLen;
|
|
|
285d04 |
}
|
|
|
285d04 |
+#ifdef NSS_FIPS_140_3
|
|
|
285d04 |
+ /* in FIPS 104-3 we don't fallback, just fail */
|
|
|
285d04 |
+ PORT_SetError(SEC_ERROR_NEED_RANDOM);
|
|
|
285d04 |
+ return 0;
|
|
|
285d04 |
+#else
|
|
|
285d04 |
/* If we failed with an error other than ENOSYS, it means the destination
|
|
|
285d04 |
* buffer is not writeable. We don't need to try writing to it again. */
|
|
|
285d04 |
if (errno != ENOSYS) {
|
|
|
285d04 |
PORT_SetError(SEC_ERROR_NEED_RANDOM);
|
|
|
285d04 |
return 0;
|
|
|
285d04 |
}
|
|
|
285d04 |
+#endif /*!NSS_FIPS_140_3 */
|
|
|
285d04 |
+#endif /* platorm has getentropy */
|
|
|
285d04 |
+#ifndef NSS_FIPS_140_3
|
|
|
285d04 |
/* ENOSYS means the kernel doesn't support getentropy()/getrandom().
|
|
|
285d04 |
* Reset the number of bytes to get and fall back to /dev/urandom. */
|
|
|
285d04 |
fileBytes = 0;
|
|
|
285d04 |
-#endif
|
|
|
285d04 |
fd = open("/dev/urandom", O_RDONLY);
|
|
|
285d04 |
if (fd < 0) {
|
|
|
285d04 |
PORT_SetError(SEC_ERROR_NEED_RANDOM);
|
|
|
285d04 |
return 0;
|
|
|
285d04 |
}
|
|
|
285d04 |
while (fileBytes < maxLen) {
|
|
|
285d04 |
bytes = read(fd, buffer, maxLen - fileBytes);
|
|
|
285d04 |
if (bytes <= 0) {
|
|
|
285d04 |
@@ -76,9 +133,10 @@ RNG_SystemRNG(void *dest, size_t maxLen)
|
|
|
285d04 |
buffer += bytes;
|
|
|
285d04 |
}
|
|
|
285d04 |
(void)close(fd);
|
|
|
285d04 |
if (fileBytes != maxLen) {
|
|
|
285d04 |
PORT_SetError(SEC_ERROR_NEED_RANDOM);
|
|
|
285d04 |
return 0;
|
|
|
285d04 |
}
|
|
|
285d04 |
return fileBytes;
|
|
|
285d04 |
+#endif
|
|
|
285d04 |
}
|
|
|
285d04 |
diff --git a/lib/softoken/config.mk b/lib/softoken/config.mk
|
|
|
285d04 |
--- a/lib/softoken/config.mk
|
|
|
285d04 |
+++ b/lib/softoken/config.mk
|
|
|
285d04 |
@@ -58,8 +58,12 @@ endif
|
|
|
285d04 |
ifdef NSS_ENABLE_FIPS_INDICATORS
|
|
|
285d04 |
DEFINES += -DNSS_ENABLE_FIPS_INDICATORS
|
|
|
285d04 |
endif
|
|
|
285d04 |
|
|
|
285d04 |
ifdef NSS_FIPS_MODULE_ID
|
|
|
285d04 |
DEFINES += -DNSS_FIPS_MODULE_ID=\"${NSS_FIPS_MODULE_ID}\"
|
|
|
285d04 |
endif
|
|
|
285d04 |
|
|
|
285d04 |
+ifdef NSS_FIPS_140_3
|
|
|
285d04 |
+DEFINES += -DNSS_FIPS_140_3
|
|
|
285d04 |
+endif
|
|
|
285d04 |
+
|
|
|
285d04 |
diff --git a/lib/softoken/fips_algorithms.h b/lib/softoken/fips_algorithms.h
|
|
|
285d04 |
--- a/lib/softoken/fips_algorithms.h
|
|
|
285d04 |
+++ b/lib/softoken/fips_algorithms.h
|
|
|
285d04 |
@@ -49,33 +49,46 @@ SFTKFIPSAlgorithmList sftk_fips_mechs[]
|
|
|
285d04 |
#define CKF_KEK (CKF_WRAP | CKF_UNWRAP)
|
|
|
285d04 |
#define CKF_KEA CKF_DERIVE
|
|
|
285d04 |
#define CKF_KDF CKF_DERIVE
|
|
|
285d04 |
#define CKF_HSH CKF_DIGEST
|
|
|
285d04 |
#define CK_MAX 0xffffffffUL
|
|
|
285d04 |
/* mechanisms using the same key types share the same key type
|
|
|
285d04 |
* limits */
|
|
|
285d04 |
#define RSA_FB_KEY 2048, 4096 /* min, max */
|
|
|
285d04 |
-#define RSA_FB_STEP 1024
|
|
|
285d04 |
+#define RSA_FB_STEP 1
|
|
|
285d04 |
+#define RSA_LEGACY_FB_KEY 1024, 1792 /* min, max */
|
|
|
285d04 |
+#define RSA_LEGACY_FB_STEP 256
|
|
|
285d04 |
+
|
|
|
285d04 |
#define DSA_FB_KEY 2048, 4096 /* min, max */
|
|
|
285d04 |
#define DSA_FB_STEP 1024
|
|
|
285d04 |
#define DH_FB_KEY 2048, 4096 /* min, max */
|
|
|
285d04 |
#define DH_FB_STEP 1024
|
|
|
285d04 |
#define EC_FB_KEY 256, 521 /* min, max */
|
|
|
285d04 |
#define EC_FB_STEP 1 /* key limits handled by special operation */
|
|
|
285d04 |
#define AES_FB_KEY 128, 256
|
|
|
285d04 |
#define AES_FB_STEP 64
|
|
|
285d04 |
{ CKM_RSA_PKCS_KEY_PAIR_GEN, { RSA_FB_KEY, CKF_KPG }, RSA_FB_STEP, SFTKFIPSNone },
|
|
|
285d04 |
{ CKM_RSA_PKCS_PSS, { RSA_FB_KEY, CKF_SGN }, RSA_FB_STEP, SFTKFIPSNone },
|
|
|
285d04 |
{ CKM_RSA_PKCS_OAEP, { RSA_FB_KEY, CKF_ENC }, RSA_FB_STEP, SFTKFIPSNone },
|
|
|
285d04 |
+ { CKM_RSA_PKCS_PSS, { RSA_LEGACY_FB_KEY, CKF_VERIFY }, RSA_LEGACY_FB_STEP, SFTKFIPSNone },
|
|
|
285d04 |
+
|
|
|
285d04 |
/* -------------- RSA Multipart Signing Operations -------------------- */
|
|
|
285d04 |
{ CKM_SHA224_RSA_PKCS, { RSA_FB_KEY, CKF_SGN }, RSA_FB_STEP, SFTKFIPSNone },
|
|
|
285d04 |
{ CKM_SHA256_RSA_PKCS, { RSA_FB_KEY, CKF_SGN }, RSA_FB_STEP, SFTKFIPSNone },
|
|
|
285d04 |
{ CKM_SHA384_RSA_PKCS, { RSA_FB_KEY, CKF_SGN }, RSA_FB_STEP, SFTKFIPSNone },
|
|
|
285d04 |
{ CKM_SHA512_RSA_PKCS, { RSA_FB_KEY, CKF_SGN }, RSA_FB_STEP, SFTKFIPSNone },
|
|
|
285d04 |
+ { CKM_SHA224_RSA_PKCS, { RSA_LEGACY_FB_KEY, CKF_VERIFY }, RSA_LEGACY_FB_STEP, SFTKFIPSNone },
|
|
|
285d04 |
+ { CKM_SHA256_RSA_PKCS, { RSA_LEGACY_FB_KEY, CKF_VERIFY }, RSA_LEGACY_FB_STEP, SFTKFIPSNone },
|
|
|
285d04 |
+ { CKM_SHA384_RSA_PKCS, { RSA_LEGACY_FB_KEY, CKF_VERIFY }, RSA_LEGACY_FB_STEP, SFTKFIPSNone },
|
|
|
285d04 |
+ { CKM_SHA512_RSA_PKCS, { RSA_LEGACY_FB_KEY, CKF_VERIFY }, RSA_LEGACY_FB_STEP, SFTKFIPSNone },
|
|
|
285d04 |
+ { CKM_SHA224_RSA_PKCS_PSS, { RSA_LEGACY_FB_KEY, CKF_VERIFY }, RSA_LEGACY_FB_STEP, SFTKFIPSNone },
|
|
|
285d04 |
+ { CKM_SHA256_RSA_PKCS_PSS, { RSA_LEGACY_FB_KEY, CKF_VERIFY }, RSA_LEGACY_FB_STEP, SFTKFIPSNone },
|
|
|
285d04 |
+ { CKM_SHA384_RSA_PKCS_PSS, { RSA_LEGACY_FB_KEY, CKF_VERIFY }, RSA_LEGACY_FB_STEP, SFTKFIPSNone },
|
|
|
285d04 |
+ { CKM_SHA512_RSA_PKCS_PSS, { RSA_LEGACY_FB_KEY, CKF_VERIFY }, RSA_LEGACY_FB_STEP, SFTKFIPSNone },
|
|
|
285d04 |
{ CKM_SHA224_RSA_PKCS_PSS, { RSA_FB_KEY, CKF_SGN }, RSA_FB_STEP, SFTKFIPSNone },
|
|
|
285d04 |
{ CKM_SHA256_RSA_PKCS_PSS, { RSA_FB_KEY, CKF_SGN }, RSA_FB_STEP, SFTKFIPSNone },
|
|
|
285d04 |
{ CKM_SHA384_RSA_PKCS_PSS, { RSA_FB_KEY, CKF_SGN }, RSA_FB_STEP, SFTKFIPSNone },
|
|
|
285d04 |
{ CKM_SHA512_RSA_PKCS_PSS, { RSA_FB_KEY, CKF_SGN }, RSA_FB_STEP, SFTKFIPSNone },
|
|
|
285d04 |
/* ------------------------- DSA Operations --------------------------- */
|
|
|
285d04 |
{ CKM_DSA_KEY_PAIR_GEN, { DSA_FB_KEY, CKF_KPG }, DSA_FB_STEP, SFTKFIPSNone },
|
|
|
285d04 |
{ CKM_DSA, { DSA_FB_KEY, CKF_SGN }, DSA_FB_STEP, SFTKFIPSNone },
|
|
|
285d04 |
{ CKM_DSA_PARAMETER_GEN, { DSA_FB_KEY, CKF_KPG }, DSA_FB_STEP, SFTKFIPSNone },
|
|
|
285d04 |
@@ -95,76 +108,73 @@ SFTKFIPSAlgorithmList sftk_fips_mechs[]
|
|
|
285d04 |
{ CKM_ECDSA_SHA256, { EC_FB_KEY, CKF_SGN }, EC_FB_STEP, SFTKFIPSECC },
|
|
|
285d04 |
{ CKM_ECDSA_SHA384, { EC_FB_KEY, CKF_SGN }, EC_FB_STEP, SFTKFIPSECC },
|
|
|
285d04 |
{ CKM_ECDSA_SHA512, { EC_FB_KEY, CKF_SGN }, EC_FB_STEP, SFTKFIPSECC },
|
|
|
285d04 |
/* ------------------------- RC2 Operations --------------------------- */
|
|
|
285d04 |
/* ------------------------- AES Operations --------------------------- */
|
|
|
285d04 |
{ CKM_AES_KEY_GEN, { AES_FB_KEY, CKF_GEN }, AES_FB_STEP, SFTKFIPSNone },
|
|
|
285d04 |
{ CKM_AES_ECB, { AES_FB_KEY, CKF_ENC }, AES_FB_STEP, SFTKFIPSNone },
|
|
|
285d04 |
{ CKM_AES_CBC, { AES_FB_KEY, CKF_ENC }, AES_FB_STEP, SFTKFIPSNone },
|
|
|
285d04 |
- { CKM_AES_MAC, { AES_FB_KEY, CKF_SGN }, AES_FB_STEP, SFTKFIPSNone },
|
|
|
285d04 |
- { CKM_AES_MAC_GENERAL, { AES_FB_KEY, CKF_SGN }, AES_FB_STEP, SFTKFIPSNone },
|
|
|
285d04 |
{ CKM_AES_CMAC, { AES_FB_KEY, CKF_SGN }, AES_FB_STEP, SFTKFIPSNone },
|
|
|
285d04 |
{ CKM_AES_CMAC_GENERAL, { AES_FB_KEY, CKF_SGN }, AES_FB_STEP, SFTKFIPSNone },
|
|
|
285d04 |
{ CKM_AES_CBC_PAD, { AES_FB_KEY, CKF_ENC }, AES_FB_STEP, SFTKFIPSNone },
|
|
|
285d04 |
{ CKM_AES_CTS, { AES_FB_KEY, CKF_ENC }, AES_FB_STEP, SFTKFIPSNone },
|
|
|
285d04 |
{ CKM_AES_CTR, { AES_FB_KEY, CKF_ENC }, AES_FB_STEP, SFTKFIPSNone },
|
|
|
285d04 |
{ CKM_AES_GCM, { AES_FB_KEY, CKF_ENC }, AES_FB_STEP, SFTKFIPSAEAD },
|
|
|
285d04 |
{ CKM_AES_KEY_WRAP, { AES_FB_KEY, CKF_ENC }, AES_FB_STEP, SFTKFIPSNone },
|
|
|
285d04 |
{ CKM_AES_KEY_WRAP_PAD, { AES_FB_KEY, CKF_ENC }, AES_FB_STEP, SFTKFIPSNone },
|
|
|
285d04 |
{ CKM_AES_KEY_WRAP_KWP, { AES_FB_KEY, CKF_ENC }, AES_FB_STEP, SFTKFIPSNone },
|
|
|
285d04 |
- { CKM_AES_XCBC_MAC_96, { 96, 96, CKF_SGN }, 1, SFTKFIPSNone },
|
|
|
285d04 |
- { CKM_AES_XCBC_MAC, { 128, 128, CKF_SGN }, 1, SFTKFIPSNone },
|
|
|
285d04 |
/* ------------------------- Hashing Operations ----------------------- */
|
|
|
285d04 |
{ CKM_SHA224, { 0, 0, CKF_HSH }, 1, SFTKFIPSNone },
|
|
|
285d04 |
{ CKM_SHA224_HMAC, { 112, 224, CKF_SGN }, 1, SFTKFIPSNone },
|
|
|
285d04 |
{ CKM_SHA224_HMAC_GENERAL, { 112, 224, CKF_SGN }, 1, SFTKFIPSNone },
|
|
|
285d04 |
{ CKM_SHA256, { 0, 0, CKF_HSH }, 1, SFTKFIPSNone },
|
|
|
285d04 |
- { CKM_SHA256_HMAC, { 128, 256, CKF_SGN }, 1, SFTKFIPSNone },
|
|
|
285d04 |
- { CKM_SHA256_HMAC_GENERAL, { 128, 256, CKF_SGN }, 1, SFTKFIPSNone },
|
|
|
285d04 |
+ { CKM_SHA256_HMAC, { 112, 256, CKF_SGN }, 1, SFTKFIPSNone },
|
|
|
285d04 |
+ { CKM_SHA256_HMAC_GENERAL, { 112, 256, CKF_SGN }, 1, SFTKFIPSNone },
|
|
|
285d04 |
{ CKM_SHA384, { 0, 0, CKF_HSH }, 1, SFTKFIPSNone },
|
|
|
285d04 |
- { CKM_SHA384_HMAC, { 192, 384, CKF_SGN }, 1, SFTKFIPSNone },
|
|
|
285d04 |
- { CKM_SHA384_HMAC_GENERAL, { 192, 384, CKF_SGN }, 1, SFTKFIPSNone },
|
|
|
285d04 |
+ { CKM_SHA384_HMAC, { 112, 384, CKF_SGN }, 1, SFTKFIPSNone },
|
|
|
285d04 |
+ { CKM_SHA384_HMAC_GENERAL, { 112, 384, CKF_SGN }, 1, SFTKFIPSNone },
|
|
|
285d04 |
{ CKM_SHA512, { 0, 0, CKF_HSH }, 1, SFTKFIPSNone },
|
|
|
285d04 |
- { CKM_SHA512_HMAC, { 256, 512, CKF_SGN }, 1, SFTKFIPSNone },
|
|
|
285d04 |
- { CKM_SHA512_HMAC_GENERAL, { 256, 512, CKF_SGN }, 1, SFTKFIPSNone },
|
|
|
285d04 |
+ { CKM_SHA512_HMAC, { 112, 512, CKF_SGN }, 1, SFTKFIPSNone },
|
|
|
285d04 |
+ { CKM_SHA512_HMAC_GENERAL, { 112, 512, CKF_SGN }, 1, SFTKFIPSNone },
|
|
|
285d04 |
/* --------------------- Secret Key Operations ------------------------ */
|
|
|
285d04 |
- { CKM_GENERIC_SECRET_KEY_GEN, { 8, 256, CKF_GEN }, 1, SFTKFIPSNone },
|
|
|
285d04 |
+ { CKM_GENERIC_SECRET_KEY_GEN, { 112, 256, CKF_GEN }, 1, SFTKFIPSNone },
|
|
|
285d04 |
/* ---------------------- SSL/TLS operations ------------------------- */
|
|
|
285d04 |
{ CKM_SHA224_KEY_DERIVATION, { 112, 224, CKF_KDF }, 1, SFTKFIPSNone },
|
|
|
285d04 |
- { CKM_SHA256_KEY_DERIVATION, { 128, 256, CKF_KDF }, 1, SFTKFIPSNone },
|
|
|
285d04 |
- { CKM_SHA384_KEY_DERIVATION, { 192, 284, CKF_KDF }, 1, SFTKFIPSNone },
|
|
|
285d04 |
- { CKM_SHA512_KEY_DERIVATION, { 256, 512, CKF_KDF }, 1, SFTKFIPSNone },
|
|
|
285d04 |
+ { CKM_SHA256_KEY_DERIVATION, { 112, 256, CKF_KDF }, 1, SFTKFIPSNone },
|
|
|
285d04 |
+ { CKM_SHA384_KEY_DERIVATION, { 112, 284, CKF_KDF }, 1, SFTKFIPSNone },
|
|
|
285d04 |
+ { CKM_SHA512_KEY_DERIVATION, { 112, 512, CKF_KDF }, 1, SFTKFIPSNone },
|
|
|
285d04 |
+ { CKM_SSL3_PRE_MASTER_KEY_GEN, { 384, 384, CKF_GEN }, 1, SFTKFIPSNone },
|
|
|
285d04 |
{ CKM_TLS12_MASTER_KEY_DERIVE, { 384, 384, CKF_KDF }, 1, SFTKFIPSNone },
|
|
|
285d04 |
{ CKM_TLS12_MASTER_KEY_DERIVE_DH, { DH_FB_KEY, CKF_KDF }, 1, SFTKFIPSNone },
|
|
|
285d04 |
{ CKM_TLS12_KEY_AND_MAC_DERIVE, { 384, 384, CKF_KDF }, 1, SFTKFIPSNone },
|
|
|
285d04 |
- { CKM_TLS_PRF_GENERAL, { 8, 512, CKF_SGN }, 1, SFTKFIPSNone },
|
|
|
285d04 |
- { CKM_TLS_MAC, { 8, 512, CKF_SGN }, 1, SFTKFIPSNone },
|
|
|
285d04 |
+ { CKM_TLS_PRF_GENERAL, { 112, 512, CKF_SGN }, 1, SFTKFIPSNone },
|
|
|
285d04 |
+ { CKM_TLS_MAC, { 112, 512, CKF_SGN }, 1, SFTKFIPSNone },
|
|
|
285d04 |
/* sigh, is this algorithm really tested. ssl doesn't seem to have a
|
|
|
285d04 |
* way of turning the extension off */
|
|
|
285d04 |
{ CKM_NSS_TLS_EXTENDED_MASTER_KEY_DERIVE, { 192, 1024, CKF_KDF }, 1, SFTKFIPSNone },
|
|
|
285d04 |
{ CKM_NSS_TLS_EXTENDED_MASTER_KEY_DERIVE_DH, { 192, 1024, CKF_DERIVE }, 1, SFTKFIPSNone },
|
|
|
285d04 |
|
|
|
285d04 |
/* ------------------------- HKDF Operations -------------------------- */
|
|
|
285d04 |
- { CKM_HKDF_DERIVE, { 8, 255 * 64 * 8, CKF_KDF }, 1, SFTKFIPSNone },
|
|
|
285d04 |
- { CKM_HKDF_DATA, { 8, 255 * 64 * 8, CKF_KDF }, 1, SFTKFIPSNone },
|
|
|
285d04 |
+ { CKM_HKDF_DERIVE, { 112, 255 * 64 * 8, CKF_KDF }, 1, SFTKFIPSNone },
|
|
|
285d04 |
+ { CKM_HKDF_DATA, { 112, 255 * 64 * 8, CKF_KDF }, 1, SFTKFIPSNone },
|
|
|
285d04 |
{ CKM_HKDF_KEY_GEN, { 160, 224, CKF_GEN }, 1, SFTKFIPSNone },
|
|
|
285d04 |
{ CKM_HKDF_KEY_GEN, { 256, 512, CKF_GEN }, 128, SFTKFIPSNone },
|
|
|
285d04 |
/* ------------------ NIST 800-108 Key Derivations ------------------- */
|
|
|
285d04 |
- { CKM_SP800_108_COUNTER_KDF, { 0, CK_MAX, CKF_KDF }, 1, SFTKFIPSNone },
|
|
|
285d04 |
- { CKM_SP800_108_FEEDBACK_KDF, { 0, CK_MAX, CKF_KDF }, 1, SFTKFIPSNone },
|
|
|
285d04 |
- { CKM_SP800_108_DOUBLE_PIPELINE_KDF, { 0, CK_MAX, CKF_KDF }, 1, SFTKFIPSNone },
|
|
|
285d04 |
- { CKM_NSS_SP800_108_COUNTER_KDF_DERIVE_DATA, { 0, CK_MAX, CKF_KDF }, 1, SFTKFIPSNone },
|
|
|
285d04 |
- { CKM_NSS_SP800_108_FEEDBACK_KDF_DERIVE_DATA, { 0, CK_MAX, CKF_KDF }, 1, SFTKFIPSNone },
|
|
|
285d04 |
- { CKM_NSS_SP800_108_DOUBLE_PIPELINE_KDF_DERIVE_DATA, { 0, CK_MAX, CKF_KDF }, 1, SFTKFIPSNone },
|
|
|
285d04 |
+ { CKM_SP800_108_COUNTER_KDF, { 112, CK_MAX, CKF_KDF }, 1, SFTKFIPSNone },
|
|
|
285d04 |
+ { CKM_SP800_108_FEEDBACK_KDF, { 112, CK_MAX, CKF_KDF }, 1, SFTKFIPSNone },
|
|
|
285d04 |
+ { CKM_SP800_108_DOUBLE_PIPELINE_KDF, { 112, CK_MAX, CKF_KDF }, 1, SFTKFIPSNone },
|
|
|
285d04 |
+ { CKM_NSS_SP800_108_COUNTER_KDF_DERIVE_DATA, { 112, CK_MAX, CKF_KDF }, 1, SFTKFIPSNone },
|
|
|
285d04 |
+ { CKM_NSS_SP800_108_FEEDBACK_KDF_DERIVE_DATA, { 112, CK_MAX, CKF_KDF }, 1, SFTKFIPSNone },
|
|
|
285d04 |
+ { CKM_NSS_SP800_108_DOUBLE_PIPELINE_KDF_DERIVE_DATA, { 112, CK_MAX, CKF_KDF }, 1, SFTKFIPSNone },
|
|
|
285d04 |
/* --------------------IPSEC ----------------------- */
|
|
|
285d04 |
- { CKM_NSS_IKE_PRF_PLUS_DERIVE, { 8, 255 * 64, CKF_KDF }, 1, SFTKFIPSNone },
|
|
|
285d04 |
- { CKM_NSS_IKE_PRF_DERIVE, { 8, 64, CKF_KDF }, 1, SFTKFIPSNone },
|
|
|
285d04 |
- { CKM_NSS_IKE1_PRF_DERIVE, { 8, 64, CKF_KDF }, 1, SFTKFIPSNone },
|
|
|
285d04 |
- { CKM_NSS_IKE1_APP_B_PRF_DERIVE, { 8, 255 * 64, CKF_KDF }, 1, SFTKFIPSNone },
|
|
|
285d04 |
+ { CKM_NSS_IKE_PRF_PLUS_DERIVE, { 112, 255 * 64, CKF_KDF }, 1, SFTKFIPSNone },
|
|
|
285d04 |
+ { CKM_NSS_IKE_PRF_DERIVE, { 112, 64, CKF_KDF }, 1, SFTKFIPSNone },
|
|
|
285d04 |
+ { CKM_NSS_IKE1_PRF_DERIVE, { 112, 64, CKF_KDF }, 1, SFTKFIPSNone },
|
|
|
285d04 |
+ { CKM_NSS_IKE1_APP_B_PRF_DERIVE, { 112, 255 * 64, CKF_KDF }, 1, SFTKFIPSNone },
|
|
|
285d04 |
/* ------------------ PBE Key Derivations ------------------- */
|
|
|
285d04 |
- { CKM_PKCS5_PBKD2, { 1, 256, CKF_GEN }, 1, SFTKFIPSNone },
|
|
|
285d04 |
+ { CKM_PKCS5_PBKD2, { 112, 256, CKF_GEN }, 1, SFTKFIPSNone },
|
|
|
285d04 |
{ CKM_NSS_PKCS12_PBE_SHA224_HMAC_KEY_GEN, { 224, 224, CKF_GEN }, 1, SFTKFIPSNone },
|
|
|
285d04 |
{ CKM_NSS_PKCS12_PBE_SHA256_HMAC_KEY_GEN, { 256, 256, CKF_GEN }, 1, SFTKFIPSNone },
|
|
|
285d04 |
{ CKM_NSS_PKCS12_PBE_SHA384_HMAC_KEY_GEN, { 384, 384, CKF_GEN }, 1, SFTKFIPSNone },
|
|
|
285d04 |
{ CKM_NSS_PKCS12_PBE_SHA512_HMAC_KEY_GEN, { 512, 512, CKF_GEN }, 1, SFTKFIPSNone }
|
|
|
285d04 |
};
|
|
|
285d04 |
const int SFTK_NUMBER_FIPS_ALGORITHMS = PR_ARRAY_SIZE(sftk_fips_mechs);
|
|
|
285d04 |
diff --git a/lib/softoken/lowpbe.c b/lib/softoken/lowpbe.c
|
|
|
285d04 |
--- a/lib/softoken/lowpbe.c
|
|
|
285d04 |
+++ b/lib/softoken/lowpbe.c
|
|
|
285d04 |
@@ -1765,27 +1765,29 @@ SECStatus
|
|
|
285d04 |
sftk_fips_pbkdf_PowerUpSelfTests(void)
|
|
|
285d04 |
{
|
|
|
285d04 |
SECItem *result;
|
|
|
285d04 |
SECItem inKey;
|
|
|
285d04 |
NSSPKCS5PBEParameter pbe_params;
|
|
|
285d04 |
unsigned char iteration_count = 5;
|
|
|
285d04 |
unsigned char keyLen = 64;
|
|
|
285d04 |
char *inKeyData = TEST_KEY;
|
|
|
285d04 |
- static const unsigned char saltData[] =
|
|
|
285d04 |
- { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
|
|
|
285d04 |
+ static const unsigned char saltData[] = {
|
|
|
285d04 |
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
|
|
285d04 |
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
|
|
|
285d04 |
+ };
|
|
|
285d04 |
static const unsigned char pbkdf_known_answer[] = {
|
|
|
285d04 |
- 0x31, 0xf0, 0xe5, 0x39, 0x9f, 0x39, 0xb9, 0x29,
|
|
|
285d04 |
- 0x68, 0xac, 0xf2, 0xe9, 0x53, 0x9b, 0xb4, 0x9c,
|
|
|
285d04 |
- 0x28, 0x59, 0x8b, 0x5c, 0xd8, 0xd4, 0x02, 0x37,
|
|
|
285d04 |
- 0x18, 0x22, 0xc1, 0x92, 0xd0, 0xfa, 0x72, 0x90,
|
|
|
285d04 |
- 0x2c, 0x8d, 0x19, 0xd4, 0x56, 0xfb, 0x16, 0xfa,
|
|
|
285d04 |
- 0x8d, 0x5c, 0x06, 0x33, 0xd1, 0x5f, 0x17, 0xb1,
|
|
|
285d04 |
- 0x22, 0xd9, 0x9c, 0xaf, 0x5e, 0x3f, 0xf3, 0x66,
|
|
|
285d04 |
- 0xc6, 0x14, 0xfe, 0x83, 0xfa, 0x1a, 0x2a, 0xc5
|
|
|
285d04 |
+ 0x73, 0x8c, 0xfa, 0x02, 0xe8, 0xdb, 0x43, 0xe4,
|
|
|
285d04 |
+ 0x99, 0xc5, 0xfd, 0xd9, 0x4d, 0x8e, 0x3e, 0x7b,
|
|
|
285d04 |
+ 0xc4, 0xda, 0x22, 0x1b, 0xe1, 0xae, 0x23, 0x7a,
|
|
|
285d04 |
+ 0x21, 0x27, 0xbd, 0xcc, 0x78, 0xc4, 0xe6, 0xc5,
|
|
|
285d04 |
+ 0x33, 0x38, 0x35, 0xe0, 0x68, 0x1a, 0x1e, 0x06,
|
|
|
285d04 |
+ 0xad, 0xaf, 0x7f, 0xd7, 0x3f, 0x0e, 0xc0, 0x90,
|
|
|
285d04 |
+ 0x17, 0x97, 0x73, 0x75, 0x7b, 0x88, 0x49, 0xd8,
|
|
|
285d04 |
+ 0x6f, 0x78, 0x5a, 0xde, 0x50, 0x20, 0x55, 0x33
|
|
|
285d04 |
};
|
|
|
285d04 |
|
|
|
285d04 |
sftk_PBELockInit();
|
|
|
285d04 |
|
|
|
285d04 |
inKey.data = (unsigned char *)inKeyData;
|
|
|
285d04 |
inKey.len = sizeof(TEST_KEY) - 1;
|
|
|
285d04 |
|
|
|
285d04 |
pbe_params.salt.data = (unsigned char *)saltData;
|
|
|
285d04 |
diff --git a/lib/softoken/pkcs11c.c b/lib/softoken/pkcs11c.c
|
|
|
285d04 |
--- a/lib/softoken/pkcs11c.c
|
|
|
285d04 |
+++ b/lib/softoken/pkcs11c.c
|
|
|
285d04 |
@@ -4609,16 +4609,17 @@ NSC_GenerateKey(CK_SESSION_HANDLE hSessi
|
|
|
285d04 |
goto loser;
|
|
|
285d04 |
}
|
|
|
285d04 |
|
|
|
285d04 |
/* make sure we don't have any class, key_type, or value fields */
|
|
|
285d04 |
sftk_DeleteAttributeType(key, CKA_CLASS);
|
|
|
285d04 |
sftk_DeleteAttributeType(key, CKA_KEY_TYPE);
|
|
|
285d04 |
sftk_DeleteAttributeType(key, CKA_VALUE);
|
|
|
285d04 |
|
|
|
285d04 |
+
|
|
|
285d04 |
/* Now Set up the parameters to generate the key (based on mechanism) */
|
|
|
285d04 |
key_gen_type = nsc_bulk; /* bulk key by default */
|
|
|
285d04 |
switch (pMechanism->mechanism) {
|
|
|
285d04 |
case CKM_CDMF_KEY_GEN:
|
|
|
285d04 |
case CKM_DES_KEY_GEN:
|
|
|
285d04 |
case CKM_DES2_KEY_GEN:
|
|
|
285d04 |
case CKM_DES3_KEY_GEN:
|
|
|
285d04 |
checkWeak = PR_TRUE;
|
|
|
285d04 |
@@ -4812,16 +4813,19 @@ NSC_GenerateKey(CK_SESSION_HANDLE hSessi
|
|
|
285d04 |
crv = sftk_handleObject(key, session);
|
|
|
285d04 |
sftk_FreeSession(session);
|
|
|
285d04 |
if (crv == CKR_OK && sftk_isTrue(key, CKA_SENSITIVE)) {
|
|
|
285d04 |
crv = sftk_forceAttribute(key, CKA_ALWAYS_SENSITIVE, &cktrue, sizeof(CK_BBOOL));
|
|
|
285d04 |
}
|
|
|
285d04 |
if (crv == CKR_OK && !sftk_isTrue(key, CKA_EXTRACTABLE)) {
|
|
|
285d04 |
crv = sftk_forceAttribute(key, CKA_NEVER_EXTRACTABLE, &cktrue, sizeof(CK_BBOOL));
|
|
|
285d04 |
}
|
|
|
285d04 |
+ /* we need to do this check at the end, so we can check the generated key length against
|
|
|
285d04 |
+ * fips requirements */
|
|
|
285d04 |
+ key->isFIPS = sftk_operationIsFIPS(slot, pMechanism, CKA_NSS_GENERATE, key);
|
|
|
285d04 |
if (crv == CKR_OK) {
|
|
|
285d04 |
*phKey = key->handle;
|
|
|
285d04 |
}
|
|
|
285d04 |
loser:
|
|
|
285d04 |
PORT_Memset(buf, 0, sizeof buf);
|
|
|
285d04 |
sftk_FreeObject(key);
|
|
|
285d04 |
return crv;
|
|
|
285d04 |
}
|
|
|
285d04 |
@@ -5780,16 +5784,19 @@ NSC_GenerateKeyPair(CK_SESSION_HANDLE hS
|
|
|
285d04 |
|
|
|
285d04 |
if (crv != CKR_OK) {
|
|
|
285d04 |
NSC_DestroyObject(hSession, publicKey->handle);
|
|
|
285d04 |
sftk_FreeObject(publicKey);
|
|
|
285d04 |
NSC_DestroyObject(hSession, privateKey->handle);
|
|
|
285d04 |
sftk_FreeObject(privateKey);
|
|
|
285d04 |
return crv;
|
|
|
285d04 |
}
|
|
|
285d04 |
+ /* we need to do this check at the end to make sure the generated key meets the key length requirements */
|
|
|
285d04 |
+ privateKey->isFIPS = sftk_operationIsFIPS(slot, pMechanism, CKA_NSS_GENERATE_KEY_PAIR, privateKey);
|
|
|
285d04 |
+ publicKey->isFIPS = privateKey->isFIPS;
|
|
|
285d04 |
|
|
|
285d04 |
*phPrivateKey = privateKey->handle;
|
|
|
285d04 |
*phPublicKey = publicKey->handle;
|
|
|
285d04 |
sftk_FreeObject(publicKey);
|
|
|
285d04 |
sftk_FreeObject(privateKey);
|
|
|
285d04 |
|
|
|
285d04 |
return CKR_OK;
|
|
|
285d04 |
}
|
|
|
285d04 |
@@ -6990,16 +6997,17 @@ sftk_HKDF(CK_HKDF_PARAMS_PTR params, CK_
|
|
|
285d04 |
}
|
|
|
285d04 |
|
|
|
285d04 |
/* HKDF-Extract(salt, base key value) */
|
|
|
285d04 |
if (params->bExtract) {
|
|
|
285d04 |
CK_BYTE *salt;
|
|
|
285d04 |
CK_ULONG saltLen;
|
|
|
285d04 |
HMACContext *hmac;
|
|
|
285d04 |
unsigned int bufLen;
|
|
|
285d04 |
+ SFTKSource saltKeySource = SFTK_SOURCE_DEFAULT;
|
|
|
285d04 |
|
|
|
285d04 |
switch (params->ulSaltType) {
|
|
|
285d04 |
case CKF_HKDF_SALT_NULL:
|
|
|
285d04 |
saltLen = hashLen;
|
|
|
285d04 |
salt = hashbuf;
|
|
|
285d04 |
memset(salt, 0, saltLen);
|
|
|
285d04 |
break;
|
|
|
285d04 |
case CKF_HKDF_SALT_DATA:
|
|
|
285d04 |
@@ -7026,29 +7034,54 @@ sftk_HKDF(CK_HKDF_PARAMS_PTR params, CK_
|
|
|
285d04 |
if (isFIPS && (key->isFIPS == 0) && (saltKey->isFIPS == 1)) {
|
|
|
285d04 |
CK_MECHANISM mech;
|
|
|
285d04 |
mech.mechanism = CKM_HKDF_DERIVE;
|
|
|
285d04 |
mech.pParameter = params;
|
|
|
285d04 |
mech.ulParameterLen = sizeof(*params);
|
|
|
285d04 |
key->isFIPS = sftk_operationIsFIPS(saltKey->slot, &mech,
|
|
|
285d04 |
CKA_DERIVE, saltKey);
|
|
|
285d04 |
}
|
|
|
285d04 |
+ saltKeySource = saltKey->source;
|
|
|
285d04 |
saltKey_att = sftk_FindAttribute(saltKey, CKA_VALUE);
|
|
|
285d04 |
if (saltKey_att == NULL) {
|
|
|
285d04 |
sftk_FreeObject(saltKey);
|
|
|
285d04 |
return CKR_KEY_HANDLE_INVALID;
|
|
|
285d04 |
}
|
|
|
285d04 |
/* save the resulting salt */
|
|
|
285d04 |
salt = saltKey_att->attrib.pValue;
|
|
|
285d04 |
saltLen = saltKey_att->attrib.ulValueLen;
|
|
|
285d04 |
break;
|
|
|
285d04 |
default:
|
|
|
285d04 |
return CKR_MECHANISM_PARAM_INVALID;
|
|
|
285d04 |
break;
|
|
|
285d04 |
}
|
|
|
285d04 |
+ /* only TLS style usage is FIPS approved,
|
|
|
285d04 |
+ * turn off the FIPS indicator for other usages */
|
|
|
285d04 |
+ if (isFIPS && key && sourceKey) {
|
|
|
285d04 |
+ PRBool fipsOK = PR_FALSE;
|
|
|
285d04 |
+ /* case one: mix the kea with a previous or default
|
|
|
285d04 |
+ * salt */
|
|
|
285d04 |
+ if ((sourceKey->source == SFTK_SOURCE_KEA) &&
|
|
|
285d04 |
+ (saltKeySource == SFTK_SOURCE_HKDF_EXPAND) &&
|
|
|
285d04 |
+ (saltLen == rawHash->length)) {
|
|
|
285d04 |
+ fipsOK = PR_TRUE;
|
|
|
285d04 |
+ }
|
|
|
285d04 |
+ /* case two: restart, remix the previous secret as a salt */
|
|
|
285d04 |
+ if ((sourceKey->objclass == CKO_DATA) &&
|
|
|
285d04 |
+ (NSS_SecureMemcmpZero(sourceKeyBytes, sourceKeyLen) == 0) &&
|
|
|
285d04 |
+ (sourceKeyLen == rawHash->length) &&
|
|
|
285d04 |
+ (saltKeySource == SFTK_SOURCE_HKDF_EXPAND) &&
|
|
|
285d04 |
+ (saltLen == rawHash->length)) {
|
|
|
285d04 |
+ fipsOK = PR_TRUE;
|
|
|
285d04 |
+ }
|
|
|
285d04 |
+ if (!fipsOK) {
|
|
|
285d04 |
+ key->isFIPS = PR_FALSE;
|
|
|
285d04 |
+ }
|
|
|
285d04 |
+ }
|
|
|
285d04 |
+ if (key) key->source = SFTK_SOURCE_HKDF_EXTRACT;
|
|
|
285d04 |
|
|
|
285d04 |
hmac = HMAC_Create(rawHash, salt, saltLen, isFIPS);
|
|
|
285d04 |
if (saltKey_att) {
|
|
|
285d04 |
sftk_FreeAttribute(saltKey_att);
|
|
|
285d04 |
}
|
|
|
285d04 |
if (saltKey) {
|
|
|
285d04 |
sftk_FreeObject(saltKey);
|
|
|
285d04 |
}
|
|
|
285d04 |
@@ -7076,16 +7109,40 @@ sftk_HKDF(CK_HKDF_PARAMS_PTR params, CK_
|
|
|
285d04 |
/* T(1) = HMAC-Hash(prk, "" | info | 0x01)
|
|
|
285d04 |
* T(n) = HMAC-Hash(prk, T(n-1) | info | n
|
|
|
285d04 |
* key material = T(1) | ... | T(n)
|
|
|
285d04 |
*/
|
|
|
285d04 |
HMACContext *hmac;
|
|
|
285d04 |
CK_BYTE bi;
|
|
|
285d04 |
unsigned iterations;
|
|
|
285d04 |
|
|
|
285d04 |
+ /* only TLS style usage is FIPS approved,
|
|
|
285d04 |
+ * turn off the FIPS indicator for other usages */
|
|
|
285d04 |
+ if (isFIPS && key && key->isFIPS && sourceKey) {
|
|
|
285d04 |
+ unsigned char *info=¶ms->pInfo[3];
|
|
|
285d04 |
+ /* only one case,
|
|
|
285d04 |
+ * 1) Expand only
|
|
|
285d04 |
+ * 2) with a key whose source was
|
|
|
285d04 |
+ * SFTK_SOURCE_HKDF_EXPAND or SFTK_SOURCE_HKDF_EXTRACT
|
|
|
285d04 |
+ * 3) source key length == rawHash->length
|
|
|
285d04 |
+ * 4) Info has tls or dtls
|
|
|
285d04 |
+ * If any of those conditions aren't met, then we turn
|
|
|
285d04 |
+ * off the fips indicator */
|
|
|
285d04 |
+ if (params->bExtract ||
|
|
|
285d04 |
+ ((sourceKey->source != SFTK_SOURCE_HKDF_EXTRACT) &&
|
|
|
285d04 |
+ (sourceKey->source != SFTK_SOURCE_HKDF_EXPAND)) ||
|
|
|
285d04 |
+ (sourceKeyLen != rawHash->length) ||
|
|
|
285d04 |
+ (params->ulInfoLen < 7) ||
|
|
|
285d04 |
+ ((PORT_Memcmp(info,"tls",3) != 0) &&
|
|
|
285d04 |
+ (PORT_Memcmp(info,"dtls",4) != 0))) {
|
|
|
285d04 |
+ key->isFIPS = PR_FALSE;
|
|
|
285d04 |
+ }
|
|
|
285d04 |
+ }
|
|
|
285d04 |
+ if (key) key->source = SFTK_SOURCE_HKDF_EXPAND;
|
|
|
285d04 |
+
|
|
|
285d04 |
genLen = PR_ROUNDUP(keySize, hashLen);
|
|
|
285d04 |
iterations = genLen / hashLen;
|
|
|
285d04 |
|
|
|
285d04 |
if (genLen > sizeof(keyBlock)) {
|
|
|
285d04 |
keyBlockAlloc = PORT_Alloc(genLen);
|
|
|
285d04 |
if (keyBlockAlloc == NULL) {
|
|
|
285d04 |
return CKR_HOST_MEMORY;
|
|
|
285d04 |
}
|
|
|
285d04 |
@@ -8434,16 +8491,17 @@ NSC_DeriveKey(CK_SESSION_HANDLE hSession
|
|
|
285d04 |
|
|
|
285d04 |
/* calculate private value - oct */
|
|
|
285d04 |
rv = DH_Derive(&dhPublic, &dhPrime, &dhValue, &derived, keySize);
|
|
|
285d04 |
|
|
|
285d04 |
SECITEM_ZfreeItem(&dhPrime, PR_FALSE);
|
|
|
285d04 |
SECITEM_ZfreeItem(&dhValue, PR_FALSE);
|
|
|
285d04 |
|
|
|
285d04 |
if (rv == SECSuccess) {
|
|
|
285d04 |
+ key->source = SFTK_SOURCE_KEA;
|
|
|
285d04 |
sftk_forceAttribute(key, CKA_VALUE, derived.data, derived.len);
|
|
|
285d04 |
SECITEM_ZfreeItem(&derived, PR_FALSE);
|
|
|
285d04 |
crv = CKR_OK;
|
|
|
285d04 |
} else
|
|
|
285d04 |
crv = CKR_HOST_MEMORY;
|
|
|
285d04 |
|
|
|
285d04 |
break;
|
|
|
285d04 |
}
|
|
|
285d04 |
@@ -8564,16 +8622,17 @@ NSC_DeriveKey(CK_SESSION_HANDLE hSession
|
|
|
285d04 |
}
|
|
|
285d04 |
PORT_Memcpy(&keyData[keySize - secretlen], secret, secretlen);
|
|
|
285d04 |
secret = keyData;
|
|
|
285d04 |
} else {
|
|
|
285d04 |
secret += (secretlen - keySize);
|
|
|
285d04 |
}
|
|
|
285d04 |
secretlen = keySize;
|
|
|
285d04 |
}
|
|
|
285d04 |
+ key->source = SFTK_SOURCE_KEA;
|
|
|
285d04 |
|
|
|
285d04 |
sftk_forceAttribute(key, CKA_VALUE, secret, secretlen);
|
|
|
285d04 |
PORT_ZFree(tmp.data, tmp.len);
|
|
|
285d04 |
if (keyData) {
|
|
|
285d04 |
PORT_ZFree(keyData, keySize);
|
|
|
285d04 |
}
|
|
|
285d04 |
break;
|
|
|
285d04 |
|
|
|
285d04 |
diff --git a/lib/softoken/pkcs11i.h b/lib/softoken/pkcs11i.h
|
|
|
285d04 |
--- a/lib/softoken/pkcs11i.h
|
|
|
285d04 |
+++ b/lib/softoken/pkcs11i.h
|
|
|
285d04 |
@@ -147,16 +147,26 @@ typedef enum {
|
|
|
285d04 |
*/
|
|
|
285d04 |
typedef enum {
|
|
|
285d04 |
SFTK_DestroyFailure,
|
|
|
285d04 |
SFTK_Destroyed,
|
|
|
285d04 |
SFTK_Busy
|
|
|
285d04 |
} SFTKFreeStatus;
|
|
|
285d04 |
|
|
|
285d04 |
/*
|
|
|
285d04 |
+ * Source of various objects
|
|
|
285d04 |
+ */
|
|
|
285d04 |
+typedef enum {
|
|
|
285d04 |
+ SFTK_SOURCE_DEFAULT=0,
|
|
|
285d04 |
+ SFTK_SOURCE_KEA,
|
|
|
285d04 |
+ SFTK_SOURCE_HKDF_EXPAND,
|
|
|
285d04 |
+ SFTK_SOURCE_HKDF_EXTRACT
|
|
|
285d04 |
+} SFTKSource;
|
|
|
285d04 |
+
|
|
|
285d04 |
+/*
|
|
|
285d04 |
* attribute values of an object.
|
|
|
285d04 |
*/
|
|
|
285d04 |
struct SFTKAttributeStr {
|
|
|
285d04 |
SFTKAttribute *next;
|
|
|
285d04 |
SFTKAttribute *prev;
|
|
|
285d04 |
PRBool freeAttr;
|
|
|
285d04 |
PRBool freeData;
|
|
|
285d04 |
/*must be called handle to make sftkqueue_find work */
|
|
|
285d04 |
@@ -189,16 +199,17 @@ struct SFTKObjectStr {
|
|
|
285d04 |
CK_OBJECT_CLASS objclass;
|
|
|
285d04 |
CK_OBJECT_HANDLE handle;
|
|
|
285d04 |
int refCount;
|
|
|
285d04 |
PZLock *refLock;
|
|
|
285d04 |
SFTKSlot *slot;
|
|
|
285d04 |
void *objectInfo;
|
|
|
285d04 |
SFTKFree infoFree;
|
|
|
285d04 |
PRBool isFIPS;
|
|
|
285d04 |
+ SFTKSource source;
|
|
|
285d04 |
};
|
|
|
285d04 |
|
|
|
285d04 |
struct SFTKTokenObjectStr {
|
|
|
285d04 |
SFTKObject obj;
|
|
|
285d04 |
SECItem dbKey;
|
|
|
285d04 |
};
|
|
|
285d04 |
|
|
|
285d04 |
struct SFTKSessionObjectStr {
|
|
|
285d04 |
diff --git a/lib/softoken/pkcs11u.c b/lib/softoken/pkcs11u.c
|
|
|
285d04 |
--- a/lib/softoken/pkcs11u.c
|
|
|
285d04 |
+++ b/lib/softoken/pkcs11u.c
|
|
|
285d04 |
@@ -1090,16 +1090,17 @@ sftk_NewObject(SFTKSlot *slot)
|
|
|
285d04 |
sessObject->attrList[i].freeData = PR_FALSE;
|
|
|
285d04 |
}
|
|
|
285d04 |
sessObject->optimizeSpace = slot->optimizeSpace;
|
|
|
285d04 |
|
|
|
285d04 |
object->handle = 0;
|
|
|
285d04 |
object->next = object->prev = NULL;
|
|
|
285d04 |
object->slot = slot;
|
|
|
285d04 |
object->isFIPS = sftk_isFIPS(slot->slotID);
|
|
|
285d04 |
+ object->source = SFTK_SOURCE_DEFAULT;
|
|
|
285d04 |
|
|
|
285d04 |
object->refCount = 1;
|
|
|
285d04 |
sessObject->sessionList.next = NULL;
|
|
|
285d04 |
sessObject->sessionList.prev = NULL;
|
|
|
285d04 |
sessObject->sessionList.parent = object;
|
|
|
285d04 |
sessObject->session = NULL;
|
|
|
285d04 |
sessObject->wasDerived = PR_FALSE;
|
|
|
285d04 |
if (!hasLocks)
|
|
|
285d04 |
@@ -1674,16 +1675,17 @@ fail:
|
|
|
285d04 |
CK_RV
|
|
|
285d04 |
sftk_CopyObject(SFTKObject *destObject, SFTKObject *srcObject)
|
|
|
285d04 |
{
|
|
|
285d04 |
SFTKAttribute *attribute;
|
|
|
285d04 |
SFTKSessionObject *src_so = sftk_narrowToSessionObject(srcObject);
|
|
|
285d04 |
unsigned int i;
|
|
|
285d04 |
|
|
|
285d04 |
destObject->isFIPS = srcObject->isFIPS;
|
|
|
285d04 |
+ destObject->source = srcObject->source;
|
|
|
285d04 |
if (src_so == NULL) {
|
|
|
285d04 |
return sftk_CopyTokenObject(destObject, srcObject);
|
|
|
285d04 |
}
|
|
|
285d04 |
|
|
|
285d04 |
PZ_Lock(src_so->attributeLock);
|
|
|
285d04 |
for (i = 0; i < src_so->hashSize; i++) {
|
|
|
285d04 |
attribute = src_so->head[i];
|
|
|
285d04 |
do {
|
|
|
285d04 |
@@ -2059,16 +2061,17 @@ sftk_NewTokenObject(SFTKSlot *slot, SECI
|
|
|
285d04 |
/* every object must have a class, if we can't get it, the object
|
|
|
285d04 |
* doesn't exist */
|
|
|
285d04 |
crv = handleToClass(slot, handle, &object->objclass);
|
|
|
285d04 |
if (crv != CKR_OK) {
|
|
|
285d04 |
goto loser;
|
|
|
285d04 |
}
|
|
|
285d04 |
object->slot = slot;
|
|
|
285d04 |
object->isFIPS = sftk_isFIPS(slot->slotID);
|
|
|
285d04 |
+ object->source = SFTK_SOURCE_DEFAULT;
|
|
|
285d04 |
object->objectInfo = NULL;
|
|
|
285d04 |
object->infoFree = NULL;
|
|
|
285d04 |
if (!hasLocks) {
|
|
|
285d04 |
object->refLock = PZ_NewLock(nssILockRefLock);
|
|
|
285d04 |
}
|
|
|
285d04 |
if (object->refLock == NULL) {
|
|
|
285d04 |
goto loser;
|
|
|
285d04 |
}
|
|
|
285d04 |
@@ -2225,16 +2228,25 @@ sftk_AttributeToFlags(CK_ATTRIBUTE_TYPE
|
|
|
285d04 |
break;
|
|
|
285d04 |
case CKA_DERIVE:
|
|
|
285d04 |
flags = CKF_DERIVE;
|
|
|
285d04 |
break;
|
|
|
285d04 |
/* fake attribute to select digesting */
|
|
|
285d04 |
case CKA_DIGEST:
|
|
|
285d04 |
flags = CKF_DIGEST;
|
|
|
285d04 |
break;
|
|
|
285d04 |
+ /* fake attribute to select key gen */
|
|
|
285d04 |
+ case CKA_NSS_GENERATE:
|
|
|
285d04 |
+ flags = CKF_GENERATE;
|
|
|
285d04 |
+ break;
|
|
|
285d04 |
+ /* fake attribute to select key pair gen */
|
|
|
285d04 |
+ case CKA_NSS_GENERATE_KEY_PAIR:
|
|
|
285d04 |
+ flags = CKF_GENERATE_KEY_PAIR;
|
|
|
285d04 |
+ break;
|
|
|
285d04 |
+ /* fake attributes to to handle MESSAGE* flags */
|
|
|
285d04 |
case CKA_NSS_MESSAGE | CKA_ENCRYPT:
|
|
|
285d04 |
flags = CKF_MESSAGE_ENCRYPT;
|
|
|
285d04 |
break;
|
|
|
285d04 |
case CKA_NSS_MESSAGE | CKA_DECRYPT:
|
|
|
285d04 |
flags = CKF_MESSAGE_DECRYPT;
|
|
|
285d04 |
break;
|
|
|
285d04 |
case CKA_NSS_MESSAGE | CKA_SIGN:
|
|
|
285d04 |
flags = CKF_MESSAGE_SIGN;
|
|
|
285d04 |
@@ -2278,17 +2290,17 @@ sftk_quickGetECCCurveOid(SFTKObject *sou
|
|
|
285d04 |
}
|
|
|
285d04 |
|
|
|
285d04 |
/* This function currently only returns valid lengths for
|
|
|
285d04 |
* FIPS approved ECC curves. If we want to make this generic
|
|
|
285d04 |
* in the future, that Curve determination can be done in
|
|
|
285d04 |
* the sftk_handleSpecial. Since it's currently only used
|
|
|
285d04 |
* in FIPS indicators, it's currently only compiled with
|
|
|
285d04 |
* the FIPS indicator code */
|
|
|
285d04 |
-static int
|
|
|
285d04 |
+static CK_ULONG
|
|
|
285d04 |
sftk_getKeyLength(SFTKObject *source)
|
|
|
285d04 |
{
|
|
|
285d04 |
CK_KEY_TYPE keyType = CK_INVALID_HANDLE;
|
|
|
285d04 |
CK_ATTRIBUTE_TYPE keyAttribute;
|
|
|
285d04 |
CK_ULONG keyLength = 0;
|
|
|
285d04 |
SFTKAttribute *attribute;
|
|
|
285d04 |
CK_RV crv;
|
|
|
285d04 |
|
|
|
285d04 |
diff --git a/lib/util/pkcs11n.h b/lib/util/pkcs11n.h
|
|
|
285d04 |
--- a/lib/util/pkcs11n.h
|
|
|
285d04 |
+++ b/lib/util/pkcs11n.h
|
|
|
285d04 |
@@ -58,16 +58,18 @@
|
|
|
285d04 |
/*
|
|
|
285d04 |
* NSS-defined certificate types
|
|
|
285d04 |
*
|
|
|
285d04 |
*/
|
|
|
285d04 |
#define CKC_NSS (CKC_VENDOR_DEFINED | NSSCK_VENDOR_NSS)
|
|
|
285d04 |
|
|
|
285d04 |
/* FAKE PKCS #11 defines */
|
|
|
285d04 |
#define CKA_DIGEST 0x81000000L
|
|
|
285d04 |
+#define CKA_NSS_GENERATE 0x81000001L
|
|
|
285d04 |
+#define CKA_NSS_GENERATE_KEY_PAIR 0x81000002L
|
|
|
285d04 |
#define CKA_NSS_MESSAGE 0x82000000L
|
|
|
285d04 |
#define CKA_NSS_MESSAGE_MASK 0xff000000L
|
|
|
285d04 |
#define CKA_FLAGS_ONLY 0 /* CKA_CLASS */
|
|
|
285d04 |
|
|
|
285d04 |
/*
|
|
|
285d04 |
* NSS-defined object attributes
|
|
|
285d04 |
*
|
|
|
285d04 |
*/
|