mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-08-08 17:42:09 +03:00
Merged ECDSA tests / enhancements and example into development
This commit is contained in:
@@ -22,3 +22,17 @@ ecdsa_prim_test_vectors:POLARSSL_ECP_DP_SECP384R1:"0BEB646634BA87735D77AE4809A0E
|
||||
ECDSA primitive rfc 4754 p521
|
||||
ecdsa_prim_test_vectors:POLARSSL_ECP_DP_SECP521R1:"0065FDA3409451DCAB0A0EAD45495112A3D813C17BFD34BDF8C1209D7DF5849120597779060A7FF9D704ADF78B570FFAD6F062E95C7E0C5D5481C5B153B48B375FA1":"0151518F1AF0F563517EDD5485190DF95A4BF57B5CBA4CF2A9A3F6474725A35F7AFE0A6DDEB8BEDBCD6A197E592D40188901CECD650699C9B5E456AEA5ADD19052A8":"006F3B142EA1BFFF7E2837AD44C9E4FF6D2D34C73184BBAD90026DD5E6E85317D9DF45CAD7803C6C20035B2F3FF63AFF4E1BA64D1C077577DA3F4286C58F0AEAE643":"00C1C2B305419F5A41344D7E4359933D734096F556197A9B244342B8B62F46F9373778F9DE6B6497B1EF825FF24F42F9B4A4BD7382CFC3378A540B1B7F0C1B956C2F":"DDAF35A193617ABACC417349AE20413112E6FA4E89A97EA20A9EEEE64B55D39A2192992A274FC1A836BA3C23A3FEEBBD454D4423643CE80E2A9AC94FA54CA49F":"0154FD3836AF92D0DCA57DD5341D3053988534FDE8318FC6AAAAB68E2E6F4339B19F2F281A7E0B22C269D93CF8794A9278880ED7DBB8D9362CAEACEE544320552251":"017705A7030290D1CEB605A9A1BB03FF9CDD521E87A696EC926C8C10C8362DF4975367101F67D1CF9BCCBF2F3D239534FA509E70AAC851AE01AAC68D62F866472660"
|
||||
|
||||
ECDSA write-read random #1
|
||||
ecdsa_write_read_random:POLARSSL_ECP_DP_SECP192R1
|
||||
|
||||
ECDSA write-read random #2
|
||||
ecdsa_write_read_random:POLARSSL_ECP_DP_SECP224R1
|
||||
|
||||
ECDSA write-read random #3
|
||||
ecdsa_write_read_random:POLARSSL_ECP_DP_SECP256R1
|
||||
|
||||
ECDSA write-read random #4
|
||||
ecdsa_write_read_random:POLARSSL_ECP_DP_SECP384R1
|
||||
|
||||
ECDSA write-read random #5
|
||||
ecdsa_write_read_random:POLARSSL_ECP_DP_SECP521R1
|
||||
|
@@ -76,3 +76,61 @@ void ecdsa_prim_test_vectors( int id, char *d_str, char *xQ_str, char *yQ_str,
|
||||
mpi_free( &r_check ); mpi_free( &s_check );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void ecdsa_write_read_random( int id )
|
||||
{
|
||||
ecdsa_context ctx;
|
||||
rnd_pseudo_info rnd_info;
|
||||
unsigned char hash[66];
|
||||
unsigned char sig[200];
|
||||
size_t sig_len, i;
|
||||
|
||||
ecdsa_init( &ctx );
|
||||
memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) );
|
||||
memset( hash, 0, sizeof( hash ) );
|
||||
memset( sig, 0x2a, sizeof( sig ) );
|
||||
|
||||
/* prepare material for signature */
|
||||
TEST_ASSERT( rnd_pseudo_rand( &rnd_info, hash, sizeof( hash ) ) == 0 );
|
||||
|
||||
/* generate signing key */
|
||||
TEST_ASSERT( ecdsa_genkey( &ctx, id, &rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
|
||||
/* generate and write signature, then read and verify it */
|
||||
TEST_ASSERT( ecdsa_write_signature( &ctx, hash, sizeof( hash ),
|
||||
sig, &sig_len, &rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||
TEST_ASSERT( ecdsa_read_signature( &ctx, hash, sizeof( hash ),
|
||||
sig, sig_len ) == 0 );
|
||||
|
||||
/* check we didn't write past the announced length */
|
||||
for( i = sig_len; i < sizeof( sig ); i++ )
|
||||
TEST_ASSERT( sig[i] == 0x2a );
|
||||
|
||||
/* try verification with invalid length */
|
||||
TEST_ASSERT( ecdsa_read_signature( &ctx, hash, sizeof( hash ),
|
||||
sig, sig_len - 1 ) != 0 );
|
||||
TEST_ASSERT( ecdsa_read_signature( &ctx, hash, sizeof( hash ),
|
||||
sig, sig_len + 1 ) != 0 );
|
||||
|
||||
/* try invalid sequence tag */
|
||||
sig[0]++;
|
||||
TEST_ASSERT( ecdsa_read_signature( &ctx, hash, sizeof( hash ),
|
||||
sig, sig_len ) != 0 );
|
||||
sig[0]--;
|
||||
|
||||
/* try modifying r */
|
||||
sig[10]++;
|
||||
TEST_ASSERT( ecdsa_read_signature( &ctx, hash, sizeof( hash ),
|
||||
sig, sig_len ) != 0 );
|
||||
sig[10]--;
|
||||
|
||||
/* try modifying s */
|
||||
sig[sig_len - 1]++;
|
||||
TEST_ASSERT( ecdsa_read_signature( &ctx, hash, sizeof( hash ),
|
||||
sig, sig_len ) != 0 );
|
||||
sig[sig_len - 1]--;
|
||||
|
||||
ecdsa_free( &ctx );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
Reference in New Issue
Block a user