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