security/nss/lib/softoken/fipstest.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 * PKCS #11 FIPS Power-Up Self Test.
michael@0 3 *
michael@0 4 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 5 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 7
michael@0 8 #include "softoken.h" /* Required for RC2-ECB, RC2-CBC, RC4, DES-ECB, */
michael@0 9 /* DES-CBC, DES3-ECB, DES3-CBC, RSA */
michael@0 10 /* and DSA. */
michael@0 11 #include "seccomon.h" /* Required for RSA and DSA. */
michael@0 12 #include "lowkeyi.h" /* Required for RSA and DSA. */
michael@0 13 #include "pkcs11.h" /* Required for PKCS #11. */
michael@0 14 #include "secerr.h"
michael@0 15
michael@0 16 #ifndef NSS_DISABLE_ECC
michael@0 17 #include "ec.h" /* Required for ECDSA */
michael@0 18 #endif
michael@0 19
michael@0 20
michael@0 21 /* FIPS preprocessor directives for RC2-ECB and RC2-CBC. */
michael@0 22 #define FIPS_RC2_KEY_LENGTH 5 /* 40-bits */
michael@0 23 #define FIPS_RC2_ENCRYPT_LENGTH 8 /* 64-bits */
michael@0 24 #define FIPS_RC2_DECRYPT_LENGTH 8 /* 64-bits */
michael@0 25
michael@0 26
michael@0 27 /* FIPS preprocessor directives for RC4. */
michael@0 28 #define FIPS_RC4_KEY_LENGTH 5 /* 40-bits */
michael@0 29 #define FIPS_RC4_ENCRYPT_LENGTH 8 /* 64-bits */
michael@0 30 #define FIPS_RC4_DECRYPT_LENGTH 8 /* 64-bits */
michael@0 31
michael@0 32
michael@0 33 /* FIPS preprocessor directives for DES-ECB and DES-CBC. */
michael@0 34 #define FIPS_DES_ENCRYPT_LENGTH 8 /* 64-bits */
michael@0 35 #define FIPS_DES_DECRYPT_LENGTH 8 /* 64-bits */
michael@0 36
michael@0 37
michael@0 38 /* FIPS preprocessor directives for DES3-CBC and DES3-ECB. */
michael@0 39 #define FIPS_DES3_ENCRYPT_LENGTH 8 /* 64-bits */
michael@0 40 #define FIPS_DES3_DECRYPT_LENGTH 8 /* 64-bits */
michael@0 41
michael@0 42
michael@0 43 /* FIPS preprocessor directives for AES-ECB and AES-CBC. */
michael@0 44 #define FIPS_AES_BLOCK_SIZE 16 /* 128-bits */
michael@0 45 #define FIPS_AES_ENCRYPT_LENGTH 16 /* 128-bits */
michael@0 46 #define FIPS_AES_DECRYPT_LENGTH 16 /* 128-bits */
michael@0 47 #define FIPS_AES_128_KEY_SIZE 16 /* 128-bits */
michael@0 48 #define FIPS_AES_192_KEY_SIZE 24 /* 192-bits */
michael@0 49 #define FIPS_AES_256_KEY_SIZE 32 /* 256-bits */
michael@0 50
michael@0 51
michael@0 52 /* FIPS preprocessor directives for message digests */
michael@0 53 #define FIPS_KNOWN_HASH_MESSAGE_LENGTH 64 /* 512-bits */
michael@0 54
michael@0 55
michael@0 56 /* FIPS preprocessor directives for RSA. */
michael@0 57 #define FIPS_RSA_TYPE siBuffer
michael@0 58 #define FIPS_RSA_PUBLIC_EXPONENT_LENGTH 3 /* 24-bits */
michael@0 59 #define FIPS_RSA_PRIVATE_VERSION_LENGTH 1 /* 8-bits */
michael@0 60 #define FIPS_RSA_MESSAGE_LENGTH 256 /* 2048-bits */
michael@0 61 #define FIPS_RSA_COEFFICIENT_LENGTH 128 /* 1024-bits */
michael@0 62 #define FIPS_RSA_PRIME0_LENGTH 128 /* 1024-bits */
michael@0 63 #define FIPS_RSA_PRIME1_LENGTH 128 /* 1024-bits */
michael@0 64 #define FIPS_RSA_EXPONENT0_LENGTH 128 /* 1024-bits */
michael@0 65 #define FIPS_RSA_EXPONENT1_LENGTH 128 /* 1024-bits */
michael@0 66 #define FIPS_RSA_PRIVATE_EXPONENT_LENGTH 256 /* 2048-bits */
michael@0 67 #define FIPS_RSA_ENCRYPT_LENGTH 256 /* 2048-bits */
michael@0 68 #define FIPS_RSA_DECRYPT_LENGTH 256 /* 2048-bits */
michael@0 69 #define FIPS_RSA_SIGNATURE_LENGTH 256 /* 2048-bits */
michael@0 70 #define FIPS_RSA_MODULUS_LENGTH 256 /* 2048-bits */
michael@0 71
michael@0 72
michael@0 73 /* FIPS preprocessor directives for DSA. */
michael@0 74 #define FIPS_DSA_TYPE siBuffer
michael@0 75 #define FIPS_DSA_DIGEST_LENGTH 20 /* 160-bits */
michael@0 76 #define FIPS_DSA_SUBPRIME_LENGTH 20 /* 160-bits */
michael@0 77 #define FIPS_DSA_SIGNATURE_LENGTH 40 /* 320-bits */
michael@0 78 #define FIPS_DSA_PRIME_LENGTH 128 /* 1024-bits */
michael@0 79 #define FIPS_DSA_BASE_LENGTH 128 /* 1024-bits */
michael@0 80
michael@0 81 /* FIPS preprocessor directives for RNG. */
michael@0 82 #define FIPS_RNG_XKEY_LENGTH 32 /* 256-bits */
michael@0 83
michael@0 84 static CK_RV
michael@0 85 sftk_fips_RC2_PowerUpSelfTest( void )
michael@0 86 {
michael@0 87 /* RC2 Known Key (40-bits). */
michael@0 88 static const PRUint8 rc2_known_key[] = { "RSARC" };
michael@0 89
michael@0 90 /* RC2-CBC Known Initialization Vector (64-bits). */
michael@0 91 static const PRUint8 rc2_cbc_known_initialization_vector[] = {"Security"};
michael@0 92
michael@0 93 /* RC2 Known Plaintext (64-bits). */
michael@0 94 static const PRUint8 rc2_ecb_known_plaintext[] = {"Netscape"};
michael@0 95 static const PRUint8 rc2_cbc_known_plaintext[] = {"Netscape"};
michael@0 96
michael@0 97 /* RC2 Known Ciphertext (64-bits). */
michael@0 98 static const PRUint8 rc2_ecb_known_ciphertext[] = {
michael@0 99 0x1a,0x71,0x33,0x54,0x8d,0x5c,0xd2,0x30};
michael@0 100 static const PRUint8 rc2_cbc_known_ciphertext[] = {
michael@0 101 0xff,0x41,0xdb,0x94,0x8a,0x4c,0x33,0xb3};
michael@0 102
michael@0 103 /* RC2 variables. */
michael@0 104 PRUint8 rc2_computed_ciphertext[FIPS_RC2_ENCRYPT_LENGTH];
michael@0 105 PRUint8 rc2_computed_plaintext[FIPS_RC2_DECRYPT_LENGTH];
michael@0 106 RC2Context * rc2_context;
michael@0 107 unsigned int rc2_bytes_encrypted;
michael@0 108 unsigned int rc2_bytes_decrypted;
michael@0 109 SECStatus rc2_status;
michael@0 110
michael@0 111
michael@0 112 /******************************************************/
michael@0 113 /* RC2-ECB Single-Round Known Answer Encryption Test: */
michael@0 114 /******************************************************/
michael@0 115
michael@0 116 rc2_context = RC2_CreateContext( rc2_known_key, FIPS_RC2_KEY_LENGTH,
michael@0 117 NULL, NSS_RC2,
michael@0 118 FIPS_RC2_KEY_LENGTH );
michael@0 119
michael@0 120 if( rc2_context == NULL )
michael@0 121 return( CKR_HOST_MEMORY );
michael@0 122
michael@0 123 rc2_status = RC2_Encrypt( rc2_context, rc2_computed_ciphertext,
michael@0 124 &rc2_bytes_encrypted, FIPS_RC2_ENCRYPT_LENGTH,
michael@0 125 rc2_ecb_known_plaintext,
michael@0 126 FIPS_RC2_DECRYPT_LENGTH );
michael@0 127
michael@0 128 RC2_DestroyContext( rc2_context, PR_TRUE );
michael@0 129
michael@0 130 if( ( rc2_status != SECSuccess ) ||
michael@0 131 ( rc2_bytes_encrypted != FIPS_RC2_ENCRYPT_LENGTH ) ||
michael@0 132 ( PORT_Memcmp( rc2_computed_ciphertext, rc2_ecb_known_ciphertext,
michael@0 133 FIPS_RC2_ENCRYPT_LENGTH ) != 0 ) )
michael@0 134 return( CKR_DEVICE_ERROR );
michael@0 135
michael@0 136
michael@0 137 /******************************************************/
michael@0 138 /* RC2-ECB Single-Round Known Answer Decryption Test: */
michael@0 139 /******************************************************/
michael@0 140
michael@0 141 rc2_context = RC2_CreateContext( rc2_known_key, FIPS_RC2_KEY_LENGTH,
michael@0 142 NULL, NSS_RC2,
michael@0 143 FIPS_RC2_KEY_LENGTH );
michael@0 144
michael@0 145 if( rc2_context == NULL )
michael@0 146 return( CKR_HOST_MEMORY );
michael@0 147
michael@0 148 rc2_status = RC2_Decrypt( rc2_context, rc2_computed_plaintext,
michael@0 149 &rc2_bytes_decrypted, FIPS_RC2_DECRYPT_LENGTH,
michael@0 150 rc2_ecb_known_ciphertext,
michael@0 151 FIPS_RC2_ENCRYPT_LENGTH );
michael@0 152
michael@0 153 RC2_DestroyContext( rc2_context, PR_TRUE );
michael@0 154
michael@0 155 if( ( rc2_status != SECSuccess ) ||
michael@0 156 ( rc2_bytes_decrypted != FIPS_RC2_DECRYPT_LENGTH ) ||
michael@0 157 ( PORT_Memcmp( rc2_computed_plaintext, rc2_ecb_known_plaintext,
michael@0 158 FIPS_RC2_DECRYPT_LENGTH ) != 0 ) )
michael@0 159 return( CKR_DEVICE_ERROR );
michael@0 160
michael@0 161
michael@0 162 /******************************************************/
michael@0 163 /* RC2-CBC Single-Round Known Answer Encryption Test: */
michael@0 164 /******************************************************/
michael@0 165
michael@0 166 rc2_context = RC2_CreateContext( rc2_known_key, FIPS_RC2_KEY_LENGTH,
michael@0 167 rc2_cbc_known_initialization_vector,
michael@0 168 NSS_RC2_CBC, FIPS_RC2_KEY_LENGTH );
michael@0 169
michael@0 170 if( rc2_context == NULL )
michael@0 171 return( CKR_HOST_MEMORY );
michael@0 172
michael@0 173 rc2_status = RC2_Encrypt( rc2_context, rc2_computed_ciphertext,
michael@0 174 &rc2_bytes_encrypted, FIPS_RC2_ENCRYPT_LENGTH,
michael@0 175 rc2_cbc_known_plaintext,
michael@0 176 FIPS_RC2_DECRYPT_LENGTH );
michael@0 177
michael@0 178 RC2_DestroyContext( rc2_context, PR_TRUE );
michael@0 179
michael@0 180 if( ( rc2_status != SECSuccess ) ||
michael@0 181 ( rc2_bytes_encrypted != FIPS_RC2_ENCRYPT_LENGTH ) ||
michael@0 182 ( PORT_Memcmp( rc2_computed_ciphertext, rc2_cbc_known_ciphertext,
michael@0 183 FIPS_RC2_ENCRYPT_LENGTH ) != 0 ) )
michael@0 184 return( CKR_DEVICE_ERROR );
michael@0 185
michael@0 186
michael@0 187 /******************************************************/
michael@0 188 /* RC2-CBC Single-Round Known Answer Decryption Test: */
michael@0 189 /******************************************************/
michael@0 190
michael@0 191 rc2_context = RC2_CreateContext( rc2_known_key, FIPS_RC2_KEY_LENGTH,
michael@0 192 rc2_cbc_known_initialization_vector,
michael@0 193 NSS_RC2_CBC, FIPS_RC2_KEY_LENGTH );
michael@0 194
michael@0 195 if( rc2_context == NULL )
michael@0 196 return( CKR_HOST_MEMORY );
michael@0 197
michael@0 198 rc2_status = RC2_Decrypt( rc2_context, rc2_computed_plaintext,
michael@0 199 &rc2_bytes_decrypted, FIPS_RC2_DECRYPT_LENGTH,
michael@0 200 rc2_cbc_known_ciphertext,
michael@0 201 FIPS_RC2_ENCRYPT_LENGTH );
michael@0 202
michael@0 203 RC2_DestroyContext( rc2_context, PR_TRUE );
michael@0 204
michael@0 205 if( ( rc2_status != SECSuccess ) ||
michael@0 206 ( rc2_bytes_decrypted != FIPS_RC2_DECRYPT_LENGTH ) ||
michael@0 207 ( PORT_Memcmp( rc2_computed_plaintext, rc2_ecb_known_plaintext,
michael@0 208 FIPS_RC2_DECRYPT_LENGTH ) != 0 ) )
michael@0 209 return( CKR_DEVICE_ERROR );
michael@0 210
michael@0 211 return( CKR_OK );
michael@0 212 }
michael@0 213
michael@0 214
michael@0 215 static CK_RV
michael@0 216 sftk_fips_RC4_PowerUpSelfTest( void )
michael@0 217 {
michael@0 218 /* RC4 Known Key (40-bits). */
michael@0 219 static const PRUint8 rc4_known_key[] = { "RSARC" };
michael@0 220
michael@0 221 /* RC4 Known Plaintext (64-bits). */
michael@0 222 static const PRUint8 rc4_known_plaintext[] = { "Netscape" };
michael@0 223
michael@0 224 /* RC4 Known Ciphertext (64-bits). */
michael@0 225 static const PRUint8 rc4_known_ciphertext[] = {
michael@0 226 0x29,0x33,0xc7,0x9a,0x9d,0x6c,0x09,0xdd};
michael@0 227
michael@0 228 /* RC4 variables. */
michael@0 229 PRUint8 rc4_computed_ciphertext[FIPS_RC4_ENCRYPT_LENGTH];
michael@0 230 PRUint8 rc4_computed_plaintext[FIPS_RC4_DECRYPT_LENGTH];
michael@0 231 RC4Context * rc4_context;
michael@0 232 unsigned int rc4_bytes_encrypted;
michael@0 233 unsigned int rc4_bytes_decrypted;
michael@0 234 SECStatus rc4_status;
michael@0 235
michael@0 236
michael@0 237 /**************************************************/
michael@0 238 /* RC4 Single-Round Known Answer Encryption Test: */
michael@0 239 /**************************************************/
michael@0 240
michael@0 241 rc4_context = RC4_CreateContext( rc4_known_key, FIPS_RC4_KEY_LENGTH );
michael@0 242
michael@0 243 if( rc4_context == NULL )
michael@0 244 return( CKR_HOST_MEMORY );
michael@0 245
michael@0 246 rc4_status = RC4_Encrypt( rc4_context, rc4_computed_ciphertext,
michael@0 247 &rc4_bytes_encrypted, FIPS_RC4_ENCRYPT_LENGTH,
michael@0 248 rc4_known_plaintext, FIPS_RC4_DECRYPT_LENGTH );
michael@0 249
michael@0 250 RC4_DestroyContext( rc4_context, PR_TRUE );
michael@0 251
michael@0 252 if( ( rc4_status != SECSuccess ) ||
michael@0 253 ( rc4_bytes_encrypted != FIPS_RC4_ENCRYPT_LENGTH ) ||
michael@0 254 ( PORT_Memcmp( rc4_computed_ciphertext, rc4_known_ciphertext,
michael@0 255 FIPS_RC4_ENCRYPT_LENGTH ) != 0 ) )
michael@0 256 return( CKR_DEVICE_ERROR );
michael@0 257
michael@0 258
michael@0 259 /**************************************************/
michael@0 260 /* RC4 Single-Round Known Answer Decryption Test: */
michael@0 261 /**************************************************/
michael@0 262
michael@0 263 rc4_context = RC4_CreateContext( rc4_known_key, FIPS_RC4_KEY_LENGTH );
michael@0 264
michael@0 265 if( rc4_context == NULL )
michael@0 266 return( CKR_HOST_MEMORY );
michael@0 267
michael@0 268 rc4_status = RC4_Decrypt( rc4_context, rc4_computed_plaintext,
michael@0 269 &rc4_bytes_decrypted, FIPS_RC4_DECRYPT_LENGTH,
michael@0 270 rc4_known_ciphertext, FIPS_RC4_ENCRYPT_LENGTH );
michael@0 271
michael@0 272 RC4_DestroyContext( rc4_context, PR_TRUE );
michael@0 273
michael@0 274 if( ( rc4_status != SECSuccess ) ||
michael@0 275 ( rc4_bytes_decrypted != FIPS_RC4_DECRYPT_LENGTH ) ||
michael@0 276 ( PORT_Memcmp( rc4_computed_plaintext, rc4_known_plaintext,
michael@0 277 FIPS_RC4_DECRYPT_LENGTH ) != 0 ) )
michael@0 278 return( CKR_DEVICE_ERROR );
michael@0 279
michael@0 280 return( CKR_OK );
michael@0 281 }
michael@0 282
michael@0 283
michael@0 284 static CK_RV
michael@0 285 sftk_fips_DES_PowerUpSelfTest( void )
michael@0 286 {
michael@0 287 /* DES Known Key (56-bits). */
michael@0 288 static const PRUint8 des_known_key[] = { "ANSI DES" };
michael@0 289
michael@0 290 /* DES-CBC Known Initialization Vector (64-bits). */
michael@0 291 static const PRUint8 des_cbc_known_initialization_vector[] = { "Security" };
michael@0 292
michael@0 293 /* DES Known Plaintext (64-bits). */
michael@0 294 static const PRUint8 des_ecb_known_plaintext[] = { "Netscape" };
michael@0 295 static const PRUint8 des_cbc_known_plaintext[] = { "Netscape" };
michael@0 296
michael@0 297 /* DES Known Ciphertext (64-bits). */
michael@0 298 static const PRUint8 des_ecb_known_ciphertext[] = {
michael@0 299 0x26,0x14,0xe9,0xc3,0x28,0x80,0x50,0xb0};
michael@0 300 static const PRUint8 des_cbc_known_ciphertext[] = {
michael@0 301 0x5e,0x95,0x94,0x5d,0x76,0xa2,0xd3,0x7d};
michael@0 302
michael@0 303 /* DES variables. */
michael@0 304 PRUint8 des_computed_ciphertext[FIPS_DES_ENCRYPT_LENGTH];
michael@0 305 PRUint8 des_computed_plaintext[FIPS_DES_DECRYPT_LENGTH];
michael@0 306 DESContext * des_context;
michael@0 307 unsigned int des_bytes_encrypted;
michael@0 308 unsigned int des_bytes_decrypted;
michael@0 309 SECStatus des_status;
michael@0 310
michael@0 311
michael@0 312 /******************************************************/
michael@0 313 /* DES-ECB Single-Round Known Answer Encryption Test: */
michael@0 314 /******************************************************/
michael@0 315
michael@0 316 des_context = DES_CreateContext( des_known_key, NULL, NSS_DES, PR_TRUE );
michael@0 317
michael@0 318 if( des_context == NULL )
michael@0 319 return( CKR_HOST_MEMORY );
michael@0 320
michael@0 321 des_status = DES_Encrypt( des_context, des_computed_ciphertext,
michael@0 322 &des_bytes_encrypted, FIPS_DES_ENCRYPT_LENGTH,
michael@0 323 des_ecb_known_plaintext,
michael@0 324 FIPS_DES_DECRYPT_LENGTH );
michael@0 325
michael@0 326 DES_DestroyContext( des_context, PR_TRUE );
michael@0 327
michael@0 328 if( ( des_status != SECSuccess ) ||
michael@0 329 ( des_bytes_encrypted != FIPS_DES_ENCRYPT_LENGTH ) ||
michael@0 330 ( PORT_Memcmp( des_computed_ciphertext, des_ecb_known_ciphertext,
michael@0 331 FIPS_DES_ENCRYPT_LENGTH ) != 0 ) )
michael@0 332 return( CKR_DEVICE_ERROR );
michael@0 333
michael@0 334
michael@0 335 /******************************************************/
michael@0 336 /* DES-ECB Single-Round Known Answer Decryption Test: */
michael@0 337 /******************************************************/
michael@0 338
michael@0 339 des_context = DES_CreateContext( des_known_key, NULL, NSS_DES, PR_FALSE );
michael@0 340
michael@0 341 if( des_context == NULL )
michael@0 342 return( CKR_HOST_MEMORY );
michael@0 343
michael@0 344 des_status = DES_Decrypt( des_context, des_computed_plaintext,
michael@0 345 &des_bytes_decrypted, FIPS_DES_DECRYPT_LENGTH,
michael@0 346 des_ecb_known_ciphertext,
michael@0 347 FIPS_DES_ENCRYPT_LENGTH );
michael@0 348
michael@0 349 DES_DestroyContext( des_context, PR_TRUE );
michael@0 350
michael@0 351 if( ( des_status != SECSuccess ) ||
michael@0 352 ( des_bytes_decrypted != FIPS_DES_DECRYPT_LENGTH ) ||
michael@0 353 ( PORT_Memcmp( des_computed_plaintext, des_ecb_known_plaintext,
michael@0 354 FIPS_DES_DECRYPT_LENGTH ) != 0 ) )
michael@0 355 return( CKR_DEVICE_ERROR );
michael@0 356
michael@0 357
michael@0 358 /******************************************************/
michael@0 359 /* DES-CBC Single-Round Known Answer Encryption Test. */
michael@0 360 /******************************************************/
michael@0 361
michael@0 362 des_context = DES_CreateContext( des_known_key,
michael@0 363 des_cbc_known_initialization_vector,
michael@0 364 NSS_DES_CBC, PR_TRUE );
michael@0 365
michael@0 366 if( des_context == NULL )
michael@0 367 return( CKR_HOST_MEMORY );
michael@0 368
michael@0 369 des_status = DES_Encrypt( des_context, des_computed_ciphertext,
michael@0 370 &des_bytes_encrypted, FIPS_DES_ENCRYPT_LENGTH,
michael@0 371 des_cbc_known_plaintext,
michael@0 372 FIPS_DES_DECRYPT_LENGTH );
michael@0 373
michael@0 374 DES_DestroyContext( des_context, PR_TRUE );
michael@0 375
michael@0 376 if( ( des_status != SECSuccess ) ||
michael@0 377 ( des_bytes_encrypted != FIPS_DES_ENCRYPT_LENGTH ) ||
michael@0 378 ( PORT_Memcmp( des_computed_ciphertext, des_cbc_known_ciphertext,
michael@0 379 FIPS_DES_ENCRYPT_LENGTH ) != 0 ) )
michael@0 380 return( CKR_DEVICE_ERROR );
michael@0 381
michael@0 382
michael@0 383 /******************************************************/
michael@0 384 /* DES-CBC Single-Round Known Answer Decryption Test. */
michael@0 385 /******************************************************/
michael@0 386
michael@0 387 des_context = DES_CreateContext( des_known_key,
michael@0 388 des_cbc_known_initialization_vector,
michael@0 389 NSS_DES_CBC, PR_FALSE );
michael@0 390
michael@0 391 if( des_context == NULL )
michael@0 392 return( CKR_HOST_MEMORY );
michael@0 393
michael@0 394 des_status = DES_Decrypt( des_context, des_computed_plaintext,
michael@0 395 &des_bytes_decrypted, FIPS_DES_DECRYPT_LENGTH,
michael@0 396 des_cbc_known_ciphertext,
michael@0 397 FIPS_DES_ENCRYPT_LENGTH );
michael@0 398
michael@0 399 DES_DestroyContext( des_context, PR_TRUE );
michael@0 400
michael@0 401 if( ( des_status != SECSuccess ) ||
michael@0 402 ( des_bytes_decrypted != FIPS_DES_DECRYPT_LENGTH ) ||
michael@0 403 ( PORT_Memcmp( des_computed_plaintext, des_cbc_known_plaintext,
michael@0 404 FIPS_DES_DECRYPT_LENGTH ) != 0 ) )
michael@0 405 return( CKR_DEVICE_ERROR );
michael@0 406
michael@0 407 return( CKR_OK );
michael@0 408 }
michael@0 409
michael@0 410
michael@0 411 static CK_RV
michael@0 412 sftk_fips_DES3_PowerUpSelfTest( void )
michael@0 413 {
michael@0 414 /* DES3 Known Key (56-bits). */
michael@0 415 static const PRUint8 des3_known_key[] = { "ANSI Triple-DES Key Data" };
michael@0 416
michael@0 417 /* DES3-CBC Known Initialization Vector (64-bits). */
michael@0 418 static const PRUint8 des3_cbc_known_initialization_vector[] = { "Security" };
michael@0 419
michael@0 420 /* DES3 Known Plaintext (64-bits). */
michael@0 421 static const PRUint8 des3_ecb_known_plaintext[] = { "Netscape" };
michael@0 422 static const PRUint8 des3_cbc_known_plaintext[] = { "Netscape" };
michael@0 423
michael@0 424 /* DES3 Known Ciphertext (64-bits). */
michael@0 425 static const PRUint8 des3_ecb_known_ciphertext[] = {
michael@0 426 0x55,0x8e,0xad,0x3c,0xee,0x49,0x69,0xbe};
michael@0 427 static const PRUint8 des3_cbc_known_ciphertext[] = {
michael@0 428 0x43,0xdc,0x6a,0xc1,0xaf,0xa6,0x32,0xf5};
michael@0 429
michael@0 430 /* DES3 variables. */
michael@0 431 PRUint8 des3_computed_ciphertext[FIPS_DES3_ENCRYPT_LENGTH];
michael@0 432 PRUint8 des3_computed_plaintext[FIPS_DES3_DECRYPT_LENGTH];
michael@0 433 DESContext * des3_context;
michael@0 434 unsigned int des3_bytes_encrypted;
michael@0 435 unsigned int des3_bytes_decrypted;
michael@0 436 SECStatus des3_status;
michael@0 437
michael@0 438
michael@0 439 /*******************************************************/
michael@0 440 /* DES3-ECB Single-Round Known Answer Encryption Test. */
michael@0 441 /*******************************************************/
michael@0 442
michael@0 443 des3_context = DES_CreateContext( des3_known_key, NULL,
michael@0 444 NSS_DES_EDE3, PR_TRUE );
michael@0 445
michael@0 446 if( des3_context == NULL )
michael@0 447 return( CKR_HOST_MEMORY );
michael@0 448
michael@0 449 des3_status = DES_Encrypt( des3_context, des3_computed_ciphertext,
michael@0 450 &des3_bytes_encrypted, FIPS_DES3_ENCRYPT_LENGTH,
michael@0 451 des3_ecb_known_plaintext,
michael@0 452 FIPS_DES3_DECRYPT_LENGTH );
michael@0 453
michael@0 454 DES_DestroyContext( des3_context, PR_TRUE );
michael@0 455
michael@0 456 if( ( des3_status != SECSuccess ) ||
michael@0 457 ( des3_bytes_encrypted != FIPS_DES3_ENCRYPT_LENGTH ) ||
michael@0 458 ( PORT_Memcmp( des3_computed_ciphertext, des3_ecb_known_ciphertext,
michael@0 459 FIPS_DES3_ENCRYPT_LENGTH ) != 0 ) )
michael@0 460 return( CKR_DEVICE_ERROR );
michael@0 461
michael@0 462
michael@0 463 /*******************************************************/
michael@0 464 /* DES3-ECB Single-Round Known Answer Decryption Test. */
michael@0 465 /*******************************************************/
michael@0 466
michael@0 467 des3_context = DES_CreateContext( des3_known_key, NULL,
michael@0 468 NSS_DES_EDE3, PR_FALSE );
michael@0 469
michael@0 470 if( des3_context == NULL )
michael@0 471 return( CKR_HOST_MEMORY );
michael@0 472
michael@0 473 des3_status = DES_Decrypt( des3_context, des3_computed_plaintext,
michael@0 474 &des3_bytes_decrypted, FIPS_DES3_DECRYPT_LENGTH,
michael@0 475 des3_ecb_known_ciphertext,
michael@0 476 FIPS_DES3_ENCRYPT_LENGTH );
michael@0 477
michael@0 478 DES_DestroyContext( des3_context, PR_TRUE );
michael@0 479
michael@0 480 if( ( des3_status != SECSuccess ) ||
michael@0 481 ( des3_bytes_decrypted != FIPS_DES3_DECRYPT_LENGTH ) ||
michael@0 482 ( PORT_Memcmp( des3_computed_plaintext, des3_ecb_known_plaintext,
michael@0 483 FIPS_DES3_DECRYPT_LENGTH ) != 0 ) )
michael@0 484 return( CKR_DEVICE_ERROR );
michael@0 485
michael@0 486
michael@0 487 /*******************************************************/
michael@0 488 /* DES3-CBC Single-Round Known Answer Encryption Test. */
michael@0 489 /*******************************************************/
michael@0 490
michael@0 491 des3_context = DES_CreateContext( des3_known_key,
michael@0 492 des3_cbc_known_initialization_vector,
michael@0 493 NSS_DES_EDE3_CBC, PR_TRUE );
michael@0 494
michael@0 495 if( des3_context == NULL )
michael@0 496 return( CKR_HOST_MEMORY );
michael@0 497
michael@0 498 des3_status = DES_Encrypt( des3_context, des3_computed_ciphertext,
michael@0 499 &des3_bytes_encrypted, FIPS_DES3_ENCRYPT_LENGTH,
michael@0 500 des3_cbc_known_plaintext,
michael@0 501 FIPS_DES3_DECRYPT_LENGTH );
michael@0 502
michael@0 503 DES_DestroyContext( des3_context, PR_TRUE );
michael@0 504
michael@0 505 if( ( des3_status != SECSuccess ) ||
michael@0 506 ( des3_bytes_encrypted != FIPS_DES3_ENCRYPT_LENGTH ) ||
michael@0 507 ( PORT_Memcmp( des3_computed_ciphertext, des3_cbc_known_ciphertext,
michael@0 508 FIPS_DES3_ENCRYPT_LENGTH ) != 0 ) )
michael@0 509 return( CKR_DEVICE_ERROR );
michael@0 510
michael@0 511
michael@0 512 /*******************************************************/
michael@0 513 /* DES3-CBC Single-Round Known Answer Decryption Test. */
michael@0 514 /*******************************************************/
michael@0 515
michael@0 516 des3_context = DES_CreateContext( des3_known_key,
michael@0 517 des3_cbc_known_initialization_vector,
michael@0 518 NSS_DES_EDE3_CBC, PR_FALSE );
michael@0 519
michael@0 520 if( des3_context == NULL )
michael@0 521 return( CKR_HOST_MEMORY );
michael@0 522
michael@0 523 des3_status = DES_Decrypt( des3_context, des3_computed_plaintext,
michael@0 524 &des3_bytes_decrypted, FIPS_DES3_DECRYPT_LENGTH,
michael@0 525 des3_cbc_known_ciphertext,
michael@0 526 FIPS_DES3_ENCRYPT_LENGTH );
michael@0 527
michael@0 528 DES_DestroyContext( des3_context, PR_TRUE );
michael@0 529
michael@0 530 if( ( des3_status != SECSuccess ) ||
michael@0 531 ( des3_bytes_decrypted != FIPS_DES3_DECRYPT_LENGTH ) ||
michael@0 532 ( PORT_Memcmp( des3_computed_plaintext, des3_cbc_known_plaintext,
michael@0 533 FIPS_DES3_DECRYPT_LENGTH ) != 0 ) )
michael@0 534 return( CKR_DEVICE_ERROR );
michael@0 535
michael@0 536 return( CKR_OK );
michael@0 537 }
michael@0 538
michael@0 539
michael@0 540 /* AES self-test for 128-bit, 192-bit, or 256-bit key sizes*/
michael@0 541 static CK_RV
michael@0 542 sftk_fips_AES_PowerUpSelfTest( int aes_key_size )
michael@0 543 {
michael@0 544 /* AES Known Key (up to 256-bits). */
michael@0 545 static const PRUint8 aes_known_key[] =
michael@0 546 { "AES-128 RIJNDAELLEADNJIR 821-SEA" };
michael@0 547
michael@0 548 /* AES-CBC Known Initialization Vector (128-bits). */
michael@0 549 static const PRUint8 aes_cbc_known_initialization_vector[] =
michael@0 550 { "SecurityytiruceS" };
michael@0 551
michael@0 552 /* AES Known Plaintext (128-bits). (blocksize is 128-bits) */
michael@0 553 static const PRUint8 aes_known_plaintext[] = { "NetscapeepacsteN" };
michael@0 554
michael@0 555 /* AES Known Ciphertext (128-bit key). */
michael@0 556 static const PRUint8 aes_ecb128_known_ciphertext[] = {
michael@0 557 0x3c,0xa5,0x96,0xf3,0x34,0x6a,0x96,0xc1,
michael@0 558 0x03,0x88,0x16,0x7b,0x20,0xbf,0x35,0x47 };
michael@0 559
michael@0 560 static const PRUint8 aes_cbc128_known_ciphertext[] = {
michael@0 561 0xcf,0x15,0x1d,0x4f,0x96,0xe4,0x4f,0x63,
michael@0 562 0x15,0x54,0x14,0x1d,0x4e,0xd8,0xd5,0xea };
michael@0 563
michael@0 564 /* AES Known Ciphertext (192-bit key). */
michael@0 565 static const PRUint8 aes_ecb192_known_ciphertext[] = {
michael@0 566 0xa0,0x18,0x62,0xed,0x88,0x19,0xcb,0x62,
michael@0 567 0x88,0x1d,0x4d,0xfe,0x84,0x02,0x89,0x0e };
michael@0 568
michael@0 569 static const PRUint8 aes_cbc192_known_ciphertext[] = {
michael@0 570 0x83,0xf7,0xa4,0x76,0xd1,0x6f,0x07,0xbe,
michael@0 571 0x07,0xbc,0x43,0x2f,0x6d,0xad,0x29,0xe1 };
michael@0 572
michael@0 573 /* AES Known Ciphertext (256-bit key). */
michael@0 574 static const PRUint8 aes_ecb256_known_ciphertext[] = {
michael@0 575 0xdb,0xa6,0x52,0x01,0x8a,0x70,0xae,0x66,
michael@0 576 0x3a,0x99,0xd8,0x95,0x7f,0xfb,0x01,0x67 };
michael@0 577
michael@0 578 static const PRUint8 aes_cbc256_known_ciphertext[] = {
michael@0 579 0x37,0xea,0x07,0x06,0x31,0x1c,0x59,0x27,
michael@0 580 0xc5,0xc5,0x68,0x71,0x6e,0x34,0x40,0x16 };
michael@0 581
michael@0 582 const PRUint8 *aes_ecb_known_ciphertext =
michael@0 583 ( aes_key_size == FIPS_AES_128_KEY_SIZE) ? aes_ecb128_known_ciphertext :
michael@0 584 ( aes_key_size == FIPS_AES_192_KEY_SIZE) ? aes_ecb192_known_ciphertext :
michael@0 585 aes_ecb256_known_ciphertext;
michael@0 586
michael@0 587 const PRUint8 *aes_cbc_known_ciphertext =
michael@0 588 ( aes_key_size == FIPS_AES_128_KEY_SIZE) ? aes_cbc128_known_ciphertext :
michael@0 589 ( aes_key_size == FIPS_AES_192_KEY_SIZE) ? aes_cbc192_known_ciphertext :
michael@0 590 aes_cbc256_known_ciphertext;
michael@0 591
michael@0 592 /* AES variables. */
michael@0 593 PRUint8 aes_computed_ciphertext[FIPS_AES_ENCRYPT_LENGTH];
michael@0 594 PRUint8 aes_computed_plaintext[FIPS_AES_DECRYPT_LENGTH];
michael@0 595 AESContext * aes_context;
michael@0 596 unsigned int aes_bytes_encrypted;
michael@0 597 unsigned int aes_bytes_decrypted;
michael@0 598 SECStatus aes_status;
michael@0 599
michael@0 600 /*check if aes_key_size is 128, 192, or 256 bits */
michael@0 601 if ((aes_key_size != FIPS_AES_128_KEY_SIZE) &&
michael@0 602 (aes_key_size != FIPS_AES_192_KEY_SIZE) &&
michael@0 603 (aes_key_size != FIPS_AES_256_KEY_SIZE))
michael@0 604 return( CKR_DEVICE_ERROR );
michael@0 605
michael@0 606 /******************************************************/
michael@0 607 /* AES-ECB Single-Round Known Answer Encryption Test: */
michael@0 608 /******************************************************/
michael@0 609
michael@0 610 aes_context = AES_CreateContext( aes_known_key, NULL, NSS_AES, PR_TRUE,
michael@0 611 aes_key_size, FIPS_AES_BLOCK_SIZE );
michael@0 612
michael@0 613 if( aes_context == NULL )
michael@0 614 return( CKR_HOST_MEMORY );
michael@0 615
michael@0 616 aes_status = AES_Encrypt( aes_context, aes_computed_ciphertext,
michael@0 617 &aes_bytes_encrypted, FIPS_AES_ENCRYPT_LENGTH,
michael@0 618 aes_known_plaintext,
michael@0 619 FIPS_AES_DECRYPT_LENGTH );
michael@0 620
michael@0 621 AES_DestroyContext( aes_context, PR_TRUE );
michael@0 622
michael@0 623 if( ( aes_status != SECSuccess ) ||
michael@0 624 ( aes_bytes_encrypted != FIPS_AES_ENCRYPT_LENGTH ) ||
michael@0 625 ( PORT_Memcmp( aes_computed_ciphertext, aes_ecb_known_ciphertext,
michael@0 626 FIPS_AES_ENCRYPT_LENGTH ) != 0 ) )
michael@0 627 return( CKR_DEVICE_ERROR );
michael@0 628
michael@0 629
michael@0 630 /******************************************************/
michael@0 631 /* AES-ECB Single-Round Known Answer Decryption Test: */
michael@0 632 /******************************************************/
michael@0 633
michael@0 634 aes_context = AES_CreateContext( aes_known_key, NULL, NSS_AES, PR_FALSE,
michael@0 635 aes_key_size, FIPS_AES_BLOCK_SIZE );
michael@0 636
michael@0 637 if( aes_context == NULL )
michael@0 638 return( CKR_HOST_MEMORY );
michael@0 639
michael@0 640 aes_status = AES_Decrypt( aes_context, aes_computed_plaintext,
michael@0 641 &aes_bytes_decrypted, FIPS_AES_DECRYPT_LENGTH,
michael@0 642 aes_ecb_known_ciphertext,
michael@0 643 FIPS_AES_ENCRYPT_LENGTH );
michael@0 644
michael@0 645 AES_DestroyContext( aes_context, PR_TRUE );
michael@0 646
michael@0 647 if( ( aes_status != SECSuccess ) ||
michael@0 648 ( aes_bytes_decrypted != FIPS_AES_DECRYPT_LENGTH ) ||
michael@0 649 ( PORT_Memcmp( aes_computed_plaintext, aes_known_plaintext,
michael@0 650 FIPS_AES_DECRYPT_LENGTH ) != 0 ) )
michael@0 651 return( CKR_DEVICE_ERROR );
michael@0 652
michael@0 653
michael@0 654 /******************************************************/
michael@0 655 /* AES-CBC Single-Round Known Answer Encryption Test. */
michael@0 656 /******************************************************/
michael@0 657
michael@0 658 aes_context = AES_CreateContext( aes_known_key,
michael@0 659 aes_cbc_known_initialization_vector,
michael@0 660 NSS_AES_CBC, PR_TRUE, aes_key_size,
michael@0 661 FIPS_AES_BLOCK_SIZE );
michael@0 662
michael@0 663 if( aes_context == NULL )
michael@0 664 return( CKR_HOST_MEMORY );
michael@0 665
michael@0 666 aes_status = AES_Encrypt( aes_context, aes_computed_ciphertext,
michael@0 667 &aes_bytes_encrypted, FIPS_AES_ENCRYPT_LENGTH,
michael@0 668 aes_known_plaintext,
michael@0 669 FIPS_AES_DECRYPT_LENGTH );
michael@0 670
michael@0 671 AES_DestroyContext( aes_context, PR_TRUE );
michael@0 672
michael@0 673 if( ( aes_status != SECSuccess ) ||
michael@0 674 ( aes_bytes_encrypted != FIPS_AES_ENCRYPT_LENGTH ) ||
michael@0 675 ( PORT_Memcmp( aes_computed_ciphertext, aes_cbc_known_ciphertext,
michael@0 676 FIPS_AES_ENCRYPT_LENGTH ) != 0 ) )
michael@0 677 return( CKR_DEVICE_ERROR );
michael@0 678
michael@0 679
michael@0 680 /******************************************************/
michael@0 681 /* AES-CBC Single-Round Known Answer Decryption Test. */
michael@0 682 /******************************************************/
michael@0 683
michael@0 684 aes_context = AES_CreateContext( aes_known_key,
michael@0 685 aes_cbc_known_initialization_vector,
michael@0 686 NSS_AES_CBC, PR_FALSE, aes_key_size,
michael@0 687 FIPS_AES_BLOCK_SIZE );
michael@0 688
michael@0 689 if( aes_context == NULL )
michael@0 690 return( CKR_HOST_MEMORY );
michael@0 691
michael@0 692 aes_status = AES_Decrypt( aes_context, aes_computed_plaintext,
michael@0 693 &aes_bytes_decrypted, FIPS_AES_DECRYPT_LENGTH,
michael@0 694 aes_cbc_known_ciphertext,
michael@0 695 FIPS_AES_ENCRYPT_LENGTH );
michael@0 696
michael@0 697 AES_DestroyContext( aes_context, PR_TRUE );
michael@0 698
michael@0 699 if( ( aes_status != SECSuccess ) ||
michael@0 700 ( aes_bytes_decrypted != FIPS_AES_DECRYPT_LENGTH ) ||
michael@0 701 ( PORT_Memcmp( aes_computed_plaintext, aes_known_plaintext,
michael@0 702 FIPS_AES_DECRYPT_LENGTH ) != 0 ) )
michael@0 703 return( CKR_DEVICE_ERROR );
michael@0 704
michael@0 705 return( CKR_OK );
michael@0 706 }
michael@0 707
michael@0 708 /* Known Hash Message (512-bits). Used for all hashes (incl. SHA-N [N>1]). */
michael@0 709 static const PRUint8 known_hash_message[] = {
michael@0 710 "The test message for the MD2, MD5, and SHA-1 hashing algorithms." };
michael@0 711
michael@0 712
michael@0 713 static CK_RV
michael@0 714 sftk_fips_MD2_PowerUpSelfTest( void )
michael@0 715 {
michael@0 716 /* MD2 Known Digest Message (128-bits). */
michael@0 717 static const PRUint8 md2_known_digest[] = {
michael@0 718 0x41,0x5a,0x12,0xb2,0x3f,0x28,0x97,0x17,
michael@0 719 0x0c,0x71,0x4e,0xcc,0x40,0xc8,0x1d,0x1b};
michael@0 720
michael@0 721 /* MD2 variables. */
michael@0 722 MD2Context * md2_context;
michael@0 723 unsigned int md2_bytes_hashed;
michael@0 724 PRUint8 md2_computed_digest[MD2_LENGTH];
michael@0 725
michael@0 726
michael@0 727 /***********************************************/
michael@0 728 /* MD2 Single-Round Known Answer Hashing Test. */
michael@0 729 /***********************************************/
michael@0 730
michael@0 731 md2_context = MD2_NewContext();
michael@0 732
michael@0 733 if( md2_context == NULL )
michael@0 734 return( CKR_HOST_MEMORY );
michael@0 735
michael@0 736 MD2_Begin( md2_context );
michael@0 737
michael@0 738 MD2_Update( md2_context, known_hash_message,
michael@0 739 FIPS_KNOWN_HASH_MESSAGE_LENGTH );
michael@0 740
michael@0 741 MD2_End( md2_context, md2_computed_digest, &md2_bytes_hashed, MD2_LENGTH );
michael@0 742
michael@0 743 MD2_DestroyContext( md2_context , PR_TRUE );
michael@0 744
michael@0 745 if( ( md2_bytes_hashed != MD2_LENGTH ) ||
michael@0 746 ( PORT_Memcmp( md2_computed_digest, md2_known_digest,
michael@0 747 MD2_LENGTH ) != 0 ) )
michael@0 748 return( CKR_DEVICE_ERROR );
michael@0 749
michael@0 750 return( CKR_OK );
michael@0 751 }
michael@0 752
michael@0 753
michael@0 754 static CK_RV
michael@0 755 sftk_fips_MD5_PowerUpSelfTest( void )
michael@0 756 {
michael@0 757 /* MD5 Known Digest Message (128-bits). */
michael@0 758 static const PRUint8 md5_known_digest[] = {
michael@0 759 0x25,0xc8,0xc0,0x10,0xc5,0x6e,0x68,0x28,
michael@0 760 0x28,0xa4,0xa5,0xd2,0x98,0x9a,0xea,0x2d};
michael@0 761
michael@0 762 /* MD5 variables. */
michael@0 763 PRUint8 md5_computed_digest[MD5_LENGTH];
michael@0 764 SECStatus md5_status;
michael@0 765
michael@0 766
michael@0 767 /***********************************************/
michael@0 768 /* MD5 Single-Round Known Answer Hashing Test. */
michael@0 769 /***********************************************/
michael@0 770
michael@0 771 md5_status = MD5_HashBuf( md5_computed_digest, known_hash_message,
michael@0 772 FIPS_KNOWN_HASH_MESSAGE_LENGTH );
michael@0 773
michael@0 774 if( ( md5_status != SECSuccess ) ||
michael@0 775 ( PORT_Memcmp( md5_computed_digest, md5_known_digest,
michael@0 776 MD5_LENGTH ) != 0 ) )
michael@0 777 return( CKR_DEVICE_ERROR );
michael@0 778
michael@0 779 return( CKR_OK );
michael@0 780 }
michael@0 781
michael@0 782 /****************************************************/
michael@0 783 /* Single Round HMAC SHA-X test */
michael@0 784 /****************************************************/
michael@0 785 static SECStatus
michael@0 786 sftk_fips_HMAC(unsigned char *hmac_computed,
michael@0 787 const PRUint8 *secret_key,
michael@0 788 unsigned int secret_key_length,
michael@0 789 const PRUint8 *message,
michael@0 790 unsigned int message_length,
michael@0 791 HASH_HashType hashAlg )
michael@0 792 {
michael@0 793 SECStatus hmac_status = SECFailure;
michael@0 794 HMACContext *cx = NULL;
michael@0 795 SECHashObject *hashObj = NULL;
michael@0 796 unsigned int bytes_hashed = 0;
michael@0 797
michael@0 798 hashObj = (SECHashObject *) HASH_GetRawHashObject(hashAlg);
michael@0 799
michael@0 800 if (!hashObj)
michael@0 801 return( SECFailure );
michael@0 802
michael@0 803 cx = HMAC_Create(hashObj, secret_key,
michael@0 804 secret_key_length,
michael@0 805 PR_TRUE); /* PR_TRUE for in FIPS mode */
michael@0 806
michael@0 807 if (cx == NULL)
michael@0 808 return( SECFailure );
michael@0 809
michael@0 810 HMAC_Begin(cx);
michael@0 811 HMAC_Update(cx, message, message_length);
michael@0 812 hmac_status = HMAC_Finish(cx, hmac_computed, &bytes_hashed,
michael@0 813 hashObj->length);
michael@0 814
michael@0 815 HMAC_Destroy(cx, PR_TRUE);
michael@0 816
michael@0 817 return( hmac_status );
michael@0 818 }
michael@0 819
michael@0 820 static CK_RV
michael@0 821 sftk_fips_HMAC_PowerUpSelfTest( void )
michael@0 822 {
michael@0 823 static const PRUint8 HMAC_known_secret_key[] = {
michael@0 824 "Firefox and ThunderBird are awesome!"};
michael@0 825
michael@0 826 static const PRUint8 HMAC_known_secret_key_length
michael@0 827 = sizeof HMAC_known_secret_key;
michael@0 828
michael@0 829 /* known SHA1 hmac (20 bytes) */
michael@0 830 static const PRUint8 known_SHA1_hmac[] = {
michael@0 831 0xd5, 0x85, 0xf6, 0x5b, 0x39, 0xfa, 0xb9, 0x05,
michael@0 832 0x3b, 0x57, 0x1d, 0x61, 0xe7, 0xb8, 0x84, 0x1e,
michael@0 833 0x5d, 0x0e, 0x1e, 0x11};
michael@0 834
michael@0 835 /* known SHA224 hmac (28 bytes) */
michael@0 836 static const PRUint8 known_SHA224_hmac[] = {
michael@0 837 0x1c, 0xc3, 0x06, 0x8e, 0xce, 0x37, 0x68, 0xfb,
michael@0 838 0x1a, 0x82, 0x4a, 0xbe, 0x2b, 0x00, 0x51, 0xf8,
michael@0 839 0x9d, 0xb6, 0xe0, 0x90, 0x0d, 0x00, 0xc9, 0x64,
michael@0 840 0x9a, 0xb8, 0x98, 0x4e};
michael@0 841
michael@0 842 /* known SHA256 hmac (32 bytes) */
michael@0 843 static const PRUint8 known_SHA256_hmac[] = {
michael@0 844 0x05, 0x75, 0x9a, 0x9e, 0x70, 0x5e, 0xe7, 0x44,
michael@0 845 0xe2, 0x46, 0x4b, 0x92, 0x22, 0x14, 0x22, 0xe0,
michael@0 846 0x1b, 0x92, 0x8a, 0x0c, 0xfe, 0xf5, 0x49, 0xe9,
michael@0 847 0xa7, 0x1b, 0x56, 0x7d, 0x1d, 0x29, 0x40, 0x48};
michael@0 848
michael@0 849 /* known SHA384 hmac (48 bytes) */
michael@0 850 static const PRUint8 known_SHA384_hmac[] = {
michael@0 851 0xcd, 0x56, 0x14, 0xec, 0x05, 0x53, 0x06, 0x2b,
michael@0 852 0x7e, 0x9c, 0x8a, 0x18, 0x5e, 0xea, 0xf3, 0x91,
michael@0 853 0x33, 0xfb, 0x64, 0xf6, 0xe3, 0x9f, 0x89, 0x0b,
michael@0 854 0xaf, 0xbe, 0x83, 0x4d, 0x3f, 0x3c, 0x43, 0x4d,
michael@0 855 0x4a, 0x0c, 0x56, 0x98, 0xf8, 0xca, 0xb4, 0xaa,
michael@0 856 0x9a, 0xf4, 0x0a, 0xaf, 0x4f, 0x69, 0xca, 0x87};
michael@0 857
michael@0 858 /* known SHA512 hmac (64 bytes) */
michael@0 859 static const PRUint8 known_SHA512_hmac[] = {
michael@0 860 0xf6, 0x0e, 0x97, 0x12, 0x00, 0x67, 0x6e, 0xb9,
michael@0 861 0x0c, 0xb2, 0x63, 0xf0, 0x60, 0xac, 0x75, 0x62,
michael@0 862 0x70, 0x95, 0x2a, 0x52, 0x22, 0xee, 0xdd, 0xd2,
michael@0 863 0x71, 0xb1, 0xe8, 0x26, 0x33, 0xd3, 0x13, 0x27,
michael@0 864 0xcb, 0xff, 0x44, 0xef, 0x87, 0x97, 0x16, 0xfb,
michael@0 865 0xd3, 0x0b, 0x48, 0xbe, 0x12, 0x4e, 0xda, 0xb1,
michael@0 866 0x89, 0x90, 0xfb, 0x06, 0x0c, 0xbe, 0xe5, 0xc4,
michael@0 867 0xff, 0x24, 0x37, 0x3d, 0xc7, 0xe4, 0xe4, 0x37};
michael@0 868
michael@0 869 SECStatus hmac_status;
michael@0 870 PRUint8 hmac_computed[HASH_LENGTH_MAX];
michael@0 871
michael@0 872 /***************************************************/
michael@0 873 /* HMAC SHA-1 Single-Round Known Answer HMAC Test. */
michael@0 874 /***************************************************/
michael@0 875
michael@0 876 hmac_status = sftk_fips_HMAC(hmac_computed,
michael@0 877 HMAC_known_secret_key,
michael@0 878 HMAC_known_secret_key_length,
michael@0 879 known_hash_message,
michael@0 880 FIPS_KNOWN_HASH_MESSAGE_LENGTH,
michael@0 881 HASH_AlgSHA1);
michael@0 882
michael@0 883 if( ( hmac_status != SECSuccess ) ||
michael@0 884 ( PORT_Memcmp( hmac_computed, known_SHA1_hmac,
michael@0 885 SHA1_LENGTH ) != 0 ) )
michael@0 886 return( CKR_DEVICE_ERROR );
michael@0 887
michael@0 888 /***************************************************/
michael@0 889 /* HMAC SHA-224 Single-Round Known Answer Test. */
michael@0 890 /***************************************************/
michael@0 891
michael@0 892 hmac_status = sftk_fips_HMAC(hmac_computed,
michael@0 893 HMAC_known_secret_key,
michael@0 894 HMAC_known_secret_key_length,
michael@0 895 known_hash_message,
michael@0 896 FIPS_KNOWN_HASH_MESSAGE_LENGTH,
michael@0 897 HASH_AlgSHA224);
michael@0 898
michael@0 899 if( ( hmac_status != SECSuccess ) ||
michael@0 900 ( PORT_Memcmp( hmac_computed, known_SHA224_hmac,
michael@0 901 SHA224_LENGTH ) != 0 ) )
michael@0 902 return( CKR_DEVICE_ERROR );
michael@0 903
michael@0 904 /***************************************************/
michael@0 905 /* HMAC SHA-256 Single-Round Known Answer Test. */
michael@0 906 /***************************************************/
michael@0 907
michael@0 908 hmac_status = sftk_fips_HMAC(hmac_computed,
michael@0 909 HMAC_known_secret_key,
michael@0 910 HMAC_known_secret_key_length,
michael@0 911 known_hash_message,
michael@0 912 FIPS_KNOWN_HASH_MESSAGE_LENGTH,
michael@0 913 HASH_AlgSHA256);
michael@0 914
michael@0 915 if( ( hmac_status != SECSuccess ) ||
michael@0 916 ( PORT_Memcmp( hmac_computed, known_SHA256_hmac,
michael@0 917 SHA256_LENGTH ) != 0 ) )
michael@0 918 return( CKR_DEVICE_ERROR );
michael@0 919
michael@0 920 /***************************************************/
michael@0 921 /* HMAC SHA-384 Single-Round Known Answer Test. */
michael@0 922 /***************************************************/
michael@0 923
michael@0 924 hmac_status = sftk_fips_HMAC(hmac_computed,
michael@0 925 HMAC_known_secret_key,
michael@0 926 HMAC_known_secret_key_length,
michael@0 927 known_hash_message,
michael@0 928 FIPS_KNOWN_HASH_MESSAGE_LENGTH,
michael@0 929 HASH_AlgSHA384);
michael@0 930
michael@0 931 if( ( hmac_status != SECSuccess ) ||
michael@0 932 ( PORT_Memcmp( hmac_computed, known_SHA384_hmac,
michael@0 933 SHA384_LENGTH ) != 0 ) )
michael@0 934 return( CKR_DEVICE_ERROR );
michael@0 935
michael@0 936 /***************************************************/
michael@0 937 /* HMAC SHA-512 Single-Round Known Answer Test. */
michael@0 938 /***************************************************/
michael@0 939
michael@0 940 hmac_status = sftk_fips_HMAC(hmac_computed,
michael@0 941 HMAC_known_secret_key,
michael@0 942 HMAC_known_secret_key_length,
michael@0 943 known_hash_message,
michael@0 944 FIPS_KNOWN_HASH_MESSAGE_LENGTH,
michael@0 945 HASH_AlgSHA512);
michael@0 946
michael@0 947 if( ( hmac_status != SECSuccess ) ||
michael@0 948 ( PORT_Memcmp( hmac_computed, known_SHA512_hmac,
michael@0 949 SHA512_LENGTH ) != 0 ) )
michael@0 950 return( CKR_DEVICE_ERROR );
michael@0 951
michael@0 952 return( CKR_OK );
michael@0 953 }
michael@0 954
michael@0 955 static CK_RV
michael@0 956 sftk_fips_SHA_PowerUpSelfTest( void )
michael@0 957 {
michael@0 958 /* SHA-1 Known Digest Message (160-bits). */
michael@0 959 static const PRUint8 sha1_known_digest[] = {
michael@0 960 0x0a,0x6d,0x07,0xba,0x1e,0xbd,0x8a,0x1b,
michael@0 961 0x72,0xf6,0xc7,0x22,0xf1,0x27,0x9f,0xf0,
michael@0 962 0xe0,0x68,0x47,0x7a};
michael@0 963
michael@0 964 /* SHA-224 Known Digest Message (224-bits). */
michael@0 965 static const PRUint8 sha224_known_digest[] = {
michael@0 966 0x89,0x5e,0x7f,0xfd,0x0e,0xd8,0x35,0x6f,
michael@0 967 0x64,0x6d,0xf2,0xde,0x5e,0xed,0xa6,0x7f,
michael@0 968 0x29,0xd1,0x12,0x73,0x42,0x84,0x95,0x4f,
michael@0 969 0x8e,0x08,0xe5,0xcb};
michael@0 970
michael@0 971 /* SHA-256 Known Digest Message (256-bits). */
michael@0 972 static const PRUint8 sha256_known_digest[] = {
michael@0 973 0x38,0xa9,0xc1,0xf0,0x35,0xf6,0x5d,0x61,
michael@0 974 0x11,0xd4,0x0b,0xdc,0xce,0x35,0x14,0x8d,
michael@0 975 0xf2,0xdd,0xaf,0xaf,0xcf,0xb7,0x87,0xe9,
michael@0 976 0x96,0xa5,0xd2,0x83,0x62,0x46,0x56,0x79};
michael@0 977
michael@0 978 /* SHA-384 Known Digest Message (384-bits). */
michael@0 979 static const PRUint8 sha384_known_digest[] = {
michael@0 980 0x11,0xfe,0x1c,0x00,0x89,0x48,0xde,0xb3,
michael@0 981 0x99,0xee,0x1c,0x18,0xb4,0x10,0xfb,0xfe,
michael@0 982 0xe3,0xa8,0x2c,0xf3,0x04,0xb0,0x2f,0xc8,
michael@0 983 0xa3,0xc4,0x5e,0xea,0x7e,0x60,0x48,0x7b,
michael@0 984 0xce,0x2c,0x62,0xf7,0xbc,0xa7,0xe8,0xa3,
michael@0 985 0xcf,0x24,0xce,0x9c,0xe2,0x8b,0x09,0x72};
michael@0 986
michael@0 987 /* SHA-512 Known Digest Message (512-bits). */
michael@0 988 static const PRUint8 sha512_known_digest[] = {
michael@0 989 0xc8,0xb3,0x27,0xf9,0x0b,0x24,0xc8,0xbf,
michael@0 990 0x4c,0xba,0x33,0x54,0xf2,0x31,0xbf,0xdb,
michael@0 991 0xab,0xfd,0xb3,0x15,0xd7,0xfa,0x48,0x99,
michael@0 992 0x07,0x60,0x0f,0x57,0x41,0x1a,0xdd,0x28,
michael@0 993 0x12,0x55,0x25,0xac,0xba,0x3a,0x99,0x12,
michael@0 994 0x2c,0x7a,0x8f,0x75,0x3a,0xe1,0x06,0x6f,
michael@0 995 0x30,0x31,0xc9,0x33,0xc6,0x1b,0x90,0x1a,
michael@0 996 0x6c,0x98,0x9a,0x87,0xd0,0xb2,0xf8,0x07};
michael@0 997
michael@0 998 /* SHA-X variables. */
michael@0 999 PRUint8 sha_computed_digest[HASH_LENGTH_MAX];
michael@0 1000 SECStatus sha_status;
michael@0 1001
michael@0 1002 /*************************************************/
michael@0 1003 /* SHA-1 Single-Round Known Answer Hashing Test. */
michael@0 1004 /*************************************************/
michael@0 1005
michael@0 1006 sha_status = SHA1_HashBuf( sha_computed_digest, known_hash_message,
michael@0 1007 FIPS_KNOWN_HASH_MESSAGE_LENGTH );
michael@0 1008
michael@0 1009 if( ( sha_status != SECSuccess ) ||
michael@0 1010 ( PORT_Memcmp( sha_computed_digest, sha1_known_digest,
michael@0 1011 SHA1_LENGTH ) != 0 ) )
michael@0 1012 return( CKR_DEVICE_ERROR );
michael@0 1013
michael@0 1014 /***************************************************/
michael@0 1015 /* SHA-224 Single-Round Known Answer Hashing Test. */
michael@0 1016 /***************************************************/
michael@0 1017
michael@0 1018 sha_status = SHA224_HashBuf( sha_computed_digest, known_hash_message,
michael@0 1019 FIPS_KNOWN_HASH_MESSAGE_LENGTH );
michael@0 1020
michael@0 1021 if( ( sha_status != SECSuccess ) ||
michael@0 1022 ( PORT_Memcmp( sha_computed_digest, sha224_known_digest,
michael@0 1023 SHA224_LENGTH ) != 0 ) )
michael@0 1024 return( CKR_DEVICE_ERROR );
michael@0 1025
michael@0 1026 /***************************************************/
michael@0 1027 /* SHA-256 Single-Round Known Answer Hashing Test. */
michael@0 1028 /***************************************************/
michael@0 1029
michael@0 1030 sha_status = SHA256_HashBuf( sha_computed_digest, known_hash_message,
michael@0 1031 FIPS_KNOWN_HASH_MESSAGE_LENGTH );
michael@0 1032
michael@0 1033 if( ( sha_status != SECSuccess ) ||
michael@0 1034 ( PORT_Memcmp( sha_computed_digest, sha256_known_digest,
michael@0 1035 SHA256_LENGTH ) != 0 ) )
michael@0 1036 return( CKR_DEVICE_ERROR );
michael@0 1037
michael@0 1038 /***************************************************/
michael@0 1039 /* SHA-384 Single-Round Known Answer Hashing Test. */
michael@0 1040 /***************************************************/
michael@0 1041
michael@0 1042 sha_status = SHA384_HashBuf( sha_computed_digest, known_hash_message,
michael@0 1043 FIPS_KNOWN_HASH_MESSAGE_LENGTH );
michael@0 1044
michael@0 1045 if( ( sha_status != SECSuccess ) ||
michael@0 1046 ( PORT_Memcmp( sha_computed_digest, sha384_known_digest,
michael@0 1047 SHA384_LENGTH ) != 0 ) )
michael@0 1048 return( CKR_DEVICE_ERROR );
michael@0 1049
michael@0 1050 /***************************************************/
michael@0 1051 /* SHA-512 Single-Round Known Answer Hashing Test. */
michael@0 1052 /***************************************************/
michael@0 1053
michael@0 1054 sha_status = SHA512_HashBuf( sha_computed_digest, known_hash_message,
michael@0 1055 FIPS_KNOWN_HASH_MESSAGE_LENGTH );
michael@0 1056
michael@0 1057 if( ( sha_status != SECSuccess ) ||
michael@0 1058 ( PORT_Memcmp( sha_computed_digest, sha512_known_digest,
michael@0 1059 SHA512_LENGTH ) != 0 ) )
michael@0 1060 return( CKR_DEVICE_ERROR );
michael@0 1061
michael@0 1062 return( CKR_OK );
michael@0 1063 }
michael@0 1064
michael@0 1065 /*
michael@0 1066 * Single round RSA Signature Known Answer Test
michael@0 1067 */
michael@0 1068 static SECStatus
michael@0 1069 sftk_fips_RSA_PowerUpSigSelfTest (HASH_HashType shaAlg,
michael@0 1070 NSSLOWKEYPublicKey *rsa_public_key,
michael@0 1071 NSSLOWKEYPrivateKey *rsa_private_key,
michael@0 1072 const unsigned char *rsa_known_msg,
michael@0 1073 const unsigned int rsa_kmsg_length,
michael@0 1074 const unsigned char *rsa_known_signature)
michael@0 1075 {
michael@0 1076 SECOidTag shaOid; /* SHA OID */
michael@0 1077 unsigned char sha[HASH_LENGTH_MAX]; /* SHA digest */
michael@0 1078 unsigned int shaLength = 0; /* length of SHA */
michael@0 1079 unsigned int rsa_bytes_signed;
michael@0 1080 unsigned char rsa_computed_signature[FIPS_RSA_SIGNATURE_LENGTH];
michael@0 1081 SECStatus rv;
michael@0 1082
michael@0 1083 if (shaAlg == HASH_AlgSHA1) {
michael@0 1084 if (SHA1_HashBuf(sha, rsa_known_msg, rsa_kmsg_length)
michael@0 1085 != SECSuccess) {
michael@0 1086 goto loser;
michael@0 1087 }
michael@0 1088 shaLength = SHA1_LENGTH;
michael@0 1089 shaOid = SEC_OID_SHA1;
michael@0 1090 } else if (shaAlg == HASH_AlgSHA256) {
michael@0 1091 if (SHA256_HashBuf(sha, rsa_known_msg, rsa_kmsg_length)
michael@0 1092 != SECSuccess) {
michael@0 1093 goto loser;
michael@0 1094 }
michael@0 1095 shaLength = SHA256_LENGTH;
michael@0 1096 shaOid = SEC_OID_SHA256;
michael@0 1097 } else if (shaAlg == HASH_AlgSHA384) {
michael@0 1098 if (SHA384_HashBuf(sha, rsa_known_msg, rsa_kmsg_length)
michael@0 1099 != SECSuccess) {
michael@0 1100 goto loser;
michael@0 1101 }
michael@0 1102 shaLength = SHA384_LENGTH;
michael@0 1103 shaOid = SEC_OID_SHA384;
michael@0 1104 } else if (shaAlg == HASH_AlgSHA512) {
michael@0 1105 if (SHA512_HashBuf(sha, rsa_known_msg, rsa_kmsg_length)
michael@0 1106 != SECSuccess) {
michael@0 1107 goto loser;
michael@0 1108 }
michael@0 1109 shaLength = SHA512_LENGTH;
michael@0 1110 shaOid = SEC_OID_SHA512;
michael@0 1111 } else {
michael@0 1112 goto loser;
michael@0 1113 }
michael@0 1114
michael@0 1115 /*************************************************/
michael@0 1116 /* RSA Single-Round Known Answer Signature Test. */
michael@0 1117 /*************************************************/
michael@0 1118
michael@0 1119 /* Perform RSA signature with the RSA private key. */
michael@0 1120 rv = RSA_HashSign( shaOid,
michael@0 1121 rsa_private_key,
michael@0 1122 rsa_computed_signature,
michael@0 1123 &rsa_bytes_signed,
michael@0 1124 FIPS_RSA_SIGNATURE_LENGTH,
michael@0 1125 sha,
michael@0 1126 shaLength);
michael@0 1127
michael@0 1128 if( ( rv != SECSuccess ) ||
michael@0 1129 ( rsa_bytes_signed != FIPS_RSA_SIGNATURE_LENGTH ) ||
michael@0 1130 ( PORT_Memcmp( rsa_computed_signature, rsa_known_signature,
michael@0 1131 FIPS_RSA_SIGNATURE_LENGTH ) != 0 ) ) {
michael@0 1132 goto loser;
michael@0 1133 }
michael@0 1134
michael@0 1135 /****************************************************/
michael@0 1136 /* RSA Single-Round Known Answer Verification Test. */
michael@0 1137 /****************************************************/
michael@0 1138
michael@0 1139 /* Perform RSA verification with the RSA public key. */
michael@0 1140 rv = RSA_HashCheckSign( shaOid,
michael@0 1141 rsa_public_key,
michael@0 1142 rsa_computed_signature,
michael@0 1143 rsa_bytes_signed,
michael@0 1144 sha,
michael@0 1145 shaLength);
michael@0 1146
michael@0 1147 if( rv != SECSuccess ) {
michael@0 1148 goto loser;
michael@0 1149 }
michael@0 1150 return( SECSuccess );
michael@0 1151
michael@0 1152 loser:
michael@0 1153
michael@0 1154 return( SECFailure );
michael@0 1155
michael@0 1156 }
michael@0 1157
michael@0 1158 static CK_RV
michael@0 1159 sftk_fips_RSA_PowerUpSelfTest( void )
michael@0 1160 {
michael@0 1161 /* RSA Known Modulus used in both Public/Private Key Values (2048-bits). */
michael@0 1162 static const PRUint8 rsa_modulus[FIPS_RSA_MODULUS_LENGTH] = {
michael@0 1163 0xb8, 0x15, 0x00, 0x33, 0xda, 0x0c, 0x9d, 0xa5,
michael@0 1164 0x14, 0x8c, 0xde, 0x1f, 0x23, 0x07, 0x54, 0xe2,
michael@0 1165 0xc6, 0xb9, 0x51, 0x04, 0xc9, 0x65, 0x24, 0x6e,
michael@0 1166 0x0a, 0x46, 0x34, 0x5c, 0x37, 0x86, 0x6b, 0x88,
michael@0 1167 0x24, 0x27, 0xac, 0xa5, 0x02, 0x79, 0xfb, 0xed,
michael@0 1168 0x75, 0xc5, 0x3f, 0x6e, 0xdf, 0x05, 0x5f, 0x0f,
michael@0 1169 0x20, 0x70, 0xa0, 0x5b, 0x85, 0xdb, 0xac, 0xb9,
michael@0 1170 0x5f, 0x02, 0xc2, 0x64, 0x1e, 0x84, 0x5b, 0x3e,
michael@0 1171 0xad, 0xbf, 0xf6, 0x2e, 0x51, 0xd6, 0xad, 0xf7,
michael@0 1172 0xa7, 0x86, 0x75, 0x86, 0xec, 0xa7, 0xe1, 0xf7,
michael@0 1173 0x08, 0xbf, 0xdc, 0x56, 0xb1, 0x3b, 0xca, 0xd8,
michael@0 1174 0xfc, 0x51, 0xdf, 0x9a, 0x2a, 0x37, 0x06, 0xf2,
michael@0 1175 0xd1, 0x6b, 0x9a, 0x5e, 0x2a, 0xe5, 0x20, 0x57,
michael@0 1176 0x35, 0x9f, 0x1f, 0x98, 0xcf, 0x40, 0xc7, 0xd6,
michael@0 1177 0x98, 0xdb, 0xde, 0xf5, 0x64, 0x53, 0xf7, 0x9d,
michael@0 1178 0x45, 0xf3, 0xd6, 0x78, 0xb9, 0xe3, 0xa3, 0x20,
michael@0 1179 0xcd, 0x79, 0x43, 0x35, 0xef, 0xd7, 0xfb, 0xb9,
michael@0 1180 0x80, 0x88, 0x27, 0x2f, 0x63, 0xa8, 0x67, 0x3d,
michael@0 1181 0x4a, 0xfa, 0x06, 0xc6, 0xd2, 0x86, 0x0b, 0xa7,
michael@0 1182 0x28, 0xfd, 0xe0, 0x1e, 0x93, 0x4b, 0x17, 0x2e,
michael@0 1183 0xb0, 0x11, 0x6f, 0xc6, 0x2b, 0x98, 0x0f, 0x15,
michael@0 1184 0xe3, 0x87, 0x16, 0x7a, 0x7c, 0x67, 0x3e, 0x12,
michael@0 1185 0x2b, 0xf8, 0xbe, 0x48, 0xc1, 0x97, 0x47, 0xf4,
michael@0 1186 0x1f, 0x81, 0x80, 0x12, 0x28, 0xe4, 0x7b, 0x1e,
michael@0 1187 0xb7, 0x00, 0xa4, 0xde, 0xaa, 0xfb, 0x0f, 0x77,
michael@0 1188 0x84, 0xa3, 0xd6, 0xb2, 0x03, 0x48, 0xdd, 0x53,
michael@0 1189 0x8b, 0x46, 0x41, 0x28, 0x52, 0xc4, 0x53, 0xf0,
michael@0 1190 0x1c, 0x95, 0xd9, 0x36, 0xe0, 0x0f, 0x26, 0x46,
michael@0 1191 0x9c, 0x61, 0x0e, 0x80, 0xca, 0x86, 0xaf, 0x39,
michael@0 1192 0x95, 0xe5, 0x60, 0x43, 0x61, 0x3e, 0x2b, 0xb4,
michael@0 1193 0xe8, 0xbd, 0x8d, 0x77, 0x62, 0xf5, 0x32, 0x43,
michael@0 1194 0x2f, 0x4b, 0x65, 0x82, 0x14, 0xdd, 0x29, 0x5b};
michael@0 1195
michael@0 1196 /* RSA Known Public Key Values (24-bits). */
michael@0 1197 static const PRUint8 rsa_public_exponent[FIPS_RSA_PUBLIC_EXPONENT_LENGTH]
michael@0 1198 = { 0x01, 0x00, 0x01 };
michael@0 1199 /* RSA Known Private Key Values (version is 8-bits), */
michael@0 1200 /* (private exponent is 2048-bits), */
michael@0 1201 /* (private prime0 is 1024-bits), */
michael@0 1202 /* (private prime1 is 1024-bits), */
michael@0 1203 /* (private prime exponent0 is 1024-bits), */
michael@0 1204 /* (private prime exponent1 is 1024-bits), */
michael@0 1205 /* and (private coefficient is 1024-bits). */
michael@0 1206 static const PRUint8 rsa_version[] = { 0x00 };
michael@0 1207
michael@0 1208 static const PRUint8 rsa_private_exponent[FIPS_RSA_PRIVATE_EXPONENT_LENGTH]
michael@0 1209 = {0x29, 0x08, 0x05, 0x53, 0x89, 0x76, 0xe6, 0x6c,
michael@0 1210 0xb5, 0x77, 0xf0, 0xca, 0xdf, 0xf3, 0xf2, 0x67,
michael@0 1211 0xda, 0x03, 0xd4, 0x9b, 0x4c, 0x88, 0xce, 0xe5,
michael@0 1212 0xf8, 0x44, 0x4d, 0xc7, 0x80, 0x58, 0xe5, 0xff,
michael@0 1213 0x22, 0x8f, 0xf5, 0x5b, 0x92, 0x81, 0xbe, 0x35,
michael@0 1214 0xdf, 0xda, 0x67, 0x99, 0x3e, 0xfc, 0xe3, 0x83,
michael@0 1215 0x6b, 0xa7, 0xaf, 0x16, 0xb7, 0x6f, 0x8f, 0xc0,
michael@0 1216 0x81, 0xfd, 0x0b, 0x77, 0x65, 0x95, 0xfb, 0x00,
michael@0 1217 0xad, 0x99, 0xec, 0x35, 0xc6, 0xe8, 0x23, 0x3e,
michael@0 1218 0xe0, 0x88, 0x88, 0x09, 0xdb, 0x16, 0x50, 0xb7,
michael@0 1219 0xcf, 0xab, 0x74, 0x61, 0x9e, 0x7f, 0xc5, 0x67,
michael@0 1220 0x38, 0x56, 0xc7, 0x90, 0x85, 0x78, 0x5e, 0x84,
michael@0 1221 0x21, 0x49, 0xea, 0xce, 0xb2, 0xa0, 0xff, 0xe4,
michael@0 1222 0x70, 0x7f, 0x57, 0x7b, 0xa8, 0x36, 0xb8, 0x54,
michael@0 1223 0x8d, 0x1d, 0xf5, 0x44, 0x9d, 0x68, 0x59, 0xf9,
michael@0 1224 0x24, 0x6e, 0x85, 0x8f, 0xc3, 0x5f, 0x8a, 0x2c,
michael@0 1225 0x94, 0xb7, 0xbc, 0x0e, 0xa5, 0xef, 0x93, 0x06,
michael@0 1226 0x38, 0xcd, 0x07, 0x0c, 0xae, 0xb8, 0x44, 0x1a,
michael@0 1227 0xd8, 0xe7, 0xf5, 0x9a, 0x1e, 0x9c, 0x18, 0xc7,
michael@0 1228 0x6a, 0xc2, 0x7f, 0x28, 0x01, 0x4f, 0xb4, 0xb8,
michael@0 1229 0x90, 0x97, 0x5a, 0x43, 0x38, 0xad, 0xe8, 0x95,
michael@0 1230 0x68, 0x83, 0x1a, 0x1b, 0x10, 0x07, 0xe6, 0x02,
michael@0 1231 0x52, 0x1f, 0xbf, 0x76, 0x6b, 0x46, 0xd6, 0xfb,
michael@0 1232 0xc3, 0xbe, 0xb5, 0xac, 0x52, 0x53, 0x01, 0x1c,
michael@0 1233 0xf3, 0xc5, 0xeb, 0x64, 0xf2, 0x1e, 0xc4, 0x38,
michael@0 1234 0xe9, 0xaa, 0xd9, 0xc3, 0x72, 0x51, 0xa5, 0x44,
michael@0 1235 0x58, 0x69, 0x0b, 0x1b, 0x98, 0x7f, 0xf2, 0x23,
michael@0 1236 0xff, 0xeb, 0xf0, 0x75, 0x24, 0xcf, 0xc5, 0x1e,
michael@0 1237 0xb8, 0x6a, 0xc5, 0x2f, 0x4f, 0x23, 0x50, 0x7d,
michael@0 1238 0x15, 0x9d, 0x19, 0x7a, 0x0b, 0x82, 0xe0, 0x21,
michael@0 1239 0x5b, 0x5f, 0x9d, 0x50, 0x2b, 0x83, 0xe4, 0x48,
michael@0 1240 0xcc, 0x39, 0xe5, 0xfb, 0x13, 0x7b, 0x6f, 0x81 };
michael@0 1241
michael@0 1242 static const PRUint8 rsa_prime0[FIPS_RSA_PRIME0_LENGTH] = {
michael@0 1243 0xe4, 0xbf, 0x21, 0x62, 0x9b, 0xa9, 0x77, 0x40,
michael@0 1244 0x8d, 0x2a, 0xce, 0xa1, 0x67, 0x5a, 0x4c, 0x96,
michael@0 1245 0x45, 0x98, 0x67, 0xbd, 0x75, 0x22, 0x33, 0x6f,
michael@0 1246 0xe6, 0xcb, 0x77, 0xde, 0x9e, 0x97, 0x7d, 0x96,
michael@0 1247 0x8c, 0x5e, 0x5d, 0x34, 0xfb, 0x27, 0xfc, 0x6d,
michael@0 1248 0x74, 0xdb, 0x9d, 0x2e, 0x6d, 0xf6, 0xea, 0xfc,
michael@0 1249 0xce, 0x9e, 0xda, 0xa7, 0x25, 0xa2, 0xf4, 0x58,
michael@0 1250 0x6d, 0x0a, 0x3f, 0x01, 0xc2, 0xb4, 0xab, 0x38,
michael@0 1251 0xc1, 0x14, 0x85, 0xb6, 0xfa, 0x94, 0xc3, 0x85,
michael@0 1252 0xf9, 0x3c, 0x2e, 0x96, 0x56, 0x01, 0xe7, 0xd6,
michael@0 1253 0x14, 0x71, 0x4f, 0xfb, 0x4c, 0x85, 0x52, 0xc4,
michael@0 1254 0x61, 0x1e, 0xa5, 0x1e, 0x96, 0x13, 0x0d, 0x8f,
michael@0 1255 0x66, 0xae, 0xa0, 0xcd, 0x7d, 0x25, 0x66, 0x19,
michael@0 1256 0x15, 0xc2, 0xcf, 0xc3, 0x12, 0x3c, 0xe8, 0xa4,
michael@0 1257 0x52, 0x4c, 0xcb, 0x28, 0x3c, 0xc4, 0xbf, 0x95,
michael@0 1258 0x33, 0xe3, 0x81, 0xea, 0x0c, 0x6c, 0xa2, 0x05};
michael@0 1259 static const PRUint8 rsa_prime1[FIPS_RSA_PRIME1_LENGTH] = {
michael@0 1260 0xce, 0x03, 0x94, 0xf4, 0xa9, 0x2c, 0x1e, 0x06,
michael@0 1261 0xe7, 0x40, 0x30, 0x01, 0xf7, 0xbb, 0x68, 0x8c,
michael@0 1262 0x27, 0xd2, 0x15, 0xe3, 0x28, 0x49, 0x5b, 0xa8,
michael@0 1263 0xc1, 0x9a, 0x42, 0x7e, 0x31, 0xf9, 0x08, 0x34,
michael@0 1264 0x81, 0xa2, 0x0f, 0x04, 0x61, 0x34, 0xe3, 0x36,
michael@0 1265 0x92, 0xb1, 0x09, 0x2b, 0xe9, 0xef, 0x84, 0x88,
michael@0 1266 0xbe, 0x9c, 0x98, 0x60, 0xa6, 0x60, 0x84, 0xe9,
michael@0 1267 0x75, 0x6f, 0xcc, 0x81, 0xd1, 0x96, 0xef, 0xdd,
michael@0 1268 0x2e, 0xca, 0xc4, 0xf5, 0x42, 0xfb, 0x13, 0x2b,
michael@0 1269 0x57, 0xbf, 0x14, 0x5e, 0xc2, 0x7f, 0x77, 0x35,
michael@0 1270 0x29, 0xc4, 0xe5, 0xe0, 0xf9, 0x6d, 0x15, 0x4a,
michael@0 1271 0x42, 0x56, 0x1c, 0x3e, 0x0c, 0xc5, 0xce, 0x70,
michael@0 1272 0x08, 0x63, 0x1e, 0x73, 0xdb, 0x7e, 0x74, 0x05,
michael@0 1273 0x32, 0x01, 0xc6, 0x36, 0x32, 0x75, 0x6b, 0xed,
michael@0 1274 0x9d, 0xfe, 0x7c, 0x7e, 0xa9, 0x57, 0xb4, 0xe9,
michael@0 1275 0x22, 0xe4, 0xe7, 0xfe, 0x36, 0x07, 0x9b, 0xdf};
michael@0 1276 static const PRUint8 rsa_exponent0[FIPS_RSA_EXPONENT0_LENGTH] = {
michael@0 1277 0x04, 0x5a, 0x3a, 0xa9, 0x64, 0xaa, 0xd9, 0xd1,
michael@0 1278 0x09, 0x9e, 0x99, 0xe5, 0xea, 0x50, 0x86, 0x8a,
michael@0 1279 0x89, 0x72, 0x77, 0xee, 0xdb, 0xee, 0xb5, 0xa9,
michael@0 1280 0xd8, 0x6b, 0x60, 0xb1, 0x84, 0xb4, 0xff, 0x37,
michael@0 1281 0xc1, 0x1d, 0xfe, 0x8a, 0x06, 0x89, 0x61, 0x3d,
michael@0 1282 0x37, 0xef, 0x01, 0xd3, 0xa3, 0x56, 0x02, 0x6c,
michael@0 1283 0xa3, 0x05, 0xd4, 0xc5, 0x3f, 0x6b, 0x15, 0x59,
michael@0 1284 0x25, 0x61, 0xff, 0x86, 0xea, 0x0c, 0x84, 0x01,
michael@0 1285 0x85, 0x72, 0xfd, 0x84, 0x58, 0xca, 0x41, 0xda,
michael@0 1286 0x27, 0xbe, 0xe4, 0x68, 0x09, 0xe4, 0xe9, 0x63,
michael@0 1287 0x62, 0x6a, 0x31, 0x8a, 0x67, 0x8f, 0x55, 0xde,
michael@0 1288 0xd4, 0xb6, 0x3f, 0x90, 0x10, 0x6c, 0xf6, 0x62,
michael@0 1289 0x17, 0x23, 0x15, 0x7e, 0x33, 0x76, 0x65, 0xb5,
michael@0 1290 0xee, 0x7b, 0x11, 0x76, 0xf5, 0xbe, 0xe0, 0xf2,
michael@0 1291 0x57, 0x7a, 0x8c, 0x97, 0x0c, 0x68, 0xf5, 0xf8,
michael@0 1292 0x41, 0xcf, 0x7f, 0x66, 0x53, 0xac, 0x31, 0x7d};
michael@0 1293 static const PRUint8 rsa_exponent1[FIPS_RSA_EXPONENT1_LENGTH] = {
michael@0 1294 0x93, 0x54, 0x14, 0x6e, 0x73, 0x9d, 0x4d, 0x4b,
michael@0 1295 0xfa, 0x8c, 0xf8, 0xc8, 0x2f, 0x76, 0x22, 0xea,
michael@0 1296 0x38, 0x80, 0x11, 0x8f, 0x05, 0xfc, 0x90, 0x44,
michael@0 1297 0x3b, 0x50, 0x2a, 0x45, 0x3d, 0x4f, 0xaf, 0x02,
michael@0 1298 0x7d, 0xc2, 0x7b, 0xa2, 0xd2, 0x31, 0x94, 0x5c,
michael@0 1299 0x2e, 0xc3, 0xd4, 0x9f, 0x47, 0x09, 0x37, 0x6a,
michael@0 1300 0xe3, 0x85, 0xf1, 0xa3, 0x0c, 0xd8, 0xf1, 0xb4,
michael@0 1301 0x53, 0x7b, 0xc4, 0x71, 0x02, 0x86, 0x42, 0xbb,
michael@0 1302 0x96, 0xff, 0x03, 0xa3, 0xb2, 0x67, 0x03, 0xea,
michael@0 1303 0x77, 0x31, 0xfb, 0x4b, 0x59, 0x24, 0xf7, 0x07,
michael@0 1304 0x59, 0xfb, 0xa9, 0xba, 0x1e, 0x26, 0x58, 0x97,
michael@0 1305 0x66, 0xa1, 0x56, 0x49, 0x39, 0xb1, 0x2c, 0x55,
michael@0 1306 0x0a, 0x6a, 0x78, 0x18, 0xba, 0xdb, 0xcf, 0xf4,
michael@0 1307 0xf7, 0x32, 0x35, 0xa2, 0x04, 0xab, 0xdc, 0xa7,
michael@0 1308 0x6d, 0xd9, 0xd5, 0x06, 0x6f, 0xec, 0x7d, 0x40,
michael@0 1309 0x4c, 0xe8, 0x0e, 0xd0, 0xc9, 0xaa, 0xdf, 0x59};
michael@0 1310 static const PRUint8 rsa_coefficient[FIPS_RSA_COEFFICIENT_LENGTH] = {
michael@0 1311 0x17, 0xd7, 0xf5, 0x0a, 0xf0, 0x68, 0x97, 0x96,
michael@0 1312 0xc4, 0x29, 0x18, 0x77, 0x9a, 0x1f, 0xe3, 0xf3,
michael@0 1313 0x12, 0x13, 0x0f, 0x7e, 0x7b, 0xb9, 0xc1, 0x91,
michael@0 1314 0xf9, 0xc7, 0x08, 0x56, 0x5c, 0xa4, 0xbc, 0x83,
michael@0 1315 0x71, 0xf9, 0x78, 0xd9, 0x2b, 0xec, 0xfe, 0x6b,
michael@0 1316 0xdc, 0x2f, 0x63, 0xc9, 0xcd, 0x50, 0x14, 0x5b,
michael@0 1317 0xd3, 0x6e, 0x85, 0x4d, 0x0c, 0xa2, 0x0b, 0xa0,
michael@0 1318 0x09, 0xb6, 0xca, 0x34, 0x9c, 0xc2, 0xc1, 0x4a,
michael@0 1319 0xb0, 0xbc, 0x45, 0x93, 0xa5, 0x7e, 0x99, 0xb5,
michael@0 1320 0xbd, 0xe4, 0x69, 0x29, 0x08, 0x28, 0xd2, 0xcd,
michael@0 1321 0xab, 0x24, 0x78, 0x48, 0x41, 0x26, 0x0b, 0x37,
michael@0 1322 0xa3, 0x43, 0xd1, 0x95, 0x1a, 0xd6, 0xee, 0x22,
michael@0 1323 0x1c, 0x00, 0x0b, 0xc2, 0xb7, 0xa4, 0xa3, 0x21,
michael@0 1324 0xa9, 0xcd, 0xe4, 0x69, 0xd3, 0x45, 0x02, 0xb1,
michael@0 1325 0xb7, 0x3a, 0xbf, 0x51, 0x35, 0x1b, 0x78, 0xc2,
michael@0 1326 0xcf, 0x0c, 0x0d, 0x60, 0x09, 0xa9, 0x44, 0x02};
michael@0 1327
michael@0 1328 /* RSA Known Plaintext Message (1024-bits). */
michael@0 1329 static const PRUint8 rsa_known_plaintext_msg[FIPS_RSA_MESSAGE_LENGTH] = {
michael@0 1330 "Known plaintext message utilized"
michael@0 1331 "for RSA Encryption & Decryption"
michael@0 1332 "blocks SHA256, SHA384 and "
michael@0 1333 "SHA512 RSA Signature KAT tests. "
michael@0 1334 "Known plaintext message utilized"
michael@0 1335 "for RSA Encryption & Decryption"
michael@0 1336 "blocks SHA256, SHA384 and "
michael@0 1337 "SHA512 RSA Signature KAT tests."};
michael@0 1338
michael@0 1339 /* RSA Known Ciphertext (2048-bits). */
michael@0 1340 static const PRUint8 rsa_known_ciphertext[] = {
michael@0 1341 0x04, 0x12, 0x46, 0xe3, 0x6a, 0xee, 0xde, 0xdd,
michael@0 1342 0x49, 0xa1, 0xd9, 0x83, 0xf7, 0x35, 0xf9, 0x70,
michael@0 1343 0x88, 0x03, 0x2d, 0x01, 0x8b, 0xd1, 0xbf, 0xdb,
michael@0 1344 0xe5, 0x1c, 0x85, 0xbe, 0xb5, 0x0b, 0x48, 0x45,
michael@0 1345 0x7a, 0xf0, 0xa0, 0xe3, 0xa2, 0xbb, 0x4b, 0xf6,
michael@0 1346 0x27, 0xd0, 0x1b, 0x12, 0xe3, 0x77, 0x52, 0x34,
michael@0 1347 0x9e, 0x8e, 0x03, 0xd2, 0xf8, 0x79, 0x6e, 0x39,
michael@0 1348 0x79, 0x53, 0x3c, 0x44, 0x14, 0x94, 0xbb, 0x8d,
michael@0 1349 0xaa, 0x14, 0x44, 0xa0, 0x7b, 0xa5, 0x8c, 0x93,
michael@0 1350 0x5f, 0x99, 0xa4, 0xa3, 0x6e, 0x7a, 0x38, 0x40,
michael@0 1351 0x78, 0xfa, 0x36, 0x91, 0x5e, 0x9a, 0x9c, 0xba,
michael@0 1352 0x1e, 0xd4, 0xf9, 0xda, 0x4b, 0x0f, 0xa8, 0xa3,
michael@0 1353 0x1c, 0xf3, 0x3a, 0xd1, 0xa5, 0xb4, 0x51, 0x16,
michael@0 1354 0xed, 0x4b, 0xcf, 0xec, 0x93, 0x7b, 0x90, 0x21,
michael@0 1355 0xbc, 0x3a, 0xf4, 0x0b, 0xd1, 0x3a, 0x2b, 0xba,
michael@0 1356 0xa6, 0x7d, 0x5b, 0x53, 0xd8, 0x64, 0xf9, 0x29,
michael@0 1357 0x7b, 0x7f, 0x77, 0x3e, 0x51, 0x4c, 0x9a, 0x94,
michael@0 1358 0xd2, 0x4b, 0x4a, 0x8d, 0x61, 0x74, 0x97, 0xae,
michael@0 1359 0x53, 0x6a, 0xf4, 0x90, 0xc2, 0x2c, 0x49, 0xe2,
michael@0 1360 0xfa, 0xeb, 0x91, 0xc5, 0xe5, 0x83, 0x13, 0xc9,
michael@0 1361 0x44, 0x4b, 0x95, 0x2c, 0x57, 0x70, 0x15, 0x5c,
michael@0 1362 0x64, 0x8d, 0x1a, 0xfd, 0x2a, 0xc7, 0xb2, 0x9c,
michael@0 1363 0x5c, 0x99, 0xd3, 0x4a, 0xfd, 0xdd, 0xf6, 0x82,
michael@0 1364 0x87, 0x8c, 0x5a, 0xc4, 0xa8, 0x0d, 0x2a, 0xef,
michael@0 1365 0xc3, 0xa2, 0x7e, 0x8e, 0x67, 0x9f, 0x6f, 0x63,
michael@0 1366 0xdb, 0xbb, 0x1d, 0x31, 0xc4, 0xbb, 0xbc, 0x13,
michael@0 1367 0x3f, 0x54, 0xc6, 0xf6, 0xc5, 0x28, 0x32, 0xab,
michael@0 1368 0x96, 0x42, 0x10, 0x36, 0x40, 0x92, 0xbb, 0x57,
michael@0 1369 0x55, 0x38, 0xf5, 0x43, 0x7e, 0x43, 0xc4, 0x65,
michael@0 1370 0x47, 0x64, 0xaa, 0x0f, 0x4c, 0xe9, 0x49, 0x16,
michael@0 1371 0xec, 0x6a, 0x50, 0xfd, 0x14, 0x49, 0xca, 0xdb,
michael@0 1372 0x44, 0x54, 0xca, 0xbe, 0xa3, 0x0e, 0x5f, 0xef};
michael@0 1373
michael@0 1374 /* RSA Known Signed Hash (2048-bits). */
michael@0 1375 static const PRUint8 rsa_known_sha256_signature[] = {
michael@0 1376 0x8c, 0x2d, 0x2e, 0xfb, 0x37, 0xb5, 0x6f, 0x38,
michael@0 1377 0x9f, 0x06, 0x5a, 0xf3, 0x8c, 0xa0, 0xd0, 0x7a,
michael@0 1378 0xde, 0xcf, 0xf9, 0x14, 0x95, 0x59, 0xd3, 0x5f,
michael@0 1379 0x51, 0x5d, 0x5d, 0xad, 0xd8, 0x71, 0x33, 0x50,
michael@0 1380 0x1d, 0x03, 0x3b, 0x3a, 0x32, 0x00, 0xb4, 0xde,
michael@0 1381 0x7f, 0xe4, 0xb1, 0xe5, 0x6b, 0x83, 0xf4, 0x80,
michael@0 1382 0x10, 0x3b, 0xb8, 0x8a, 0xdb, 0xe8, 0x0a, 0x42,
michael@0 1383 0x9e, 0x8d, 0xd7, 0xbe, 0xed, 0xde, 0x5a, 0x3d,
michael@0 1384 0xc6, 0xdb, 0xfe, 0x49, 0x6a, 0xe9, 0x1e, 0x75,
michael@0 1385 0x66, 0xf1, 0x3f, 0x9e, 0x3f, 0xff, 0x05, 0x65,
michael@0 1386 0xde, 0xca, 0x62, 0x62, 0xf3, 0xec, 0x53, 0x09,
michael@0 1387 0xa0, 0x37, 0xd5, 0x66, 0x62, 0x72, 0x14, 0xb6,
michael@0 1388 0x51, 0x32, 0x67, 0x50, 0xc1, 0xe1, 0x2f, 0x9e,
michael@0 1389 0x98, 0x4e, 0x53, 0x96, 0x55, 0x4b, 0xc4, 0x92,
michael@0 1390 0xc3, 0xb4, 0x80, 0xf0, 0x35, 0xc9, 0x00, 0x4b,
michael@0 1391 0x5c, 0x85, 0x92, 0xb1, 0xe8, 0x6e, 0xa5, 0x51,
michael@0 1392 0x38, 0x9f, 0xc9, 0x11, 0xb6, 0x14, 0xdf, 0x34,
michael@0 1393 0x64, 0x40, 0x82, 0x82, 0xde, 0x16, 0x69, 0x93,
michael@0 1394 0x89, 0x4e, 0x5c, 0x32, 0xf2, 0x0a, 0x4e, 0x9e,
michael@0 1395 0xbd, 0x63, 0x99, 0x4f, 0xf3, 0x15, 0x90, 0xc2,
michael@0 1396 0xfe, 0x6f, 0xb7, 0xf4, 0xad, 0xd4, 0x8e, 0x0b,
michael@0 1397 0xd2, 0xf5, 0x22, 0xd2, 0x71, 0x65, 0x13, 0xf7,
michael@0 1398 0x82, 0x7b, 0x75, 0xb6, 0xc1, 0xb4, 0x45, 0xbd,
michael@0 1399 0x8f, 0x95, 0xcf, 0x5b, 0x95, 0x32, 0xef, 0x18,
michael@0 1400 0x5f, 0xd3, 0xdf, 0x7e, 0x22, 0xdd, 0x25, 0xeb,
michael@0 1401 0xe1, 0xbf, 0x3b, 0x9a, 0x55, 0x75, 0x4f, 0x3c,
michael@0 1402 0x38, 0x67, 0x57, 0x04, 0x04, 0x57, 0x27, 0xf6,
michael@0 1403 0x34, 0x0e, 0x57, 0x8a, 0x7c, 0xff, 0x7d, 0xca,
michael@0 1404 0x8c, 0x06, 0xf8, 0x9d, 0xdb, 0xe4, 0xd8, 0x19,
michael@0 1405 0xdd, 0x4d, 0xfd, 0x8f, 0xa0, 0x06, 0x53, 0xe8,
michael@0 1406 0x33, 0x00, 0x70, 0x3f, 0x6b, 0xc3, 0xbd, 0x9a,
michael@0 1407 0x78, 0xb5, 0xa9, 0xef, 0x6d, 0xda, 0x67, 0x92};
michael@0 1408
michael@0 1409 /* RSA Known Signed Hash (2048-bits). */
michael@0 1410 static const PRUint8 rsa_known_sha384_signature[] = {
michael@0 1411 0x20, 0x2d, 0x21, 0x3a, 0xaa, 0x1e, 0x05, 0x15,
michael@0 1412 0x5c, 0xca, 0x84, 0x86, 0xc0, 0x15, 0x81, 0xdf,
michael@0 1413 0xd4, 0x06, 0x9f, 0xe0, 0xc1, 0xed, 0xef, 0x0f,
michael@0 1414 0xfe, 0xb3, 0xc3, 0xbb, 0x28, 0xa5, 0x56, 0xbf,
michael@0 1415 0xe3, 0x11, 0x5c, 0xc2, 0xc0, 0x0b, 0xfa, 0xfa,
michael@0 1416 0x3d, 0xd3, 0x06, 0x20, 0xe2, 0xc9, 0xe4, 0x66,
michael@0 1417 0x28, 0xb7, 0xc0, 0x3b, 0x3c, 0x96, 0xc6, 0x49,
michael@0 1418 0x3b, 0xcf, 0x86, 0x49, 0x31, 0xaf, 0x5b, 0xa3,
michael@0 1419 0xec, 0x63, 0x10, 0xdf, 0xda, 0x2f, 0x68, 0xac,
michael@0 1420 0x7b, 0x3a, 0x49, 0xfa, 0xe6, 0x0d, 0xfe, 0x37,
michael@0 1421 0x17, 0x56, 0x8e, 0x5c, 0x48, 0x97, 0x43, 0xf7,
michael@0 1422 0xa0, 0xbc, 0xe3, 0x4b, 0x42, 0xde, 0x58, 0x1d,
michael@0 1423 0xd9, 0x5d, 0xb3, 0x08, 0x35, 0xbd, 0xa4, 0xe1,
michael@0 1424 0x80, 0xc3, 0x64, 0xab, 0x21, 0x97, 0xad, 0xfb,
michael@0 1425 0x71, 0xee, 0xa3, 0x3d, 0x9c, 0xaa, 0xfa, 0x16,
michael@0 1426 0x60, 0x46, 0x32, 0xda, 0x44, 0x2e, 0x10, 0x92,
michael@0 1427 0x20, 0xd8, 0x98, 0x80, 0x84, 0x75, 0x5b, 0x70,
michael@0 1428 0x91, 0x00, 0x33, 0x19, 0x69, 0xc9, 0x2a, 0xec,
michael@0 1429 0x3d, 0xe5, 0x5f, 0x0f, 0x9a, 0xa7, 0x97, 0x1f,
michael@0 1430 0x79, 0xc3, 0x1d, 0x65, 0x74, 0x62, 0xc5, 0xa1,
michael@0 1431 0x23, 0x65, 0x4b, 0x84, 0xa1, 0x03, 0x98, 0xf3,
michael@0 1432 0xf1, 0x02, 0x24, 0xca, 0xe5, 0xd4, 0xc8, 0xa2,
michael@0 1433 0x30, 0xad, 0x72, 0x7d, 0x29, 0x60, 0x1a, 0x8e,
michael@0 1434 0x6f, 0x23, 0xa4, 0xda, 0x68, 0xa4, 0x45, 0x9c,
michael@0 1435 0x39, 0x70, 0x44, 0x18, 0x4b, 0x73, 0xfe, 0xf8,
michael@0 1436 0x33, 0x53, 0x1d, 0x7e, 0x93, 0x93, 0xac, 0xc7,
michael@0 1437 0x1e, 0x6e, 0x6b, 0xfd, 0x9e, 0xba, 0xa6, 0x71,
michael@0 1438 0x70, 0x47, 0x6a, 0xd6, 0x82, 0x32, 0xa2, 0x6e,
michael@0 1439 0x20, 0x72, 0xb0, 0xba, 0xec, 0x91, 0xbb, 0x6b,
michael@0 1440 0xcc, 0x84, 0x0a, 0x33, 0x2b, 0x8a, 0x8d, 0xeb,
michael@0 1441 0x71, 0xcd, 0xca, 0x67, 0x1b, 0xad, 0x10, 0xd4,
michael@0 1442 0xce, 0x4f, 0xc0, 0x29, 0xec, 0xfa, 0xed, 0xfa};
michael@0 1443
michael@0 1444 /* RSA Known Signed Hash (2048-bits). */
michael@0 1445 static const PRUint8 rsa_known_sha512_signature[] = {
michael@0 1446 0x35, 0x0e, 0x74, 0x9d, 0xeb, 0xc7, 0x67, 0x31,
michael@0 1447 0x9f, 0xff, 0x0b, 0xbb, 0x5e, 0x66, 0xb4, 0x2f,
michael@0 1448 0xbf, 0x72, 0x60, 0x4f, 0xe9, 0xbd, 0xec, 0xc8,
michael@0 1449 0x17, 0x79, 0x5f, 0x39, 0x83, 0xb4, 0x54, 0x2e,
michael@0 1450 0x01, 0xb9, 0xd3, 0x20, 0x47, 0xcb, 0xd4, 0x42,
michael@0 1451 0xf2, 0x6e, 0x36, 0xc1, 0x97, 0xad, 0xef, 0x8e,
michael@0 1452 0xe6, 0x51, 0xee, 0x5e, 0x9e, 0x88, 0xb4, 0x9d,
michael@0 1453 0xda, 0x3e, 0x77, 0x4b, 0xe8, 0xae, 0x48, 0x53,
michael@0 1454 0x2c, 0xc4, 0xd3, 0x25, 0x6b, 0x23, 0xb7, 0x54,
michael@0 1455 0x3c, 0x95, 0x8f, 0xfb, 0x6f, 0x6d, 0xc5, 0x56,
michael@0 1456 0x39, 0x69, 0x28, 0x0e, 0x74, 0x9b, 0x31, 0xe8,
michael@0 1457 0x76, 0x77, 0x2b, 0xc1, 0x44, 0x89, 0x81, 0x93,
michael@0 1458 0xfc, 0xf6, 0xec, 0x5f, 0x8f, 0x89, 0xfc, 0x1d,
michael@0 1459 0xa4, 0x53, 0x58, 0x8c, 0xe9, 0xc0, 0xc0, 0x26,
michael@0 1460 0xe6, 0xdf, 0x6d, 0x27, 0xb1, 0x8e, 0x3e, 0xb6,
michael@0 1461 0x47, 0xe1, 0x02, 0x96, 0xc2, 0x5f, 0x7f, 0x3d,
michael@0 1462 0xc5, 0x6c, 0x2f, 0xea, 0xaa, 0x5e, 0x39, 0xfc,
michael@0 1463 0x77, 0xca, 0x00, 0x02, 0x5c, 0x64, 0x7c, 0xce,
michael@0 1464 0x7d, 0x63, 0x82, 0x05, 0xed, 0xf7, 0x5b, 0x55,
michael@0 1465 0x58, 0xc0, 0xeb, 0x76, 0xd7, 0x95, 0x55, 0x37,
michael@0 1466 0x85, 0x7d, 0x17, 0xad, 0xd2, 0x11, 0xfd, 0x97,
michael@0 1467 0x48, 0xb5, 0xc2, 0x5e, 0xc7, 0x62, 0xc0, 0xe0,
michael@0 1468 0x68, 0xa8, 0x61, 0x14, 0x41, 0xca, 0x25, 0x3a,
michael@0 1469 0xec, 0x48, 0x54, 0x22, 0x83, 0x2b, 0x69, 0x54,
michael@0 1470 0xfd, 0xc8, 0x99, 0x9a, 0xee, 0x37, 0x03, 0xa3,
michael@0 1471 0x8f, 0x0f, 0x32, 0xb0, 0xaa, 0x74, 0x39, 0x04,
michael@0 1472 0x7c, 0xd9, 0xc2, 0x8f, 0xbe, 0xf2, 0xc4, 0xbe,
michael@0 1473 0xdd, 0x7a, 0x7a, 0x7f, 0x72, 0xd3, 0x80, 0x59,
michael@0 1474 0x18, 0xa0, 0xa1, 0x2d, 0x6f, 0xa3, 0xa9, 0x48,
michael@0 1475 0xed, 0x20, 0xa6, 0xea, 0xaa, 0x10, 0x83, 0x98,
michael@0 1476 0x0c, 0x13, 0x69, 0x6e, 0xcd, 0x31, 0x6b, 0xd0,
michael@0 1477 0x66, 0xa6, 0x5e, 0x30, 0x0c, 0x82, 0xd5, 0x81};
michael@0 1478
michael@0 1479 static const RSAPublicKey bl_public_key = { NULL,
michael@0 1480 { FIPS_RSA_TYPE, (unsigned char *)rsa_modulus,
michael@0 1481 FIPS_RSA_MODULUS_LENGTH },
michael@0 1482 { FIPS_RSA_TYPE, (unsigned char *)rsa_public_exponent,
michael@0 1483 FIPS_RSA_PUBLIC_EXPONENT_LENGTH }
michael@0 1484 };
michael@0 1485 static const RSAPrivateKey bl_private_key = { NULL,
michael@0 1486 { FIPS_RSA_TYPE, (unsigned char *)rsa_version,
michael@0 1487 FIPS_RSA_PRIVATE_VERSION_LENGTH },
michael@0 1488 { FIPS_RSA_TYPE, (unsigned char *)rsa_modulus,
michael@0 1489 FIPS_RSA_MODULUS_LENGTH },
michael@0 1490 { FIPS_RSA_TYPE, (unsigned char *)rsa_public_exponent,
michael@0 1491 FIPS_RSA_PUBLIC_EXPONENT_LENGTH },
michael@0 1492 { FIPS_RSA_TYPE, (unsigned char *)rsa_private_exponent,
michael@0 1493 FIPS_RSA_PRIVATE_EXPONENT_LENGTH },
michael@0 1494 { FIPS_RSA_TYPE, (unsigned char *)rsa_prime0,
michael@0 1495 FIPS_RSA_PRIME0_LENGTH },
michael@0 1496 { FIPS_RSA_TYPE, (unsigned char *)rsa_prime1,
michael@0 1497 FIPS_RSA_PRIME1_LENGTH },
michael@0 1498 { FIPS_RSA_TYPE, (unsigned char *)rsa_exponent0,
michael@0 1499 FIPS_RSA_EXPONENT0_LENGTH },
michael@0 1500 { FIPS_RSA_TYPE, (unsigned char *)rsa_exponent1,
michael@0 1501 FIPS_RSA_EXPONENT1_LENGTH },
michael@0 1502 { FIPS_RSA_TYPE, (unsigned char *)rsa_coefficient,
michael@0 1503 FIPS_RSA_COEFFICIENT_LENGTH }
michael@0 1504 };
michael@0 1505
michael@0 1506 /* RSA variables. */
michael@0 1507 #ifdef CREATE_TEMP_ARENAS
michael@0 1508 PLArenaPool * rsa_public_arena;
michael@0 1509 PLArenaPool * rsa_private_arena;
michael@0 1510 #endif
michael@0 1511 NSSLOWKEYPublicKey * rsa_public_key;
michael@0 1512 NSSLOWKEYPrivateKey * rsa_private_key;
michael@0 1513 SECStatus rsa_status;
michael@0 1514
michael@0 1515 NSSLOWKEYPublicKey low_public_key = { NULL, NSSLOWKEYRSAKey, };
michael@0 1516 NSSLOWKEYPrivateKey low_private_key = { NULL, NSSLOWKEYRSAKey, };
michael@0 1517 PRUint8 rsa_computed_ciphertext[FIPS_RSA_ENCRYPT_LENGTH];
michael@0 1518 PRUint8 rsa_computed_plaintext[FIPS_RSA_DECRYPT_LENGTH];
michael@0 1519
michael@0 1520 /****************************************/
michael@0 1521 /* Compose RSA Public/Private Key Pair. */
michael@0 1522 /****************************************/
michael@0 1523
michael@0 1524 low_public_key.u.rsa = bl_public_key;
michael@0 1525 low_private_key.u.rsa = bl_private_key;
michael@0 1526
michael@0 1527 rsa_public_key = &low_public_key;
michael@0 1528 rsa_private_key = &low_private_key;
michael@0 1529
michael@0 1530 #ifdef CREATE_TEMP_ARENAS
michael@0 1531 /* Create some space for the RSA public key. */
michael@0 1532 rsa_public_arena = PORT_NewArena( NSS_SOFTOKEN_DEFAULT_CHUNKSIZE );
michael@0 1533
michael@0 1534 if( rsa_public_arena == NULL ) {
michael@0 1535 PORT_SetError( SEC_ERROR_NO_MEMORY );
michael@0 1536 return( CKR_HOST_MEMORY );
michael@0 1537 }
michael@0 1538
michael@0 1539 /* Create some space for the RSA private key. */
michael@0 1540 rsa_private_arena = PORT_NewArena( NSS_SOFTOKEN_DEFAULT_CHUNKSIZE );
michael@0 1541
michael@0 1542 if( rsa_private_arena == NULL ) {
michael@0 1543 PORT_FreeArena( rsa_public_arena, PR_TRUE );
michael@0 1544 PORT_SetError( SEC_ERROR_NO_MEMORY );
michael@0 1545 return( CKR_HOST_MEMORY );
michael@0 1546 }
michael@0 1547
michael@0 1548 rsa_public_key->arena = rsa_public_arena;
michael@0 1549 rsa_private_key->arena = rsa_private_arena;
michael@0 1550 #endif
michael@0 1551
michael@0 1552 /**************************************************/
michael@0 1553 /* RSA Single-Round Known Answer Encryption Test. */
michael@0 1554 /**************************************************/
michael@0 1555
michael@0 1556 /* Perform RSA Public Key Encryption. */
michael@0 1557 rsa_status = RSA_PublicKeyOp(&rsa_public_key->u.rsa,
michael@0 1558 rsa_computed_ciphertext,
michael@0 1559 rsa_known_plaintext_msg);
michael@0 1560
michael@0 1561 if( ( rsa_status != SECSuccess ) ||
michael@0 1562 ( PORT_Memcmp( rsa_computed_ciphertext, rsa_known_ciphertext,
michael@0 1563 FIPS_RSA_ENCRYPT_LENGTH ) != 0 ) )
michael@0 1564 goto rsa_loser;
michael@0 1565
michael@0 1566 /**************************************************/
michael@0 1567 /* RSA Single-Round Known Answer Decryption Test. */
michael@0 1568 /**************************************************/
michael@0 1569
michael@0 1570 /* Perform RSA Private Key Decryption. */
michael@0 1571 rsa_status = RSA_PrivateKeyOp(&rsa_private_key->u.rsa,
michael@0 1572 rsa_computed_plaintext,
michael@0 1573 rsa_known_ciphertext);
michael@0 1574
michael@0 1575 if( ( rsa_status != SECSuccess ) ||
michael@0 1576 ( PORT_Memcmp( rsa_computed_plaintext, rsa_known_plaintext_msg,
michael@0 1577 FIPS_RSA_DECRYPT_LENGTH ) != 0 ) )
michael@0 1578 goto rsa_loser;
michael@0 1579
michael@0 1580 rsa_status = sftk_fips_RSA_PowerUpSigSelfTest (HASH_AlgSHA256,
michael@0 1581 rsa_public_key, rsa_private_key,
michael@0 1582 rsa_known_plaintext_msg, FIPS_RSA_MESSAGE_LENGTH,
michael@0 1583 rsa_known_sha256_signature);
michael@0 1584 if( rsa_status != SECSuccess )
michael@0 1585 goto rsa_loser;
michael@0 1586
michael@0 1587 rsa_status = sftk_fips_RSA_PowerUpSigSelfTest (HASH_AlgSHA384,
michael@0 1588 rsa_public_key, rsa_private_key,
michael@0 1589 rsa_known_plaintext_msg, FIPS_RSA_MESSAGE_LENGTH,
michael@0 1590 rsa_known_sha384_signature);
michael@0 1591 if( rsa_status != SECSuccess )
michael@0 1592 goto rsa_loser;
michael@0 1593
michael@0 1594 rsa_status = sftk_fips_RSA_PowerUpSigSelfTest (HASH_AlgSHA512,
michael@0 1595 rsa_public_key, rsa_private_key,
michael@0 1596 rsa_known_plaintext_msg, FIPS_RSA_MESSAGE_LENGTH,
michael@0 1597 rsa_known_sha512_signature);
michael@0 1598 if( rsa_status != SECSuccess )
michael@0 1599 goto rsa_loser;
michael@0 1600
michael@0 1601 /* Dispose of all RSA key material. */
michael@0 1602 nsslowkey_DestroyPublicKey( rsa_public_key );
michael@0 1603 nsslowkey_DestroyPrivateKey( rsa_private_key );
michael@0 1604
michael@0 1605 return( CKR_OK );
michael@0 1606
michael@0 1607 rsa_loser:
michael@0 1608
michael@0 1609 nsslowkey_DestroyPublicKey( rsa_public_key );
michael@0 1610 nsslowkey_DestroyPrivateKey( rsa_private_key );
michael@0 1611
michael@0 1612 return( CKR_DEVICE_ERROR );
michael@0 1613 }
michael@0 1614
michael@0 1615 #ifndef NSS_DISABLE_ECC
michael@0 1616
michael@0 1617 static CK_RV
michael@0 1618 sftk_fips_ECDSA_Test(const PRUint8 *encodedParams,
michael@0 1619 unsigned int encodedParamsLen,
michael@0 1620 const PRUint8 *knownSignature,
michael@0 1621 unsigned int knownSignatureLen) {
michael@0 1622
michael@0 1623 /* ECDSA Known Seed info for curves nistp256 and nistk283 */
michael@0 1624 static const PRUint8 ecdsa_Known_Seed[] = {
michael@0 1625 0x6a, 0x9b, 0xf6, 0xf7, 0xce, 0xed, 0x79, 0x11,
michael@0 1626 0xf0, 0xc7, 0xc8, 0x9a, 0xa5, 0xd1, 0x57, 0xb1,
michael@0 1627 0x7b, 0x5a, 0x3b, 0x76, 0x4e, 0x7b, 0x7c, 0xbc,
michael@0 1628 0xf2, 0x76, 0x1c, 0x1c, 0x7f, 0xc5, 0x53, 0x2f};
michael@0 1629
michael@0 1630 static const PRUint8 msg[] = {
michael@0 1631 "Firefox and ThunderBird are awesome!"};
michael@0 1632
michael@0 1633 unsigned char sha1[SHA1_LENGTH]; /* SHA-1 hash (160 bits) */
michael@0 1634 unsigned char sig[2*MAX_ECKEY_LEN];
michael@0 1635 SECItem signature, digest;
michael@0 1636 SECItem encodedparams;
michael@0 1637 ECParams *ecparams = NULL;
michael@0 1638 ECPrivateKey *ecdsa_private_key = NULL;
michael@0 1639 ECPublicKey ecdsa_public_key;
michael@0 1640 SECStatus ecdsaStatus = SECSuccess;
michael@0 1641
michael@0 1642 /* construct the ECDSA private/public key pair */
michael@0 1643 encodedparams.type = siBuffer;
michael@0 1644 encodedparams.data = (unsigned char *) encodedParams;
michael@0 1645 encodedparams.len = encodedParamsLen;
michael@0 1646
michael@0 1647 if (EC_DecodeParams(&encodedparams, &ecparams) != SECSuccess) {
michael@0 1648 return( CKR_DEVICE_ERROR );
michael@0 1649 }
michael@0 1650
michael@0 1651 /* Generates a new EC key pair. The private key is a supplied
michael@0 1652 * random value (in seed) and the public key is the result of
michael@0 1653 * performing a scalar point multiplication of that value with
michael@0 1654 * the curve's base point.
michael@0 1655 */
michael@0 1656 ecdsaStatus = EC_NewKeyFromSeed(ecparams, &ecdsa_private_key,
michael@0 1657 ecdsa_Known_Seed,
michael@0 1658 sizeof(ecdsa_Known_Seed));
michael@0 1659 /* free the ecparams they are no longer needed */
michael@0 1660 PORT_FreeArena(ecparams->arena, PR_FALSE);
michael@0 1661 ecparams = NULL;
michael@0 1662 if (ecdsaStatus != SECSuccess) {
michael@0 1663 return ( CKR_DEVICE_ERROR );
michael@0 1664 }
michael@0 1665
michael@0 1666 /* construct public key from private key. */
michael@0 1667 ecdsaStatus = EC_CopyParams(ecdsa_private_key->ecParams.arena,
michael@0 1668 &ecdsa_public_key.ecParams,
michael@0 1669 &ecdsa_private_key->ecParams);
michael@0 1670 if (ecdsaStatus != SECSuccess) {
michael@0 1671 goto loser;
michael@0 1672 }
michael@0 1673 ecdsa_public_key.publicValue = ecdsa_private_key->publicValue;
michael@0 1674
michael@0 1675 /* validate public key value */
michael@0 1676 ecdsaStatus = EC_ValidatePublicKey(&ecdsa_public_key.ecParams,
michael@0 1677 &ecdsa_public_key.publicValue);
michael@0 1678 if (ecdsaStatus != SECSuccess) {
michael@0 1679 goto loser;
michael@0 1680 }
michael@0 1681
michael@0 1682 /* validate public key value */
michael@0 1683 ecdsaStatus = EC_ValidatePublicKey(&ecdsa_private_key->ecParams,
michael@0 1684 &ecdsa_private_key->publicValue);
michael@0 1685 if (ecdsaStatus != SECSuccess) {
michael@0 1686 goto loser;
michael@0 1687 }
michael@0 1688
michael@0 1689 /***************************************************/
michael@0 1690 /* ECDSA Single-Round Known Answer Signature Test. */
michael@0 1691 /***************************************************/
michael@0 1692
michael@0 1693 ecdsaStatus = SHA1_HashBuf(sha1, msg, sizeof msg);
michael@0 1694 if (ecdsaStatus != SECSuccess) {
michael@0 1695 goto loser;
michael@0 1696 }
michael@0 1697 digest.type = siBuffer;
michael@0 1698 digest.data = sha1;
michael@0 1699 digest.len = SHA1_LENGTH;
michael@0 1700
michael@0 1701 memset(sig, 0, sizeof sig);
michael@0 1702 signature.type = siBuffer;
michael@0 1703 signature.data = sig;
michael@0 1704 signature.len = sizeof sig;
michael@0 1705
michael@0 1706 ecdsaStatus = ECDSA_SignDigestWithSeed(ecdsa_private_key, &signature,
michael@0 1707 &digest, ecdsa_Known_Seed, sizeof ecdsa_Known_Seed);
michael@0 1708 if (ecdsaStatus != SECSuccess) {
michael@0 1709 goto loser;
michael@0 1710 }
michael@0 1711
michael@0 1712 if( ( signature.len != knownSignatureLen ) ||
michael@0 1713 ( PORT_Memcmp( signature.data, knownSignature,
michael@0 1714 knownSignatureLen ) != 0 ) ) {
michael@0 1715 ecdsaStatus = SECFailure;
michael@0 1716 goto loser;
michael@0 1717 }
michael@0 1718
michael@0 1719 /******************************************************/
michael@0 1720 /* ECDSA Single-Round Known Answer Verification Test. */
michael@0 1721 /******************************************************/
michael@0 1722
michael@0 1723 /* Perform ECDSA verification process. */
michael@0 1724 ecdsaStatus = ECDSA_VerifyDigest(&ecdsa_public_key, &signature, &digest);
michael@0 1725
michael@0 1726 loser:
michael@0 1727 /* free the memory for the private key arena*/
michael@0 1728 if (ecdsa_private_key != NULL) {
michael@0 1729 PORT_FreeArena(ecdsa_private_key->ecParams.arena, PR_FALSE);
michael@0 1730 }
michael@0 1731
michael@0 1732 if (ecdsaStatus != SECSuccess) {
michael@0 1733 return CKR_DEVICE_ERROR ;
michael@0 1734 }
michael@0 1735 return( CKR_OK );
michael@0 1736 }
michael@0 1737
michael@0 1738 static CK_RV
michael@0 1739 sftk_fips_ECDSA_PowerUpSelfTest() {
michael@0 1740
michael@0 1741 /* ECDSA Known curve nistp256 == SEC_OID_SECG_EC_SECP256R1 params */
michael@0 1742 static const PRUint8 ecdsa_known_P256_EncodedParams[] = {
michael@0 1743 0x06,0x08,0x2a,0x86,0x48,0xce,0x3d,0x03,
michael@0 1744 0x01,0x07};
michael@0 1745
michael@0 1746 static const PRUint8 ecdsa_known_P256_signature[] = {
michael@0 1747 0x07,0xb1,0xcb,0x57,0x20,0xa7,0x10,0xd6,
michael@0 1748 0x9d,0x37,0x4b,0x1c,0xdc,0x35,0x90,0xff,
michael@0 1749 0x1a,0x2d,0x98,0x95,0x1b,0x2f,0xeb,0x7f,
michael@0 1750 0xbb,0x81,0xca,0xc0,0x69,0x75,0xea,0xc5,
michael@0 1751 0x59,0x6a,0x62,0x49,0x3d,0x50,0xc9,0xe1,
michael@0 1752 0x27,0x3b,0xff,0x9b,0x13,0x66,0x67,0xdd,
michael@0 1753 0x7d,0xd1,0x0d,0x2d,0x7c,0x44,0x04,0x1b,
michael@0 1754 0x16,0x21,0x12,0xc5,0xcb,0xbd,0x9e,0x75};
michael@0 1755
michael@0 1756 #ifdef NSS_ECC_MORE_THAN_SUITE_B
michael@0 1757 /* ECDSA Known curve nistk283 == SEC_OID_SECG_EC_SECT283K1 params */
michael@0 1758 static const PRUint8 ecdsa_known_K283_EncodedParams[] = {
michael@0 1759 0x06,0x05,0x2b,0x81,0x04,0x00,0x10};
michael@0 1760
michael@0 1761 static const PRUint8 ecdsa_known_K283_signature[] = {
michael@0 1762 0x00,0x45,0x88,0xc0,0x79,0x09,0x07,0xd1,
michael@0 1763 0x4e,0x88,0xe6,0xd5,0x2f,0x22,0x04,0x74,
michael@0 1764 0x35,0x24,0x65,0xe8,0x15,0xde,0x90,0x66,
michael@0 1765 0x94,0x70,0xdd,0x3a,0x14,0x70,0x02,0xd1,
michael@0 1766 0xef,0x86,0xbd,0x15,0x00,0xd9,0xdc,0xfc,
michael@0 1767 0x87,0x2e,0x7c,0x99,0xe2,0xe3,0x79,0xb8,
michael@0 1768 0xd9,0x10,0x49,0x78,0x4b,0x59,0x8b,0x05,
michael@0 1769 0x77,0xec,0x6c,0xe8,0x35,0xe6,0x2e,0xa9,
michael@0 1770 0xf9,0x77,0x1f,0x71,0x86,0xa5,0x4a,0xd0};
michael@0 1771 #endif
michael@0 1772
michael@0 1773 CK_RV crv;
michael@0 1774
michael@0 1775 /* ECDSA GF(p) prime field curve test */
michael@0 1776 crv = sftk_fips_ECDSA_Test(ecdsa_known_P256_EncodedParams,
michael@0 1777 sizeof ecdsa_known_P256_EncodedParams,
michael@0 1778 ecdsa_known_P256_signature,
michael@0 1779 sizeof ecdsa_known_P256_signature );
michael@0 1780 if (crv != CKR_OK) {
michael@0 1781 return( CKR_DEVICE_ERROR );
michael@0 1782 }
michael@0 1783
michael@0 1784 #ifdef NSS_ECC_MORE_THAN_SUITE_B
michael@0 1785 /* ECDSA GF(2m) binary field curve test */
michael@0 1786 crv = sftk_fips_ECDSA_Test(ecdsa_known_K283_EncodedParams,
michael@0 1787 sizeof ecdsa_known_K283_EncodedParams,
michael@0 1788 ecdsa_known_K283_signature,
michael@0 1789 sizeof ecdsa_known_K283_signature );
michael@0 1790 if (crv != CKR_OK) {
michael@0 1791 return( CKR_DEVICE_ERROR );
michael@0 1792 }
michael@0 1793 #endif
michael@0 1794
michael@0 1795 return( CKR_OK );
michael@0 1796 }
michael@0 1797
michael@0 1798 #endif /* NSS_DISABLE_ECC */
michael@0 1799
michael@0 1800 static CK_RV
michael@0 1801 sftk_fips_DSA_PowerUpSelfTest( void )
michael@0 1802 {
michael@0 1803 /* DSA Known P (1024-bits), Q (160-bits), and G (1024-bits) Values. */
michael@0 1804 static const PRUint8 dsa_P[] = {
michael@0 1805 0x80,0xb0,0xd1,0x9d,0x6e,0xa4,0xf3,0x28,
michael@0 1806 0x9f,0x24,0xa9,0x8a,0x49,0xd0,0x0c,0x63,
michael@0 1807 0xe8,0x59,0x04,0xf9,0x89,0x4a,0x5e,0xc0,
michael@0 1808 0x6d,0xd2,0x67,0x6b,0x37,0x81,0x83,0x0c,
michael@0 1809 0xfe,0x3a,0x8a,0xfd,0xa0,0x3b,0x08,0x91,
michael@0 1810 0x1c,0xcb,0xb5,0x63,0xb0,0x1c,0x70,0xd0,
michael@0 1811 0xae,0xe1,0x60,0x2e,0x12,0xeb,0x54,0xc7,
michael@0 1812 0xcf,0xc6,0xcc,0xae,0x97,0x52,0x32,0x63,
michael@0 1813 0xd3,0xeb,0x55,0xea,0x2f,0x4c,0xd5,0xd7,
michael@0 1814 0x3f,0xda,0xec,0x49,0x27,0x0b,0x14,0x56,
michael@0 1815 0xc5,0x09,0xbe,0x4d,0x09,0x15,0x75,0x2b,
michael@0 1816 0xa3,0x42,0x0d,0x03,0x71,0xdf,0x0f,0xf4,
michael@0 1817 0x0e,0xe9,0x0c,0x46,0x93,0x3d,0x3f,0xa6,
michael@0 1818 0x6c,0xdb,0xca,0xe5,0xac,0x96,0xc8,0x64,
michael@0 1819 0x5c,0xec,0x4b,0x35,0x65,0xfc,0xfb,0x5a,
michael@0 1820 0x1b,0x04,0x1b,0xa1,0x0e,0xfd,0x88,0x15};
michael@0 1821
michael@0 1822 static const PRUint8 dsa_Q[] = {
michael@0 1823 0xad,0x22,0x59,0xdf,0xe5,0xec,0x4c,0x6e,
michael@0 1824 0xf9,0x43,0xf0,0x4b,0x2d,0x50,0x51,0xc6,
michael@0 1825 0x91,0x99,0x8b,0xcf};
michael@0 1826
michael@0 1827 static const PRUint8 dsa_G[] = {
michael@0 1828 0x78,0x6e,0xa9,0xd8,0xcd,0x4a,0x85,0xa4,
michael@0 1829 0x45,0xb6,0x6e,0x5d,0x21,0x50,0x61,0xf6,
michael@0 1830 0x5f,0xdf,0x5c,0x7a,0xde,0x0d,0x19,0xd3,
michael@0 1831 0xc1,0x3b,0x14,0xcc,0x8e,0xed,0xdb,0x17,
michael@0 1832 0xb6,0xca,0xba,0x86,0xa9,0xea,0x51,0x2d,
michael@0 1833 0xc1,0xa9,0x16,0xda,0xf8,0x7b,0x59,0x8a,
michael@0 1834 0xdf,0xcb,0xa4,0x67,0x00,0x44,0xea,0x24,
michael@0 1835 0x73,0xe5,0xcb,0x4b,0xaf,0x2a,0x31,0x25,
michael@0 1836 0x22,0x28,0x3f,0x16,0x10,0x82,0xf7,0xeb,
michael@0 1837 0x94,0x0d,0xdd,0x09,0x22,0x14,0x08,0x79,
michael@0 1838 0xba,0x11,0x0b,0xf1,0xff,0x2d,0x67,0xac,
michael@0 1839 0xeb,0xb6,0x55,0x51,0x69,0x97,0xa7,0x25,
michael@0 1840 0x6b,0x9c,0xa0,0x9b,0xd5,0x08,0x9b,0x27,
michael@0 1841 0x42,0x1c,0x7a,0x69,0x57,0xe6,0x2e,0xed,
michael@0 1842 0xa9,0x5b,0x25,0xe8,0x1f,0xd2,0xed,0x1f,
michael@0 1843 0xdf,0xe7,0x80,0x17,0xba,0x0d,0x4d,0x38};
michael@0 1844
michael@0 1845 /* DSA Known Random Values (known random key block is 160-bits) */
michael@0 1846 /* and (known random signature block is 160-bits). */
michael@0 1847 static const PRUint8 dsa_known_random_key_block[] = {
michael@0 1848 "Mozilla Rules World!"};
michael@0 1849 static const PRUint8 dsa_known_random_signature_block[] = {
michael@0 1850 "Random DSA Signature"};
michael@0 1851
michael@0 1852 /* DSA Known Digest (160-bits) */
michael@0 1853 static const PRUint8 dsa_known_digest[] = { "DSA Signature Digest" };
michael@0 1854
michael@0 1855 /* DSA Known Signature (320-bits). */
michael@0 1856 static const PRUint8 dsa_known_signature[] = {
michael@0 1857 0x25,0x7c,0x3a,0x79,0x32,0x45,0xb7,0x32,
michael@0 1858 0x70,0xca,0x62,0x63,0x2b,0xf6,0x29,0x2c,
michael@0 1859 0x22,0x2a,0x03,0xce,0x48,0x15,0x11,0x72,
michael@0 1860 0x7b,0x7e,0xf5,0x7a,0xf3,0x10,0x3b,0xde,
michael@0 1861 0x34,0xc1,0x9e,0xd7,0x27,0x9e,0x77,0x38};
michael@0 1862
michael@0 1863 /* DSA variables. */
michael@0 1864 DSAPrivateKey * dsa_private_key;
michael@0 1865 SECStatus dsa_status;
michael@0 1866 SECItem dsa_signature_item;
michael@0 1867 SECItem dsa_digest_item;
michael@0 1868 DSAPublicKey dsa_public_key;
michael@0 1869 PRUint8 dsa_computed_signature[FIPS_DSA_SIGNATURE_LENGTH];
michael@0 1870 static const PQGParams dsa_pqg = { NULL,
michael@0 1871 { FIPS_DSA_TYPE, (unsigned char *)dsa_P, FIPS_DSA_PRIME_LENGTH },
michael@0 1872 { FIPS_DSA_TYPE, (unsigned char *)dsa_Q, FIPS_DSA_SUBPRIME_LENGTH },
michael@0 1873 { FIPS_DSA_TYPE, (unsigned char *)dsa_G, FIPS_DSA_BASE_LENGTH }};
michael@0 1874
michael@0 1875 /*******************************************/
michael@0 1876 /* Generate a DSA public/private key pair. */
michael@0 1877 /*******************************************/
michael@0 1878
michael@0 1879 /* Generate a DSA public/private key pair. */
michael@0 1880 dsa_status = DSA_NewKeyFromSeed(&dsa_pqg, dsa_known_random_key_block,
michael@0 1881 &dsa_private_key);
michael@0 1882
michael@0 1883 if( dsa_status != SECSuccess )
michael@0 1884 return( CKR_HOST_MEMORY );
michael@0 1885
michael@0 1886 /* construct public key from private key. */
michael@0 1887 dsa_public_key.params = dsa_private_key->params;
michael@0 1888 dsa_public_key.publicValue = dsa_private_key->publicValue;
michael@0 1889
michael@0 1890 /*************************************************/
michael@0 1891 /* DSA Single-Round Known Answer Signature Test. */
michael@0 1892 /*************************************************/
michael@0 1893
michael@0 1894 dsa_signature_item.data = dsa_computed_signature;
michael@0 1895 dsa_signature_item.len = sizeof dsa_computed_signature;
michael@0 1896
michael@0 1897 dsa_digest_item.data = (unsigned char *)dsa_known_digest;
michael@0 1898 dsa_digest_item.len = SHA1_LENGTH;
michael@0 1899
michael@0 1900 /* Perform DSA signature process. */
michael@0 1901 dsa_status = DSA_SignDigestWithSeed( dsa_private_key,
michael@0 1902 &dsa_signature_item,
michael@0 1903 &dsa_digest_item,
michael@0 1904 dsa_known_random_signature_block );
michael@0 1905
michael@0 1906 if( ( dsa_status != SECSuccess ) ||
michael@0 1907 ( dsa_signature_item.len != FIPS_DSA_SIGNATURE_LENGTH ) ||
michael@0 1908 ( PORT_Memcmp( dsa_computed_signature, dsa_known_signature,
michael@0 1909 FIPS_DSA_SIGNATURE_LENGTH ) != 0 ) ) {
michael@0 1910 dsa_status = SECFailure;
michael@0 1911 } else {
michael@0 1912
michael@0 1913 /****************************************************/
michael@0 1914 /* DSA Single-Round Known Answer Verification Test. */
michael@0 1915 /****************************************************/
michael@0 1916
michael@0 1917 /* Perform DSA verification process. */
michael@0 1918 dsa_status = DSA_VerifyDigest( &dsa_public_key,
michael@0 1919 &dsa_signature_item,
michael@0 1920 &dsa_digest_item);
michael@0 1921 }
michael@0 1922
michael@0 1923 PORT_FreeArena(dsa_private_key->params.arena, PR_TRUE);
michael@0 1924 /* Don't free public key, it uses same arena as private key */
michael@0 1925
michael@0 1926 /* Verify DSA signature. */
michael@0 1927 if( dsa_status != SECSuccess )
michael@0 1928 return( CKR_DEVICE_ERROR );
michael@0 1929
michael@0 1930 return( CKR_OK );
michael@0 1931
michael@0 1932
michael@0 1933 }
michael@0 1934
michael@0 1935 static CK_RV
michael@0 1936 sftk_fips_RNG_PowerUpSelfTest( void )
michael@0 1937 {
michael@0 1938 static const PRUint8 Q[] = {
michael@0 1939 0x85,0x89,0x9c,0x77,0xa3,0x79,0xff,0x1a,
michael@0 1940 0x86,0x6f,0x2f,0x3e,0x2e,0xf9,0x8c,0x9c,
michael@0 1941 0x9d,0xef,0xeb,0xed};
michael@0 1942 static const PRUint8 GENX[] = {
michael@0 1943 0x65,0x48,0xe3,0xca,0xac,0x64,0x2d,0xf7,
michael@0 1944 0x7b,0xd3,0x4e,0x79,0xc9,0x7d,0xa6,0xa8,
michael@0 1945 0xa2,0xc2,0x1f,0x8f,0xe9,0xb9,0xd3,0xa1,
michael@0 1946 0x3f,0xf7,0x0c,0xcd,0xa6,0xca,0xbf,0xce,
michael@0 1947 0x84,0x0e,0xb6,0xf1,0x0d,0xbe,0xa9,0xa3};
michael@0 1948 static const PRUint8 rng_known_DSAX[] = {
michael@0 1949 0x7a,0x86,0xf1,0x7f,0xbd,0x4e,0x6e,0xd9,
michael@0 1950 0x0a,0x26,0x21,0xd0,0x19,0xcb,0x86,0x73,
michael@0 1951 0x10,0x1f,0x60,0xd7};
michael@0 1952
michael@0 1953
michael@0 1954
michael@0 1955 SECStatus rng_status = SECSuccess;
michael@0 1956 PRUint8 DSAX[FIPS_DSA_SUBPRIME_LENGTH];
michael@0 1957
michael@0 1958 /*******************************************/
michael@0 1959 /* Run the SP 800-90 Health tests */
michael@0 1960 /*******************************************/
michael@0 1961 rng_status = PRNGTEST_RunHealthTests();
michael@0 1962 if (rng_status != SECSuccess) {
michael@0 1963 return (CKR_DEVICE_ERROR);
michael@0 1964 }
michael@0 1965
michael@0 1966 /*******************************************/
michael@0 1967 /* Generate DSAX fow given Q. */
michael@0 1968 /*******************************************/
michael@0 1969
michael@0 1970 rng_status = FIPS186Change_ReduceModQForDSA(GENX, Q, DSAX);
michael@0 1971
michael@0 1972 /* Verify DSAX to perform the RNG integrity check */
michael@0 1973 if( ( rng_status != SECSuccess ) ||
michael@0 1974 ( PORT_Memcmp( DSAX, rng_known_DSAX,
michael@0 1975 (FIPS_DSA_SUBPRIME_LENGTH) ) != 0 ) )
michael@0 1976 return( CKR_DEVICE_ERROR );
michael@0 1977
michael@0 1978 return( CKR_OK );
michael@0 1979 }
michael@0 1980
michael@0 1981 static CK_RV
michael@0 1982 sftk_fipsSoftwareIntegrityTest(void)
michael@0 1983 {
michael@0 1984 CK_RV crv = CKR_OK;
michael@0 1985
michael@0 1986 /* make sure that our check file signatures are OK */
michael@0 1987 if( !BLAPI_VerifySelf( NULL ) ||
michael@0 1988 !BLAPI_SHVerify( SOFTOKEN_LIB_NAME, (PRFuncPtr) sftk_fips_HMAC ) ) {
michael@0 1989 crv = CKR_DEVICE_ERROR; /* better error code? checksum error? */
michael@0 1990 }
michael@0 1991 return crv;
michael@0 1992 }
michael@0 1993
michael@0 1994 CK_RV
michael@0 1995 sftk_fipsPowerUpSelfTest( void )
michael@0 1996 {
michael@0 1997 CK_RV rv;
michael@0 1998
michael@0 1999 /* RC2 Power-Up SelfTest(s). */
michael@0 2000 rv = sftk_fips_RC2_PowerUpSelfTest();
michael@0 2001
michael@0 2002 if( rv != CKR_OK )
michael@0 2003 return rv;
michael@0 2004
michael@0 2005 /* RC4 Power-Up SelfTest(s). */
michael@0 2006 rv = sftk_fips_RC4_PowerUpSelfTest();
michael@0 2007
michael@0 2008 if( rv != CKR_OK )
michael@0 2009 return rv;
michael@0 2010
michael@0 2011 /* DES Power-Up SelfTest(s). */
michael@0 2012 rv = sftk_fips_DES_PowerUpSelfTest();
michael@0 2013
michael@0 2014 if( rv != CKR_OK )
michael@0 2015 return rv;
michael@0 2016
michael@0 2017 /* DES3 Power-Up SelfTest(s). */
michael@0 2018 rv = sftk_fips_DES3_PowerUpSelfTest();
michael@0 2019
michael@0 2020 if( rv != CKR_OK )
michael@0 2021 return rv;
michael@0 2022
michael@0 2023 /* AES Power-Up SelfTest(s) for 128-bit key. */
michael@0 2024 rv = sftk_fips_AES_PowerUpSelfTest(FIPS_AES_128_KEY_SIZE);
michael@0 2025
michael@0 2026 if( rv != CKR_OK )
michael@0 2027 return rv;
michael@0 2028
michael@0 2029 /* AES Power-Up SelfTest(s) for 192-bit key. */
michael@0 2030 rv = sftk_fips_AES_PowerUpSelfTest(FIPS_AES_192_KEY_SIZE);
michael@0 2031
michael@0 2032 if( rv != CKR_OK )
michael@0 2033 return rv;
michael@0 2034
michael@0 2035 /* AES Power-Up SelfTest(s) for 256-bit key. */
michael@0 2036 rv = sftk_fips_AES_PowerUpSelfTest(FIPS_AES_256_KEY_SIZE);
michael@0 2037
michael@0 2038 if( rv != CKR_OK )
michael@0 2039 return rv;
michael@0 2040
michael@0 2041 /* MD2 Power-Up SelfTest(s). */
michael@0 2042 rv = sftk_fips_MD2_PowerUpSelfTest();
michael@0 2043
michael@0 2044 if( rv != CKR_OK )
michael@0 2045 return rv;
michael@0 2046
michael@0 2047 /* MD5 Power-Up SelfTest(s). */
michael@0 2048 rv = sftk_fips_MD5_PowerUpSelfTest();
michael@0 2049
michael@0 2050 if( rv != CKR_OK )
michael@0 2051 return rv;
michael@0 2052
michael@0 2053 /* SHA-X Power-Up SelfTest(s). */
michael@0 2054 rv = sftk_fips_SHA_PowerUpSelfTest();
michael@0 2055
michael@0 2056 if( rv != CKR_OK )
michael@0 2057 return rv;
michael@0 2058
michael@0 2059 /* HMAC SHA-X Power-Up SelfTest(s). */
michael@0 2060 rv = sftk_fips_HMAC_PowerUpSelfTest();
michael@0 2061
michael@0 2062 if( rv != CKR_OK )
michael@0 2063 return rv;
michael@0 2064
michael@0 2065 /* RSA Power-Up SelfTest(s). */
michael@0 2066 rv = sftk_fips_RSA_PowerUpSelfTest();
michael@0 2067
michael@0 2068 if( rv != CKR_OK )
michael@0 2069 return rv;
michael@0 2070
michael@0 2071 /* DSA Power-Up SelfTest(s). */
michael@0 2072 rv = sftk_fips_DSA_PowerUpSelfTest();
michael@0 2073
michael@0 2074 if( rv != CKR_OK )
michael@0 2075 return rv;
michael@0 2076
michael@0 2077 /* RNG Power-Up SelfTest(s). */
michael@0 2078 rv = sftk_fips_RNG_PowerUpSelfTest();
michael@0 2079
michael@0 2080 if( rv != CKR_OK )
michael@0 2081 return rv;
michael@0 2082
michael@0 2083 #ifndef NSS_DISABLE_ECC
michael@0 2084 /* ECDSA Power-Up SelfTest(s). */
michael@0 2085 rv = sftk_fips_ECDSA_PowerUpSelfTest();
michael@0 2086
michael@0 2087 if( rv != CKR_OK )
michael@0 2088 return rv;
michael@0 2089 #endif
michael@0 2090
michael@0 2091 /* Software/Firmware Integrity Test. */
michael@0 2092 rv = sftk_fipsSoftwareIntegrityTest();
michael@0 2093
michael@0 2094 if( rv != CKR_OK )
michael@0 2095 return rv;
michael@0 2096
michael@0 2097 /* Passed Power-Up SelfTest(s). */
michael@0 2098 return( CKR_OK );
michael@0 2099 }
michael@0 2100

mercurial