66 status = importBignum( bigNum, hash, hashLength,
67 hashLength - 3, hashLength + 1, NULL,
81 if(
BN_cmp( bigNum, n ) >= 0 )
104 0x1B, 0xD4, 0xED, 0x43, 0x0B, 0x0F, 0x38, 0x4B,
105 0x4E, 0x8D, 0x45, 0x8E, 0xFF, 0x1A, 0x8A, 0x55,
106 0x32, 0x86, 0xD7, 0xAC, 0x21, 0xCB, 0x2F, 0x68,
107 0x06, 0x17, 0x2E, 0xF5, 0xF9, 0x4A, 0x06, 0xAD
125 status = capabilityInfoPtr->signFunction( contextInfoPtr,
131 sigSize = dlpParams.
outLen;
133 dlpParams.inParam2 =
buffer;
134 dlpParams.
inLen2 = sigSize;
135 status = capabilityInfoPtr->sigCheckFunction( contextInfoPtr,
140 #ifndef CONFIG_NO_SELFTEST
154 #define ECDSA_TESTVECTOR_SIZE 32
157 const int qxLen;
const BYTE qx[ 32 ];
158 const int qyLen;
const BYTE qy[ 32 ];
159 const int dLen;
const BYTE d[ 32 ];
165 { 0x59, 0x63, 0x75, 0xE6, 0xCE, 0x57, 0xE0, 0xF2,
166 0x02, 0x94, 0xFC, 0x46, 0xBD, 0xFC, 0xFD, 0x19,
167 0xA3, 0x9F, 0x81, 0x61, 0xB5, 0x86, 0x95, 0xB3,
168 0xEC, 0x5B, 0x3D, 0x16, 0x42, 0x7C, 0x27, 0x4D },
171 { 0x42, 0x75, 0x4D, 0xFD, 0x25, 0xC5, 0x6F, 0x93,
172 0x9A, 0x79, 0xF2, 0xB2, 0x04, 0x87, 0x6B, 0x3A,
173 0x3A, 0xB1, 0xCE, 0xB2, 0xE4, 0xFF, 0x57, 0x1A,
174 0xBF, 0x4F, 0xBF, 0x36, 0x32, 0x6C, 0x8B, 0x27 },
177 { 0x2C, 0xA1, 0x41, 0x1A, 0x41, 0xB1, 0x7B, 0x24,
178 0xCC, 0x8C, 0x3B, 0x08, 0x9C, 0xFD, 0x03, 0x3F,
179 0x19, 0x20, 0x20, 0x2A, 0x6C, 0x0D, 0xE8, 0xAB,
180 0xB9, 0x7D, 0xF1, 0x49, 0x8D, 0x50, 0xD2, 0xC8 }
191 0xA0, 0x64, 0x0D, 0x49, 0x57, 0xF2, 0x7D, 0x09,
192 0x1A, 0xB1, 0xAE, 0xBC, 0x69, 0x94, 0x9D, 0x96,
193 0xE5, 0xAC, 0x2B, 0xB2, 0x83, 0xED, 0x52, 0x84,
194 0xA5, 0x67, 0x47, 0x58, 0xB1, 0x2F, 0x08, 0xDF
198 static
int selfTest(
void )
201 PKC_INFO contextData, *pkcInfo = &contextData;
205 status = staticInitContext( &contextInfo,
CONTEXT_PKC,
207 sizeof( PKC_INFO ), NULL );
211 status = importBignum( &pkcInfo->eccParam_qx, ecdsaTestKey.qx,
215 status = importBignum( &pkcInfo->eccParam_qy, ecdsaTestKey.qy,
219 status = importBignum( &pkcInfo->eccParam_d, ecdsaTestKey.d,
224 staticDestroyContext( &contextInfo );
229 status = contextInfo.
capabilityInfo->initKeyFunction( &contextInfo, NULL, 0 );
231 !pairwiseConsistencyTest( &contextInfo ) )
235 staticDestroyContext( &contextInfo );
240 #define selfTest NULL
287 PKC_INFO *pkcInfo = contextInfoPtr->ctxPKC;
289 BIGNUM *
n = &pkcInfo->eccParam_n;
290 BIGNUM *hash = &pkcInfo->tmp1, *x = &pkcInfo->tmp2;
291 BIGNUM *k = &pkcInfo->tmp3, *r = &pkcInfo->tmp4, *
s = &pkcInfo->tmp5;
302 REQUIRES( eccParams->inParam2 == NULL && \
303 ( eccParams->
inLen2 == 0 || eccParams->
inLen2 == -999 ) );
319 if( eccParams->
inLen2 == -999 )
321 status = importBignum( k, (
BYTE * ) kVal, ECDSA_TESTVECTOR_SIZE,
322 ECDSA_TESTVECTOR_SIZE,
323 ECDSA_TESTVECTOR_SIZE, NULL,
361 status = hashToBignum( hash, eccParams->inParam1, eccParams->
inLen1, n );
375 CK(
BN_mod( r, x, n, pkcInfo->bnCTX ) );
385 CK(
BN_mod_mul(
s, &pkcInfo->eccParam_d, r, n, pkcInfo->bnCTX ) );
396 status = pkcInfo->encodeDLValuesFunction( eccParams->outParam,
419 PKC_INFO *pkcInfo = contextInfoPtr->ctxPKC;
421 BIGNUM *n = &pkcInfo->eccParam_n;
422 BIGNUM *qx = &pkcInfo->eccParam_qx, *qy = &pkcInfo->eccParam_qy;
423 BIGNUM *u1 = &pkcInfo->tmp1, *u2 = &pkcInfo->tmp2;
424 BIGNUM *r = &pkcInfo->tmp3, *
s = &pkcInfo->tmp4;
426 EC_POINT *u1gu2q = pkcInfo->tmpPoint, *u2q;
435 REQUIRES( eccParams->outParam == NULL && eccParams->
outLen == 0 );
439 status = pkcInfo->decodeDLValuesFunction( eccParams->inParam2,
446 status = hashToBignum( u1, eccParams->inParam1, eccParams->
inLen1, n );
487 CK(
BN_mod( u1, u1, n, pkcInfo->bnCTX ) );
525 assert( ( key == NULL && keyLength == 0 ) || \
529 REQUIRES( ( key == NULL && keyLength == 0 ) || \
537 PKC_INFO *pkcInfo = contextInfoPtr->ctxPKC;
541 contextInfoPtr->flags |= ( eccKey->
isPublicKey ) ? \
545 status = importBignum( &pkcInfo->eccParam_p, eccKey->
p,
550 status = importBignum( &pkcInfo->eccParam_a, eccKey->
a,
555 status = importBignum( &pkcInfo->eccParam_b, eccKey->
b,
560 status = importBignum( &pkcInfo->eccParam_gx, eccKey->
gx,
565 status = importBignum( &pkcInfo->eccParam_gy, eccKey->
gy,
570 status = importBignum( &pkcInfo->eccParam_n, eccKey->
n,
584 status = importBignum( &pkcInfo->eccParam_qx, eccKey->
qx,
589 status = importBignum( &pkcInfo->eccParam_qy, eccKey->
qy,
594 status = importBignum( &pkcInfo->eccParam_d, eccKey->
d,
598 contextInfoPtr->flags |= CONTEXT_FLAG_PBO;
605 return( initCheckECCkey( contextInfoPtr,
FALSE ) );
613 const int keySizeBits )
622 status = generateECCkey( contextInfoPtr, keySizeBits );
627 !pairwiseConsistencyTest( contextInfoPtr ) )
629 DEBUG_DIAG((
"Consistency check of freshly-generated ECDSA key "
646 selfTest, getDefaultInfo, NULL, NULL, initKey, generateKey,
647 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
653 return( &capabilityInfo );