1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-30 22:43:08 +03:00

ECDSA : test vectors from RFC 4754

This commit is contained in:
Manuel Pégourié-Gonnard
2013-01-27 08:10:28 +01:00
parent d1c7150bf5
commit 602a8973d7
3 changed files with 102 additions and 11 deletions

View File

@ -218,3 +218,49 @@ static int rnd_pseudo_rand( void *rng_state, unsigned char *output, size_t len )
return( 0 );
}
/**
* This function returns a buffer given as a hex string.
*
* The buffer is reversed so that the following are equivalent:
* mpi_fill_random( x, len, not_rnd, str );
* mpi_read_string( x, 16, str );
* (So, not random at all. Usefull to match test vectors.)
* Based on unhexify(), just reversed (changes marked by "sic")
*/
static int not_rnd( void *in, unsigned char *out, size_t len )
{
unsigned char *obuf;
const char *ibuf = in;
unsigned char c, c2;
assert( len == strlen(ibuf) / 2 );
assert(!(strlen(ibuf) %1)); // must be even number of bytes
obuf = out + (len - 1); // sic
while (*ibuf != 0)
{
c = *ibuf++;
if( c >= '0' && c <= '9' )
c -= '0';
else if( c >= 'a' && c <= 'f' )
c -= 'a' - 10;
else if( c >= 'A' && c <= 'F' )
c -= 'A' - 10;
else
assert( 0 );
c2 = *ibuf++;
if( c2 >= '0' && c2 <= '9' )
c2 -= '0';
else if( c2 >= 'a' && c2 <= 'f' )
c2 -= 'a' - 10;
else if( c2 >= 'A' && c2 <= 'F' )
c2 -= 'A' - 10;
else
assert( 0 );
*obuf-- = ( c << 4 ) | c2; // sic
}
return( 0 );
}