110500SHai-May.Chao@Sun.COM /*
210500SHai-May.Chao@Sun.COM * CDDL HEADER START
310500SHai-May.Chao@Sun.COM *
410500SHai-May.Chao@Sun.COM * The contents of this file are subject to the terms of the
510500SHai-May.Chao@Sun.COM * Common Development and Distribution License (the "License").
610500SHai-May.Chao@Sun.COM * You may not use this file except in compliance with the License.
710500SHai-May.Chao@Sun.COM *
810500SHai-May.Chao@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
910500SHai-May.Chao@Sun.COM * or http://www.opensolaris.org/os/licensing.
1010500SHai-May.Chao@Sun.COM * See the License for the specific language governing permissions
1110500SHai-May.Chao@Sun.COM * and limitations under the License.
1210500SHai-May.Chao@Sun.COM *
1310500SHai-May.Chao@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each
1410500SHai-May.Chao@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1510500SHai-May.Chao@Sun.COM * If applicable, add the following below this CDDL HEADER, with the
1610500SHai-May.Chao@Sun.COM * fields enclosed by brackets "[]" replaced with your own identifying
1710500SHai-May.Chao@Sun.COM * information: Portions Copyright [yyyy] [name of copyright owner]
1810500SHai-May.Chao@Sun.COM *
1910500SHai-May.Chao@Sun.COM * CDDL HEADER END
2010500SHai-May.Chao@Sun.COM */
21*12573SDina.Nimeh@Sun.COM
2210500SHai-May.Chao@Sun.COM /*
23*12573SDina.Nimeh@Sun.COM * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
2410500SHai-May.Chao@Sun.COM */
2510500SHai-May.Chao@Sun.COM
2610500SHai-May.Chao@Sun.COM #include <sys/types.h>
2710500SHai-May.Chao@Sun.COM #include <sys/sha1.h>
2810500SHai-May.Chao@Sun.COM #define _SHA2_IMPL
2910500SHai-May.Chao@Sun.COM #include <sys/sha2.h>
30*12573SDina.Nimeh@Sun.COM
31*12573SDina.Nimeh@Sun.COM #ifdef _KERNEL
32*12573SDina.Nimeh@Sun.COM
33*12573SDina.Nimeh@Sun.COM #include <sys/param.h>
34*12573SDina.Nimeh@Sun.COM #include <sys/kmem.h>
35*12573SDina.Nimeh@Sun.COM
36*12573SDina.Nimeh@Sun.COM #else
37*12573SDina.Nimeh@Sun.COM
38*12573SDina.Nimeh@Sun.COM #include <strings.h>
39*12573SDina.Nimeh@Sun.COM #include <cryptoutil.h>
40*12573SDina.Nimeh@Sun.COM #include "softMAC.h"
41*12573SDina.Nimeh@Sun.COM
42*12573SDina.Nimeh@Sun.COM #include <security/cryptoki.h>
4310500SHai-May.Chao@Sun.COM #include <sys/crypto/common.h>
44*12573SDina.Nimeh@Sun.COM
45*12573SDina.Nimeh@Sun.COM #endif
46*12573SDina.Nimeh@Sun.COM
47*12573SDina.Nimeh@Sun.COM #include <padding/padding.h>
48*12573SDina.Nimeh@Sun.COM #include <sha2/sha2_impl.h>
4910500SHai-May.Chao@Sun.COM #define _RSA_FIPS_POST
5010500SHai-May.Chao@Sun.COM #include <rsa/rsa_impl.h>
5110500SHai-May.Chao@Sun.COM
5210500SHai-May.Chao@Sun.COM int
fips_rsa_encrypt(RSAPrivateKey_t * key,uint8_t * in,int in_len,uint8_t * out)53*12573SDina.Nimeh@Sun.COM fips_rsa_encrypt(RSAPrivateKey_t *key, uint8_t *in, int in_len, uint8_t *out)
5410500SHai-May.Chao@Sun.COM {
55*12573SDina.Nimeh@Sun.COM return (rsa_encrypt(&(key->bkey), in, in_len, out));
5610500SHai-May.Chao@Sun.COM }
5710500SHai-May.Chao@Sun.COM
5810500SHai-May.Chao@Sun.COM int
fips_rsa_decrypt(RSAPrivateKey_t * key,uint8_t * in,int in_len,uint8_t * out)5910500SHai-May.Chao@Sun.COM fips_rsa_decrypt(RSAPrivateKey_t *key, uint8_t *in, int in_len,
6010500SHai-May.Chao@Sun.COM uint8_t *out)
6110500SHai-May.Chao@Sun.COM {
62*12573SDina.Nimeh@Sun.COM return (rsa_decrypt(&(key->bkey), in, in_len, out));
6310500SHai-May.Chao@Sun.COM }
6410500SHai-May.Chao@Sun.COM
6510500SHai-May.Chao@Sun.COM static CK_RV
6610500SHai-May.Chao@Sun.COM #ifdef _KERNEL
fips_rsa_sign_verify_test(sha2_mech_t mechanism,RSAPrivateKey_t * rsa_private_key,unsigned char * rsa_known_msg,unsigned int rsa_msg_length,unsigned char * rsa_computed_signature,unsigned char * der_data,int sign)6710500SHai-May.Chao@Sun.COM fips_rsa_sign_verify_test(sha2_mech_t mechanism,
6810500SHai-May.Chao@Sun.COM #else
6910500SHai-May.Chao@Sun.COM fips_rsa_sign_verify_test(CK_MECHANISM_TYPE mechanism,
7010500SHai-May.Chao@Sun.COM #endif
7110500SHai-May.Chao@Sun.COM RSAPrivateKey_t *rsa_private_key,
7210500SHai-May.Chao@Sun.COM unsigned char *rsa_known_msg,
7310500SHai-May.Chao@Sun.COM unsigned int rsa_msg_length,
7410500SHai-May.Chao@Sun.COM unsigned char *rsa_computed_signature,
7510500SHai-May.Chao@Sun.COM unsigned char *der_data, int sign)
7610500SHai-May.Chao@Sun.COM
7710500SHai-May.Chao@Sun.COM {
7810500SHai-May.Chao@Sun.COM unsigned char hash[SHA512_DIGEST_LENGTH]; /* SHA digest */
7910500SHai-May.Chao@Sun.COM SHA1_CTX *sha1_context = NULL;
8010500SHai-May.Chao@Sun.COM SHA2_CTX *sha2_context = NULL;
8110500SHai-May.Chao@Sun.COM int hash_len;
8210500SHai-May.Chao@Sun.COM CK_RV rv;
8310500SHai-May.Chao@Sun.COM CK_ULONG der_len;
8410500SHai-May.Chao@Sun.COM CK_BYTE *der_prefix;
8510500SHai-May.Chao@Sun.COM CK_ULONG der_data_len;
8610500SHai-May.Chao@Sun.COM CK_BYTE plain_data[MAX_RSA_KEYLENGTH_IN_BYTES];
8710500SHai-May.Chao@Sun.COM uint32_t modulus_len;
8810500SHai-May.Chao@Sun.COM
8910500SHai-May.Chao@Sun.COM switch (mechanism) {
9010500SHai-May.Chao@Sun.COM #ifdef _KERNEL
9110500SHai-May.Chao@Sun.COM case SHA1_TYPE:
9210500SHai-May.Chao@Sun.COM #else
9310500SHai-May.Chao@Sun.COM case CKM_SHA_1:
9410500SHai-May.Chao@Sun.COM #endif
9510500SHai-May.Chao@Sun.COM {
9610500SHai-May.Chao@Sun.COM
9710500SHai-May.Chao@Sun.COM #ifdef _KERNEL
9810500SHai-May.Chao@Sun.COM if ((sha1_context = kmem_zalloc(sizeof (SHA1_CTX),
9910500SHai-May.Chao@Sun.COM KM_SLEEP)) == NULL)
10010500SHai-May.Chao@Sun.COM #else
10110500SHai-May.Chao@Sun.COM if ((sha1_context = malloc(sizeof (SHA1_CTX))) == NULL)
10210500SHai-May.Chao@Sun.COM #endif
10310500SHai-May.Chao@Sun.COM return (CKR_HOST_MEMORY);
10410500SHai-May.Chao@Sun.COM
10510500SHai-May.Chao@Sun.COM SHA1Init(sha1_context);
10610500SHai-May.Chao@Sun.COM
10710500SHai-May.Chao@Sun.COM #ifdef __sparcv9
10810500SHai-May.Chao@Sun.COM SHA1Update(sha1_context, rsa_known_msg,
10910500SHai-May.Chao@Sun.COM (uint_t)rsa_msg_length);
11010500SHai-May.Chao@Sun.COM #else /* !__sparcv9 */
11110500SHai-May.Chao@Sun.COM SHA1Update(sha1_context, rsa_known_msg, rsa_msg_length);
11210500SHai-May.Chao@Sun.COM #endif /* __sparcv9 */
11310500SHai-May.Chao@Sun.COM SHA1Final(hash, sha1_context);
11410500SHai-May.Chao@Sun.COM
11510500SHai-May.Chao@Sun.COM hash_len = SHA1_DIGEST_LENGTH;
11610500SHai-May.Chao@Sun.COM
11710500SHai-May.Chao@Sun.COM /*
11810500SHai-May.Chao@Sun.COM * Prepare the DER encoding of the DigestInfo value
11910500SHai-May.Chao@Sun.COM * by setting it to:
12010500SHai-May.Chao@Sun.COM * <MECH>_DER_PREFIX || H
12110500SHai-May.Chao@Sun.COM */
12210500SHai-May.Chao@Sun.COM der_len = SHA1_DER_PREFIX_Len;
12310500SHai-May.Chao@Sun.COM der_prefix = (CK_BYTE *)SHA1_DER_PREFIX;
12410500SHai-May.Chao@Sun.COM (void) memcpy(der_data, der_prefix, der_len);
12510500SHai-May.Chao@Sun.COM (void) memcpy(der_data + der_len, hash, hash_len);
12610500SHai-May.Chao@Sun.COM der_data_len = der_len + hash_len;
12710979SHai-May.Chao@Sun.COM #ifdef _KERNEL
12810979SHai-May.Chao@Sun.COM kmem_free(sha1_context, sizeof (SHA1_CTX));
12910979SHai-May.Chao@Sun.COM #else
13010979SHai-May.Chao@Sun.COM free(sha1_context);
13110979SHai-May.Chao@Sun.COM #endif
13210500SHai-May.Chao@Sun.COM break;
13310500SHai-May.Chao@Sun.COM }
13410500SHai-May.Chao@Sun.COM
13510500SHai-May.Chao@Sun.COM #ifdef _KERNEL
13610500SHai-May.Chao@Sun.COM case SHA256_TYPE:
13710500SHai-May.Chao@Sun.COM #else
13810500SHai-May.Chao@Sun.COM case CKM_SHA256:
13910500SHai-May.Chao@Sun.COM #endif
14010500SHai-May.Chao@Sun.COM {
14110500SHai-May.Chao@Sun.COM
14210500SHai-May.Chao@Sun.COM sha2_context = fips_sha2_build_context(mechanism);
14310500SHai-May.Chao@Sun.COM if (sha2_context == NULL)
14410500SHai-May.Chao@Sun.COM return (CKR_HOST_MEMORY);
14510500SHai-May.Chao@Sun.COM
14610500SHai-May.Chao@Sun.COM rv = fips_sha2_hash(sha2_context, rsa_known_msg,
14710500SHai-May.Chao@Sun.COM rsa_msg_length, hash);
14810500SHai-May.Chao@Sun.COM hash_len = SHA256_DIGEST_LENGTH;
14910500SHai-May.Chao@Sun.COM
15010500SHai-May.Chao@Sun.COM /*
15110500SHai-May.Chao@Sun.COM * Prepare the DER encoding of the DigestInfo value
15210500SHai-May.Chao@Sun.COM * by setting it to:
15310500SHai-May.Chao@Sun.COM * <MECH>_DER_PREFIX || H
15410500SHai-May.Chao@Sun.COM */
15510500SHai-May.Chao@Sun.COM (void) memcpy(der_data, SHA256_DER_PREFIX,
15610500SHai-May.Chao@Sun.COM SHA2_DER_PREFIX_Len);
15710500SHai-May.Chao@Sun.COM (void) memcpy(der_data + SHA2_DER_PREFIX_Len, hash, hash_len);
15810500SHai-May.Chao@Sun.COM der_data_len = SHA2_DER_PREFIX_Len + hash_len;
15910500SHai-May.Chao@Sun.COM break;
16010500SHai-May.Chao@Sun.COM }
16110500SHai-May.Chao@Sun.COM #ifdef _KERNEL
16210500SHai-May.Chao@Sun.COM case SHA384_TYPE:
16310500SHai-May.Chao@Sun.COM #else
16410500SHai-May.Chao@Sun.COM case CKM_SHA384:
16510500SHai-May.Chao@Sun.COM #endif
16610500SHai-May.Chao@Sun.COM {
16710500SHai-May.Chao@Sun.COM
16810500SHai-May.Chao@Sun.COM sha2_context = fips_sha2_build_context(mechanism);
16910500SHai-May.Chao@Sun.COM if (sha2_context == NULL)
17010500SHai-May.Chao@Sun.COM return (CKR_HOST_MEMORY);
17110500SHai-May.Chao@Sun.COM
17210500SHai-May.Chao@Sun.COM rv = fips_sha2_hash(sha2_context, rsa_known_msg,
17310500SHai-May.Chao@Sun.COM rsa_msg_length, hash);
17410500SHai-May.Chao@Sun.COM hash_len = SHA384_DIGEST_LENGTH;
17510500SHai-May.Chao@Sun.COM
17610500SHai-May.Chao@Sun.COM /*
17710500SHai-May.Chao@Sun.COM * Prepare the DER encoding of the DigestInfo value
17810500SHai-May.Chao@Sun.COM * by setting it to:
17910500SHai-May.Chao@Sun.COM * <MECH>_DER_PREFIX || H
18010500SHai-May.Chao@Sun.COM */
18110500SHai-May.Chao@Sun.COM (void) memcpy(der_data, SHA384_DER_PREFIX,
18210500SHai-May.Chao@Sun.COM SHA2_DER_PREFIX_Len);
18310500SHai-May.Chao@Sun.COM (void) memcpy(der_data + SHA2_DER_PREFIX_Len, hash, hash_len);
18410500SHai-May.Chao@Sun.COM der_data_len = SHA2_DER_PREFIX_Len + hash_len;
18510500SHai-May.Chao@Sun.COM break;
18610500SHai-May.Chao@Sun.COM }
18710500SHai-May.Chao@Sun.COM #ifdef _KERNEL
18810500SHai-May.Chao@Sun.COM case SHA512_TYPE:
18910500SHai-May.Chao@Sun.COM #else
19010500SHai-May.Chao@Sun.COM case CKM_SHA512:
19110500SHai-May.Chao@Sun.COM #endif
19210500SHai-May.Chao@Sun.COM {
19310500SHai-May.Chao@Sun.COM
19410500SHai-May.Chao@Sun.COM sha2_context = fips_sha2_build_context(mechanism);
19510500SHai-May.Chao@Sun.COM if (sha2_context == NULL)
19610500SHai-May.Chao@Sun.COM return (CKR_HOST_MEMORY);
19710500SHai-May.Chao@Sun.COM
19810500SHai-May.Chao@Sun.COM rv = fips_sha2_hash(sha2_context, rsa_known_msg,
19910500SHai-May.Chao@Sun.COM rsa_msg_length, hash);
20010500SHai-May.Chao@Sun.COM hash_len = SHA512_DIGEST_LENGTH;
20110500SHai-May.Chao@Sun.COM
20210500SHai-May.Chao@Sun.COM /*
20310500SHai-May.Chao@Sun.COM * Prepare the DER encoding of the DigestInfo value
20410500SHai-May.Chao@Sun.COM * by setting it to:
20510500SHai-May.Chao@Sun.COM * <MECH>_DER_PREFIX || H
20610500SHai-May.Chao@Sun.COM */
20710500SHai-May.Chao@Sun.COM (void) memcpy(der_data, SHA512_DER_PREFIX,
20810500SHai-May.Chao@Sun.COM SHA2_DER_PREFIX_Len);
20910500SHai-May.Chao@Sun.COM (void) memcpy(der_data + SHA2_DER_PREFIX_Len, hash, hash_len);
21010500SHai-May.Chao@Sun.COM der_data_len = SHA2_DER_PREFIX_Len + hash_len;
21110500SHai-May.Chao@Sun.COM break;
21210500SHai-May.Chao@Sun.COM }
21310500SHai-May.Chao@Sun.COM }
21410500SHai-May.Chao@Sun.COM
215*12573SDina.Nimeh@Sun.COM modulus_len = CRYPTO_BITS2BYTES(rsa_private_key->bkey.modulus_bits);
21610500SHai-May.Chao@Sun.COM
21710500SHai-May.Chao@Sun.COM if (sign) {
218*12573SDina.Nimeh@Sun.COM rv = pkcs1_encode(PKCS1_SIGN, der_data, der_data_len,
21910500SHai-May.Chao@Sun.COM plain_data, modulus_len);
22010500SHai-May.Chao@Sun.COM
22110500SHai-May.Chao@Sun.COM if (rv != CKR_OK) {
22210500SHai-May.Chao@Sun.COM return (CKR_DEVICE_ERROR);
22310500SHai-May.Chao@Sun.COM }
22410500SHai-May.Chao@Sun.COM
225*12573SDina.Nimeh@Sun.COM /* Sign operation uses decryption with private key */
226*12573SDina.Nimeh@Sun.COM rv = fips_rsa_decrypt(rsa_private_key, plain_data, modulus_len,
22710500SHai-May.Chao@Sun.COM rsa_computed_signature);
22810500SHai-May.Chao@Sun.COM
22910500SHai-May.Chao@Sun.COM if (rv != CKR_OK) {
23010500SHai-May.Chao@Sun.COM return (CKR_DEVICE_ERROR);
23110500SHai-May.Chao@Sun.COM }
23210500SHai-May.Chao@Sun.COM } else {
23310500SHai-May.Chao@Sun.COM /*
23410500SHai-May.Chao@Sun.COM * Perform RSA decryption with the signer's RSA public key
23510500SHai-May.Chao@Sun.COM * for verification process.
23610500SHai-May.Chao@Sun.COM */
237*12573SDina.Nimeh@Sun.COM rv = fips_rsa_encrypt(rsa_private_key, rsa_computed_signature,
23810500SHai-May.Chao@Sun.COM modulus_len, plain_data);
23910500SHai-May.Chao@Sun.COM
24010500SHai-May.Chao@Sun.COM if (rv == CKR_OK) {
24110500SHai-May.Chao@Sun.COM
24210500SHai-May.Chao@Sun.COM /*
24310500SHai-May.Chao@Sun.COM * Strip off the encoded padding bytes in front of the
24410500SHai-May.Chao@Sun.COM * recovered data, then compare the recovered data with
24510500SHai-May.Chao@Sun.COM * the original data.
24610500SHai-May.Chao@Sun.COM */
247*12573SDina.Nimeh@Sun.COM size_t data_len = modulus_len;
24810500SHai-May.Chao@Sun.COM
249*12573SDina.Nimeh@Sun.COM rv = pkcs1_decode(PKCS1_VERIFY, plain_data, &data_len);
25010500SHai-May.Chao@Sun.COM if (rv != CKR_OK) {
25110500SHai-May.Chao@Sun.COM return (CKR_DEVICE_ERROR);
25210500SHai-May.Chao@Sun.COM }
25310500SHai-May.Chao@Sun.COM
25410500SHai-May.Chao@Sun.COM if ((CK_ULONG)data_len != der_data_len) {
25510500SHai-May.Chao@Sun.COM return (CKR_SIGNATURE_LEN_RANGE);
25610500SHai-May.Chao@Sun.COM } else if (memcmp(der_data,
25710500SHai-May.Chao@Sun.COM &plain_data[modulus_len - data_len],
25810500SHai-May.Chao@Sun.COM data_len) != 0) {
25910500SHai-May.Chao@Sun.COM return (CKR_SIGNATURE_INVALID);
26010500SHai-May.Chao@Sun.COM }
26110500SHai-May.Chao@Sun.COM } else {
26210500SHai-May.Chao@Sun.COM
26310500SHai-May.Chao@Sun.COM return (CKR_DEVICE_ERROR);
26410500SHai-May.Chao@Sun.COM }
26510500SHai-May.Chao@Sun.COM }
26610500SHai-May.Chao@Sun.COM return (CKR_OK);
26710500SHai-May.Chao@Sun.COM }
26810500SHai-May.Chao@Sun.COM
26910500SHai-May.Chao@Sun.COM
27010500SHai-May.Chao@Sun.COM /*
27110500SHai-May.Chao@Sun.COM * RSA Power-On SelfTest(s).
27210500SHai-May.Chao@Sun.COM */
27310500SHai-May.Chao@Sun.COM int
fips_rsa_post(void)27410500SHai-May.Chao@Sun.COM fips_rsa_post(void)
27510500SHai-May.Chao@Sun.COM {
27610500SHai-May.Chao@Sun.COM /*
27710500SHai-May.Chao@Sun.COM * RSA Known Modulus used in both Public/Private Key Values (1024-bits).
27810500SHai-May.Chao@Sun.COM */
27910500SHai-May.Chao@Sun.COM static uint8_t rsa_modulus[FIPS_RSA_MODULUS_LENGTH] = {
28010500SHai-May.Chao@Sun.COM 0xd5, 0x84, 0x95, 0x07, 0xf4, 0xd0, 0x1f, 0x82,
28110500SHai-May.Chao@Sun.COM 0xf3, 0x79, 0xf4, 0x99, 0x48, 0x10, 0xe1, 0x71,
28210500SHai-May.Chao@Sun.COM 0xa5, 0x62, 0x22, 0xa3, 0x4b, 0x00, 0xe3, 0x5b,
28310500SHai-May.Chao@Sun.COM 0x3a, 0xcc, 0x10, 0x83, 0xe0, 0xaf, 0x61, 0x13,
28410500SHai-May.Chao@Sun.COM 0x54, 0x6a, 0xa2, 0x6a, 0x2c, 0x5e, 0xb3, 0xcc,
28510500SHai-May.Chao@Sun.COM 0xa3, 0x71, 0x9a, 0xb2, 0x3e, 0x78, 0xec, 0xb5,
28610500SHai-May.Chao@Sun.COM 0x0e, 0x6e, 0x31, 0x3b, 0x77, 0x1f, 0x6e, 0x94,
28710500SHai-May.Chao@Sun.COM 0x41, 0x60, 0xd5, 0x6e, 0xd9, 0xc6, 0xf9, 0x29,
28810500SHai-May.Chao@Sun.COM 0xc3, 0x40, 0x36, 0x25, 0xdb, 0xea, 0x0b, 0x07,
28910500SHai-May.Chao@Sun.COM 0xae, 0x76, 0xfd, 0x99, 0x29, 0xf4, 0x22, 0xc1,
29010500SHai-May.Chao@Sun.COM 0x1a, 0x8f, 0x05, 0xfe, 0x98, 0x09, 0x07, 0x05,
29110500SHai-May.Chao@Sun.COM 0xc2, 0x0f, 0x0b, 0x11, 0x83, 0x39, 0xca, 0xc7,
29210500SHai-May.Chao@Sun.COM 0x43, 0x63, 0xff, 0x33, 0x80, 0xe7, 0xc3, 0x78,
29310500SHai-May.Chao@Sun.COM 0xae, 0xf1, 0x73, 0x52, 0x98, 0x1d, 0xde, 0x5c,
29410500SHai-May.Chao@Sun.COM 0x53, 0x6e, 0x01, 0x73, 0x0d, 0x12, 0x7e, 0x77,
29510500SHai-May.Chao@Sun.COM 0x03, 0xf1, 0xef, 0x1b, 0xc8, 0xa8, 0x0f, 0x97
29610500SHai-May.Chao@Sun.COM };
29710500SHai-May.Chao@Sun.COM
29810500SHai-May.Chao@Sun.COM /* RSA Known Public Key Values (24-bits). */
29910500SHai-May.Chao@Sun.COM static uint8_t rsa_public_exponent[FIPS_RSA_PUBLIC_EXPONENT_LENGTH] = {
30010500SHai-May.Chao@Sun.COM 0x01, 0x00, 0x01
30110500SHai-May.Chao@Sun.COM };
30210500SHai-May.Chao@Sun.COM
30310500SHai-May.Chao@Sun.COM /*
30410500SHai-May.Chao@Sun.COM * RSA Known Private Key Values (version is 8-bits),
30510500SHai-May.Chao@Sun.COM * (private exponent is 1024-bits),
30610500SHai-May.Chao@Sun.COM * (private prime0 is 512-bits),
30710500SHai-May.Chao@Sun.COM * (private prime1 is 512-bits),
30810500SHai-May.Chao@Sun.COM * (private prime exponent0 is 512-bits),
30910500SHai-May.Chao@Sun.COM * (private prime exponent1 is 512-bits),
31010500SHai-May.Chao@Sun.COM * and (private coefficient is 512-bits).
31110500SHai-May.Chao@Sun.COM */
31210500SHai-May.Chao@Sun.COM static uint8_t rsa_version[] = { 0x00 };
31310500SHai-May.Chao@Sun.COM
31410500SHai-May.Chao@Sun.COM static uint8_t rsa_private_exponent[FIPS_RSA_PRIVATE_EXPONENT_LENGTH]
31510500SHai-May.Chao@Sun.COM = {
31610500SHai-May.Chao@Sun.COM 0x85, 0x27, 0x47, 0x61, 0x4c, 0xd4, 0xb5, 0xb2,
31710500SHai-May.Chao@Sun.COM 0x0e, 0x70, 0x91, 0x8f, 0x3d, 0x97, 0xf9, 0x5f,
31810500SHai-May.Chao@Sun.COM 0xcc, 0x09, 0x65, 0x1c, 0x7c, 0x5b, 0xb3, 0x6d,
31910500SHai-May.Chao@Sun.COM 0x63, 0x3f, 0x7b, 0x55, 0x22, 0xbb, 0x7c, 0x48,
32010500SHai-May.Chao@Sun.COM 0x77, 0xae, 0x80, 0x56, 0xc2, 0x10, 0xd5, 0x03,
32110500SHai-May.Chao@Sun.COM 0xdb, 0x31, 0xaf, 0x8d, 0x54, 0xd4, 0x48, 0x99,
32210500SHai-May.Chao@Sun.COM 0xa8, 0xc4, 0x23, 0x43, 0xb8, 0x48, 0x0b, 0xc7,
32310500SHai-May.Chao@Sun.COM 0xbc, 0xf5, 0xcc, 0x64, 0x72, 0xbf, 0x59, 0x06,
32410500SHai-May.Chao@Sun.COM 0x04, 0x1c, 0x32, 0xf5, 0x14, 0x2e, 0x6e, 0xe2,
32510500SHai-May.Chao@Sun.COM 0x0f, 0x5c, 0xde, 0x36, 0x3c, 0x6e, 0x7c, 0x4d,
32610500SHai-May.Chao@Sun.COM 0xcc, 0xd3, 0x00, 0x6e, 0xe5, 0x45, 0x46, 0xef,
32710500SHai-May.Chao@Sun.COM 0x4d, 0x25, 0x46, 0x6d, 0x7f, 0xed, 0xbb, 0x4f,
32810500SHai-May.Chao@Sun.COM 0x4d, 0x9f, 0xda, 0x87, 0x47, 0x8f, 0x74, 0x44,
32910500SHai-May.Chao@Sun.COM 0xb7, 0xbe, 0x9d, 0xf5, 0xdd, 0xd2, 0x4c, 0xa5,
33010500SHai-May.Chao@Sun.COM 0xab, 0x74, 0xe5, 0x29, 0xa1, 0xd2, 0x45, 0x3b,
33110500SHai-May.Chao@Sun.COM 0x33, 0xde, 0xd5, 0xae, 0xf7, 0x03, 0x10, 0x21
33210500SHai-May.Chao@Sun.COM };
33310500SHai-May.Chao@Sun.COM
33410500SHai-May.Chao@Sun.COM static uint8_t rsa_prime0[FIPS_RSA_PRIME0_LENGTH] = {
33510500SHai-May.Chao@Sun.COM 0xf9, 0x74, 0x8f, 0x16, 0x02, 0x6b, 0xa0, 0xee,
33610500SHai-May.Chao@Sun.COM 0x7f, 0x28, 0x97, 0x91, 0xdc, 0xec, 0xc0, 0x7c,
33710500SHai-May.Chao@Sun.COM 0x49, 0xc2, 0x85, 0x76, 0xee, 0x66, 0x74, 0x2d,
33810500SHai-May.Chao@Sun.COM 0x1a, 0xb8, 0xf7, 0x2f, 0x11, 0x5b, 0x36, 0xd8,
33910500SHai-May.Chao@Sun.COM 0x46, 0x33, 0x3b, 0xd8, 0xf3, 0x2d, 0xa1, 0x03,
34010500SHai-May.Chao@Sun.COM 0x83, 0x2b, 0xec, 0x35, 0x43, 0x32, 0xff, 0xdd,
34110500SHai-May.Chao@Sun.COM 0x81, 0x7c, 0xfd, 0x65, 0x13, 0x04, 0x7c, 0xfc,
34210500SHai-May.Chao@Sun.COM 0x03, 0x97, 0xf0, 0xd5, 0x62, 0xdc, 0x0d, 0xbf
34310500SHai-May.Chao@Sun.COM };
34410500SHai-May.Chao@Sun.COM
34510500SHai-May.Chao@Sun.COM static uint8_t rsa_prime1[FIPS_RSA_PRIME1_LENGTH] = {
34610500SHai-May.Chao@Sun.COM 0xdb, 0x1e, 0xa7, 0x3d, 0xe7, 0xfa, 0x8b, 0x04,
34710500SHai-May.Chao@Sun.COM 0x83, 0x48, 0xf3, 0xa5, 0x31, 0x9d, 0x35, 0x5e,
34810500SHai-May.Chao@Sun.COM 0x4d, 0x54, 0x77, 0xcc, 0x84, 0x09, 0xf3, 0x11,
34910500SHai-May.Chao@Sun.COM 0x0d, 0x54, 0xed, 0x85, 0x39, 0xa9, 0xca, 0xa8,
35010500SHai-May.Chao@Sun.COM 0xea, 0xae, 0x19, 0x9c, 0x75, 0xdb, 0x88, 0xb8,
35110500SHai-May.Chao@Sun.COM 0x04, 0x8d, 0x54, 0xc6, 0xa4, 0x80, 0xf8, 0x93,
35210500SHai-May.Chao@Sun.COM 0xf0, 0xdb, 0x19, 0xef, 0xd7, 0x87, 0x8a, 0x8f,
35310500SHai-May.Chao@Sun.COM 0x5a, 0x09, 0x2e, 0x54, 0xf3, 0x45, 0x24, 0x29
35410500SHai-May.Chao@Sun.COM };
35510500SHai-May.Chao@Sun.COM
35610500SHai-May.Chao@Sun.COM static uint8_t rsa_exponent0[FIPS_RSA_EXPONENT0_LENGTH] = {
35710500SHai-May.Chao@Sun.COM 0x6a, 0xd1, 0x25, 0x80, 0x18, 0x33, 0x3c, 0x2b,
35810500SHai-May.Chao@Sun.COM 0x44, 0x19, 0xfe, 0xa5, 0x40, 0x03, 0xc4, 0xfc,
35910500SHai-May.Chao@Sun.COM 0xb3, 0x9c, 0xef, 0x07, 0x99, 0x58, 0x17, 0xc1,
36010500SHai-May.Chao@Sun.COM 0x44, 0xa3, 0x15, 0x7d, 0x7b, 0x22, 0x22, 0xdf,
36110500SHai-May.Chao@Sun.COM 0x03, 0x58, 0x66, 0xf5, 0x24, 0x54, 0x52, 0x91,
36210500SHai-May.Chao@Sun.COM 0x2d, 0x76, 0xfe, 0x63, 0x64, 0x4e, 0x0f, 0x50,
36310500SHai-May.Chao@Sun.COM 0x2b, 0x65, 0x79, 0x1f, 0xf1, 0xbf, 0xc7, 0x41,
36410500SHai-May.Chao@Sun.COM 0x26, 0xcc, 0xc6, 0x1c, 0xa9, 0x83, 0x6f, 0x03
36510500SHai-May.Chao@Sun.COM };
36610500SHai-May.Chao@Sun.COM
36710500SHai-May.Chao@Sun.COM static uint8_t rsa_exponent1[FIPS_RSA_EXPONENT1_LENGTH] = {
36810500SHai-May.Chao@Sun.COM 0x12, 0x84, 0x1a, 0x99, 0xce, 0x9a, 0x8b, 0x58,
36910500SHai-May.Chao@Sun.COM 0xcc, 0x47, 0x43, 0xdf, 0x77, 0xbb, 0xd3, 0x20,
37010500SHai-May.Chao@Sun.COM 0xae, 0xe4, 0x2e, 0x63, 0x67, 0xdc, 0xf7, 0x5f,
37110500SHai-May.Chao@Sun.COM 0x3f, 0x83, 0x27, 0xb7, 0x14, 0x52, 0x56, 0xbf,
37210500SHai-May.Chao@Sun.COM 0xc3, 0x65, 0x06, 0xe1, 0x03, 0xcc, 0x93, 0x57,
37310500SHai-May.Chao@Sun.COM 0x09, 0x7b, 0x6f, 0xe8, 0x81, 0x4a, 0x2c, 0xb7,
37410500SHai-May.Chao@Sun.COM 0x43, 0xa9, 0x20, 0x1d, 0xf6, 0x56, 0x8b, 0xcc,
37510500SHai-May.Chao@Sun.COM 0xe5, 0x4c, 0xd5, 0x4f, 0x74, 0x67, 0x29, 0x51
37610500SHai-May.Chao@Sun.COM };
37710500SHai-May.Chao@Sun.COM
37810500SHai-May.Chao@Sun.COM static uint8_t rsa_coefficient[FIPS_RSA_COEFFICIENT_LENGTH] = {
37910500SHai-May.Chao@Sun.COM 0x23, 0xab, 0xf4, 0x03, 0x2f, 0x29, 0x95, 0x74,
38010500SHai-May.Chao@Sun.COM 0xac, 0x1a, 0x33, 0x96, 0x62, 0xed, 0xf7, 0xf6,
38110500SHai-May.Chao@Sun.COM 0xae, 0x07, 0x2a, 0x2e, 0xe8, 0xab, 0xfb, 0x1e,
38210500SHai-May.Chao@Sun.COM 0xb9, 0xb2, 0x88, 0x1e, 0x85, 0x05, 0x42, 0x64,
38310500SHai-May.Chao@Sun.COM 0x03, 0xb2, 0x8b, 0xc1, 0x81, 0x75, 0xd7, 0xba,
38410500SHai-May.Chao@Sun.COM 0xaa, 0xd4, 0x31, 0x3c, 0x8a, 0x96, 0x23, 0x9d,
38510500SHai-May.Chao@Sun.COM 0x3f, 0x06, 0x3e, 0x44, 0xa9, 0x62, 0x2f, 0x61,
38610500SHai-May.Chao@Sun.COM 0x5a, 0x51, 0x82, 0x2c, 0x04, 0x85, 0x73, 0xd1
38710500SHai-May.Chao@Sun.COM };
38810500SHai-May.Chao@Sun.COM
38910500SHai-May.Chao@Sun.COM /* RSA Known Plaintext Message (1024-bits). */
39010500SHai-May.Chao@Sun.COM static uint8_t rsa_known_plaintext_msg[FIPS_RSA_MESSAGE_LENGTH] = {
39110500SHai-May.Chao@Sun.COM "Known plaintext message utilized"
39210500SHai-May.Chao@Sun.COM "for RSA Encryption & Decryption"
39310500SHai-May.Chao@Sun.COM "block, SHA1, SHA256, SHA384 and"
39410500SHai-May.Chao@Sun.COM "SHA512 RSA Signature KAT tests."
39510500SHai-May.Chao@Sun.COM };
39610500SHai-May.Chao@Sun.COM
39710500SHai-May.Chao@Sun.COM /* RSA Known Ciphertext (1024-bits). */
39810500SHai-May.Chao@Sun.COM static uint8_t rsa_known_ciphertext[] = {
39910500SHai-May.Chao@Sun.COM 0x1e, 0x7e, 0x12, 0xbb, 0x15, 0x62, 0xd0, 0x23,
40010500SHai-May.Chao@Sun.COM 0x53, 0x4c, 0x51, 0x97, 0x77, 0x06, 0xa0, 0xbb,
40110500SHai-May.Chao@Sun.COM 0x26, 0x99, 0x9a, 0x8f, 0x39, 0xad, 0x88, 0x5c,
40210500SHai-May.Chao@Sun.COM 0xc4, 0xce, 0x33, 0x40, 0x94, 0x92, 0xb4, 0x0e,
40310500SHai-May.Chao@Sun.COM 0xab, 0x71, 0xa9, 0x5d, 0x9a, 0x37, 0xe3, 0x9a,
40410500SHai-May.Chao@Sun.COM 0x24, 0x95, 0x13, 0xea, 0x0f, 0xbb, 0xf7, 0xff,
40510500SHai-May.Chao@Sun.COM 0xdf, 0x31, 0x33, 0x23, 0x1d, 0xce, 0x26, 0x9e,
40610500SHai-May.Chao@Sun.COM 0xd1, 0xde, 0x98, 0x40, 0xde, 0x57, 0x86, 0x12,
40710500SHai-May.Chao@Sun.COM 0xf1, 0xe6, 0x5a, 0x3f, 0x08, 0x02, 0x81, 0x85,
40810500SHai-May.Chao@Sun.COM 0xe0, 0xd9, 0xad, 0x3c, 0x8c, 0x71, 0xf8, 0xcf,
40910500SHai-May.Chao@Sun.COM 0x0a, 0x98, 0xc5, 0x08, 0xdc, 0xc4, 0xca, 0x8c,
41010500SHai-May.Chao@Sun.COM 0x23, 0x1b, 0x4d, 0x9b, 0xb5, 0x13, 0x44, 0xe1,
41110500SHai-May.Chao@Sun.COM 0x5f, 0xf9, 0x30, 0x80, 0x25, 0xe0, 0x1e, 0x94,
41210500SHai-May.Chao@Sun.COM 0xa3, 0x0c, 0xdc, 0x82, 0x2e, 0xfb, 0x30, 0xbe,
41310500SHai-May.Chao@Sun.COM 0x89, 0xba, 0x76, 0xb6, 0x23, 0xf7, 0xda, 0x7c,
41410500SHai-May.Chao@Sun.COM 0xca, 0xe6, 0x02, 0xbd, 0x92, 0xce, 0x64, 0xfc
41510500SHai-May.Chao@Sun.COM };
41610500SHai-May.Chao@Sun.COM
41710500SHai-May.Chao@Sun.COM /* RSA Known Signed Hash (1024-bits). */
41810500SHai-May.Chao@Sun.COM static uint8_t rsa_known_sha1_signature[] = {
41910500SHai-May.Chao@Sun.COM 0xd2, 0xa4, 0xe0, 0x2b, 0xc7, 0x03, 0x7f, 0xc6,
42010500SHai-May.Chao@Sun.COM 0x06, 0x9e, 0xa2, 0x82, 0x19, 0xe9, 0x2b, 0xaf,
42110500SHai-May.Chao@Sun.COM 0xe3, 0x48, 0x88, 0xc1, 0xf3, 0xb5, 0x0d, 0xe4,
42210500SHai-May.Chao@Sun.COM 0x52, 0x9e, 0xad, 0xd5, 0x58, 0xb5, 0x9f, 0xe8,
42310500SHai-May.Chao@Sun.COM 0x40, 0xe9, 0xb7, 0x2e, 0xc6, 0x71, 0x58, 0x56,
42410500SHai-May.Chao@Sun.COM 0x04, 0xac, 0xb0, 0xf3, 0x3a, 0x42, 0x38, 0x08,
42510500SHai-May.Chao@Sun.COM 0xc4, 0x43, 0x39, 0xba, 0x19, 0xce, 0xb1, 0x99,
42610500SHai-May.Chao@Sun.COM 0xf1, 0x8d, 0x89, 0xd8, 0x50, 0x07, 0x14, 0x3d,
42710500SHai-May.Chao@Sun.COM 0xcf, 0xd0, 0xb6, 0x79, 0xde, 0x9c, 0x89, 0x32,
42810500SHai-May.Chao@Sun.COM 0xb0, 0x73, 0x3f, 0xed, 0x03, 0x0b, 0xdf, 0x6d,
42910500SHai-May.Chao@Sun.COM 0x7e, 0xc9, 0x1c, 0x39, 0xe8, 0x2b, 0x16, 0x09,
43010500SHai-May.Chao@Sun.COM 0xbb, 0x5f, 0x99, 0x2f, 0xeb, 0xf3, 0x37, 0x73,
43110500SHai-May.Chao@Sun.COM 0x0d, 0x0e, 0xcc, 0x95, 0xad, 0x90, 0x80, 0x03,
43210500SHai-May.Chao@Sun.COM 0x1d, 0x80, 0x55, 0x37, 0xa1, 0x2a, 0x71, 0x76,
43310500SHai-May.Chao@Sun.COM 0x23, 0x87, 0x8c, 0x9b, 0x41, 0x07, 0xc6, 0x3d,
43410500SHai-May.Chao@Sun.COM 0xc6, 0xa3, 0x7d, 0x1b, 0xff, 0x4e, 0x11, 0x19
43510500SHai-May.Chao@Sun.COM };
43610500SHai-May.Chao@Sun.COM
43710500SHai-May.Chao@Sun.COM /* RSA Known Signed Hash (1024-bits). */
43810500SHai-May.Chao@Sun.COM static uint8_t rsa_known_sha256_signature[] = {
43910500SHai-May.Chao@Sun.COM 0x27, 0x35, 0xdd, 0xc4, 0xf8, 0xe2, 0x0b, 0xa3,
44010500SHai-May.Chao@Sun.COM 0xef, 0x63, 0x57, 0x3b, 0xe1, 0x58, 0x9a, 0xbc,
44110500SHai-May.Chao@Sun.COM 0x20, 0x9c, 0x25, 0x12, 0x01, 0xbf, 0xbb, 0x29,
44210500SHai-May.Chao@Sun.COM 0x80, 0x1a, 0xb1, 0x37, 0x9c, 0xcd, 0x67, 0xc7,
44310500SHai-May.Chao@Sun.COM 0x0d, 0xf8, 0x64, 0x10, 0x9f, 0xe2, 0xa1, 0x9b,
44410500SHai-May.Chao@Sun.COM 0x21, 0x90, 0xcc, 0xda, 0x8b, 0x76, 0x5e, 0x79,
44510500SHai-May.Chao@Sun.COM 0x00, 0x9d, 0x58, 0x8b, 0x8a, 0xb3, 0xc3, 0xb5,
44610500SHai-May.Chao@Sun.COM 0xf1, 0x54, 0xc5, 0x8c, 0x72, 0xba, 0xde, 0x51,
44710500SHai-May.Chao@Sun.COM 0x3c, 0x6b, 0x94, 0xd6, 0xf3, 0x1b, 0xa2, 0x53,
44810500SHai-May.Chao@Sun.COM 0xe6, 0x1a, 0x46, 0x1d, 0x7f, 0x14, 0x86, 0xcc,
44910500SHai-May.Chao@Sun.COM 0xa6, 0x30, 0x92, 0x96, 0xc0, 0x96, 0x24, 0xf0,
45010500SHai-May.Chao@Sun.COM 0x42, 0x53, 0x4c, 0xdd, 0x27, 0xdf, 0x1d, 0x2e,
45110500SHai-May.Chao@Sun.COM 0x8b, 0x83, 0xbe, 0xed, 0x85, 0x1d, 0x50, 0x46,
45210500SHai-May.Chao@Sun.COM 0xa3, 0x7d, 0x20, 0xea, 0x3e, 0x91, 0xfb, 0xf6,
45310500SHai-May.Chao@Sun.COM 0x86, 0x51, 0xfd, 0x8c, 0xe5, 0x31, 0xe6, 0x7e,
45410500SHai-May.Chao@Sun.COM 0x60, 0x08, 0x0e, 0xec, 0xa6, 0xea, 0x24, 0x8d
45510500SHai-May.Chao@Sun.COM };
45610500SHai-May.Chao@Sun.COM
45710500SHai-May.Chao@Sun.COM /* RSA Known Signed Hash (1024-bits). */
45810500SHai-May.Chao@Sun.COM static uint8_t rsa_known_sha384_signature[] = {
45910500SHai-May.Chao@Sun.COM 0x0b, 0x03, 0x94, 0x4f, 0x94, 0x78, 0x9b, 0x96,
46010500SHai-May.Chao@Sun.COM 0x76, 0xeb, 0x72, 0x58, 0xe1, 0xc5, 0xc7, 0x5f,
46110500SHai-May.Chao@Sun.COM 0x85, 0x01, 0xa8, 0xc4, 0xf6, 0x1a, 0xb5, 0x2c,
46210500SHai-May.Chao@Sun.COM 0xd1, 0xd8, 0x87, 0xde, 0x3a, 0x9c, 0x9f, 0x57,
46310500SHai-May.Chao@Sun.COM 0x81, 0x2a, 0x1e, 0x23, 0x07, 0x70, 0xb0, 0xf9,
46410500SHai-May.Chao@Sun.COM 0x28, 0x3d, 0xfa, 0xe5, 0x2e, 0x1b, 0x9a, 0x72,
46510500SHai-May.Chao@Sun.COM 0xc3, 0x74, 0xb3, 0x42, 0x1c, 0x9a, 0x13, 0xdc,
46610500SHai-May.Chao@Sun.COM 0xc9, 0xd6, 0xd5, 0x88, 0xc9, 0x9c, 0x46, 0xf1,
46710500SHai-May.Chao@Sun.COM 0x0c, 0xa6, 0xf7, 0xd8, 0x06, 0xa3, 0x1b, 0xdf,
46810500SHai-May.Chao@Sun.COM 0x55, 0xb3, 0x1b, 0x7b, 0x58, 0x1d, 0xff, 0x19,
46910500SHai-May.Chao@Sun.COM 0xc7, 0xe0, 0xdd, 0x59, 0xac, 0x2f, 0x78, 0x71,
47010500SHai-May.Chao@Sun.COM 0xe7, 0xe0, 0x17, 0xa3, 0x1c, 0x5c, 0x92, 0xef,
47110500SHai-May.Chao@Sun.COM 0xb6, 0x75, 0xed, 0xbe, 0x18, 0x39, 0x6b, 0xd7,
47210500SHai-May.Chao@Sun.COM 0xc9, 0x08, 0x62, 0x55, 0x62, 0xac, 0x5d, 0xa1,
47310500SHai-May.Chao@Sun.COM 0x9b, 0xd5, 0xb8, 0x98, 0x15, 0xc0, 0xf5, 0x41,
47410500SHai-May.Chao@Sun.COM 0x85, 0x44, 0x96, 0xca, 0x10, 0xdc, 0x57, 0x21
47510500SHai-May.Chao@Sun.COM };
47610500SHai-May.Chao@Sun.COM
47710500SHai-May.Chao@Sun.COM /* RSA Known Signed Hash (1024-bits). */
47810500SHai-May.Chao@Sun.COM static uint8_t rsa_known_sha512_signature[] = {
47910500SHai-May.Chao@Sun.COM 0xa5, 0xd0, 0x80, 0x04, 0x22, 0xfc, 0x80, 0x73,
48010500SHai-May.Chao@Sun.COM 0x7d, 0x46, 0xc8, 0x7b, 0xac, 0x44, 0x7b, 0xe6,
48110500SHai-May.Chao@Sun.COM 0x07, 0xe5, 0x61, 0x4c, 0x33, 0x7f, 0x6f, 0x46,
48210500SHai-May.Chao@Sun.COM 0x7c, 0x30, 0xe3, 0x75, 0x59, 0x4b, 0x42, 0xf3,
48310500SHai-May.Chao@Sun.COM 0x9f, 0x35, 0x3c, 0x10, 0x56, 0xdb, 0xd2, 0x69,
48410500SHai-May.Chao@Sun.COM 0x43, 0xcb, 0x77, 0xe9, 0x7d, 0xcd, 0x07, 0x43,
48510500SHai-May.Chao@Sun.COM 0xc5, 0xd4, 0x0c, 0x9d, 0xf5, 0x92, 0xbd, 0x0e,
48610500SHai-May.Chao@Sun.COM 0x3b, 0xb7, 0x68, 0x88, 0x84, 0xca, 0xae, 0x0d,
48710500SHai-May.Chao@Sun.COM 0xab, 0x71, 0x10, 0xad, 0xab, 0x27, 0xe4, 0xa3,
48810500SHai-May.Chao@Sun.COM 0x24, 0x41, 0xeb, 0x1c, 0xa6, 0x5f, 0xf1, 0x85,
48910500SHai-May.Chao@Sun.COM 0xd0, 0xf6, 0x22, 0x74, 0x3d, 0x81, 0xbe, 0xdd,
49010500SHai-May.Chao@Sun.COM 0x1b, 0x2a, 0x4c, 0xd1, 0x6c, 0xb5, 0x6d, 0x7a,
49110500SHai-May.Chao@Sun.COM 0xbb, 0x99, 0x69, 0x01, 0xa6, 0xc0, 0x98, 0xfa,
49210500SHai-May.Chao@Sun.COM 0x97, 0xa3, 0xd1, 0xb0, 0xdf, 0x09, 0xe3, 0x3d,
49310500SHai-May.Chao@Sun.COM 0x88, 0xee, 0x90, 0xf3, 0x10, 0x41, 0x0f, 0x06,
49410500SHai-May.Chao@Sun.COM 0x31, 0xe9, 0x60, 0x2d, 0xbf, 0x63, 0x7b, 0xf8
49510500SHai-May.Chao@Sun.COM };
49610500SHai-May.Chao@Sun.COM
49710500SHai-May.Chao@Sun.COM RSAPrivateKey_t rsa_private_key;
49810500SHai-May.Chao@Sun.COM CK_RV rv;
49910500SHai-May.Chao@Sun.COM uint8_t rsa_computed_ciphertext[FIPS_RSA_ENCRYPT_LENGTH];
50010500SHai-May.Chao@Sun.COM uint8_t rsa_computed_plaintext[FIPS_RSA_DECRYPT_LENGTH];
501*12573SDina.Nimeh@Sun.COM uint8_t rsa_computed_signature[FIPS_RSA_SIGNATURE_LENGTH];
50210500SHai-May.Chao@Sun.COM CK_BYTE der_data[SHA512_DIGEST_LENGTH + SHA2_DER_PREFIX_Len];
50310500SHai-May.Chao@Sun.COM
50410500SHai-May.Chao@Sun.COM /*
50510500SHai-May.Chao@Sun.COM * RSA Known Answer Encryption Test.
50610500SHai-May.Chao@Sun.COM */
507*12573SDina.Nimeh@Sun.COM rsa_private_key.bkey.modulus = rsa_modulus;
508*12573SDina.Nimeh@Sun.COM rsa_private_key.bkey.modulus_bits =
509*12573SDina.Nimeh@Sun.COM CRYPTO_BYTES2BITS(FIPS_RSA_MODULUS_LENGTH);
510*12573SDina.Nimeh@Sun.COM rsa_private_key.bkey.pubexpo = rsa_public_exponent;
511*12573SDina.Nimeh@Sun.COM rsa_private_key.bkey.pubexpo_bytes = FIPS_RSA_PUBLIC_EXPONENT_LENGTH;
512*12573SDina.Nimeh@Sun.COM rsa_private_key.bkey.rfunc = NULL;
51310500SHai-May.Chao@Sun.COM
51410500SHai-May.Chao@Sun.COM /* Perform RSA Public Key Encryption. */
515*12573SDina.Nimeh@Sun.COM rv = fips_rsa_encrypt(&rsa_private_key,
51610500SHai-May.Chao@Sun.COM rsa_known_plaintext_msg, FIPS_RSA_MESSAGE_LENGTH,
51710500SHai-May.Chao@Sun.COM rsa_computed_ciphertext);
51810500SHai-May.Chao@Sun.COM
51910500SHai-May.Chao@Sun.COM if ((rv != CKR_OK) ||
52010500SHai-May.Chao@Sun.COM (memcmp(rsa_computed_ciphertext, rsa_known_ciphertext,
52110500SHai-May.Chao@Sun.COM FIPS_RSA_ENCRYPT_LENGTH) != 0))
52210500SHai-May.Chao@Sun.COM return (CKR_DEVICE_ERROR);
52310500SHai-May.Chao@Sun.COM
52410500SHai-May.Chao@Sun.COM /*
52510500SHai-May.Chao@Sun.COM * RSA Known Answer Decryption Test.
52610500SHai-May.Chao@Sun.COM */
52710500SHai-May.Chao@Sun.COM rsa_private_key.version = rsa_version;
52810500SHai-May.Chao@Sun.COM rsa_private_key.version_len = FIPS_RSA_PRIVATE_VERSION_LENGTH;
529*12573SDina.Nimeh@Sun.COM rsa_private_key.bkey.modulus = rsa_modulus;
530*12573SDina.Nimeh@Sun.COM rsa_private_key.bkey.modulus_bits =
531*12573SDina.Nimeh@Sun.COM CRYPTO_BYTES2BITS(FIPS_RSA_MODULUS_LENGTH);
532*12573SDina.Nimeh@Sun.COM rsa_private_key.bkey.pubexpo = rsa_public_exponent;
533*12573SDina.Nimeh@Sun.COM rsa_private_key.bkey.pubexpo_bytes = FIPS_RSA_PUBLIC_EXPONENT_LENGTH;
534*12573SDina.Nimeh@Sun.COM rsa_private_key.bkey.privexpo = rsa_private_exponent;
535*12573SDina.Nimeh@Sun.COM rsa_private_key.bkey.privexpo_bytes = FIPS_RSA_PRIVATE_EXPONENT_LENGTH;
536*12573SDina.Nimeh@Sun.COM rsa_private_key.bkey.prime1 = rsa_prime0;
537*12573SDina.Nimeh@Sun.COM rsa_private_key.bkey.prime1_bytes = FIPS_RSA_PRIME0_LENGTH;
538*12573SDina.Nimeh@Sun.COM rsa_private_key.bkey.prime2 = rsa_prime1;
539*12573SDina.Nimeh@Sun.COM rsa_private_key.bkey.prime2_bytes = FIPS_RSA_PRIME1_LENGTH;
540*12573SDina.Nimeh@Sun.COM rsa_private_key.bkey.expo1 = rsa_exponent0;
541*12573SDina.Nimeh@Sun.COM rsa_private_key.bkey.expo1_bytes = FIPS_RSA_EXPONENT0_LENGTH;
542*12573SDina.Nimeh@Sun.COM rsa_private_key.bkey.expo2 = rsa_exponent1;
543*12573SDina.Nimeh@Sun.COM rsa_private_key.bkey.expo2_bytes = FIPS_RSA_EXPONENT1_LENGTH;
544*12573SDina.Nimeh@Sun.COM rsa_private_key.bkey.coeff = rsa_coefficient;
545*12573SDina.Nimeh@Sun.COM rsa_private_key.bkey.coeff_bytes = FIPS_RSA_COEFFICIENT_LENGTH;
54610500SHai-May.Chao@Sun.COM
54710500SHai-May.Chao@Sun.COM /* Perform RSA Private Key Decryption. */
54810500SHai-May.Chao@Sun.COM rv = fips_rsa_decrypt(&rsa_private_key, rsa_known_ciphertext,
54910500SHai-May.Chao@Sun.COM FIPS_RSA_MESSAGE_LENGTH, rsa_computed_plaintext);
55010500SHai-May.Chao@Sun.COM
55110500SHai-May.Chao@Sun.COM if ((rv != CKR_OK) ||
55210500SHai-May.Chao@Sun.COM (memcmp(rsa_computed_plaintext, rsa_known_plaintext_msg,
55310500SHai-May.Chao@Sun.COM FIPS_RSA_DECRYPT_LENGTH) != 0))
55410500SHai-May.Chao@Sun.COM return (CKR_DEVICE_ERROR);
55510500SHai-May.Chao@Sun.COM
55610500SHai-May.Chao@Sun.COM /* SHA-1 Sign/Verify */
55710500SHai-May.Chao@Sun.COM #ifdef _KERNEL
55810500SHai-May.Chao@Sun.COM rv = fips_rsa_sign_verify_test(SHA1_TYPE, &rsa_private_key,
55910500SHai-May.Chao@Sun.COM rsa_known_plaintext_msg, FIPS_RSA_MESSAGE_LENGTH,
56010500SHai-May.Chao@Sun.COM rsa_computed_signature, der_data, 1);
56110500SHai-May.Chao@Sun.COM #else
56210500SHai-May.Chao@Sun.COM rv = fips_rsa_sign_verify_test(CKM_SHA_1, &rsa_private_key,
56310500SHai-May.Chao@Sun.COM rsa_known_plaintext_msg, FIPS_RSA_MESSAGE_LENGTH,
56410500SHai-May.Chao@Sun.COM rsa_computed_signature, der_data, 1);
56510500SHai-May.Chao@Sun.COM #endif
56610500SHai-May.Chao@Sun.COM
56710500SHai-May.Chao@Sun.COM if ((rv != CKR_OK) ||
56810500SHai-May.Chao@Sun.COM (memcmp(rsa_computed_signature, rsa_known_sha1_signature,
56910500SHai-May.Chao@Sun.COM FIPS_RSA_SIGNATURE_LENGTH) != 0))
57010500SHai-May.Chao@Sun.COM return (CKR_DEVICE_ERROR);
57110500SHai-May.Chao@Sun.COM
57210500SHai-May.Chao@Sun.COM #ifdef _KERNEL
57310500SHai-May.Chao@Sun.COM rv = fips_rsa_sign_verify_test(SHA1_TYPE, &rsa_private_key,
57410500SHai-May.Chao@Sun.COM rsa_known_plaintext_msg, FIPS_RSA_MESSAGE_LENGTH,
57510500SHai-May.Chao@Sun.COM rsa_computed_signature, der_data, 0);
57610500SHai-May.Chao@Sun.COM #else
57710500SHai-May.Chao@Sun.COM rv = fips_rsa_sign_verify_test(CKM_SHA_1, &rsa_private_key,
57810500SHai-May.Chao@Sun.COM rsa_known_plaintext_msg, FIPS_RSA_MESSAGE_LENGTH,
57910500SHai-May.Chao@Sun.COM rsa_computed_signature, der_data, 0);
58010500SHai-May.Chao@Sun.COM #endif
58110500SHai-May.Chao@Sun.COM
58210500SHai-May.Chao@Sun.COM if (rv != CKR_OK)
58310500SHai-May.Chao@Sun.COM goto rsa_loser;
58410500SHai-May.Chao@Sun.COM
58510500SHai-May.Chao@Sun.COM /* SHA256 Sign/Verify */
58610500SHai-May.Chao@Sun.COM #ifdef _KERNEL
58710500SHai-May.Chao@Sun.COM rv = fips_rsa_sign_verify_test(SHA256_TYPE, &rsa_private_key,
58810500SHai-May.Chao@Sun.COM rsa_known_plaintext_msg, FIPS_RSA_MESSAGE_LENGTH,
58910500SHai-May.Chao@Sun.COM rsa_computed_signature, der_data, 1);
59010500SHai-May.Chao@Sun.COM #else
59110500SHai-May.Chao@Sun.COM rv = fips_rsa_sign_verify_test(CKM_SHA256, &rsa_private_key,
59210500SHai-May.Chao@Sun.COM rsa_known_plaintext_msg, FIPS_RSA_MESSAGE_LENGTH,
59310500SHai-May.Chao@Sun.COM rsa_computed_signature, der_data, 1);
59410500SHai-May.Chao@Sun.COM #endif
59510500SHai-May.Chao@Sun.COM
59610500SHai-May.Chao@Sun.COM if ((rv != CKR_OK) ||
59710500SHai-May.Chao@Sun.COM (memcmp(rsa_computed_signature, rsa_known_sha256_signature,
59810500SHai-May.Chao@Sun.COM FIPS_RSA_SIGNATURE_LENGTH) != 0))
59910500SHai-May.Chao@Sun.COM return (CKR_DEVICE_ERROR);
60010500SHai-May.Chao@Sun.COM
60110500SHai-May.Chao@Sun.COM #ifdef _KERNEL
60210500SHai-May.Chao@Sun.COM rv = fips_rsa_sign_verify_test(SHA256_TYPE, &rsa_private_key,
60310500SHai-May.Chao@Sun.COM rsa_known_plaintext_msg, FIPS_RSA_MESSAGE_LENGTH,
60410500SHai-May.Chao@Sun.COM rsa_computed_signature, der_data, 0);
60510500SHai-May.Chao@Sun.COM #else
60610500SHai-May.Chao@Sun.COM rv = fips_rsa_sign_verify_test(CKM_SHA256, &rsa_private_key,
60710500SHai-May.Chao@Sun.COM rsa_known_plaintext_msg, FIPS_RSA_MESSAGE_LENGTH,
60810500SHai-May.Chao@Sun.COM rsa_computed_signature, der_data, 0);
60910500SHai-May.Chao@Sun.COM #endif
61010500SHai-May.Chao@Sun.COM
61110500SHai-May.Chao@Sun.COM if (rv != CKR_OK)
61210500SHai-May.Chao@Sun.COM goto rsa_loser;
61310500SHai-May.Chao@Sun.COM
61410500SHai-May.Chao@Sun.COM /* SHA384 Sign/Verify */
61510500SHai-May.Chao@Sun.COM #ifdef _KERNEL
61610500SHai-May.Chao@Sun.COM rv = fips_rsa_sign_verify_test(SHA384_TYPE, &rsa_private_key,
61710500SHai-May.Chao@Sun.COM rsa_known_plaintext_msg, FIPS_RSA_MESSAGE_LENGTH,
61810500SHai-May.Chao@Sun.COM rsa_computed_signature, der_data, 1);
61910500SHai-May.Chao@Sun.COM #else
62010500SHai-May.Chao@Sun.COM rv = fips_rsa_sign_verify_test(CKM_SHA384, &rsa_private_key,
62110500SHai-May.Chao@Sun.COM rsa_known_plaintext_msg, FIPS_RSA_MESSAGE_LENGTH,
62210500SHai-May.Chao@Sun.COM rsa_computed_signature, der_data, 1);
62310500SHai-May.Chao@Sun.COM #endif
62410500SHai-May.Chao@Sun.COM
62510500SHai-May.Chao@Sun.COM if ((rv != CKR_OK) ||
62610500SHai-May.Chao@Sun.COM (memcmp(rsa_computed_signature, rsa_known_sha384_signature,
62710500SHai-May.Chao@Sun.COM FIPS_RSA_SIGNATURE_LENGTH) != 0))
62810500SHai-May.Chao@Sun.COM return (CKR_DEVICE_ERROR);
62910500SHai-May.Chao@Sun.COM
63010500SHai-May.Chao@Sun.COM #ifdef _KERNEL
63110500SHai-May.Chao@Sun.COM rv = fips_rsa_sign_verify_test(SHA384_TYPE, &rsa_private_key,
63210500SHai-May.Chao@Sun.COM rsa_known_plaintext_msg, FIPS_RSA_MESSAGE_LENGTH,
63310500SHai-May.Chao@Sun.COM rsa_computed_signature, der_data, 0);
63410500SHai-May.Chao@Sun.COM #else
63510500SHai-May.Chao@Sun.COM rv = fips_rsa_sign_verify_test(CKM_SHA384, &rsa_private_key,
63610500SHai-May.Chao@Sun.COM rsa_known_plaintext_msg, FIPS_RSA_MESSAGE_LENGTH,
63710500SHai-May.Chao@Sun.COM rsa_computed_signature, der_data, 0);
63810500SHai-May.Chao@Sun.COM #endif
63910500SHai-May.Chao@Sun.COM
64010500SHai-May.Chao@Sun.COM if (rv != CKR_OK)
64110500SHai-May.Chao@Sun.COM goto rsa_loser;
64210500SHai-May.Chao@Sun.COM
64310500SHai-May.Chao@Sun.COM /* SHA512 Sign/Verify */
64410500SHai-May.Chao@Sun.COM #ifdef _KERNEL
64510500SHai-May.Chao@Sun.COM rv = fips_rsa_sign_verify_test(SHA512_TYPE, &rsa_private_key,
64610500SHai-May.Chao@Sun.COM rsa_known_plaintext_msg, FIPS_RSA_MESSAGE_LENGTH,
64710500SHai-May.Chao@Sun.COM rsa_computed_signature, der_data, 1);
64810500SHai-May.Chao@Sun.COM #else
64910500SHai-May.Chao@Sun.COM rv = fips_rsa_sign_verify_test(CKM_SHA512, &rsa_private_key,
65010500SHai-May.Chao@Sun.COM rsa_known_plaintext_msg, FIPS_RSA_MESSAGE_LENGTH,
65110500SHai-May.Chao@Sun.COM rsa_computed_signature, der_data, 1);
65210500SHai-May.Chao@Sun.COM #endif
65310500SHai-May.Chao@Sun.COM
65410500SHai-May.Chao@Sun.COM if ((rv != CKR_OK) ||
65510500SHai-May.Chao@Sun.COM (memcmp(rsa_computed_signature, rsa_known_sha512_signature,
65610500SHai-May.Chao@Sun.COM FIPS_RSA_SIGNATURE_LENGTH) != 0))
65710500SHai-May.Chao@Sun.COM return (CKR_DEVICE_ERROR);
65810500SHai-May.Chao@Sun.COM
65910500SHai-May.Chao@Sun.COM #ifdef _KERNEL
66010500SHai-May.Chao@Sun.COM rv = fips_rsa_sign_verify_test(SHA512_TYPE, &rsa_private_key,
66110500SHai-May.Chao@Sun.COM rsa_known_plaintext_msg, FIPS_RSA_MESSAGE_LENGTH,
66210500SHai-May.Chao@Sun.COM rsa_computed_signature, der_data, 0);
66310500SHai-May.Chao@Sun.COM #else
66410500SHai-May.Chao@Sun.COM rv = fips_rsa_sign_verify_test(CKM_SHA512, &rsa_private_key,
66510500SHai-May.Chao@Sun.COM rsa_known_plaintext_msg, FIPS_RSA_MESSAGE_LENGTH,
66610500SHai-May.Chao@Sun.COM rsa_computed_signature, der_data, 0);
66710500SHai-May.Chao@Sun.COM #endif
66810500SHai-May.Chao@Sun.COM
66910500SHai-May.Chao@Sun.COM rsa_loser:
67010500SHai-May.Chao@Sun.COM if (rv != CKR_OK)
67110500SHai-May.Chao@Sun.COM return (CKR_DEVICE_ERROR);
67210500SHai-May.Chao@Sun.COM else
67310500SHai-May.Chao@Sun.COM return (CKR_OK);
67410500SHai-May.Chao@Sun.COM
67510500SHai-May.Chao@Sun.COM }
676