7 #define POLARSSL_ECP_PF_UNKNOWN -1
11 #if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
15 #if defined(WANT_NOT_RND_MPI)
16 #if defined(POLARSSL_BIGNUM_C)
19 #error "not_rnd_mpi() need bignum.c"
25 typedef UINT32 uint32_t;
38 #define GET_UINT32_BE(n,b,i) \
40 (n) = ( (uint32_t) (b)[(i) ] << 24 ) \
41 | ( (uint32_t) (b)[(i) + 1] << 16 ) \
42 | ( (uint32_t) (b)[(i) + 2] << 8 ) \
43 | ( (uint32_t) (b)[(i) + 3] ); \
48 #define PUT_UINT32_BE(n,b,i) \
50 (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
51 (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
52 (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
53 (b)[(i) + 3] = (unsigned char) ( (n) ); \
57 static int unhexify(
unsigned char *obuf,
const char *ibuf)
60 int len = strlen(ibuf) / 2;
61 assert(!(strlen(ibuf) %1));
66 if( c >=
'0' && c <=
'9' )
68 else if( c >=
'a' && c <=
'f' )
70 else if( c >=
'A' && c <=
'F' )
76 if( c2 >=
'0' && c2 <=
'9' )
78 else if( c2 >=
'a' && c2 <=
'f' )
80 else if( c2 >=
'A' && c2 <=
'F' )
85 *obuf++ = ( c << 4 ) | c2;
91 static void hexify(
unsigned char *obuf,
const unsigned char *ibuf,
int len)
103 *obuf++ =
'a' + h - 10;
108 *obuf++ =
'a' + l - 10;
124 static int rnd_std_rand(
void *rng_state,
unsigned char *output,
size_t len )
128 if( rng_state != NULL )
131 for( i = 0; i < len; ++i )
142 static int rnd_zero_rand(
void *rng_state,
unsigned char *output,
size_t len )
144 if( rng_state != NULL )
147 memset( output, 0, len );
174 if( rng_state == NULL )
183 memcpy( output, info->
buf, use_len );
184 info->
buf += use_len;
188 if( len - use_len > 0 )
189 return(
rnd_std_rand( NULL, output + use_len, len - use_len ) );
218 uint32_t i, *k, sum, delta=0x9E3779B9;
219 unsigned char result[4];
221 if( rng_state == NULL )
228 size_t use_len = ( len > 4 ) ? 4 : len;
231 for( i = 0; i < 32; i++ )
233 info->
v0 += (((info->
v1 << 4) ^ (info->
v1 >> 5)) + info->
v1) ^ (sum + k[sum & 3]);
235 info->
v1 += (((info->
v0 << 4) ^ (info->
v0 >> 5)) + info->
v0) ^ (sum + k[(sum>>11) & 3]);
239 memcpy( output, result, use_len );
246 #if defined(WANT_NOT_RND_MPI)
255 #define ciL (sizeof(t_uint))
256 #define CHARS_TO_LIMBS(i) (((i) + ciL - 1) / ciL)
257 static int not_rnd_mpi(
void *in,
unsigned char *out,
size_t len )
259 char *str = (
char *) in;
268 X.
n = CHARS_TO_LIMBS( len );
274 assert( strlen( str ) / 2 == len );
286 #ifdef POLARSSL_ECP_C
288 #define TEST_SUITE_ACTIVE
296 if( test_errors == 1 )
297 printf(
"FAILED\n" );
298 printf(
" %s\n", test );
303 #define TEST_ASSERT( TEST ) \
304 do { test_assert( (TEST) ? 1 : 0, #TEST ); \
305 if( test_errors) return; \
310 if( (*str)[0] !=
'"' ||
311 (*str)[strlen( *str ) - 1] !=
'"' )
313 printf(
"Expected string (with \"\") for parameter and got: %s\n", *str );
318 (*str)[strlen( *str ) - 1] =
'\0';
330 for( i = 0; i < strlen( str ); i++ )
332 if( i == 0 && str[i] ==
'-' )
338 if( ( ( minus && i == 2 ) || ( !minus && i == 1 ) ) &&
339 str[i - 1] ==
'0' && str[i] ==
'x' )
345 if( str[i] <
'0' || str[i] >
'9' )
355 *value = strtol( str, NULL, 16 );
357 *value = strtol( str, NULL, 10 );
362 if( strcmp( str,
"POLARSSL_ECP_PF_COMPRESSED" ) == 0 )
367 if( strcmp( str,
"POLARSSL_ECP_PF_UNCOMPRESSED" ) == 0 )
372 if( strcmp( str,
"POLARSSL_ECP_DP_SECP192R1" ) == 0 )
377 if( strcmp( str,
"-1" ) == 0 )
382 if( strcmp( str,
"POLARSSL_ECP_PF_UNKNOWN" ) == 0 )
384 *value = ( POLARSSL_ECP_PF_UNKNOWN );
387 if( strcmp( str,
"POLARSSL_ECP_DP_BP512R1" ) == 0 )
392 if( strcmp( str,
"POLARSSL_ECP_DP_SECP384R1" ) == 0 )
397 if( strcmp( str,
"POLARSSL_ERR_ECP_BUFFER_TOO_SMALL" ) == 0 )
402 if( strcmp( str,
"POLARSSL_ERR_ECP_FEATURE_UNAVAILABLE" ) == 0 )
407 if( strcmp( str,
"POLARSSL_ECP_DP_BP384R1" ) == 0 )
412 if( strcmp( str,
"POLARSSL_ECP_DP_SECP224R1" ) == 0 )
417 if( strcmp( str,
"POLARSSL_ECP_DP_SECP256R1" ) == 0 )
422 if( strcmp( str,
"POLARSSL_ERR_ECP_INVALID_KEY" ) == 0 )
427 if( strcmp( str,
"POLARSSL_ECP_DP_BP256R1" ) == 0 )
432 if( strcmp( str,
"POLARSSL_ERR_ECP_BAD_INPUT_DATA" ) == 0 )
437 if( strcmp( str,
"POLARSSL_ECP_DP_SECP521R1" ) == 0 )
444 printf(
"Expected integer for parameter and got: %s\n", str );
448 void test_suite_ecp_small_add(
int a_zero,
char *x_a,
char *y_a,
int b_zero,
char *x_b,
449 char *y_b,
int c_zero,
int x_c,
int y_c )
458 "47",
"4",
"17",
"42",
"13" ) == 0 );
494 void test_suite_ecp_small_sub(
int a_zero,
char *x_a,
char *y_a,
int b_zero,
char *x_b,
495 char *y_b,
int c_zero,
int x_c,
int y_c )
504 "47",
"4",
"17",
"42",
"13" ) == 0 );
530 void test_suite_ecp_small_mul(
int m_str,
int r_zero,
int x_r,
int y_r,
int ret )
543 "47",
"4",
"17",
"42",
"13" ) == 0 );
576 void test_suite_ecp_small_check_pub(
int x,
int y,
int z,
int ret )
585 "47",
"4",
"17",
"42",
"13" ) == 0 );
597 void test_suite_ecp_test_vect(
int id,
char *dA_str,
char *xA_str,
char *yA_str,
598 char *dB_str,
char *xB_str,
char *yB_str,
char *xZ_str,
603 mpi dA, xA, yA, dB, xB, yB, xZ, yZ;
649 void test_suite_ecp_fast_mod(
int id,
char *N_str )
679 void test_suite_ecp_write_binary(
int id,
char *x,
char *y,
char *z,
int format,
680 char *out,
int blen,
int ret )
684 unsigned char buf[256], str[512];
687 memset( buf, 0,
sizeof( buf ) );
688 memset( str, 0,
sizeof( str ) );
699 &olen, buf, blen ) == ret );
704 TEST_ASSERT( strcasecmp( (
char *) str, out ) == 0 );
710 void test_suite_ecp_read_binary(
int id,
char *input,
char *x,
char *y,
char *z,
717 unsigned char buf[256];
719 memset( buf, 0,
sizeof( buf ) );
745 void test_suite_ecp_tls_read_point(
int id,
char *input,
char *x,
char *y,
char *z,
752 unsigned char buf[256];
753 const unsigned char *vbuf = buf;
755 memset( buf, 0,
sizeof( buf ) );
782 void test_suite_ecp_tls_write_read_point(
int id )
786 unsigned char buf[256];
787 const unsigned char *vbuf;
795 memset( buf, 0x00,
sizeof( buf ) ); vbuf = buf;
802 memset( buf, 0x00,
sizeof( buf ) ); vbuf = buf;
811 memset( buf, 0x00,
sizeof( buf ) ); vbuf = buf;
819 memset( buf, 0x00,
sizeof( buf ) ); vbuf = buf;
831 void test_suite_ecp_tls_read_group(
char *record,
int result,
int bits )
834 unsigned char buf[10];
835 const unsigned char *vbuf = buf;
839 memset( buf, 0x00,
sizeof( buf ) );
855 void test_suite_ecp_tls_write_read_group(
int id )
858 unsigned char buf[10];
859 const unsigned char *vbuf = buf;
865 memset( buf, 0x00,
sizeof( buf ) );
882 void test_suite_ecp_check_privkey(
int id )
902 void test_suite_ecp_gen_keypair(
int id )
927 #ifdef POLARSSL_SELF_TEST
928 void test_suite_ecp_selftest()
943 if( strcmp( str,
"POLARSSL_ECP_DP_SECP521R1_ENABLED" ) == 0 )
945 #if defined(POLARSSL_ECP_DP_SECP521R1_ENABLED)
951 if( strcmp( str,
"POLARSSL_ECP_DP_SECP384R1_ENABLED" ) == 0 )
953 #if defined(POLARSSL_ECP_DP_SECP384R1_ENABLED)
959 if( strcmp( str,
"POLARSSL_ECP_DP_BP256R1_ENABLED" ) == 0 )
961 #if defined(POLARSSL_ECP_DP_BP256R1_ENABLED)
967 if( strcmp( str,
"POLARSSL_ECP_DP_SECP224R1_ENABLED" ) == 0 )
969 #if defined(POLARSSL_ECP_DP_SECP224R1_ENABLED)
975 if( strcmp( str,
"POLARSSL_ECP_DP_SECP192R1_ENABLED" ) == 0 )
977 #if defined(POLARSSL_ECP_DP_SECP192R1_ENABLED)
983 if( strcmp( str,
"POLARSSL_ECP_DP_BP512R1_ENABLED" ) == 0 )
985 #if defined(POLARSSL_ECP_DP_BP512R1_ENABLED)
991 if( strcmp( str,
"POLARSSL_ECP_DP_SECP256R1_ENABLED" ) == 0 )
993 #if defined(POLARSSL_ECP_DP_SECP256R1_ENABLED)
999 if( strcmp( str,
"POLARSSL_ECP_DP_BP384R1_ENABLED" ) == 0 )
1001 #if defined(POLARSSL_ECP_DP_BP384R1_ENABLED)
1018 #if defined(TEST_SUITE_ACTIVE)
1019 if( strcmp( params[0],
"ecp_small_add" ) == 0 )
1023 char *param2 = params[2];
1024 char *param3 = params[3];
1026 char *param5 = params[5];
1027 char *param6 = params[6];
1034 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 10 );
1038 if(
verify_int( params[1], ¶m1 ) != 0 )
return( 2 );
1041 if(
verify_int( params[4], ¶m4 ) != 0 )
return( 2 );
1044 if(
verify_int( params[7], ¶m7 ) != 0 )
return( 2 );
1045 if(
verify_int( params[8], ¶m8 ) != 0 )
return( 2 );
1046 if(
verify_int( params[9], ¶m9 ) != 0 )
return( 2 );
1048 test_suite_ecp_small_add( param1, param2, param3, param4, param5, param6, param7, param8, param9 );
1054 if( strcmp( params[0],
"ecp_small_sub" ) == 0 )
1058 char *param2 = params[2];
1059 char *param3 = params[3];
1061 char *param5 = params[5];
1062 char *param6 = params[6];
1069 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 10 );
1073 if(
verify_int( params[1], ¶m1 ) != 0 )
return( 2 );
1076 if(
verify_int( params[4], ¶m4 ) != 0 )
return( 2 );
1079 if(
verify_int( params[7], ¶m7 ) != 0 )
return( 2 );
1080 if(
verify_int( params[8], ¶m8 ) != 0 )
return( 2 );
1081 if(
verify_int( params[9], ¶m9 ) != 0 )
return( 2 );
1083 test_suite_ecp_small_sub( param1, param2, param3, param4, param5, param6, param7, param8, param9 );
1089 if( strcmp( params[0],
"ecp_small_mul" ) == 0 )
1100 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 6 );
1104 if(
verify_int( params[1], ¶m1 ) != 0 )
return( 2 );
1105 if(
verify_int( params[2], ¶m2 ) != 0 )
return( 2 );
1106 if(
verify_int( params[3], ¶m3 ) != 0 )
return( 2 );
1107 if(
verify_int( params[4], ¶m4 ) != 0 )
return( 2 );
1108 if(
verify_int( params[5], ¶m5 ) != 0 )
return( 2 );
1110 test_suite_ecp_small_mul( param1, param2, param3, param4, param5 );
1116 if( strcmp( params[0],
"ecp_small_check_pub" ) == 0 )
1126 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 5 );
1130 if(
verify_int( params[1], ¶m1 ) != 0 )
return( 2 );
1131 if(
verify_int( params[2], ¶m2 ) != 0 )
return( 2 );
1132 if(
verify_int( params[3], ¶m3 ) != 0 )
return( 2 );
1133 if(
verify_int( params[4], ¶m4 ) != 0 )
return( 2 );
1135 test_suite_ecp_small_check_pub( param1, param2, param3, param4 );
1141 if( strcmp( params[0],
"ecp_test_vect" ) == 0 )
1145 char *param2 = params[2];
1146 char *param3 = params[3];
1147 char *param4 = params[4];
1148 char *param5 = params[5];
1149 char *param6 = params[6];
1150 char *param7 = params[7];
1151 char *param8 = params[8];
1152 char *param9 = params[9];
1156 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 10 );
1160 if(
verify_int( params[1], ¶m1 ) != 0 )
return( 2 );
1170 test_suite_ecp_test_vect( param1, param2, param3, param4, param5, param6, param7, param8, param9 );
1176 if( strcmp( params[0],
"ecp_fast_mod" ) == 0 )
1180 char *param2 = params[2];
1184 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 3 );
1188 if(
verify_int( params[1], ¶m1 ) != 0 )
return( 2 );
1191 test_suite_ecp_fast_mod( param1, param2 );
1197 if( strcmp( params[0],
"ecp_write_binary" ) == 0 )
1201 char *param2 = params[2];
1202 char *param3 = params[3];
1203 char *param4 = params[4];
1205 char *param6 = params[6];
1211 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 9 );
1215 if(
verify_int( params[1], ¶m1 ) != 0 )
return( 2 );
1219 if(
verify_int( params[5], ¶m5 ) != 0 )
return( 2 );
1221 if(
verify_int( params[7], ¶m7 ) != 0 )
return( 2 );
1222 if(
verify_int( params[8], ¶m8 ) != 0 )
return( 2 );
1224 test_suite_ecp_write_binary( param1, param2, param3, param4, param5, param6, param7, param8 );
1230 if( strcmp( params[0],
"ecp_read_binary" ) == 0 )
1234 char *param2 = params[2];
1235 char *param3 = params[3];
1236 char *param4 = params[4];
1237 char *param5 = params[5];
1242 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 7 );
1246 if(
verify_int( params[1], ¶m1 ) != 0 )
return( 2 );
1251 if(
verify_int( params[6], ¶m6 ) != 0 )
return( 2 );
1253 test_suite_ecp_read_binary( param1, param2, param3, param4, param5, param6 );
1259 if( strcmp( params[0],
"ecp_tls_read_point" ) == 0 )
1263 char *param2 = params[2];
1264 char *param3 = params[3];
1265 char *param4 = params[4];
1266 char *param5 = params[5];
1271 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 7 );
1275 if(
verify_int( params[1], ¶m1 ) != 0 )
return( 2 );
1280 if(
verify_int( params[6], ¶m6 ) != 0 )
return( 2 );
1282 test_suite_ecp_tls_read_point( param1, param2, param3, param4, param5, param6 );
1288 if( strcmp( params[0],
"ecp_tls_write_read_point" ) == 0 )
1295 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 2 );
1299 if(
verify_int( params[1], ¶m1 ) != 0 )
return( 2 );
1301 test_suite_ecp_tls_write_read_point( param1 );
1307 if( strcmp( params[0],
"ecp_tls_read_group" ) == 0 )
1310 char *param1 = params[1];
1316 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 4 );
1321 if(
verify_int( params[2], ¶m2 ) != 0 )
return( 2 );
1322 if(
verify_int( params[3], ¶m3 ) != 0 )
return( 2 );
1324 test_suite_ecp_tls_read_group( param1, param2, param3 );
1330 if( strcmp( params[0],
"ecp_tls_write_read_group" ) == 0 )
1337 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 2 );
1341 if(
verify_int( params[1], ¶m1 ) != 0 )
return( 2 );
1343 test_suite_ecp_tls_write_read_group( param1 );
1349 if( strcmp( params[0],
"ecp_check_privkey" ) == 0 )
1356 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 2 );
1360 if(
verify_int( params[1], ¶m1 ) != 0 )
return( 2 );
1362 test_suite_ecp_check_privkey( param1 );
1368 if( strcmp( params[0],
"ecp_gen_keypair" ) == 0 )
1375 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 2 );
1379 if(
verify_int( params[1], ¶m1 ) != 0 )
return( 2 );
1381 test_suite_ecp_gen_keypair( param1 );
1387 if( strcmp( params[0],
"ecp_selftest" ) == 0 )
1389 #ifdef POLARSSL_SELF_TEST
1394 fprintf( stderr,
"\nIncorrect argument count (%d != %d)\n", cnt, 1 );
1399 test_suite_ecp_selftest( );
1408 fprintf( stdout,
"FAILED\nSkipping unknown test function '%s'\n", params[0] );
1422 ret = fgets( buf, len, f );
1426 if( strlen( buf ) && buf[strlen(buf) - 1] ==
'\n' )
1427 buf[strlen(buf) - 1] =
'\0';
1428 if( strlen( buf ) && buf[strlen(buf) - 1] ==
'\r' )
1429 buf[strlen(buf) - 1] =
'\0';
1440 params[cnt++] = cur;
1442 while( *p !=
'\0' && p < buf + len )
1452 if( p + 1 < buf + len )
1455 params[cnt++] = cur;
1464 for( i = 0; i < cnt; i++ )
1471 if( *p ==
'\\' && *(p + 1) ==
'n' )
1476 else if( *p ==
'\\' && *(p + 1) ==
':' )
1481 else if( *p ==
'\\' && *(p + 1) ==
'?' )
1497 int ret, i, cnt, total_errors = 0, total_tests = 0, total_skipped = 0;
1498 const char *filename =
"/tmp/B.6b9404fc-5e27-486e-9bbd-77463d7343ee/BUILD/polarssl-1.3.2/tests/suites/test_suite_ecp.data";
1503 #if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
1504 unsigned char alloc_buf[1000000];
1505 memory_buffer_alloc_init( alloc_buf,
sizeof(alloc_buf) );
1508 file = fopen( filename,
"r" );
1511 fprintf( stderr,
"Failed to open\n" );
1515 while( !feof( file ) )
1519 if( ( ret =
get_line( file, buf,
sizeof(buf) ) ) != 0 )
1521 fprintf( stdout,
"%s%.66s", test_errors ?
"\n" :
"", buf );
1522 fprintf( stdout,
" " );
1523 for( i = strlen( buf ) + 1; i < 67; i++ )
1524 fprintf( stdout,
"." );
1525 fprintf( stdout,
" " );
1530 if( ( ret =
get_line( file, buf,
sizeof(buf) ) ) != 0 )
1534 if( strcmp( params[0],
"depends_on" ) == 0 )
1536 for( i = 1; i < cnt; i++ )
1540 if( ( ret =
get_line( file, buf,
sizeof(buf) ) ) != 0 )
1551 if( skip == 1 || ret == 3 )
1554 fprintf( stdout,
"----\n" );
1557 else if( ret == 0 && test_errors == 0 )
1559 fprintf( stdout,
"PASS\n" );
1564 fprintf( stderr,
"FAILED: FATAL PARSE ERROR\n" );
1571 if( ( ret =
get_line( file, buf,
sizeof(buf) ) ) != 0 )
1573 if( strlen(buf) != 0 )
1575 fprintf( stderr,
"Should be empty %d\n", (
int) strlen(buf) );
1581 fprintf( stdout,
"\n----------------------------------------------------------------------------\n\n");
1582 if( total_errors == 0 )
1583 fprintf( stdout,
"PASSED" );
1585 fprintf( stdout,
"FAILED" );
1587 fprintf( stdout,
" (%d / %d tests (%d skipped))\n",
1588 total_tests - total_errors, total_tests, total_skipped );
1590 #if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
1591 #if defined(POLARSSL_MEMORY_DEBUG)
1592 memory_buffer_alloc_status();
1594 memory_buffer_alloc_free();
1597 return( total_errors != 0 );
int mpi_cmp_int(const mpi *X, t_sint z)
Compare signed values.
static int unhexify(unsigned char *obuf, const char *ibuf)
int ecp_sub(const ecp_group *grp, ecp_point *R, const ecp_point *P, const ecp_point *Q)
Subtraction: R = P - Q.
int ecp_check_privkey(const ecp_group *grp, const mpi *d)
Check that an mpi is a valid private key for this curve.
#define POLARSSL_ERR_ECP_BAD_INPUT_DATA
Bad input parameters to function.
#define POLARSSL_ECP_PF_COMPRESSED
Compressed point format.
Info structure for the pseudo random function.
int ecp_self_test(int verbose)
Checkup routine.
Elliptic curves over GF(p)
static int rnd_pseudo_rand(void *rng_state, unsigned char *output, size_t len)
This function returns random based on a pseudo random function.
#define POLARSSL_ECP_PF_UNCOMPRESSED
Uncompressed point format.
Configuration options (set of defines)
int mpi_lset(mpi *X, t_sint z)
Set value from integer.
int ecp_mul(ecp_group *grp, ecp_point *R, const mpi *m, const ecp_point *P, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Multiplication by an integer: R = m * P (Not thread-safe to use same group in multiple threads) ...
static int test_assert(int correct, char *test)
int ecp_point_read_binary(const ecp_group *grp, ecp_point *P, const unsigned char *buf, size_t ilen)
Import a point from unsigned binary data.
#define POLARSSL_ERR_ECP_FEATURE_UNAVAILABLE
Requested curve not available.
void mpi_init(mpi *X)
Initialize one MPI.
int main(int argc, char *argv[])
int mpi_cmp_mpi(const mpi *X, const mpi *Y)
Compare signed values.
Multi-precision integer library.
#define POLARSSL_ERR_ECP_BUFFER_TOO_SMALL
The buffer is too small to write to.
#define PUT_UINT32_BE(n, b, i)
#define TEST_ASSERT(TEST)
ECP point structure (jacobian coordinates)
int ecp_is_zero(ecp_point *pt)
Tell if a point is zero.
void ecp_point_init(ecp_point *pt)
Initialize a point (as zero)
int ecp_point_read_string(ecp_point *P, int radix, const char *x, const char *y)
Import a non-zero point from two ASCII strings.
void mpi_free(mpi *X)
Unallocate one MPI.
void ecp_group_free(ecp_group *grp)
Free the components of an ECP group.
static int rnd_buffer_rand(void *rng_state, unsigned char *output, size_t len)
This function returns random based on a buffer it receives.
int ecp_tls_write_point(const ecp_group *grp, const ecp_point *pt, int format, size_t *olen, unsigned char *buf, size_t blen)
Export a point as a TLS ECPoint record.
int ecp_gen_keypair(ecp_group *grp, mpi *d, ecp_point *Q, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Generate a keypair.
int parse_arguments(char *buf, size_t len, char *params[50])
static void hexify(unsigned char *obuf, const unsigned char *ibuf, int len)
size_t mpi_msb(const mpi *X)
Return the number of bits up to and including the most significant '1' bit'.
int ecp_use_known_dp(ecp_group *grp, ecp_group_id index)
Set a group using well-known domain parameters.
int mpi_read_string(mpi *X, int radix, const char *s)
Import from an ASCII string.
int ecp_tls_write_group(const ecp_group *grp, size_t *olen, unsigned char *buf, size_t blen)
Write the TLS ECParameters record for a group.
int verify_string(char **str)
int ecp_point_write_binary(const ecp_group *grp, const ecp_point *P, int format, size_t *olen, unsigned char *buf, size_t buflen)
Export a point into unsigned binary data.
void ecp_group_init(ecp_group *grp)
Initialize a group (to something meaningless)
int mpi_copy(mpi *X, const mpi *Y)
Copy the contents of Y into X.
int dispatch_test(int cnt, char *params[50])
static int rnd_std_rand(void *rng_state, unsigned char *output, size_t len)
This function just returns data from rand().
int mpi_mod_mpi(mpi *R, const mpi *A, const mpi *B)
Modulo: R = A mod B.
int ecp_tls_read_group(ecp_group *grp, const unsigned char **buf, size_t len)
Set a group from a TLS ECParameters record.
int ecp_check_pubkey(const ecp_group *grp, const ecp_point *pt)
Check that a point is a valid public key on this curve.
int ecp_add(const ecp_group *grp, ecp_point *R, const ecp_point *P, const ecp_point *Q)
Addition: R = P + Q.
int verify_int(char *str, int *value)
int ecp_set_zero(ecp_point *pt)
Set a point to zero.
#define POLARSSL_ERR_ECP_INVALID_KEY
Invalid private or public key.
int ecp_tls_read_point(const ecp_group *grp, ecp_point *pt, const unsigned char **buf, size_t len)
Import a point from a TLS ECPoint record.
int get_line(FILE *f, char *buf, size_t len)
int ecp_group_read_string(ecp_group *grp, int radix, const char *p, const char *b, const char *gx, const char *gy, const char *n)
Import an ECP group from null-terminated ASCII strings.
static int rnd_zero_rand(void *rng_state, unsigned char *output, size_t len)
This function only returns zeros.
void ecp_point_free(ecp_point *pt)
Free the components of a point.