/*
* PKCS #11 FIPS Power-Up Self Test.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* $Id: fipstest.c,v 1.31 2012/06/28 17:55:06 rrelyea%redhat.com Exp $ */
#ifndef NSS_FIPS_DISABLED
#ifdef FREEBL_NO_DEPEND
#include "stubs.h"
#endif
#include "blapi.h"
#include "seccomon.h" /* Required for RSA. */
#include "secerr.h"
#include "prtypes.h"
#include "secitem.h"
#include "pkcs11t.h"
#include "cmac.h"
#include "ec.h" /* Required for EC */
/*
* different platforms have different ways of calling and initial entry point
* when the dll/.so is loaded. Most platforms support either a posix pragma
* or the GCC attribute. Some platforms suppor a pre-defined name, and some
* platforms have a link line way of invoking this function.
*/
/* The pragma */
#if defined (USE_INIT_PRAGMA)
#pragma init(bl_startup_tests)
#endif
/* GCC Attribute */
#if defined (__GNUC__) && !
defined (NSS_NO_INIT_SUPPORT)
#define INIT_FUNCTION __attribute__((constructor))
#else
#define INIT_FUNCTION
#endif
static void INIT_FUNCTION bl_startup_tests(
void );
/* Windows pre-defined entry */
#if defined (XP_WIN) && !
defined (NSS_NO_INIT_SUPPORT)
#include <windows.h>
BOOL WINAPI
DllMain(
HINSTANCE hinstDLL,
// handle to DLL module
DWORD fdwReason,
// reason for calling function
LPVOID lpReserved)
// reserved
{
// Perform actions based on the reason for calling.
switch (fdwReason) {
case DLL_PROCESS_ATTACH:
// Initialize once for each new process.
// Return FALSE to fail DLL load.
bl_startup_tests();
break ;
case DLL_THREAD_ATTACH:
// Do thread-specific initialization.
break ;
case DLL_THREAD_DETACH:
// Do thread-specific cleanup.
break ;
case DLL_PROCESS_DETACH:
// Perform any necessary cleanup.
break ;
}
return TRUE ;
// Successful DLL_PROCESS_ATTACH.
}
#endif
/* insert other platform dependent init entry points here, or modify
* the linker line */
/* FIPS preprocessor directives for RC2-ECB and RC2-CBC. */
#define FIPS_RC2_KEY_LENGTH
5 /* 40-bits */
#define FIPS_RC2_ENCRYPT_LENGTH
8 /* 64-bits */
#define FIPS_RC2_DECRYPT_LENGTH
8 /* 64-bits */
/* FIPS preprocessor directives for RC4. */
#define FIPS_RC4_KEY_LENGTH
5 /* 40-bits */
#define FIPS_RC4_ENCRYPT_LENGTH
8 /* 64-bits */
#define FIPS_RC4_DECRYPT_LENGTH
8 /* 64-bits */
/* FIPS preprocessor directives for DES-ECB and DES-CBC. */
#define FIPS_DES_ENCRYPT_LENGTH
8 /* 64-bits */
#define FIPS_DES_DECRYPT_LENGTH
8 /* 64-bits */
/* FIPS preprocessor directives for DES3-CBC and DES3-ECB. */
#define FIPS_DES3_ENCRYPT_LENGTH
8 /* 64-bits */
#define FIPS_DES3_DECRYPT_LENGTH
8 /* 64-bits */
/* FIPS preprocessor directives for AES-ECB and AES-CBC. */
#define FIPS_AES_BLOCK_SIZE
16 /* 128-bits */
#define FIPS_AES_ENCRYPT_LENGTH
16 /* 128-bits */
#define FIPS_AES_DECRYPT_LENGTH
16 /* 128-bits */
#define FIPS_AES_CMAC_LENGTH
16 /* 128-bits */
#define FIPS_AES_128_KEY_SIZE
16 /* 128-bits */
#define FIPS_AES_192_KEY_SIZE
24 /* 192-bits */
#define FIPS_AES_256_KEY_SIZE
32 /* 256-bits */
/* FIPS preprocessor directives for message digests */
#define FIPS_KNOWN_HASH_MESSAGE_LENGTH
64 /* 512-bits */
/* FIPS preprocessor directives for RSA. */
#define FIPS_RSA_TYPE siBuffer
#define FIPS_RSA_PUBLIC_EXPONENT_LENGTH
3 /* 24-bits */
#define FIPS_RSA_PRIVATE_VERSION_LENGTH
1 /* 8-bits */
#define FIPS_RSA_MESSAGE_LENGTH
256 /* 2048-bits */
#define FIPS_RSA_COEFFICIENT_LENGTH
128 /* 1024-bits */
#define FIPS_RSA_PRIME0_LENGTH
128 /* 1024-bits */
#define FIPS_RSA_PRIME1_LENGTH
128 /* 1024-bits */
#define FIPS_RSA_EXPONENT0_LENGTH
128 /* 1024-bits */
#define FIPS_RSA_EXPONENT1_LENGTH
128 /* 1024-bits */
#define FIPS_RSA_PRIVATE_EXPONENT_LENGTH
256 /* 2048-bits */
#define FIPS_RSA_ENCRYPT_LENGTH
256 /* 2048-bits */
#define FIPS_RSA_DECRYPT_LENGTH
256 /* 2048-bits */
#define FIPS_RSA_SIGNATURE_LENGTH
256 /* 2048-bits */
#define FIPS_RSA_MODULUS_LENGTH
256 /* 2048-bits */
/* FIPS preprocessor directives for RNG. */
#define FIPS_RNG_XKEY_LENGTH
32 /* 256-bits */
static SECStatus
freebl_fips_DES3_PowerUpSelfTest(
void )
{
/* DES3 Known Key (56-bits). */
static const PRUint8 des3_known_key[] = {
"ANSI Triple-DES Key Data" };
/* DES3-CBC Known Initialization Vector (64-bits). */
static const PRUint8 des3_cbc_known_initialization_vector[] = {
"Security" };
/* DES3 Known Plaintext (64-bits). */
static const PRUint8 des3_ecb_known_plaintext[] = {
"Netscape" };
static const PRUint8 des3_cbc_known_plaintext[] = {
"Netscape" };
/* DES3 Known Ciphertext (64-bits). */
static const PRUint8 des3_ecb_known_ciphertext[] = {
0 x55,
0 x8e,
0 xad,
0 x3c,
0 xee,
0 x49,
0 x69,
0 xbe
};
static const PRUint8 des3_cbc_known_ciphertext[] = {
0 x43,
0 xdc,
0 x6a,
0 xc1,
0 xaf,
0 xa6,
0 x32,
0 xf5
};
/* DES3 variables. */
PRUint8 des3_computed_ciphertext[FIPS_DES3_ENCRYPT_LENGTH];
PRUint8 des3_computed_plaintext[FIPS_DES3_DECRYPT_LENGTH];
DESContext *des3_context;
unsigned int des3_bytes_encrypted;
unsigned int des3_bytes_decrypted;
SECStatus des3_status;
/*******************************************************/
/* DES3-ECB Single-Round Known Answer Encryption Test. */
/*******************************************************/
des3_context = DES_CreateContext(des3_known_key, NULL,
NSS_DES_EDE3, PR_TRUE);
if (des3_context == NULL) {
PORT_SetError(SEC_ERROR_NO_MEMORY);
return (SECFailure);
}
des3_status = DES_Encrypt(des3_context, des3_computed_ciphertext,
&des3_bytes_encrypted, FIPS_DES3_ENCRYPT_LENGTH,
des3_ecb_known_plaintext,
FIPS_DES3_DECRYPT_LENGTH);
DES_DestroyContext(des3_context, PR_TRUE);
if ((des3_status != SECSuccess) ||
(des3_bytes_encrypted != FIPS_DES3_ENCRYPT_LENGTH) ||
(PORT_Memcmp(des3_computed_ciphertext, des3_ecb_known_ciphertext,
FIPS_DES3_ENCRYPT_LENGTH) !=
0 )) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return (SECFailure);
}
/*******************************************************/
/* DES3-ECB Single-Round Known Answer Decryption Test. */
/*******************************************************/
des3_context = DES_CreateContext(des3_known_key, NULL,
NSS_DES_EDE3, PR_FALSE);
if (des3_context == NULL) {
PORT_SetError(SEC_ERROR_NO_MEMORY);
return (SECFailure);
}
des3_status = DES_Decrypt(des3_context, des3_computed_plaintext,
&des3_bytes_decrypted, FIPS_DES3_DECRYPT_LENGTH,
des3_ecb_known_ciphertext,
FIPS_DES3_ENCRYPT_LENGTH);
DES_DestroyContext(des3_context, PR_TRUE);
if ((des3_status != SECSuccess) ||
(des3_bytes_decrypted != FIPS_DES3_DECRYPT_LENGTH) ||
(PORT_Memcmp(des3_computed_plaintext, des3_ecb_known_plaintext,
FIPS_DES3_DECRYPT_LENGTH) !=
0 )) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return (SECFailure);
}
/*******************************************************/
/* DES3-CBC Single-Round Known Answer Encryption Test. */
/*******************************************************/
des3_context = DES_CreateContext(des3_known_key,
des3_cbc_known_initialization_vector,
NSS_DES_EDE3_CBC, PR_TRUE);
if (des3_context == NULL) {
PORT_SetError(SEC_ERROR_NO_MEMORY);
return (SECFailure);
}
des3_status = DES_Encrypt(des3_context, des3_computed_ciphertext,
&des3_bytes_encrypted, FIPS_DES3_ENCRYPT_LENGTH,
des3_cbc_known_plaintext,
FIPS_DES3_DECRYPT_LENGTH);
DES_DestroyContext(des3_context, PR_TRUE);
if ((des3_status != SECSuccess) ||
(des3_bytes_encrypted != FIPS_DES3_ENCRYPT_LENGTH) ||
(PORT_Memcmp(des3_computed_ciphertext, des3_cbc_known_ciphertext,
FIPS_DES3_ENCRYPT_LENGTH) !=
0 )) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return (SECFailure);
}
/*******************************************************/
/* DES3-CBC Single-Round Known Answer Decryption Test. */
/*******************************************************/
des3_context = DES_CreateContext(des3_known_key,
des3_cbc_known_initialization_vector,
NSS_DES_EDE3_CBC, PR_FALSE);
if (des3_context == NULL) {
PORT_SetError(SEC_ERROR_NO_MEMORY);
return (SECFailure);
}
des3_status = DES_Decrypt(des3_context, des3_computed_plaintext,
&des3_bytes_decrypted, FIPS_DES3_DECRYPT_LENGTH,
des3_cbc_known_ciphertext,
FIPS_DES3_ENCRYPT_LENGTH);
DES_DestroyContext(des3_context, PR_TRUE);
if ((des3_status != SECSuccess) ||
(des3_bytes_decrypted != FIPS_DES3_DECRYPT_LENGTH) ||
(PORT_Memcmp(des3_computed_plaintext, des3_cbc_known_plaintext,
FIPS_DES3_DECRYPT_LENGTH) !=
0 )) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return (SECFailure);
}
return (SECSuccess);
}
/* AES self-test for 128-bit, 192-bit, or 256-bit key sizes*/
static SECStatus
freebl_fips_AES_PowerUpSelfTest(
int aes_key_size)
{
/* AES Known Key (up to 256-bits). */
static const PRUint8 aes_known_key[] = {
"AES-128 RIJNDAELLEADNJIR 821-SEA" };
/* AES-CBC Known Initialization Vector (128-bits). */
static const PRUint8 aes_cbc_known_initialization_vector[] = {
"SecurityytiruceS" };
/* AES Known Plaintext (128-bits). (blocksize is 128-bits) */
static const PRUint8 aes_known_plaintext[] = {
"NetscapeepacsteN" };
static const PRUint8 aes_gcm_known_aad[] = {
"MozillaallizoM" };
/* AES Known Ciphertext (128-bit key). */
static const PRUint8 aes_ecb128_known_ciphertext[] = {
0 x3c,
0 xa5,
0 x96,
0 xf3,
0 x34,
0 x6a,
0 x96,
0 xc1,
0 x03,
0 x88,
0 x16,
0 x7b,
0 x20,
0 xbf,
0 x35,
0 x47
};
static const PRUint8 aes_cbc128_known_ciphertext[] = {
0 xcf,
0 x15,
0 x1d,
0 x4f,
0 x96,
0 xe4,
0 x4f,
0 x63,
0 x15,
0 x54,
0 x14,
0 x1d,
0 x4e,
0 xd8,
0 xd5,
0 xea
};
static const PRUint8 aes_gcm128_known_ciphertext[] = {
0 x63,
0 xf4,
0 x95,
0 x28,
0 xe6,
0 x78,
0 xee,
0 x6e,
0 x4f,
0 xe0,
0 xfc,
0 x8d,
0 xd7,
0 xa2,
0 xb1,
0 xff,
0 x0c,
0 x97,
0 x1b,
0 x0a,
0 xdd,
0 x97,
0 x75,
0 xed,
0 x8b,
0 xde,
0 xbf,
0 x16,
0 x5e,
0 x57,
0 x6b,
0 x4f
};
static const PRUint8 aes_cmac128_known_ciphertext[] = {
0 x54,
0 x11,
0 xe2,
0 x57,
0 xbd,
0 x2a,
0 xdf,
0 x9d,
0 x1a,
0 x89,
0 x72,
0 x80,
0 x84,
0 x4c,
0 x7e,
0 x93
};
/* AES Known Ciphertext (192-bit key). */
static const PRUint8 aes_ecb192_known_ciphertext[] = {
0 xa0,
0 x18,
0 x62,
0 xed,
0 x88,
0 x19,
0 xcb,
0 x62,
0 x88,
0 x1d,
0 x4d,
0 xfe,
0 x84,
0 x02,
0 x89,
0 x0e
};
static const PRUint8 aes_cbc192_known_ciphertext[] = {
0 x83,
0 xf7,
0 xa4,
0 x76,
0 xd1,
0 x6f,
0 x07,
0 xbe,
0 x07,
0 xbc,
0 x43,
0 x2f,
0 x6d,
0 xad,
0 x29,
0 xe1
};
static const PRUint8 aes_gcm192_known_ciphertext[] = {
0 xc1,
0 x0b,
0 x92,
0 x1d,
0 x68,
0 x21,
0 xf4,
0 x25,
0 x41,
0 x61,
0 x20,
0 x2d,
0 x59,
0 x7f,
0 x53,
0 xde,
0 x93,
0 x39,
0 xab,
0 x09,
0 x76,
0 x41,
0 x57,
0 x2b,
0 x90,
0 x2e,
0 x44,
0 xbb,
0 x52,
0 x03,
0 xe9,
0 x07
};
static const PRUint8 aes_cmac192_known_ciphertext[] = {
0 x0e,
0 x07,
0 x99,
0 x1e,
0 xf6,
0 xee,
0 xfa,
0 x2c,
0 x1b,
0 xfc,
0 xce,
0 x94,
0 x92,
0 x2d,
0 xf1,
0 xab
};
/* AES Known Ciphertext (256-bit key). */
static const PRUint8 aes_ecb256_known_ciphertext[] = {
0 xdb,
0 xa6,
0 x52,
0 x01,
0 x8a,
0 x70,
0 xae,
0 x66,
0 x3a,
0 x99,
0 xd8,
0 x95,
0 x7f,
0 xfb,
0 x01,
0 x67
};
static const PRUint8 aes_cbc256_known_ciphertext[] = {
0 x37,
0 xea,
0 x07,
0 x06,
0 x31,
0 x1c,
0 x59,
0 x27,
0 xc5,
0 xc5,
0 x68,
0 x71,
0 x6e,
0 x34,
0 x40,
0 x16
};
static const PRUint8 aes_gcm256_known_ciphertext[] = {
0 x5d,
0 x9e,
0 xd2,
0 xa2,
0 x74,
0 x9c,
0 xd9,
0 x1c,
0 xd1,
0 xc9,
0 xee,
0 x5d,
0 xb6,
0 xf2,
0 xc9,
0 xb6,
0 x79,
0 x27,
0 x53,
0 x02,
0 xa3,
0 xdc,
0 x22,
0 xce,
0 xf4,
0 xb0,
0 xc1,
0 x8c,
0 x86,
0 x51,
0 xf5,
0 xa1
};
static const PRUint8 aes_cmac256_known_ciphertext[] = {
0 xc1,
0 x26,
0 x69,
0 x32,
0 x51,
0 x13,
0 x65,
0 xac,
0 x71,
0 x23,
0 xe4,
0 xe7,
0 xb9,
0 x0c,
0 x88,
0 x9f
};
const PRUint8 *aes_ecb_known_ciphertext =
(aes_key_size == FIPS_AES_128_KEY_SIZE) ? aes_ecb128_known_ciphertext : (aes_key_size =
= FIPS_AES_192_KEY_SIZE) ? aes_ecb192_known_ciphertext
: aes_ecb256_known_ciphertext;
const PRUint8 *aes_cbc_known_ciphertext =
(aes_key_size == FIPS_AES_128_KEY_SIZE) ? aes_cbc128_known_ciphertext : (aes_key_size == FIPS_AES_192_KEY_SIZE) ? aes_cbc192_known_ciphertext
: aes_cbc256_known_ciphertext;
const PRUint8 *aes_gcm_known_ciphertext =
(aes_key_size == FIPS_AES_128_KEY_SIZE) ? aes_gcm128_known_ciphertext : (aes_key_size == FIPS_AES_192_KEY_SIZE) ? aes_gcm192_known_ciphertext
: aes_gcm256_known_ciphertext;
const PRUint8 *aes_cmac_known_ciphertext =
(aes_key_size == FIPS_AES_128_KEY_SIZE) ? aes_cmac128_known_ciphertext : (aes_key_size == FIPS_AES_192_KEY_SIZE) ? aes_cmac192_known_ciphertext
: aes_cmac256_known_ciphertext;
/* AES variables. */
PRUint8 aes_computed_ciphertext[FIPS_AES_ENCRYPT_LENGTH * 2 ];
PRUint8 aes_computed_plaintext[FIPS_AES_DECRYPT_LENGTH * 2 ];
AESContext *aes_context;
CMACContext *cmac_context;
unsigned int aes_bytes_encrypted;
unsigned int aes_bytes_decrypted;
CK_NSS_GCM_PARAMS gcmParams;
SECStatus aes_status;
/*check if aes_key_size is 128, 192, or 256 bits */
if ((aes_key_size != FIPS_AES_128_KEY_SIZE) &&
(aes_key_size != FIPS_AES_192_KEY_SIZE) &&
(aes_key_size != FIPS_AES_256_KEY_SIZE)) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return (SECFailure);
}
/******************************************************/
/* AES-ECB Single-Round Known Answer Encryption Test: */
/******************************************************/
aes_context = AES_CreateContext(aes_known_key, NULL, NSS_AES, PR_TRUE,
aes_key_size, FIPS_AES_BLOCK_SIZE);
if (aes_context == NULL) {
PORT_SetError(SEC_ERROR_NO_MEMORY);
return (SECFailure);
}
aes_status = AES_Encrypt(aes_context, aes_computed_ciphertext,
&aes_bytes_encrypted, FIPS_AES_ENCRYPT_LENGTH,
aes_known_plaintext,
FIPS_AES_DECRYPT_LENGTH);
AES_DestroyContext(aes_context, PR_TRUE);
if ((aes_status != SECSuccess) ||
(aes_bytes_encrypted != FIPS_AES_ENCRYPT_LENGTH) ||
(PORT_Memcmp(aes_computed_ciphertext, aes_ecb_known_ciphertext,
FIPS_AES_ENCRYPT_LENGTH) != 0 )) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return (SECFailure);
}
/******************************************************/
/* AES-ECB Single-Round Known Answer Decryption Test: */
/******************************************************/
aes_context = AES_CreateContext(aes_known_key, NULL, NSS_AES, PR_FALSE,
aes_key_size, FIPS_AES_BLOCK_SIZE);
if (aes_context == NULL) {
PORT_SetError(SEC_ERROR_NO_MEMORY);
return (SECFailure);
}
aes_status = AES_Decrypt(aes_context, aes_computed_plaintext,
&aes_bytes_decrypted, FIPS_AES_DECRYPT_LENGTH,
aes_ecb_known_ciphertext,
FIPS_AES_ENCRYPT_LENGTH);
AES_DestroyContext(aes_context, PR_TRUE);
if ((aes_status != SECSuccess) ||
(aes_bytes_decrypted != FIPS_AES_DECRYPT_LENGTH) ||
(PORT_Memcmp(aes_computed_plaintext, aes_known_plaintext,
FIPS_AES_DECRYPT_LENGTH) != 0 )) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return (SECFailure);
}
/******************************************************/
/* AES-CBC Single-Round Known Answer Encryption Test. */
/******************************************************/
aes_context = AES_CreateContext(aes_known_key,
aes_cbc_known_initialization_vector,
NSS_AES_CBC, PR_TRUE, aes_key_size,
FIPS_AES_BLOCK_SIZE);
if (aes_context == NULL) {
PORT_SetError(SEC_ERROR_NO_MEMORY);
return (SECFailure);
}
aes_status = AES_Encrypt(aes_context, aes_computed_ciphertext,
&aes_bytes_encrypted, FIPS_AES_ENCRYPT_LENGTH,
aes_known_plaintext,
FIPS_AES_DECRYPT_LENGTH);
AES_DestroyContext(aes_context, PR_TRUE);
if ((aes_status != SECSuccess) ||
(aes_bytes_encrypted != FIPS_AES_ENCRYPT_LENGTH) ||
(PORT_Memcmp(aes_computed_ciphertext, aes_cbc_known_ciphertext,
FIPS_AES_ENCRYPT_LENGTH) != 0 )) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return (SECFailure);
}
/******************************************************/
/* AES-CBC Single-Round Known Answer Decryption Test. */
/******************************************************/
aes_context = AES_CreateContext(aes_known_key,
aes_cbc_known_initialization_vector,
NSS_AES_CBC, PR_FALSE, aes_key_size,
FIPS_AES_BLOCK_SIZE);
if (aes_context == NULL) {
PORT_SetError(SEC_ERROR_NO_MEMORY);
return (SECFailure);
}
aes_status = AES_Decrypt(aes_context, aes_computed_plaintext,
&aes_bytes_decrypted, FIPS_AES_DECRYPT_LENGTH,
aes_cbc_known_ciphertext,
FIPS_AES_ENCRYPT_LENGTH);
AES_DestroyContext(aes_context, PR_TRUE);
if ((aes_status != SECSuccess) ||
(aes_bytes_decrypted != FIPS_AES_DECRYPT_LENGTH) ||
(PORT_Memcmp(aes_computed_plaintext, aes_known_plaintext,
FIPS_AES_DECRYPT_LENGTH) != 0 )) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return (SECFailure);
}
/******************************************************/
/* AES-GCM Single-Round Known Answer Encryption Test. */
/******************************************************/
gcmParams.pIv = (PRUint8 *)aes_cbc_known_initialization_vector;
gcmParams.ulIvLen = FIPS_AES_BLOCK_SIZE;
gcmParams.pAAD = (PRUint8 *)aes_gcm_known_aad;
gcmParams.ulAADLen = sizeof (aes_gcm_known_aad);
gcmParams.ulTagBits = FIPS_AES_BLOCK_SIZE * 8 ;
aes_context = AES_CreateContext(aes_known_key,
(PRUint8 *)&gcmParams,
NSS_AES_GCM, PR_TRUE, aes_key_size,
FIPS_AES_BLOCK_SIZE);
if (aes_context == NULL) {
PORT_SetError(SEC_ERROR_NO_MEMORY);
return (SECFailure);
}
aes_status = AES_Encrypt(aes_context, aes_computed_ciphertext,
&aes_bytes_encrypted, FIPS_AES_ENCRYPT_LENGTH * 2 ,
aes_known_plaintext,
FIPS_AES_DECRYPT_LENGTH);
AES_DestroyContext(aes_context, PR_TRUE);
if ((aes_status != SECSuccess) ||
(aes_bytes_encrypted != FIPS_AES_ENCRYPT_LENGTH * 2 ) ||
(PORT_Memcmp(aes_computed_ciphertext, aes_gcm_known_ciphertext,
FIPS_AES_ENCRYPT_LENGTH * 2 ) != 0 )) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return (SECFailure);
}
/******************************************************/
/* AES-GCM Single-Round Known Answer Decryption Test. */
/******************************************************/
aes_context = AES_CreateContext(aes_known_key,
(PRUint8 *)&gcmParams,
NSS_AES_GCM, PR_FALSE, aes_key_size,
FIPS_AES_BLOCK_SIZE);
if (aes_context == NULL) {
PORT_SetError(SEC_ERROR_NO_MEMORY);
return (SECFailure);
}
aes_status = AES_Decrypt(aes_context, aes_computed_plaintext,
&aes_bytes_decrypted, FIPS_AES_DECRYPT_LENGTH * 2 ,
aes_gcm_known_ciphertext,
FIPS_AES_ENCRYPT_LENGTH * 2 );
AES_DestroyContext(aes_context, PR_TRUE);
if ((aes_status != SECSuccess) ||
(aes_bytes_decrypted != FIPS_AES_DECRYPT_LENGTH) ||
(PORT_Memcmp(aes_computed_plaintext, aes_known_plaintext,
FIPS_AES_DECRYPT_LENGTH) != 0 )) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return (SECFailure);
}
/******************************************************/
/* AES-CMAC Known Answer Encryption Test. */
/******************************************************/
cmac_context = CMAC_Create(CMAC_AES, aes_known_key, aes_key_size);
if (cmac_context == NULL) {
PORT_SetError(SEC_ERROR_NO_MEMORY);
return (SECFailure);
}
aes_status = CMAC_Begin(cmac_context);
if (aes_status != SECSuccess) {
CMAC_Destroy(cmac_context, PR_TRUE);
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return (SECFailure);
}
aes_status = CMAC_Update(cmac_context, aes_known_plaintext,
FIPS_AES_DECRYPT_LENGTH);
if (aes_status != SECSuccess) {
CMAC_Destroy(cmac_context, PR_TRUE);
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return (SECFailure);
}
aes_status = CMAC_Finish(cmac_context, aes_computed_ciphertext,
&aes_bytes_encrypted, FIPS_AES_CMAC_LENGTH);
CMAC_Destroy(cmac_context, PR_TRUE);
if ((aes_status != SECSuccess) ||
(aes_bytes_encrypted != FIPS_AES_CMAC_LENGTH) ||
(PORT_Memcmp(aes_computed_ciphertext, aes_cmac_known_ciphertext,
FIPS_AES_CMAC_LENGTH) != 0 )) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return (SECFailure);
}
return (SECSuccess);
}
/* Known Hash Message (512-bits). Used for all hashes (incl. SHA-N [N>1]). */
static const PRUint8 known_hash_message[] = {
"The test message for the MD2, MD5, and SHA-1 hashing algorithms."
};
/****************************************************/
/* Single Round HMAC SHA-X test */
/****************************************************/
static SECStatus
freebl_fips_HMAC(unsigned char *hmac_computed,
const PRUint8 *secret_key,
unsigned int secret_key_length,
const PRUint8 *message,
unsigned int message_length,
HASH_HashType hashAlg)
{
SECStatus hmac_status = SECFailure;
HMACContext *cx = NULL;
SECHashObject *hashObj = NULL;
unsigned int bytes_hashed = 0 ;
hashObj = (SECHashObject *)HASH_GetRawHashObject(hashAlg);
if (!hashObj)
return (SECFailure);
cx = HMAC_Create(hashObj, secret_key,
secret_key_length,
PR_TRUE); /* PR_TRUE for in FIPS mode */
if (cx == NULL)
return (SECFailure);
HMAC_Begin(cx);
HMAC_Update(cx, message, message_length);
hmac_status = HMAC_Finish(cx, hmac_computed, &bytes_hashed,
hashObj->length);
HMAC_Destroy(cx, PR_TRUE);
return (hmac_status);
}
static SECStatus
freebl_fips_HMAC_PowerUpSelfTest(void )
{
static const PRUint8 HMAC_known_secret_key[] = {
"Firefox and ThunderBird are awesome!"
};
static const PRUint8 HMAC_known_secret_key_length = sizeof HMAC_known_secret_key;
/* known SHA1 hmac (20 bytes) */
static const PRUint8 known_SHA1_hmac[] = {
0 xd5, 0 x85, 0 xf6, 0 x5b, 0 x39, 0 xfa, 0 xb9, 0 x05,
0 x3b, 0 x57, 0 x1d, 0 x61, 0 xe7, 0 xb8, 0 x84, 0 x1e,
0 x5d, 0 x0e, 0 x1e, 0 x11
};
/* known SHA224 hmac (28 bytes) */
static const PRUint8 known_SHA224_hmac[] = {
0 x1c, 0 xc3, 0 x06, 0 x8e, 0 xce, 0 x37, 0 x68, 0 xfb,
0 x1a, 0 x82, 0 x4a, 0 xbe, 0 x2b, 0 x00, 0 x51, 0 xf8,
0 x9d, 0 xb6, 0 xe0, 0 x90, 0 x0d, 0 x00, 0 xc9, 0 x64,
0 x9a, 0 xb8, 0 x98, 0 x4e
};
/* known SHA256 hmac (32 bytes) */
static const PRUint8 known_SHA256_hmac[] = {
0 x05, 0 x75, 0 x9a, 0 x9e, 0 x70, 0 x5e, 0 xe7, 0 x44,
0 xe2, 0 x46, 0 x4b, 0 x92, 0 x22, 0 x14, 0 x22, 0 xe0,
0 x1b, 0 x92, 0 x8a, 0 x0c, 0 xfe, 0 xf5, 0 x49, 0 xe9,
0 xa7, 0 x1b, 0 x56, 0 x7d, 0 x1d, 0 x29, 0 x40, 0 x48
};
/* known SHA384 hmac (48 bytes) */
static const PRUint8 known_SHA384_hmac[] = {
0 xcd, 0 x56, 0 x14, 0 xec, 0 x05, 0 x53, 0 x06, 0 x2b,
0 x7e, 0 x9c, 0 x8a, 0 x18, 0 x5e, 0 xea, 0 xf3, 0 x91,
0 x33, 0 xfb, 0 x64, 0 xf6, 0 xe3, 0 x9f, 0 x89, 0 x0b,
0 xaf, 0 xbe, 0 x83, 0 x4d, 0 x3f, 0 x3c, 0 x43, 0 x4d,
0 x4a, 0 x0c, 0 x56, 0 x98, 0 xf8, 0 xca, 0 xb4, 0 xaa,
0 x9a, 0 xf4, 0 x0a, 0 xaf, 0 x4f, 0 x69, 0 xca, 0 x87
};
/* known SHA512 hmac (64 bytes) */
static const PRUint8 known_SHA512_hmac[] = {
0 xf6, 0 x0e, 0 x97, 0 x12, 0 x00, 0 x67, 0 x6e, 0 xb9,
0 x0c, 0 xb2, 0 x63, 0 xf0, 0 x60, 0 xac, 0 x75, 0 x62,
0 x70, 0 x95, 0 x2a, 0 x52, 0 x22, 0 xee, 0 xdd, 0 xd2,
0 x71, 0 xb1, 0 xe8, 0 x26, 0 x33, 0 xd3, 0 x13, 0 x27,
0 xcb, 0 xff, 0 x44, 0 xef, 0 x87, 0 x97, 0 x16, 0 xfb,
0 xd3, 0 x0b, 0 x48, 0 xbe, 0 x12, 0 x4e, 0 xda, 0 xb1,
0 x89, 0 x90, 0 xfb, 0 x06, 0 x0c, 0 xbe, 0 xe5, 0 xc4,
0 xff, 0 x24, 0 x37, 0 x3d, 0 xc7, 0 xe4, 0 xe4, 0 x37
};
SECStatus hmac_status;
PRUint8 hmac_computed[HASH_LENGTH_MAX];
/***************************************************/
/* HMAC SHA-1 Single-Round Known Answer HMAC Test. */
/***************************************************/
hmac_status = freebl_fips_HMAC(hmac_computed,
HMAC_known_secret_key,
HMAC_known_secret_key_length,
known_hash_message,
FIPS_KNOWN_HASH_MESSAGE_LENGTH,
HASH_AlgSHA1);
if ((hmac_status != SECSuccess) ||
(PORT_Memcmp(hmac_computed, known_SHA1_hmac,
SHA1_LENGTH) != 0 )) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return (SECFailure);
}
/***************************************************/
/* HMAC SHA-224 Single-Round Known Answer Test. */
/***************************************************/
hmac_status = freebl_fips_HMAC(hmac_computed,
HMAC_known_secret_key,
HMAC_known_secret_key_length,
known_hash_message,
FIPS_KNOWN_HASH_MESSAGE_LENGTH,
HASH_AlgSHA224);
if ((hmac_status != SECSuccess) ||
(PORT_Memcmp(hmac_computed, known_SHA224_hmac,
SHA224_LENGTH) != 0 )) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return (SECFailure);
}
/***************************************************/
/* HMAC SHA-256 Single-Round Known Answer Test. */
/***************************************************/
hmac_status = freebl_fips_HMAC(hmac_computed,
HMAC_known_secret_key,
HMAC_known_secret_key_length,
known_hash_message,
FIPS_KNOWN_HASH_MESSAGE_LENGTH,
HASH_AlgSHA256);
if ((hmac_status != SECSuccess) ||
(PORT_Memcmp(hmac_computed, known_SHA256_hmac,
SHA256_LENGTH) != 0 )) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return (SECFailure);
}
/***************************************************/
/* HMAC SHA-384 Single-Round Known Answer Test. */
/***************************************************/
hmac_status = freebl_fips_HMAC(hmac_computed,
HMAC_known_secret_key,
HMAC_known_secret_key_length,
known_hash_message,
FIPS_KNOWN_HASH_MESSAGE_LENGTH,
HASH_AlgSHA384);
if ((hmac_status != SECSuccess) ||
(PORT_Memcmp(hmac_computed, known_SHA384_hmac,
SHA384_LENGTH) != 0 )) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return (SECFailure);
}
/***************************************************/
/* HMAC SHA-512 Single-Round Known Answer Test. */
/***************************************************/
hmac_status = freebl_fips_HMAC(hmac_computed,
HMAC_known_secret_key,
HMAC_known_secret_key_length,
known_hash_message,
FIPS_KNOWN_HASH_MESSAGE_LENGTH,
HASH_AlgSHA512);
if ((hmac_status != SECSuccess) ||
(PORT_Memcmp(hmac_computed, known_SHA512_hmac,
SHA512_LENGTH) != 0 )) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return (SECFailure);
}
return (SECSuccess);
}
SECStatus
freebl_fips_TLS_PowerUpSelfTest(void )
{
static const PRUint8 TLS_known_secret_key[] = {
"Firefox and ThunderBird are awesome!"
};
static const PRUint8 TLS_known_secret_key_length = sizeof TLS_known_secret_key;
/* known tls prf with sha1/md5 */
static const PRUint8 known_TLS_PRF[] = {
0 x87, 0 x4c, 0 xc0, 0 xc5, 0 x15, 0 x14, 0 x2b, 0 xdc,
0 x73, 0 x48, 0 x9e, 0 x88, 0 x9d, 0 xf5, 0 x83, 0 x2f,
0 x2d, 0 x66, 0 x1e, 0 x78, 0 x6c, 0 x54, 0 x78, 0 x29,
0 xb9, 0 xa4, 0 x4c, 0 x90, 0 x5e, 0 xa2, 0 xe6, 0 x5c,
0 xf1, 0 x4f, 0 xb5, 0 x95, 0 xa5, 0 x54, 0 xc0, 0 x9f,
0 x84, 0 x47, 0 xb4, 0 x4c, 0 xda, 0 xae, 0 x19, 0 x29,
0 x2b, 0 x91, 0 x2a, 0 x81, 0 x9d, 0 x3a, 0 x30, 0 x40,
0 xc5, 0 xdf, 0 xbb, 0 xfa, 0 xd8, 0 x4c, 0 xbc, 0 x18
};
/* known SHA256 tls mac */
static const PRUint8 known_TLS_SHA256[] = {
0 x66, 0 xd6, 0 x94, 0 xd4, 0 x0d, 0 x32, 0 x61, 0 x38,
0 x26, 0 xf6, 0 x8b, 0 xfe, 0 x9e, 0 xac, 0 xa2, 0 xf5,
0 x40, 0 x52, 0 x74, 0 x3f, 0 xbe, 0 xb8, 0 xca, 0 x94,
0 xc3, 0 x64, 0 xd6, 0 x02, 0 xf5, 0 x88, 0 x98, 0 x35,
0 x73, 0 x9f, 0 xce, 0 xaa, 0 x68, 0 xe3, 0 x7c, 0 x93,
0 x30, 0 x21, 0 x45, 0 xec, 0 xe9, 0 x8f, 0 x1c, 0 x7e,
0 xd1, 0 x54, 0 xf5, 0 xbe, 0 xff, 0 xc8, 0 xd7, 0 x72,
0 x7f, 0 x9c, 0 x0c, 0 x7f, 0 xa9, 0 xd3, 0 x4a, 0 xd2
};
#ifdef NSS_FULL_POST
/* known SHA224 tls mac */
static const PRUint8 known_TLS_SHA224[] = {
0 xd8, 0 x68, 0 x15, 0 xff, 0 xa1, 0 xa2, 0 x5e, 0 x16,
0 xce, 0 xb1, 0 xfd, 0 xbd, 0 xda, 0 x39, 0 xbc, 0 xa7,
0 x27, 0 x32, 0 x78, 0 x94, 0 x66, 0 xf0, 0 x84, 0 xcf,
0 x46, 0 xc0, 0 x22, 0 x76, 0 xdc, 0 x6b, 0 x2e, 0 xed,
0 x1d, 0 x2d, 0 xd2, 0 x93, 0 xfd, 0 xae, 0 xca, 0 xf9,
0 xe0, 0 x4c, 0 x17, 0 x23, 0 x22, 0 x5a, 0 x73, 0 x93,
0 x20, 0 x0a, 0 xbd, 0 xa0, 0 x72, 0 xf8, 0 x8b, 0 x74,
0 xfb, 0 xf1, 0 xab, 0 xb7, 0 xe0, 0 xec, 0 x34, 0 xc9
};
/* known SHA384 tls mac */
static const PRUint8 known_TLS_SHA384[] = {
0 xb2, 0 xac, 0 x06, 0 x10, 0 xad, 0 x50, 0 xd5, 0 xdc,
0 xdb, 0 x01, 0 xea, 0 xa6, 0 x2d, 0 x8a, 0 x34, 0 xb6,
0 xeb, 0 x84, 0 xbc, 0 x37, 0 xc9, 0 x9f, 0 xa1, 0 x9c,
0 xd5, 0 xbd, 0 x4e, 0 x66, 0 x16, 0 x24, 0 xe5, 0 x3d,
0 xce, 0 x74, 0 xe0, 0 x30, 0 x41, 0 x5c, 0 xdb, 0 xb7,
0 x52, 0 x1d, 0 x2d, 0 x4d, 0 x9b, 0 xbe, 0 x6b, 0 x86,
0 xda, 0 x8a, 0 xca, 0 x73, 0 x39, 0 xb4, 0 xc7, 0 x8f,
0 x03, 0 xb1, 0 xf9, 0 x7e, 0 x65, 0 xae, 0 x17, 0 x10
};
/* known SHA512 tls mac */
static const PRUint8 known_TLS_SHA512[] = {
0 x73, 0 x21, 0 x4f, 0 x40, 0 x81, 0 x1e, 0 x90, 0 xa1,
0 x16, 0 x40, 0 x1e, 0 x33, 0 x69, 0 xc5, 0 x00, 0 xc7,
0 xc4, 0 x81, 0 xa3, 0 x4f, 0 xa7, 0 xcc, 0 x4a, 0 xeb,
0 x1a, 0 x66, 0 x00, 0 x82, 0 x52, 0 xe2, 0 x2f, 0 x69,
0 x14, 0 x59, 0 x05, 0 x7c, 0 xb0, 0 x32, 0 xce, 0 xcc,
0 xb7, 0 xc9, 0 xab, 0 x0f, 0 x73, 0 x00, 0 xe5, 0 x52,
0 x9d, 0 x6b, 0 x0e, 0 x66, 0 x4b, 0 xb3, 0 x0b, 0 x0d,
0 x34, 0 x53, 0 x97, 0 x13, 0 x84, 0 x18, 0 x31, 0 x7a
};
#endif
SECStatus status;
PRUint8 tls_computed[HASH_LENGTH_MAX];
SECItem secret;
SECItem seed;
SECItem result;
const char *tls_label = "fips test label" ;
secret.data = (unsigned char *)TLS_known_secret_key;
secret.len = TLS_known_secret_key_length;
seed.data = (unsigned char *)known_hash_message;
seed.len = FIPS_KNOWN_HASH_MESSAGE_LENGTH;
result.data = tls_computed;
result.len = sizeof (tls_computed);
/***************************************************/
/* TLS 1.0 PRF Known Answer Test */
/***************************************************/
status = TLS_PRF(&secret, tls_label, &seed, &result, PR_TRUE);
if ((status != SECSuccess) ||
(result.len != HASH_LENGTH_MAX) ||
(PORT_Memcmp(tls_computed, known_TLS_PRF,
HASH_LENGTH_MAX) != 0 )) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return (SECFailure);
}
/***************************************************/
/* TLS 1.2 SHA-256 Known Answer Test. */
/***************************************************/
status = TLS_P_hash(HASH_AlgSHA256, &secret, tls_label,
&seed, &result, PR_TRUE);
if ((status != SECSuccess) ||
(result.len != HASH_LENGTH_MAX) ||
(PORT_Memcmp(tls_computed, known_TLS_SHA256,
HASH_LENGTH_MAX) != 0 )) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return (SECFailure);
}
#ifdef NSS_FULL_POST
/***************************************************/
/* TLS 1.2 SHA-224 Known Answer Test. */
/***************************************************/
status = TLS_P_hash(HASH_AlgSHA224, &secret, tls_label,
&seed, &result, PR_TRUE);
if ((status != SECSuccess) ||
(result.len != HASH_LENGTH_MAX) ||
(PORT_Memcmp(tls_computed, known_TLS_SHA224,
HASH_LENGTH_MAX) != 0 )) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return (SECFailure);
}
/***************************************************/
/* TLS 1.2 SHA-384 Known Answer Test. */
/***************************************************/
status = TLS_P_hash(HASH_AlgSHA384, &secret, tls_label,
&seed, &result, PR_TRUE);
if ((status != SECSuccess) ||
(result.len != HASH_LENGTH_MAX) ||
(PORT_Memcmp(tls_computed, known_TLS_SHA384,
HASH_LENGTH_MAX) != 0 )) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return (SECFailure);
}
/***************************************************/
/* TLS 1.2 SHA-512 Known Answer Test. */
/***************************************************/
status = TLS_P_hash(HASH_AlgSHA512, &secret, tls_label,
&seed, &result, PR_TRUE);
if ((status != SECSuccess) ||
(result.len != HASH_LENGTH_MAX) ||
(PORT_Memcmp(tls_computed, known_TLS_SHA512,
HASH_LENGTH_MAX) != 0 )) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return (SECFailure);
}
#endif
return (SECSuccess);
}
static SECStatus
freebl_fips_SHA_PowerUpSelfTest(void )
{
/* SHA-1 Known Digest Message (160-bits). */
static const PRUint8 sha1_known_digest[] = {
0 x0a, 0 x6d, 0 x07, 0 xba, 0 x1e, 0 xbd, 0 x8a, 0 x1b,
0 x72, 0 xf6, 0 xc7, 0 x22, 0 xf1, 0 x27, 0 x9f, 0 xf0,
0 xe0, 0 x68, 0 x47, 0 x7a
};
/* SHA-224 Known Digest Message (224-bits). */
static const PRUint8 sha224_known_digest[] = {
0 x89, 0 x5e, 0 x7f, 0 xfd, 0 x0e, 0 xd8, 0 x35, 0 x6f,
0 x64, 0 x6d, 0 xf2, 0 xde, 0 x5e, 0 xed, 0 xa6, 0 x7f,
0 x29, 0 xd1, 0 x12, 0 x73, 0 x42, 0 x84, 0 x95, 0 x4f,
0 x8e, 0 x08, 0 xe5, 0 xcb
};
/* SHA-256 Known Digest Message (256-bits). */
static const PRUint8 sha256_known_digest[] = {
0 x38, 0 xa9, 0 xc1, 0 xf0, 0 x35, 0 xf6, 0 x5d, 0 x61,
0 x11, 0 xd4, 0 x0b, 0 xdc, 0 xce, 0 x35, 0 x14, 0 x8d,
0 xf2, 0 xdd, 0 xaf, 0 xaf, 0 xcf, 0 xb7, 0 x87, 0 xe9,
0 x96, 0 xa5, 0 xd2, 0 x83, 0 x62, 0 x46, 0 x56, 0 x79
};
/* SHA-384 Known Digest Message (384-bits). */
static const PRUint8 sha384_known_digest[] = {
0 x11, 0 xfe, 0 x1c, 0 x00, 0 x89, 0 x48, 0 xde, 0 xb3,
0 x99, 0 xee, 0 x1c, 0 x18, 0 xb4, 0 x10, 0 xfb, 0 xfe,
0 xe3, 0 xa8, 0 x2c, 0 xf3, 0 x04, 0 xb0, 0 x2f, 0 xc8,
0 xa3, 0 xc4, 0 x5e, 0 xea, 0 x7e, 0 x60, 0 x48, 0 x7b,
0 xce, 0 x2c, 0 x62, 0 xf7, 0 xbc, 0 xa7, 0 xe8, 0 xa3,
0 xcf, 0 x24, 0 xce, 0 x9c, 0 xe2, 0 x8b, 0 x09, 0 x72
};
/* SHA-512 Known Digest Message (512-bits). */
static const PRUint8 sha512_known_digest[] = {
0 xc8, 0 xb3, 0 x27, 0 xf9, 0 x0b, 0 x24, 0 xc8, 0 xbf,
0 x4c, 0 xba, 0 x33, 0 x54, 0 xf2, 0 x31, 0 xbf, 0 xdb,
0 xab, 0 xfd, 0 xb3, 0 x15, 0 xd7, 0 xfa, 0 x48, 0 x99,
0 x07, 0 x60, 0 x0f, 0 x57, 0 x41, 0 x1a, 0 xdd, 0 x28,
0 x12, 0 x55, 0 x25, 0 xac, 0 xba, 0 x3a, 0 x99, 0 x12,
0 x2c, 0 x7a, 0 x8f, 0 x75, 0 x3a, 0 xe1, 0 x06, 0 x6f,
0 x30, 0 x31, 0 xc9, 0 x33, 0 xc6, 0 x1b, 0 x90, 0 x1a,
0 x6c, 0 x98, 0 x9a, 0 x87, 0 xd0, 0 xb2, 0 xf8, 0 x07
};
/* SHA-X variables. */
PRUint8 sha_computed_digest[HASH_LENGTH_MAX];
SECStatus sha_status;
/*************************************************/
/* SHA-1 Single-Round Known Answer Hashing Test. */
/*************************************************/
sha_status = SHA1_HashBuf(sha_computed_digest, known_hash_message,
FIPS_KNOWN_HASH_MESSAGE_LENGTH);
if ((sha_status != SECSuccess) ||
(PORT_Memcmp(sha_computed_digest, sha1_known_digest,
SHA1_LENGTH) != 0 )) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return (SECFailure);
}
/***************************************************/
/* SHA-224 Single-Round Known Answer Hashing Test. */
/***************************************************/
sha_status = SHA224_HashBuf(sha_computed_digest, known_hash_message,
FIPS_KNOWN_HASH_MESSAGE_LENGTH);
if ((sha_status != SECSuccess) ||
(PORT_Memcmp(sha_computed_digest, sha224_known_digest,
SHA224_LENGTH) != 0 )) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return (SECFailure);
}
/***************************************************/
/* SHA-256 Single-Round Known Answer Hashing Test. */
/***************************************************/
sha_status = SHA256_HashBuf(sha_computed_digest, known_hash_message,
FIPS_KNOWN_HASH_MESSAGE_LENGTH);
if ((sha_status != SECSuccess) ||
(PORT_Memcmp(sha_computed_digest, sha256_known_digest,
SHA256_LENGTH) != 0 )) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return (SECFailure);
}
/***************************************************/
/* SHA-384 Single-Round Known Answer Hashing Test. */
/***************************************************/
sha_status = SHA384_HashBuf(sha_computed_digest, known_hash_message,
FIPS_KNOWN_HASH_MESSAGE_LENGTH);
if ((sha_status != SECSuccess) ||
(PORT_Memcmp(sha_computed_digest, sha384_known_digest,
SHA384_LENGTH) != 0 )) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return (SECFailure);
}
/***************************************************/
/* SHA-512 Single-Round Known Answer Hashing Test. */
/***************************************************/
sha_status = SHA512_HashBuf(sha_computed_digest, known_hash_message,
FIPS_KNOWN_HASH_MESSAGE_LENGTH);
if ((sha_status != SECSuccess) ||
(PORT_Memcmp(sha_computed_digest, sha512_known_digest,
SHA512_LENGTH) != 0 )) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return (SECFailure);
}
return (SECSuccess);
}
static SECStatus
freebl_fips_RSA_PowerUpSelfTest(void )
{
/* RSA Known Modulus used in both Public/Private Key Values (2048-bits). */
static const PRUint8 rsa_modulus[FIPS_RSA_MODULUS_LENGTH] = {
0 xb8, 0 x15, 0 x00, 0 x33, 0 xda, 0 x0c, 0 x9d, 0 xa5,
0 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2b, 0 x98, 0 x0f, 0 x15,
0 xe3, 0 x87, 0 x16, 0 x7a, 0 x7c, 0 x67, 0 x3e, 0 x12,
0 x2b, 0 xf8, 0 xbe, 0 x48, 0 xc1, 0 x97, 0 x47, 0 xf4,
0 x1f, 0 x81, 0 x80, 0 x12, 0 x28, 0 xe4, 0 x7b, 0 x1e,
0 xb7, 0 x00, 0 xa4, 0 xde, 0 xaa, 0 xfb, 0 x0f, 0 x77,
0 x84, 0 xa3, 0 xd6, 0 xb2, 0 x03, 0 x48, 0 xdd, 0 x53,
0 x8b, 0 x46, 0 x41, 0 x28, 0 x52, 0 xc4, 0 x53, 0 xf0,
0 x1c, 0 x95, 0 xd9, 0 x36, 0 xe0, 0 x0f, 0 x26, 0 x46,
0 x9c, 0 x61, 0 x0e, 0 x80, 0 xca, 0 x86, 0 xaf, 0 x39,
0 x95, 0 xe5, 0 x60, 0 x43, 0 x61, 0 x3e, 0 x2b, 0 xb4,
0 xe8, 0 xbd, 0 x8d, 0 x77, 0 x62, 0 xf5, 0 x32, 0 x43,
0 x2f, 0 x4b, 0 x65, 0 x82, 0 x14, 0 xdd, 0 x29, 0 x5b
};
/* RSA Known Public Key Values (24-bits). */
static const PRUint8 rsa_public_exponent[FIPS_RSA_PUBLIC_EXPONENT_LENGTH] = { 0 x01, 0 x00, 0 x01 };
/* RSA Known Private Key Values (version is 8-bits), */
/* (private exponent is 2048-bits), */
/* (private prime0 is 1024-bits), */
/* (private prime1 is 1024-bits), */
/* (private prime exponent0 is 1024-bits), */
/* (private prime exponent1 is 1024-bits), */
/* and (private coefficient is 1024-bits). */
static const PRUint8 rsa_version[] = { 0 x00 };
static const PRUint8 rsa_private_exponent[FIPS_RSA_PRIVATE_EXPONENT_LENGTH] = {
0 x29, 0 x08, 0 x05, 0 x53, 0 x89, 0 x76, 0 xe6, 0 x6c,
0 xb5, 0 x77, 0 xf0, 0 xca, 0 xdf, 0 xf3, 0 xf2, 0 x67,
0 xda, 0 x03, 0 xd4, 0 x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x0c, 0 xc5, 0 xce, 0 x70,
0 x08, 0 x63, 0 x1e, 0 x73, 0 xdb, 0 x7e, 0 x74, 0 x05,
0 x32, 0 x01, 0 xc6, 0 x36, 0 x32, 0 x75, 0 x6b, 0 xed,
0 x9d, 0 xfe, 0 x7c, 0 x7e, 0 xa9, 0 x57, 0 xb4, 0 xe9,
0 x22, 0 xe4, 0 xe7, 0 xfe, 0 x36, 0 x07, 0 x9b, 0 xdf
};
static const PRUint8 rsa_exponent0[FIPS_RSA_EXPONENT0_LENGTH] = {
0 x04, 0 x5a, 0 x3a, 0 xa9, 0 x64, 0 xaa, 0 xd9, 0 xd1,
0 x09, 0 x9e, 0 x99, 0 xe5, 0 xea, 0 x50, 0 x86, 0 x8a,
0 x89, 0 x72, 0 x77, 0 xee, 0 xdb, 0 xee, 0 xb5, 0 xa9,
0 xd8, 0 x6b, 0 x60, 0 xb1, 0 x84, 0 xb4, 0 xff, 0 x37,
0 xc1, 0 x1d, 0 xfe, 0 x8a, 0 x06, 0 x89, 0 x61, 0 x3d,
0 x37, 0 xef, 0 x01, 0 xd3, 0 xa3, 0 x56, 0 x02, 0 x6c,
0 xa3, 0 x05, 0 xd4, 0 xc5, 0 x3f, 0 x6b, 0 x15, 0 x59,
0 x25, 0 x61, 0 xff, 0 x86, 0 xea, 0 x0c, 0 x84, 0 x01,
0 x85, 0 x72, 0 xfd, 0 x84, 0 x58, 0 xca, 0 x41, 0 xda,
0 x27, 0 xbe, 0 xe4, 0 x68, 0 x09, 0 xe4, 0 xe9, 0 x63,
0 x62, 0 x6a, 0 x31, 0 x8a, 0 x67, 0 x8f, 0 x55, 0 xde,
0 xd4, 0 xb6, 0 x3f, 0 x90, 0 x10, 0 x6c, 0 xf6, 0 x62,
0 x17, 0 x23, 0 x15, 0 x7e, 0 x33, 0 x76, 0 x65, 0 xb5,
0 xee, 0 x7b, 0 x11, 0 x76, 0 xf5, 0 xbe, 0 xe0, 0 xf2,
0 x57, 0 x7a, 0 x8c, 0 x97, 0 x0c, 0 x68, 0 xf5, 0 xf8,
0 x41, 0 xcf, 0 x7f, 0 x66, 0 x53, 0 xac, 0 x31, 0 x7d
};
static const PRUint8 rsa_exponent1[FIPS_RSA_EXPONENT1_LENGTH] = {
0 x93, 0 x54, 0 x14, 0 x6e, 0 x73, 0 x9d, 0 x4d, 0 x4b,
0 xfa, 0 x8c, 0 xf8, 0 xc8, 0 x2f, 0 x76, 0 x22, 0 xea,
0 x38, 0 x80, 0 x11, 0 x8f, 0 x05, 0 xfc, 0 x90, 0 x44,
0 x3b, 0 x50, 0 x2a, 0 x45, 0 x3d, 0 x4f, 0 xaf, 0 x02,
0 x7d, 0 xc2, 0 x7b, 0 xa2, 0 xd2, 0 x31, 0 x94, 0 x5c,
0 x2e, 0 xc3, 0 xd4, 0 x9f, 0 x47, 0 x09, 0 x37, 0 x6a,
0 xe3, 0 x85, 0 xf1, 0 xa3, 0 x0c, 0 xd8, 0 xf1, 0 xb4,
0 x53, 0 x7b, 0 xc4, 0 x71, 0 x02, 0 x86, 0 x42, 0 xbb,
0 x96, 0 xff, 0 x03, 0 xa3, 0 xb2, 0 x67, 0 x03, 0 xea,
0 x77, 0 x31, 0 xfb, 0 x4b, 0 x59, 0 x24, 0 xf7, 0 x07,
0 x59, 0 xfb, 0 xa9, 0 xba, 0 x1e, 0 x26, 0 x58, 0 x97,
0 x66, 0 xa1, 0 x56, 0 x49, 0 x39, 0 xb1, 0 x2c, 0 x55,
0 x0a, 0 x6a, 0 x78, 0 x18, 0 xba, 0 xdb, 0 xcf, 0 xf4,
0 xf7, 0 x32, 0 x35, 0 xa2, 0 x04, 0 xab, 0 xdc, 0 xa7,
0 x6d, 0 xd9, 0 xd5, 0 x06, 0 x6f, 0 xec, 0 x7d, 0 x40,
0 x4c, 0 xe8, 0 x0e, 0 xd0, 0 xc9, 0 xaa, 0 xdf, 0 x59
};
static const PRUint8 rsa_coefficient[FIPS_RSA_COEFFICIENT_LENGTH] = {
0 x17, 0 xd7, 0 xf5, 0 x0a, 0 xf0, 0 x68, 0 x97, 0 x96,
0 xc4, 0 x29, 0 x18, 0 x77, 0 x9a, 0 x1f, 0 xe3, 0 xf3,
0 x12, 0 x13, 0 x0f, 0 x7e, 0 x7b, 0 xb9, 0 xc1, 0 x91,
0 xf9, 0 xc7, 0 x08, 0 x56, 0 x5c, 0 xa4, 0 xbc, 0 x83,
0 x71, 0 xf9, 0 x78, 0 xd9, 0 x2b, 0 xec, 0 xfe, 0 x6b,
0 xdc, 0 x2f, 0 x63, 0 xc9, 0 xcd, 0 x50, 0 x14, 0 x5b,
0 xd3, 0 x6e, 0 x85, 0 x4d, 0 x0c, 0 xa2, 0 x0b, 0 xa0,
0 x09, 0 xb6, 0 xca, 0 x34, 0 x9c, 0 xc2, 0 xc1, 0 x4a,
0 xb0, 0 xbc, 0 x45, 0 x93, 0 xa5, 0 x7e, 0 x99, 0 xb5,
0 xbd, 0 xe4, 0 x69, 0 x29, 0 x08, 0 x28, 0 xd2, 0 xcd,
0 xab, 0 x24, 0 x78, 0 x48, 0 x41, 0 x26, 0 x0b, 0 x37,
0 xa3, 0 x43, 0 xd1, 0 x95, 0 x1a, 0 xd6, 0 xee, 0 x22,
0 x1c, 0 x00, 0 x0b, 0 xc2, 0 xb7, 0 xa4, 0 xa3, 0 x21,
0 xa9, 0 xcd, 0 xe4, 0 x69, 0 xd3, 0 x45, 0 x02, 0 xb1,
0 xb7, 0 x3a, 0 xbf, 0 x51, 0 x35, 0 x1b, 0 x78, 0 xc2,
0 xcf, 0 x0c, 0 x0d, 0 x60, 0 x09, 0 xa9, 0 x44, 0 x02
};
/* RSA Known Plaintext Message (1024-bits). */
static const PRUint8 rsa_known_plaintext_msg[FIPS_RSA_MESSAGE_LENGTH] = {
"Known plaintext message utilized"
"for RSA Encryption & Decryption"
"blocks SHA256, SHA384 and "
"SHA512 RSA Signature KAT tests. "
"Known plaintext message utilized"
"for RSA Encryption & Decryption"
"blocks SHA256, SHA384 and "
"SHA512 RSA Signature KAT tests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90, 0 xc2, 0 x2c, 0 x49, 0 xe2,
0 xfa, 0 xeb, 0 x91, 0 xc5, 0 xe5, 0 x83, 0 x13, 0 xc9,
0 x44, 0 x4b, 0 x95, 0 x2c, 0 x57, 0 x70, 0 x15, 0 x5c,
0 x64, 0 x8d, 0 x1a, 0 xfd, 0 x2a, 0 xc7, 0 xb2, 0 x9c,
0 x5c, 0 x99, 0 xd3, 0 x4a, 0 xfd, 0 xdd, 0 xf6, 0 x82,
0 x87, 0 x8c, 0 x5a, 0 xc4, 0 xa8, 0 x0d, 0 x2a, 0 xef,
0 xc3, 0 xa2, 0 x7e, 0 x8e, 0 x67, 0 x9f, 0 x6f, 0 x63,
0 xdb, 0 xbb, 0 x1d, 0 x31, 0 xc4, 0 xbb, 0 xbc, 0 x13,
0 x3f, 0 x54, 0 xc6, 0 xf6, 0 xc5, 0 x28, 0 x32, 0 xab,
0 x96, 0 x42, 0 x10, 0 x36, 0 x40, 0 x92, 0 xbb, 0 x57,
0 x55, 0 x38, 0 xf5, 0 x43, 0 x7e, 0 x43, 0 xc4, 0 x65,
0 x47, 0 x64, 0 xaa, 0 x0f, 0 x4c, 0 xe9, 0 x49, 0 x16,
0 xec, 0 x6a, 0 x50, 0 xfd, 0 x14, 0 x49, 0 xca, 0 xdb,
0 x44, 0 x54, 0 xca, 0 xbe, 0 xa3, 0 x0e, 0 x5f, 0 xef
};
static const RSAPublicKey bl_public_key = {
NULL,
{ FIPS_RSA_TYPE, (unsigned char *)rsa_modulus,
FIPS_RSA_MODULUS_LENGTH },
{ FIPS_RSA_TYPE, (unsigned char *)rsa_public_exponent,
FIPS_RSA_PUBLIC_EXPONENT_LENGTH }
};
static const RSAPrivateKey bl_private_key = {
NULL,
{ FIPS_RSA_TYPE, (unsigned char *)rsa_version,
FIPS_RSA_PRIVATE_VERSION_LENGTH },
{ FIPS_RSA_TYPE, (unsigned char *)rsa_modulus,
FIPS_RSA_MODULUS_LENGTH },
{ FIPS_RSA_TYPE, (unsigned char *)rsa_public_exponent,
FIPS_RSA_PUBLIC_EXPONENT_LENGTH },
{ FIPS_RSA_TYPE, (unsigned char *)rsa_private_exponent,
FIPS_RSA_PRIVATE_EXPONENT_LENGTH },
{ FIPS_RSA_TYPE, (unsigned char *)rsa_prime0,
FIPS_RSA_PRIME0_LENGTH },
{ FIPS_RSA_TYPE, (unsigned char *)rsa_prime1,
FIPS_RSA_PRIME1_LENGTH },
{ FIPS_RSA_TYPE, (unsigned char *)rsa_exponent0,
FIPS_RSA_EXPONENT0_LENGTH },
{ FIPS_RSA_TYPE, (unsigned char *)rsa_exponent1,
FIPS_RSA_EXPONENT1_LENGTH },
{ FIPS_RSA_TYPE, (unsigned char *)rsa_coefficient,
FIPS_RSA_COEFFICIENT_LENGTH }
};
/* RSA variables. */
SECStatus rsa_status;
RSAPublicKey rsa_public_key;
RSAPrivateKey rsa_private_key;
PRUint8 rsa_computed_ciphertext[FIPS_RSA_ENCRYPT_LENGTH];
PRUint8 rsa_computed_plaintext[FIPS_RSA_DECRYPT_LENGTH];
rsa_public_key = bl_public_key;
rsa_private_key = bl_private_key;
/**************************************************/
/* RSA Single-Round Known Answer Encryption Test. */
/**************************************************/
/* Perform RSA Public Key Encryption. */
rsa_status = RSA_PublicKeyOp(&rsa_public_key,
rsa_computed_ciphertext,
rsa_known_plaintext_msg);
if ((rsa_status != SECSuccess) ||
(PORT_Memcmp(rsa_computed_ciphertext, rsa_known_ciphertext,
FIPS_RSA_ENCRYPT_LENGTH) != 0 ))
goto rsa_loser;
/**************************************************/
/* RSA Single-Round Known Answer Decryption Test. */
/**************************************************/
/* Perform RSA Private Key Decryption. */
rsa_status = RSA_PrivateKeyOp(&rsa_private_key,
rsa_computed_plaintext,
rsa_known_ciphertext);
if ((rsa_status != SECSuccess) ||
(PORT_Memcmp(rsa_computed_plaintext, rsa_known_plaintext_msg,
FIPS_RSA_DECRYPT_LENGTH) != 0 ))
goto rsa_loser;
return (SECSuccess);
rsa_loser:
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return (SECFailure);
}
static SECStatus
freebl_fips_ECDSA_Test(ECParams *ecparams,
const PRUint8 *knownSignature,
unsigned int knownSignatureLen)
{
/* ECDSA Known Seed info for curves nistp256 and nistk283 */
static const PRUint8 ecdsa_Known_Seed[] = {
0 x6a, 0 x9b, 0 xf6, 0 xf7, 0 xce, 0 xed, 0 x79, 0 x11,
0 xf0, 0 xc7, 0 xc8, 0 x9a, 0 xa5, 0 xd1, 0 x57, 0 xb1,
0 x7b, 0 x5a, 0 x3b, 0 x76, 0 x4e, 0 x7b, 0 x7c, 0 xbc,
0 xf2, 0 x76, 0 x1c, 0 x1c, 0 x7f, 0 xc5, 0 x53, 0 x2f
};
static const PRUint8 msg[] = {
"Firefox and ThunderBird are awesome!"
};
unsigned char sha256[SHA256_LENGTH]; /* SHA-256 hash (256 bits) */
unsigned char sig[2 * MAX_ECKEY_LEN];
SECItem signature, digest;
ECPrivateKey *ecdsa_private_key = NULL;
ECPublicKey ecdsa_public_key;
SECStatus ecdsaStatus = SECSuccess;
/* Generates a new EC key pair. The private key is a supplied
* random value (in seed) and the public key is the result of
* performing a scalar point multiplication of that value with
* the curve's base point.
*/
ecdsaStatus = EC_NewKeyFromSeed(ecparams, &ecdsa_private_key,
ecdsa_Known_Seed,
sizeof (ecdsa_Known_Seed));
if (ecdsaStatus != SECSuccess) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return (SECFailure);
}
/* construct public key from private key. */
ecdsa_public_key.ecParams = ecdsa_private_key->ecParams;
ecdsa_public_key.publicValue = ecdsa_private_key->publicValue;
/* validate public key value */
ecdsaStatus = EC_ValidatePublicKey(&ecdsa_public_key.ecParams,
&ecdsa_public_key.publicValue);
if (ecdsaStatus != SECSuccess) {
goto loser;
}
/* validate public key value */
ecdsaStatus = EC_ValidatePublicKey(&ecdsa_private_key->ecParams,
&ecdsa_private_key->publicValue);
if (ecdsaStatus != SECSuccess) {
goto loser;
}
/***************************************************/
/* ECDSA Single-Round Known Answer Signature Test. */
/***************************************************/
ecdsaStatus = SHA256_HashBuf(sha256, msg, sizeof msg);
if (ecdsaStatus != SECSuccess) {
goto loser;
}
digest.type = siBuffer;
digest.data = sha256;
digest.len = SHA256_LENGTH;
memset(sig, 0 , sizeof sig);
signature.type = siBuffer;
signature.data = sig;
signature.len = sizeof sig;
ecdsaStatus = ECDSA_SignDigestWithSeed(ecdsa_private_key, &signature,
&digest, ecdsa_Known_Seed, sizeof ecdsa_Known_Seed);
if (ecdsaStatus != SECSuccess) {
goto loser;
}
if ((signature.len != knownSignatureLen) ||
(PORT_Memcmp(signature.data, knownSignature,
knownSignatureLen) != 0 )) {
ecdsaStatus = SECFailure;
goto loser;
}
/******************************************************/
/* ECDSA Single-Round Known Answer Verification Test. */
/******************************************************/
/* Perform ECDSA verification process. */
ecdsaStatus = ECDSA_VerifyDigest(&ecdsa_public_key, &signature, &digest);
loser:
/* free the memory for the private key arena*/
PORT_FreeArena(ecdsa_private_key->ecParams.arena, PR_FALSE);
if (ecdsaStatus != SECSuccess) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return (SECFailure);
}
return (SECSuccess);
}
static SECStatus
freebl_fips_ECDH_Test(ECParams *ecparams)
{
/* ECDH Known result (reused old CAVS vector) */
static const PRUint8 ecdh_known_pub_key_1[] = {
EC_POINT_FORM_UNCOMPRESSED,
/* pubX */
0 x16, 0 x81, 0 x32, 0 x86, 0 xc8, 0 xe4, 0 x3a, 0 x1f,
0 x5d, 0 xe3, 0 x06, 0 x22, 0 x8b, 0 x99, 0 x14, 0 x25,
0 xf7, 0 x9c, 0 x5b, 0 x1e, 0 x96, 0 x84, 0 x85, 0 x3b,
0 x17, 0 xfe, 0 xf3, 0 x1c, 0 x0e, 0 xed, 0 xc4, 0 xce,
/* pubY */
0 x7a, 0 x44, 0 xfe, 0 xbd, 0 x91, 0 x71, 0 x7d, 0 x73,
0 xd9, 0 x45, 0 xea, 0 xae, 0 x66, 0 x78, 0 xfa, 0 x6e,
0 x46, 0 xcd, 0 xfa, 0 x95, 0 x15, 0 x47, 0 x62, 0 x5d,
0 xbb, 0 x1b, 0 x9f, 0 xe6, 0 x39, 0 xfc, 0 xfd, 0 x47
};
static const PRUint8 ecdh_known_priv_key_2[] = {
0 xb4, 0 x2a, 0 xe3, 0 x69, 0 x19, 0 xec, 0 xf0, 0 x42,
0 x6d, 0 x45, 0 x8c, 0 x94, 0 x4a, 0 x26, 0 xa7, 0 x5c,
0 xea, 0 x9d, 0 xd9, 0 x0f, 0 x59, 0 xe0, 0 x1a, 0 x9d,
0 x7c, 0 xb7, 0 x1c, 0 x04, 0 x53, 0 xb8, 0 x98, 0 x5a
};
static const PRUint8 ecdh_known_hash_result[] = {
0 x16, 0 xf3, 0 x85, 0 xa2, 0 x41, 0 xf3, 0 x7f, 0 xc4,
0 x0b, 0 x56, 0 x47, 0 xee, 0 xa7, 0 x74, 0 xb9, 0 xdb,
0 xe1, 0 xfa, 0 x22, 0 xe9, 0 x04, 0 xf1, 0 xb6, 0 x12,
0 x4b, 0 x44, 0 x8a, 0 xbb, 0 xbc, 0 x08, 0 x2b, 0 xa7
};
SECItem ecdh_priv_2, ecdh_pub_1;
SECItem ZZ = { 0 , 0 , 0 };
SECStatus ecdhStatus = SECSuccess;
PRUint8 computed_hash_result[HASH_LENGTH_MAX];
ecdh_priv_2.data = (PRUint8 *)ecdh_known_priv_key_2;
ecdh_priv_2.len = sizeof (ecdh_known_priv_key_2);
ecdh_pub_1.data = (PRUint8 *)ecdh_known_pub_key_1;
ecdh_pub_1.len = sizeof (ecdh_known_pub_key_1);
/* Generates a new EC key pair. The private key is a supplied
* random value (in seed) and the public key is the result of
* performing a scalar point multiplication of that value with
* the curve's base point.
*/
ecdhStatus = ECDH_Derive(&ecdh_pub_1, ecparams, &ecdh_priv_2, PR_FALSE, &ZZ);
if (ecdhStatus != SECSuccess) {
goto loser;
}
ecdhStatus = SHA256_HashBuf(computed_hash_result, ZZ.data, ZZ.len);
if (ecdhStatus != SECSuccess) {
goto loser;
}
if (PORT_Memcmp(computed_hash_result, ecdh_known_hash_result,
sizeof (ecdh_known_hash_result)) != 0 ) {
ecdhStatus = SECFailure;
goto loser;
}
loser:
if (ZZ.data) {
SECITEM_FreeItem(&ZZ, PR_FALSE);
}
if (ecdhStatus != SECSuccess) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return (SECFailure);
}
return (SECSuccess);
}
static SECStatus
freebl_fips_EC_PowerUpSelfTest()
{
/* EC Known curve nistp256 == ECCCurve_X9_62_PRIME_256V1 params */
static const unsigned char p256_prime[] = {
0 xFF, 0 xFF, 0 xFF, 0 xFF, 0 x00, 0 x00, 0 x00, 0 x01, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00,
0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 xFF, 0 xFF, 0 xFF, 0 xFF, 0 xFF, 0 xFF,
0 xFF, 0 xFF, 0 xFF, 0 xFF, 0 xFF, 0 xFF
};
static const unsigned char p256_a[] = {
0 xFF, 0 xFF, 0 xFF, 0 xFF, 0 x00, 0 x00, 0 x00, 0 x01, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00,
0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 xFF, 0 xFF, 0 xFF, 0 xFF, 0 xFF, 0 xFF,
0 xFF, 0 xFF, 0 xFF, 0 xFF, 0 xFF, 0 xFC
};
static const unsigned char p256_b[] = {
0 x5A, 0 xC6, 0 x35, 0 xD8, 0 xAA, 0 x3A, 0 x93, 0 xE7, 0 xB3, 0 xEB, 0 xBD, 0 x55, 0 x76,
0 x98, 0 x86, 0 xBC, 0 x65, 0 x1D, 0 x06, 0 xB0, 0 xCC, 0 x53, 0 xB0, 0 xF6, 0 x3B, 0 xCE,
0 x3C, 0 x3E, 0 x27, 0 xD2, 0 x60, 0 x4B
};
static const unsigned char p256_base[] = {
0 x04,
0 x6B, 0 x17, 0 xD1, 0 xF2, 0 xE1, 0 x2C, 0 x42, 0 x47, 0 xF8, 0 xBC, 0 xE6, 0 xE5, 0 x63,
0 xA4, 0 x40, 0 xF2, 0 x77, 0 x03, 0 x7D, 0 x81, 0 x2D, 0 xEB, 0 x33, 0 xA0, 0 xF4, 0 xA1,
0 x39, 0 x45, 0 xD8, 0 x98, 0 xC2, 0 x96,
0 x4F, 0 xE3, 0 x42, 0 xE2, 0 xFE, 0 x1A, 0 x7F, 0 x9B, 0 x8E, 0 xE7, 0 xEB, 0 x4A, 0 x7C,
0 x0F, 0 x9E, 0 x16, 0 x2B, 0 xCE, 0 x33, 0 x57, 0 x6B, 0 x31, 0 x5E, 0 xCE, 0 xCB, 0 xB6,
0 x40, 0 x68, 0 x37, 0 xBF, 0 x51, 0 xF5
};
static const unsigned char p256_order[] = {
0 xFF, 0 xFF, 0 xFF, 0 xFF, 0 x00, 0 x00, 0 x00, 0 x00, 0 xFF, 0 xFF, 0 xFF, 0 xFF, 0 xFF,
0 xFF, 0 xFF, 0 xFF, 0 xBC, 0 xE6, 0 xFA, 0 xAD, 0 xA7, 0 x17, 0 x9E, 0 x84, 0 xF3, 0 xB9,
0 xCA, 0 xC2, 0 xFC, 0 x63, 0 x25, 0 x51
};
static const unsigned char p256_encoding[] = {
0 x06, 0 x08, 0 x2a, 0 x86, 0 x48, 0 xce, 0 x3d, 0 x03, 0 x01, 0 x07
};
static const ECParams ec_known_P256_Params = {
NULL,
ec_params_named, /* arena, type */
/* fieldID */
{ 256 , ec_field_plain, /* size and type */
{ { siBuffer, (unsigned char *)p256_prime, sizeof (p256_prime) } }, /* u.prime */
0 ,
0 ,
0 },
/* curve */
{ /* a = curvea b = curveb */
/* curve.a */
{ siBuffer, (unsigned char *)p256_a, sizeof (p256_a) },
/* curve.b */
{ siBuffer, (unsigned char *)p256_b, sizeof (p256_b) },
/* curve.seed */
{ siBuffer, NULL, 0 } },
/* base = 04xy*/
{ siBuffer, (unsigned char *)p256_base, sizeof (p256_base) },
/* order */
{ siBuffer, (unsigned char *)p256_order, sizeof (p256_order) },
1 , /* cofactor */
/* DEREncoding */
{ siBuffer, (unsigned char *)p256_encoding, sizeof (p256_encoding) },
ECCurve_X9_62_PRIME_256V1,
/* curveOID */
{ siBuffer, (unsigned char *)(p256_encoding) + 2 , sizeof (p256_encoding) - 2 },
};
static const PRUint8 ecdsa_known_P256_signature[] = {
0 x07, 0 xb1, 0 xcb, 0 x57, 0 x20, 0 xa7, 0 x10, 0 xd6,
0 x9d, 0 x37, 0 x4b, 0 x1c, 0 xdc, 0 x35, 0 x90, 0 xff,
0 x1a, 0 x2d, 0 x98, 0 x95, 0 x1b, 0 x2f, 0 xeb, 0 x7f,
0 xbb, 0 x81, 0 xca, 0 xc0, 0 x69, 0 x75, 0 xea, 0 xc5,
0 xa7, 0 xd2, 0 x20, 0 xdd, 0 x45, 0 xf9, 0 x2b, 0 xdd,
0 xda, 0 x98, 0 x99, 0 x5b, 0 x1c, 0 x02, 0 x3a, 0 x27,
0 x8b, 0 x7d, 0 xb6, 0 xed, 0 x0e, 0 xe0, 0 xa7, 0 xac,
0 xaa, 0 x36, 0 x2c, 0 xfa, 0 x1a, 0 xdf, 0 x0d, 0 xe1
};
ECParams ecparams;
SECStatus rv;
/* ECDSA GF(p) prime field curve test */
ecparams = ec_known_P256_Params;
rv = freebl_fips_ECDSA_Test(&ecparams,
ecdsa_known_P256_signature,
sizeof ecdsa_known_P256_signature);
if (rv != SECSuccess) {
return (SECFailure);
}
/* ECDH GF(p) prime field curve test */
rv = freebl_fips_ECDH_Test(&ecparams);
if (rv != SECSuccess) {
return (SECFailure);
}
return (SECSuccess);
}
static SECStatus
freebl_fips_DH_PowerUpSelfTest(void )
{
/* DH Known P (2048-bits) */
static const PRUint8 dh_known_P[] = {
0 xc2, 0 x79, 0 xbb, 0 x76, 0 x32, 0 x0d, 0 x43, 0 xfd,
0 x1b, 0 x8c, 0 xa2, 0 x3c, 0 x00, 0 xdd, 0 x6d, 0 xef,
0 xf8, 0 x1a, 0 xd9, 0 xc1,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07,
0 xce, 0 x46, 0 x82, 0 x75, 0 xf3, 0 x90, 0 xf3, 0 x21,
0 x55, 0 x74, 0 xc2, 0 xe4, 0 x96, 0 x7d, 0 xc3, 0 xe6,
0 x33, 0 xa5, 0 xc6, 0 x51, 0 xef, 0 xec, 0 x90, 0 x08
};
static const PRUint8 dh_known_x_2[] = {
0 x9e, 0 x9b, 0 xc3, 0 x25, 0 x53, 0 xf9, 0 xfc, 0 x92,
0 xb6, 0 xae, 0 x54, 0 x8e, 0 x23, 0 x4c, 0 x94, 0 xba,
0 x41, 0 xe6, 0 x29, 0 x33, 0 xb9, 0 xdb, 0 xff, 0 x6d,
0 xa8, 0 xb8, 0 x48, 0 x49, 0 x66, 0 x11, 0 xa6, 0 x13
};
static const PRUint8 dh_known_hash_result[] = {
0 x93, 0 xa2, 0 x89, 0 x1c, 0 x8a, 0 xc3, 0 x70, 0 xbf,
0 xa7, 0 xdf, 0 xb6, 0 xd7, 0 x82, 0 xfb, 0 x87, 0 x81,
0 x09, 0 x47, 0 xf3, 0 x9f, 0 x5a, 0 xbf, 0 x4f, 0 x3f,
0 x8e, 0 x5e, 0 x06, 0 xca, 0 x30, 0 xa7, 0 xaf, 0 x10
};
/* DH variables. */
SECStatus dhStatus;
SECItem dh_prime;
SECItem dh_pub_key_1;
SECItem dh_priv_key_2;
SECItem ZZ = { 0 , 0 , 0 };
PRUint8 computed_hash_result[HASH_LENGTH_MAX];
dh_prime.data = (PRUint8 *)dh_known_P;
dh_prime.len = sizeof (dh_known_P);
dh_pub_key_1.data = (PRUint8 *)dh_known_Y_1;
dh_pub_key_1.len = sizeof (dh_known_Y_1);
dh_priv_key_2.data = (PRUint8 *)dh_known_x_2;
dh_priv_key_2.len = sizeof (dh_known_x_2);
/* execute the derive */
dhStatus = DH_Derive(&dh_pub_key_1, &dh_prime, &dh_priv_key_2, &ZZ, dh_prime.len);
if (dhStatus != SECSuccess) {
goto loser;
}
dhStatus = SHA256_HashBuf(computed_hash_result, ZZ.data, ZZ.len);
if (dhStatus != SECSuccess) {
goto loser;
}
if (PORT_Memcmp(computed_hash_result, dh_known_hash_result,
sizeof (dh_known_hash_result)) != 0 ) {
dhStatus = SECFailure;
goto loser;
}
loser:
if (ZZ.data) {
SECITEM_FreeItem(&ZZ, PR_FALSE);
}
if (dhStatus != SECSuccess) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return (SECFailure);
}
return (SECSuccess);
}
static SECStatus
freebl_fips_RNG_PowerUpSelfTest(void )
{
SECStatus rng_status = SECSuccess;
/*******************************************/
/* Run the SP 800-90 Health tests */
/*******************************************/
rng_status = PRNGTEST_RunHealthTests();
if (rng_status != SECSuccess) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return SECFailure;
}
return (SECSuccess);
}
static SECStatus
freebl_fipsSoftwareIntegrityTest(const char *libname)
{
SECStatus rv = SECSuccess;
/* make sure that our check file signatures are OK */
if (!BLAPI_VerifySelf(libname)) {
rv = SECFailure;
}
return rv;
}
#define DO_FREEBL 1
#define DO_REST 2
static SECStatus
freebl_fipsPowerUpSelfTest(unsigned int tests)
{
SECStatus rv;
/*
* stand alone freebl. Test hash, and rng
*/
if (tests & DO_FREEBL) {
/* SHA-X Power-Up SelfTest(s). */
rv = freebl_fips_SHA_PowerUpSelfTest();
if (rv != SECSuccess)
return rv;
}
/*
* test the rest of the algorithms not accessed through freebl
* standalone */
if (tests & DO_REST) {
/* RNG Power-Up SelfTest(s). */
rv = freebl_fips_RNG_PowerUpSelfTest();
if (rv != SECSuccess)
return rv;
/* DES3 Power-Up SelfTest(s). */
rv = freebl_fips_DES3_PowerUpSelfTest();
if (rv != SECSuccess)
return rv;
/* AES Power-Up SelfTest(s) for 128-bit key. */
rv = freebl_fips_AES_PowerUpSelfTest(FIPS_AES_128_KEY_SIZE);
if (rv != SECSuccess)
return rv;
/* AES Power-Up SelfTest(s) for 192-bit key. */
rv = freebl_fips_AES_PowerUpSelfTest(FIPS_AES_192_KEY_SIZE);
if (rv != SECSuccess)
return rv;
/* AES Power-Up SelfTest(s) for 256-bit key. */
rv = freebl_fips_AES_PowerUpSelfTest(FIPS_AES_256_KEY_SIZE);
if (rv != SECSuccess)
return rv;
/* HMAC SHA-X Power-Up SelfTest(s). */
rv = freebl_fips_HMAC_PowerUpSelfTest();
if (rv != SECSuccess)
return rv;
/* TLS PRF Power-Up SelfTest(s). */
rv = freebl_fips_TLS_PowerUpSelfTest();
if (rv != SECSuccess)
return rv;
/* NOTE: RSA can only be tested in full freebl. It requires access to
* the locking primitives */
/* RSA Power-Up SelfTest(s). */
rv = freebl_fips_RSA_PowerUpSelfTest();
if (rv != SECSuccess)
return rv;
/* DH Power-Up SelfTest(s). */
rv = freebl_fips_DH_PowerUpSelfTest();
if (rv != SECSuccess)
return rv;
/* EC Power-Up SelfTest(s). */
rv = freebl_fips_EC_PowerUpSelfTest();
if (rv != SECSuccess)
return rv;
}
/* Passed Power-Up SelfTest(s). */
return (SECSuccess);
}
/*
* state variables. NOTE: freebl has two uses: a standalone use which
* provided limitted access to the hash functions throught the NSSLOWHASH_
* interface and an joint use from softoken, using the function pointer
* table. The standalone use can operation without nspr or nss-util, while
* the joint use requires both to be loaded. Certain functions (like RSA)
* needs locking from NSPR, for instance.
*
* At load time, we need to handle the two uses separately. If nspr and
* nss-util are loaded, then we can run all the selftests, but if nspr and
* nss-util are not loaded, then we can't run all the selftests, and we need
* to prevent the softoken function pointer table from operating until the
* libraries are loaded and we try to use them.
*/
static PRBool self_tests_freebl_ran = PR_FALSE;
static PRBool self_tests_ran = PR_FALSE;
static PRBool self_tests_freebl_success = PR_FALSE;
static PRBool self_tests_success = PR_FALSE;
/*
* accessors for freebl
*/
PRBool
BL_POSTRan(PRBool freebl_only)
{
SECStatus rv;
/* if the freebl self tests didn't run, there is something wrong with
* our on load tests */
if (!self_tests_freebl_ran) {
return PR_FALSE;
}
/* if all the self tests have run, we are good */
if (self_tests_ran) {
return PR_TRUE;
}
/* if we only care about the freebl tests, we are good */
if (freebl_only) {
return PR_TRUE;
}
/* run the rest of the self tests */
/* We could get there if freebl was loaded without the rest of the support
* libraries, but now we want to use more than just a standalone freebl.
* This requires the other libraries to be loaded.
* If they are now loaded, Try to run the rest of the selftests,
* otherwise fail (disabling access to these algorithms) */
self_tests_ran = PR_TRUE;
BL_Init(); /* required by RSA */
RNG_RNGInit(); /* required by RSA */
rv = freebl_fipsPowerUpSelfTest(DO_REST);
if (rv == SECSuccess) {
self_tests_success = PR_TRUE;
}
return PR_TRUE;
}
#include "blname.c"
/*
* This function is called at dll load time, the code tha makes this
* happen is platform specific on defined above.
*/
static void
bl_startup_tests(void )
{
const char *libraryName;
PRBool freebl_only = PR_FALSE;
SECStatus rv;
PORT_Assert(self_tests_freebl_ran == PR_FALSE);
PORT_Assert(self_tests_success == PR_FALSE);
self_tests_freebl_ran = PR_TRUE; /* we are running the tests */
self_tests_success = PR_FALSE; /* force it just in case */
self_tests_freebl_success = PR_FALSE; /* force it just in case */
#ifdef FREEBL_NO_DEPEND
rv = FREEBL_InitStubs();
if (rv != SECSuccess) {
freebl_only = PR_TRUE;
}
#endif
self_tests_freebl_ran = PR_TRUE; /* we are running the tests */
if (!freebl_only) {
self_tests_ran = PR_TRUE; /* we're running all the tests */
BL_Init(); /* needs to be called before RSA can be used */
RNG_RNGInit();
}
/* always run the post tests */
rv = freebl_fipsPowerUpSelfTest(freebl_only ? DO_FREEBL : DO_FREEBL | DO_REST);
if (rv != SECSuccess) {
return ;
}
libraryName = getLibName();
rv = freebl_fipsSoftwareIntegrityTest(libraryName);
if (rv != SECSuccess) {
return ;
}
/* posts are happy, allow the fips module to function now */
self_tests_freebl_success = PR_TRUE; /* we always test the freebl stuff */
if (!freebl_only) {
self_tests_success = PR_TRUE;
}
}
/*
* this is called from the freebl init entry points that controll access to
* all other freebl functions. This prevents freebl from operating if our
* power on selftest failed.
*/
SECStatus
BL_FIPSEntryOK(PRBool freebl_only, PRBool rerun)
{
#ifdef NSS_NO_INIT_SUPPORT
/* this should only be set on platforms that can't handle one of the INIT
* schemes. This code allows those platforms to continue to function,
* though they don't meet the strict NIST requirements. If NSS_NO_INIT_SUPPORT
* is not set, and init support has not been properly enabled, freebl
* will always fail because of the test below
*/
if (!self_tests_freebl_ran) {
bl_startup_tests();
}
#endif
if (rerun) {
/* reset the flags */
self_tests_freebl_ran = PR_FALSE;
self_tests_success = PR_FALSE;
self_tests_success = PR_FALSE;
self_tests_freebl_success = PR_FALSE;
bl_startup_tests();
}
/* if the general self tests succeeded, we're done */
if (self_tests_success) {
return SECSuccess;
}
/* standalone freebl can initialize */
if (freebl_only && self_tests_freebl_success) {
return SECSuccess;
}
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return SECFailure;
}
#endif
Messung V0.5 in Prozent C=90 H=90 G=90
¤ Dauer der Verarbeitung: 0.37 Sekunden
(vorverarbeitet am 2026-06-06)
¤
*© Formatika GbR, Deutschland