13 #if defined( INC_ALL )
40 memcpy( buffer + 1,
"abcde", 5 );
41 status = capabilityInfoPtr->encryptFunction( contextInfoPtr, buffer,
42 bitsToBytes( contextInfoPtr->ctxPKC->keySizeBits ) );
47 status = capabilityInfoPtr->decryptFunction( contextInfoPtr, buffer,
48 bitsToBytes( contextInfoPtr->ctxPKC->keySizeBits ) );
54 return( !memcmp( buffer,
"\x00" "abcde" "\x00\x00\x00\x00", 10 ) );
57 #ifndef CONFIG_NO_SELFTEST
78 { 0x9C, 0x4D, 0x98, 0x18, 0x67, 0xF9, 0x45, 0xBC,
79 0xB6, 0x75, 0x53, 0x5D, 0x2C, 0xFA, 0x55, 0xE4,
80 0x51, 0x54, 0x9F, 0x0C, 0x16, 0xB1, 0xAF, 0x89,
81 0xF6, 0xF3, 0xE7, 0x78, 0xB1, 0x2B, 0x07, 0xFB,
82 0xDC, 0xDE, 0x64, 0x23, 0x34, 0x87, 0xDA, 0x0B,
83 0xE5, 0xB3, 0x17, 0x16, 0xA4, 0xE3, 0x7F, 0x23,
84 0xDF, 0x96, 0x16, 0x28, 0xA6, 0xD2, 0xF0, 0x0A,
85 0x59, 0xEE, 0x06, 0xB3, 0x76, 0x6C, 0x64, 0x19,
86 0xD9, 0x76, 0x41, 0x25, 0x66, 0xD1, 0x93, 0x51,
87 0x52, 0x06, 0x6B, 0x71, 0x50, 0x0E, 0xAB, 0x30,
88 0xA5, 0xC8, 0x41, 0xFC, 0x30, 0xBC, 0x32, 0xD7,
89 0x4B, 0x22, 0xF2, 0x45, 0x4C, 0x94, 0x68, 0xF1,
90 0x92, 0x8A, 0x4C, 0xF9, 0xD4, 0x5E, 0x87, 0x92,
91 0xA8, 0x54, 0x93, 0x92, 0x94, 0x48, 0xA4, 0xA3,
92 0xEE, 0x19, 0x7F, 0x6E, 0xD3, 0x14, 0xB1, 0x48,
93 0xCE, 0x93, 0xD1, 0xEA, 0x4C, 0xE1, 0x9D, 0xEF },
101 { 0x37, 0xE2, 0x66, 0x67, 0x13, 0x85, 0xC4, 0xB1,
102 0x5C, 0x6B, 0x46, 0x8B, 0x21, 0xF1, 0xBF, 0x94,
103 0x0A, 0xA0, 0x3E, 0xDD, 0x8B, 0x9F, 0xAC, 0x2B,
104 0x9F, 0xE8, 0x44, 0xF2, 0x9A, 0x25, 0xD0, 0x8C,
105 0xF4, 0xC3, 0x6E, 0xFA, 0x47, 0x65, 0xEB, 0x48,
106 0x25, 0xB0, 0x8A, 0xA8, 0xC5, 0xFB, 0xB1, 0x11,
107 0x9A, 0x77, 0x87, 0x24, 0xB1, 0xC0, 0xE9, 0xA2,
108 0x49, 0xD5, 0x19, 0x00, 0x41, 0x6F, 0x2F, 0xBA,
109 0x9F, 0x28, 0x47, 0xF9, 0xB8, 0xBA, 0xFF, 0xF4,
110 0x8B, 0x20, 0xC9, 0xC9, 0x39, 0xAB, 0x52, 0x0E,
111 0x8A, 0x5A, 0xAF, 0xB3, 0xA3, 0x93, 0x4D, 0xBB,
112 0xFE, 0x62, 0x9B, 0x02, 0xCC, 0xA7, 0xB4, 0xAE,
113 0x86, 0x65, 0x88, 0x19, 0xD7, 0x44, 0xA7, 0xE4,
114 0x18, 0xB6, 0xCE, 0x01, 0xCD, 0xDF, 0x36, 0x81,
115 0xD5, 0xE1, 0x62, 0xF8, 0xD0, 0x27, 0xF1, 0x86,
116 0xA8, 0x58, 0xA7, 0xEB, 0x39, 0x79, 0x56, 0x41 },
120 { 0xCF, 0xDA, 0xF9, 0x99, 0x6F, 0x05, 0x95, 0x84,
121 0x09, 0x90, 0xB3, 0xAB, 0x39, 0xB7, 0xDD, 0x1D,
122 0x7B, 0xFC, 0xFD, 0x10, 0x35, 0xA0, 0x18, 0x1D,
123 0x9A, 0x11, 0x30, 0x90, 0xD4, 0x3B, 0xF0, 0x5A,
124 0xC1, 0xA6, 0xF4, 0x53, 0xD0, 0x94, 0xA0, 0xED,
125 0xE0, 0xE4, 0xE0, 0x8E, 0x44, 0x18, 0x42, 0x42,
126 0xE1, 0x2C, 0x0D, 0xF7, 0x30, 0xE2, 0xB8, 0x09,
127 0x73, 0x50, 0x28, 0xF6, 0x55, 0x85, 0x57, 0x03 },
131 { 0xC0, 0x81, 0xC4, 0x82, 0x6E, 0xF6, 0x1C, 0x92,
132 0x83, 0xEC, 0x17, 0xFB, 0x30, 0x98, 0xED, 0x6E,
133 0x89, 0x92, 0xB2, 0xA1, 0x21, 0x0D, 0xC1, 0x95,
134 0x49, 0x99, 0xD3, 0x79, 0xD3, 0xBD, 0x94, 0x93,
135 0xB9, 0x28, 0x68, 0xFF, 0xDE, 0xEB, 0xE8, 0xD2,
136 0x0B, 0xED, 0x7C, 0x08, 0xD0, 0xD5, 0x59, 0xE3,
137 0xC1, 0x76, 0xEA, 0xC1, 0xCD, 0xB6, 0x8B, 0x39,
138 0x4E, 0x29, 0x59, 0x5F, 0xFA, 0xCE, 0x83, 0xA5 },
142 { 0x4B, 0x87, 0x97, 0x1F, 0x27, 0xED, 0xAA, 0xAF,
143 0x42, 0xF4, 0x57, 0x82, 0x3F, 0xEC, 0x80, 0xED,
144 0x1E, 0x91, 0xF8, 0xB4, 0x33, 0xDA, 0xEF, 0xC3,
145 0x03, 0x53, 0x0F, 0xCE, 0xB9, 0x5F, 0xE4, 0x29,
146 0xCC, 0xEE, 0x6A, 0x5E, 0x11, 0x0E, 0xFA, 0x66,
147 0x85, 0xDC, 0xFC, 0x48, 0x31, 0x0C, 0x00, 0x97,
148 0xC6, 0x0A, 0xF2, 0x34, 0x60, 0x6B, 0xF7, 0x68,
149 0x09, 0x4E, 0xCF, 0xB1, 0x9E, 0x33, 0x9A, 0x41 },
153 { 0x6B, 0x2A, 0x0D, 0xF8, 0x22, 0x7A, 0x71, 0x8C,
154 0xE2, 0xD5, 0x9D, 0x1C, 0x91, 0xA4, 0x8F, 0x37,
155 0x0D, 0x5E, 0xF1, 0x26, 0x73, 0x4F, 0x78, 0x3F,
156 0x82, 0xD8, 0x8B, 0xFE, 0x8F, 0xBD, 0xDB, 0x7D,
157 0x1F, 0x4C, 0xB1, 0xB9, 0xA8, 0xD7, 0x88, 0x65,
158 0x3C, 0xC7, 0x24, 0x53, 0x95, 0x1E, 0x20, 0xC3,
159 0x94, 0x8E, 0x7F, 0x20, 0xCC, 0x2E, 0x88, 0x0E,
160 0x2F, 0x4A, 0xCB, 0xE3, 0xBD, 0x52, 0x02, 0xFB },
164 { 0x10, 0x27, 0xD3, 0xD2, 0x0E, 0x75, 0xE1, 0x17,
165 0xFA, 0xB2, 0x49, 0xA0, 0xEF, 0x07, 0x26, 0x85,
166 0xEC, 0x4D, 0xBF, 0x67, 0xFE, 0x5A, 0x25, 0x30,
167 0xDE, 0x28, 0x66, 0xB3, 0x06, 0xAE, 0x16, 0x55,
168 0xFF, 0x68, 0x00, 0xC7, 0xD8, 0x71, 0x7B, 0xEC,
169 0x84, 0xCB, 0xBD, 0x69, 0x0F, 0xFD, 0x97, 0xB9,
170 0xA1, 0x76, 0xD5, 0x64, 0xC6, 0x5A, 0xD7, 0x7C,
171 0x4B, 0xAE, 0xF4, 0xAD, 0x35, 0x63, 0x37, 0x71 }
175 static
int selfTest(
void )
178 PKC_INFO contextData, *pkcInfo = &contextData;
184 status = staticInitContext( &contextInfo,
CONTEXT_PKC,
186 sizeof( PKC_INFO ), NULL );
189 status = importBignum( &pkcInfo->rsaParam_n, rsaTestKey.n,
193 status = importBignum( &pkcInfo->rsaParam_e, rsaTestKey.e,
198 status = importBignum( &pkcInfo->rsaParam_d, rsaTestKey.d,
203 status = importBignum( &pkcInfo->rsaParam_p, rsaTestKey.p,
208 status = importBignum( &pkcInfo->rsaParam_q, rsaTestKey.q,
213 status = importBignum( &pkcInfo->rsaParam_u, rsaTestKey.u,
218 status = importBignum( &pkcInfo->rsaParam_exponent1, rsaTestKey.e1,
223 status = importBignum( &pkcInfo->rsaParam_exponent2, rsaTestKey.e2,
232 status = capabilityInfoPtr->initKeyFunction( &contextInfo, NULL, 0 );
234 !pairwiseConsistencyTest( &contextInfo ) )
241 memset( buffer, 0, rsaTestKey.nLen );
242 memcpy( buffer,
"abcde", 5 );
244 status = capabilityInfoPtr->initKeyFunction( &contextInfo, NULL, 0 );
246 status = capabilityInfoPtr->encryptFunction( &contextInfo,
247 buffer, rsaTestKey.nLen );
249 status = capabilityInfoPtr->decryptFunction( &contextInfo,
250 buffer, rsaTestKey.nLen );
257 memset( buffer, 0, rsaTestKey.nLen );
258 memcpy( buffer,
"abcde", 5 );
259 status = capabilityInfoPtr->initKeyFunction( &contextInfo, NULL, 0 );
261 status = capabilityInfoPtr->encryptFunction( &contextInfo,
262 buffer, rsaTestKey.nLen );
264 status = capabilityInfoPtr->decryptFunction( &contextInfo,
265 buffer, rsaTestKey.nLen );
272 staticDestroyContext( &contextInfo );
277 #define selfTest NULL
295 PKC_INFO *pkcInfo = contextInfoPtr->ctxPKC;
296 BIGNUM *
n = &pkcInfo->rsaParam_n, *e = &pkcInfo->rsaParam_e;
308 status = importBignum( data, buffer, length,
321 &pkcInfo->rsaParam_mont_n ) );
326 memset( buffer, 0, offset );
327 status = exportBignum( buffer + offset, noBytes - offset, &dummy, data );
394 PKC_INFO *pkcInfo = contextInfoPtr->ctxPKC;
395 BIGNUM *
p = &pkcInfo->rsaParam_p, *q = &pkcInfo->rsaParam_q;
396 BIGNUM *u = &pkcInfo->rsaParam_u, *e1 = &pkcInfo->rsaParam_exponent1;
397 BIGNUM *e2 = &pkcInfo->rsaParam_exponent2;
398 BIGNUM *
data = &pkcInfo->tmp1, *
p2 = &pkcInfo->tmp2, *q2 = &pkcInfo->tmp3;
429 &pkcInfo->rsaParam_n, pkcInfo->bnCTX ) );
441 &pkcInfo->rsaParam_mont_p ) );
445 &pkcInfo->rsaParam_mont_q ) );
453 for( iterationCount = 0;
461 if( iterationCount >= FAILSAFE_ITERATIONS_SMALL )
478 BIGNUM *
n = &pkcInfo->rsaParam_n;
479 BIGNUM *k = &pkcInfo->rsaParam_blind_k;
480 BIGNUM *kInv = &pkcInfo->rsaParam_blind_kInv;
482 CK(
BN_mod_mul( data, data, kInv, n, pkcInfo->bnCTX ) );
500 CK(
BN_mod_mul( kInv, kInv, kInv, n, pkcInfo->bnCTX ) );
513 memset( buffer, 0, offset );
514 status = exportBignum( buffer + offset, noBytes - offset, &dummy, data );
542 assert( ( key == NULL && keyLength == 0 ) || \
546 REQUIRES( ( key == NULL && keyLength == 0 ) || \
554 PKC_INFO *pkcInfo = contextInfoPtr->ctxPKC;
558 contextInfoPtr->flags |= ( rsaKey->
isPublicKey ) ? \
560 status = importBignum( &pkcInfo->rsaParam_n, rsaKey->
n,
565 status = importBignum( &pkcInfo->rsaParam_e, rsaKey->
e,
568 &pkcInfo->rsaParam_n,
572 status = importBignum( &pkcInfo->rsaParam_d, rsaKey->
d,
575 &pkcInfo->rsaParam_n,
578 status = importBignum( &pkcInfo->rsaParam_p, rsaKey->
p,
581 &pkcInfo->rsaParam_n,
584 status = importBignum( &pkcInfo->rsaParam_q, rsaKey->
q,
587 &pkcInfo->rsaParam_n,
590 status = importBignum( &pkcInfo->rsaParam_u, rsaKey->
u,
593 &pkcInfo->rsaParam_n,
596 status = importBignum( &pkcInfo->rsaParam_exponent1, rsaKey->
e1,
599 &pkcInfo->rsaParam_n,
602 status = importBignum( &pkcInfo->rsaParam_exponent2, rsaKey->
e2,
605 &pkcInfo->rsaParam_n,
608 contextInfoPtr->flags |= CONTEXT_FLAG_PBO;
615 return( initCheckRSAkey( contextInfoPtr ) );
623 const int keySizeBits )
632 status = generateRSAkey( contextInfoPtr, keySizeBits );
637 !pairwiseConsistencyTest( contextInfoPtr ) )
639 DEBUG_DIAG((
"Consistency check of freshly-generated RSA key "
656 selfTest, getDefaultInfo, NULL, NULL, initKey, generateKey, encryptFn, decryptFn,
657 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
663 return( &capabilityInfo );