69#if !defined(MBEDTLS_CONFIG_FILE)
72#include MBEDTLS_CONFIG_FILE
101#if defined(MBEDTLS_ECP_INTERNAL_ALT)
104#if defined(MBEDTLS_ECP_C)
113#if !defined(MBEDTLS_ECP_ALT)
116#define ECP_VALIDATE_RET( cond ) \
117 MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_ECP_BAD_INPUT_DATA )
118#define ECP_VALIDATE( cond ) \
119 MBEDTLS_INTERNAL_VALIDATE( cond )
121#if defined(MBEDTLS_PLATFORM_C)
126#define mbedtls_printf printf
127#define mbedtls_calloc calloc
128#define mbedtls_free free
133#if !defined(MBEDTLS_ECP_NO_INTERNAL_RNG)
134#if defined(MBEDTLS_HMAC_DRBG_C)
136#elif defined(MBEDTLS_CTR_DRBG_C)
138#elif defined(MBEDTLS_SHA512_C)
140#elif defined(MBEDTLS_SHA256_C)
143#error "Invalid configuration detected. Include check_config.h to ensure that the configuration is valid."
147#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
148 !defined(inline) && !defined(__cplusplus)
149#define inline __inline
152#if defined(MBEDTLS_SELF_TEST)
157static unsigned long add_count, dbl_count, mul_count;
160#if !defined(MBEDTLS_ECP_NO_INTERNAL_RNG)
179#if defined(MBEDTLS_HMAC_DRBG_C)
185static inline void ecp_drbg_init( ecp_drbg_context *
ctx )
191static inline void ecp_drbg_free( ecp_drbg_context *
ctx )
197static inline int ecp_drbg_random(
void *p_rng,
198 unsigned char *output,
size_t output_len )
204static int ecp_drbg_seed( ecp_drbg_context *
ctx,
214 secret_bytes, secret_len ) );
224#elif defined(MBEDTLS_CTR_DRBG_C)
230static inline void ecp_drbg_init( ecp_drbg_context *
ctx )
236static inline void ecp_drbg_free( ecp_drbg_context *
ctx )
242static inline int ecp_drbg_random(
void *p_rng,
243 unsigned char *output,
size_t output_len )
255static int ecp_ctr_drbg_null_entropy(
void *
ctx,
unsigned char *
out,
size_t len)
263static int ecp_drbg_seed( ecp_drbg_context *
ctx,
270 secret_bytes, secret_len ) );
273 secret_bytes, secret_len );
281#elif defined(MBEDTLS_SHA512_C) || defined(MBEDTLS_SHA256_C)
284#define ECP_ONE_STEP_KDF
295#if defined(MBEDTLS_SHA512_C)
297#define HASH_FUNC( in, ilen, out ) mbedtls_sha512_ret( in, ilen, out, 0 );
298#define HASH_BLOCK_BYTES ( 512 / 8 )
300#elif defined(MBEDTLS_SHA256_C)
302#define HASH_FUNC( in, ilen, out ) mbedtls_sha256_ret( in, ilen, out, 0 );
303#define HASH_BLOCK_BYTES ( 256 / 8 )
318static void ecp_drbg_init( ecp_drbg_context *
ctx )
320 memset(
ctx, 0,
sizeof( ecp_drbg_context ) );
323static void ecp_drbg_free( ecp_drbg_context *
ctx )
328static int ecp_drbg_seed( ecp_drbg_context *
ctx,
331 ctx->total_len = 4 + secret_len;
336static int ecp_drbg_random(
void *p_rng,
unsigned char *output,
size_t output_len )
338 ecp_drbg_context *
ctx = p_rng;
343 while( len_done < output_len )
361 if(
ctx->buf[3] == 0 )
364 ret = HASH_FUNC(
ctx->buf,
ctx->total_len, tmp );
368 if( output_len - len_done > HASH_BLOCK_BYTES )
369 use_len = HASH_BLOCK_BYTES;
371 use_len = output_len - len_done;
373 memcpy( output + len_done, tmp, use_len );
383#error "Invalid configuration detected. Include check_config.h to ensure that the configuration is valid."
387#if defined(MBEDTLS_ECP_RESTARTABLE)
398static unsigned ecp_max_ops = 0;
403void mbedtls_ecp_set_max_ops(
unsigned max_ops )
405 ecp_max_ops = max_ops;
411int mbedtls_ecp_restart_is_enabled(
void )
413 return( ecp_max_ops != 0 );
419struct mbedtls_ecp_restart_mul
424 unsigned char T_size;
428 ecp_rsm_pre_norm_dbl,
430 ecp_rsm_pre_norm_add,
434#if !defined(MBEDTLS_ECP_NO_INTERNAL_RNG)
435 ecp_drbg_context drbg_ctx;
436 unsigned char drbg_seeded;
443static void ecp_restart_rsm_init( mbedtls_ecp_restart_mul_ctx *
ctx )
449 ctx->state = ecp_rsm_init;
450#if !defined(MBEDTLS_ECP_NO_INTERNAL_RNG)
451 ecp_drbg_init( &
ctx->drbg_ctx );
452 ctx->drbg_seeded = 0;
459static void ecp_restart_rsm_free( mbedtls_ecp_restart_mul_ctx *
ctx )
470 for(
i = 0;
i <
ctx->T_size;
i++ )
475#if !defined(MBEDTLS_ECP_NO_INTERNAL_RNG)
476 ecp_drbg_free( &
ctx->drbg_ctx );
479 ecp_restart_rsm_init(
ctx );
485struct mbedtls_ecp_restart_muladd
500static void ecp_restart_ma_init( mbedtls_ecp_restart_muladd_ctx *
ctx )
504 ctx->state = ecp_rsma_mul1;
510static void ecp_restart_ma_free( mbedtls_ecp_restart_muladd_ctx *
ctx )
518 ecp_restart_ma_init(
ctx );
541 ecp_restart_rsm_free(
ctx->rsm );
544 ecp_restart_ma_free(
ctx->ma );
547 mbedtls_ecp_restart_init(
ctx );
557 ECP_VALIDATE_RET( grp !=
NULL );
559 if( rs_ctx !=
NULL && ecp_max_ops != 0 )
563 if( grp->
pbits >= 512 )
565 else if( grp->
pbits >= 384 )
572 if( ( rs_ctx->ops_done != 0 ) &&
573 ( rs_ctx->ops_done > ecp_max_ops ||
574 ops > ecp_max_ops - rs_ctx->ops_done ) )
580 rs_ctx->ops_done += ops;
587#define ECP_RS_ENTER( SUB ) do { \
589 if( rs_ctx != NULL && rs_ctx->depth++ == 0 ) \
590 rs_ctx->ops_done = 0; \
593 if( mbedtls_ecp_restart_is_enabled() && \
594 rs_ctx != NULL && rs_ctx->SUB == NULL ) \
596 rs_ctx->SUB = mbedtls_calloc( 1, sizeof( *rs_ctx->SUB ) ); \
597 if( rs_ctx->SUB == NULL ) \
598 return( MBEDTLS_ERR_ECP_ALLOC_FAILED ); \
600 ecp_restart_## SUB ##_init( rs_ctx->SUB ); \
605#define ECP_RS_LEAVE( SUB ) do { \
607 if( rs_ctx != NULL && rs_ctx->SUB != NULL && \
608 ret != MBEDTLS_ERR_ECP_IN_PROGRESS ) \
610 ecp_restart_## SUB ##_free( rs_ctx->SUB ); \
611 mbedtls_free( rs_ctx->SUB ); \
612 rs_ctx->SUB = NULL; \
615 if( rs_ctx != NULL ) \
621#define ECP_RS_ENTER( sub ) (void) rs_ctx;
622#define ECP_RS_LEAVE( sub ) (void) rs_ctx;
626#if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) || \
627 defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) || \
628 defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) || \
629 defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) || \
630 defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED) || \
631 defined(MBEDTLS_ECP_DP_BP256R1_ENABLED) || \
632 defined(MBEDTLS_ECP_DP_BP384R1_ENABLED) || \
633 defined(MBEDTLS_ECP_DP_BP512R1_ENABLED) || \
634 defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED) || \
635 defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED) || \
636 defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED)
637#define ECP_SHORTWEIERSTRASS
640#if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED) || \
641 defined(MBEDTLS_ECP_DP_CURVE448_ENABLED)
642#define ECP_MONTGOMERY
651 ECP_TYPE_SHORT_WEIERSTRASS,
669#if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED)
672#if defined(MBEDTLS_ECP_DP_BP512R1_ENABLED)
675#if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED)
678#if defined(MBEDTLS_ECP_DP_BP384R1_ENABLED)
681#if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED)
684#if defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED)
687#if defined(MBEDTLS_ECP_DP_BP256R1_ENABLED)
690#if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED)
693#if defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED)
696#if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
699#if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED)
705#define ECP_NB_CURVES sizeof( ecp_supported_curves ) / \
706 sizeof( ecp_supported_curves[0] )
715 return( ecp_supported_curves );
723 static int init_done = 0;
734 ecp_supported_grp_id[
i++] = curve_info->
grp_id;
741 return( ecp_supported_grp_id );
755 if( curve_info->
grp_id == grp_id )
756 return( curve_info );
773 if( curve_info->
tls_id == tls_id )
774 return( curve_info );
795 return( curve_info );
807 return( ECP_TYPE_NONE );
810 return( ECP_TYPE_MONTGOMERY );
812 return( ECP_TYPE_SHORT_WEIERSTRASS );
820 ECP_VALIDATE(
pt !=
NULL );
832 ECP_VALIDATE( grp !=
NULL );
924 ECP_VALIDATE_RET(
P !=
NULL );
925 ECP_VALIDATE_RET( Q !=
NULL );
940 ECP_VALIDATE_RET(
dst !=
NULL );
941 ECP_VALIDATE_RET(
src !=
NULL );
952 ECP_VALIDATE_RET(
pt !=
NULL );
967 ECP_VALIDATE_RET(
pt !=
NULL );
978 ECP_VALIDATE_RET(
P !=
NULL );
979 ECP_VALIDATE_RET( Q !=
NULL );
995 const char *
x,
const char *
y )
998 ECP_VALIDATE_RET(
P !=
NULL );
999 ECP_VALIDATE_RET(
x !=
NULL );
1000 ECP_VALIDATE_RET(
y !=
NULL );
1015 int format,
size_t *olen,
1016 unsigned char *
buf,
size_t buflen )
1020 ECP_VALIDATE_RET( grp !=
NULL );
1021 ECP_VALIDATE_RET(
P !=
NULL );
1022 ECP_VALIDATE_RET( olen !=
NULL );
1023 ECP_VALIDATE_RET(
buf !=
NULL );
1045 *olen = 2 * plen + 1;
1047 if( buflen < *olen )
1058 if( buflen < *olen )
1074 const unsigned char *
buf,
size_t ilen )
1078 ECP_VALIDATE_RET( grp !=
NULL );
1079 ECP_VALIDATE_RET(
pt !=
NULL );
1080 ECP_VALIDATE_RET(
buf !=
NULL );
1085 if(
buf[0] == 0x00 )
1095 if(
buf[0] != 0x04 )
1098 if( ilen != 2 * plen + 1 )
1117 const unsigned char **
buf,
size_t buf_len )
1119 unsigned char data_len;
1120 const unsigned char *buf_start;
1121 ECP_VALIDATE_RET( grp !=
NULL );
1122 ECP_VALIDATE_RET(
pt !=
NULL );
1123 ECP_VALIDATE_RET(
buf !=
NULL );
1124 ECP_VALIDATE_RET( *
buf !=
NULL );
1132 data_len = *(*buf)++;
1133 if( data_len < 1 || data_len > buf_len - 1 )
1152 int format,
size_t *olen,
1153 unsigned char *
buf,
size_t blen )
1156 ECP_VALIDATE_RET( grp !=
NULL );
1157 ECP_VALIDATE_RET(
pt !=
NULL );
1158 ECP_VALIDATE_RET( olen !=
NULL );
1159 ECP_VALIDATE_RET(
buf !=
NULL );
1170 olen,
buf + 1, blen - 1) ) != 0 )
1176 buf[0] = (
unsigned char) *olen;
1186 const unsigned char **
buf,
size_t len )
1190 ECP_VALIDATE_RET( grp !=
NULL );
1191 ECP_VALIDATE_RET(
buf !=
NULL );
1192 ECP_VALIDATE_RET( *
buf !=
NULL );
1205 const unsigned char **
buf,
size_t len )
1209 ECP_VALIDATE_RET( grp !=
NULL );
1210 ECP_VALIDATE_RET(
buf !=
NULL );
1211 ECP_VALIDATE_RET( *
buf !=
NULL );
1230 tls_id |= *(*buf)++;
1235 *grp = curve_info->
grp_id;
1244 unsigned char *
buf,
size_t blen )
1247 ECP_VALIDATE_RET( grp !=
NULL );
1248 ECP_VALIDATE_RET(
buf !=
NULL );
1249 ECP_VALIDATE_RET( olen !=
NULL );
1322#if defined(MBEDTLS_SELF_TEST)
1323#define INC_MUL_COUNT mul_count++;
1325#define INC_MUL_COUNT
1328#define MOD_MUL( N ) \
1331 MBEDTLS_MPI_CHK( ecp_modp( &(N), grp ) ); \
1339#define MOD_SUB( N ) \
1340 while( (N).s < 0 && mbedtls_mpi_cmp_int( &(N), 0 ) != 0 ) \
1341 MBEDTLS_MPI_CHK( mbedtls_mpi_add_mpi( &(N), &(N), &grp->P ) )
1348#define MOD_ADD( N ) \
1349 while( mbedtls_mpi_cmp_mpi( &(N), &grp->P ) >= 0 ) \
1350 MBEDTLS_MPI_CHK( mbedtls_mpi_sub_abs( &(N), &(N), &grp->P ) )
1352#if defined(ECP_SHORTWEIERSTRASS)
1373#if defined(MBEDTLS_ECP_NORMALIZE_JAC_ALT)
1374 if( mbedtls_internal_ecp_grp_capable( grp ) )
1375 return( mbedtls_internal_ecp_normalize_jac( grp,
pt ) );
1424 return( ecp_normalize_jac( grp, *
T ) );
1426#if defined(MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT)
1427 if( mbedtls_internal_ecp_grp_capable( grp ) )
1428 return( mbedtls_internal_ecp_normalize_jac_many( grp,
T, T_size ) );
1434 for(
i = 0;
i < T_size;
i++ )
1443 for(
i = 1;
i < T_size;
i++ )
1454 for(
i = T_size - 1; ;
i-- )
1494 for(
i = 0;
i < T_size;
i++ )
1510 unsigned char nonzero;
1546#if defined(MBEDTLS_SELF_TEST)
1550#if defined(MBEDTLS_ECP_DOUBLE_JAC_ALT)
1551 if( mbedtls_internal_ecp_grp_capable( grp ) )
1552 return( mbedtls_internal_ecp_double_jac( grp,
R,
P ) );
1642#if defined(MBEDTLS_SELF_TEST)
1646#if defined(MBEDTLS_ECP_ADD_MIXED_ALT)
1647 if( mbedtls_internal_ecp_grp_capable( grp ) )
1648 return( mbedtls_internal_ecp_add_mixed( grp,
R,
P, Q ) );
1681 ret = ecp_double_jac( grp,
R,
P );
1724 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng )
1731#if defined(MBEDTLS_ECP_RANDOMIZE_JAC_ALT)
1732 if( mbedtls_internal_ecp_grp_capable( grp ) )
1733 return( mbedtls_internal_ecp_randomize_jac( grp,
pt, f_rng, p_rng ) );
1736 p_size = ( grp->
pbits + 7 ) / 8;
1774#if MBEDTLS_ECP_WINDOW_SIZE < 2 || MBEDTLS_ECP_WINDOW_SIZE > 7
1775#error "MBEDTLS_ECP_WINDOW_SIZE out of bounds"
1779#define COMB_MAX_D ( MBEDTLS_ECP_MAX_BITS + 1 ) / 2
1782#define COMB_MAX_PRE ( 1 << ( MBEDTLS_ECP_WINDOW_SIZE - 1 ) )
1831static void ecp_comb_recode_core(
unsigned char x[],
size_t d,
1835 unsigned char c,
cc, adjust;
1840 for(
i = 0;
i <
d;
i++ )
1841 for(
j = 0;
j <
w;
j++ )
1846 for(
i = 1;
i <=
d;
i++ )
1854 adjust = 1 - (
x[
i] & 0x01 );
1855 c |=
x[
i] & (
x[
i-1] * adjust );
1856 x[
i] =
x[
i] ^ (
x[
i-1] * adjust );
1857 x[
i-1] |= adjust << 7;
1897 unsigned char w,
size_t d,
1903 const unsigned char T_size = 1U << (
w - 1 );
1906#if defined(MBEDTLS_ECP_RESTARTABLE)
1907 if( rs_ctx !=
NULL && rs_ctx->rsm !=
NULL )
1909 if( rs_ctx->rsm->state == ecp_rsm_pre_dbl )
1911 if( rs_ctx->rsm->state == ecp_rsm_pre_norm_dbl )
1913 if( rs_ctx->rsm->state == ecp_rsm_pre_add )
1915 if( rs_ctx->rsm->state == ecp_rsm_pre_norm_add )
1922#if defined(MBEDTLS_ECP_RESTARTABLE)
1923 if( rs_ctx !=
NULL && rs_ctx->rsm !=
NULL )
1925 rs_ctx->rsm->state = ecp_rsm_pre_dbl;
1939#if defined(MBEDTLS_ECP_RESTARTABLE)
1940 if( rs_ctx !=
NULL && rs_ctx->rsm !=
NULL && rs_ctx->rsm->i != 0 )
1946 for( ;
j <
d * (
w - 1 );
j++ )
1950 i = 1U << (
j /
d );
1959#if defined(MBEDTLS_ECP_RESTARTABLE)
1960 if( rs_ctx !=
NULL && rs_ctx->rsm !=
NULL )
1961 rs_ctx->rsm->state = ecp_rsm_pre_norm_dbl;
1970 for(
i = 1;
i < T_size;
i <<= 1 )
1977#if defined(MBEDTLS_ECP_RESTARTABLE)
1978 if( rs_ctx !=
NULL && rs_ctx->rsm !=
NULL )
1979 rs_ctx->rsm->state = ecp_rsm_pre_add;
1989 for(
i = 1;
i < T_size;
i <<= 1 )
1996#if defined(MBEDTLS_ECP_RESTARTABLE)
1997 if( rs_ctx !=
NULL && rs_ctx->rsm !=
NULL )
1998 rs_ctx->rsm->state = ecp_rsm_pre_norm_add;
2007 for(
j = 0;
j + 1 < T_size;
j++ )
2015#if defined(MBEDTLS_ECP_RESTARTABLE)
2016 if( rs_ctx !=
NULL && rs_ctx->rsm !=
NULL &&
2019 if( rs_ctx->rsm->state == ecp_rsm_pre_dbl )
2037 unsigned char ii,
j;
2040 ii = (
i & 0x7Fu ) >> 1;
2043 for(
j = 0;
j < T_size;
j++ )
2064 const unsigned char x[],
size_t d,
2065 int (*f_rng)(
void *,
unsigned char *,
size_t),
2075#if !defined(MBEDTLS_ECP_RESTARTABLE)
2079#if defined(MBEDTLS_ECP_RESTARTABLE)
2080 if( rs_ctx !=
NULL && rs_ctx->rsm !=
NULL &&
2081 rs_ctx->rsm->state != ecp_rsm_comb_core )
2084 rs_ctx->rsm->state = ecp_rsm_comb_core;
2088 if( rs_ctx !=
NULL && rs_ctx->rsm !=
NULL && rs_ctx->rsm->i != 0 )
2100#if defined(MBEDTLS_ECP_NO_INTERNAL_RNG)
2120#if defined(MBEDTLS_ECP_RESTARTABLE)
2121 if( rs_ctx !=
NULL && rs_ctx->rsm !=
NULL &&
2146 unsigned char k[COMB_MAX_D + 1],
2149 unsigned char *parity_trick )
2170 ecp_comb_recode_core(
k,
d,
w, &
M );
2190 unsigned char T_size,
2193 int (*f_rng)(
void *,
unsigned char *,
size_t),
2198 unsigned char parity_trick;
2199 unsigned char k[COMB_MAX_D + 1];
2202#if defined(MBEDTLS_ECP_RESTARTABLE)
2203 if( rs_ctx !=
NULL && rs_ctx->rsm !=
NULL )
2205 RR = &rs_ctx->rsm->R;
2207 if( rs_ctx->rsm->state == ecp_rsm_final_norm )
2215 f_rng, p_rng, rs_ctx ) );
2218#if defined(MBEDTLS_ECP_RESTARTABLE)
2219 if( rs_ctx !=
NULL && rs_ctx->rsm !=
NULL )
2220 rs_ctx->rsm->state = ecp_rsm_final_norm;
2236#if defined(MBEDTLS_ECP_NO_INTERNAL_RNG)
2243#if defined(MBEDTLS_ECP_RESTARTABLE)
2244 if( rs_ctx !=
NULL && rs_ctx->rsm !=
NULL )
2256 unsigned char p_eq_g )
2265 w = grp->
nbits >= 384 ? 5 : 4;
2302 int (*f_rng)(
void *,
unsigned char *,
size_t),
2307 unsigned char w, p_eq_g,
i;
2309 unsigned char T_size = 0, T_ok = 0;
2311#if !defined(MBEDTLS_ECP_NO_INTERNAL_RNG)
2312 ecp_drbg_context drbg_ctx;
2314 ecp_drbg_init( &drbg_ctx );
2317 ECP_RS_ENTER( rsm );
2319#if !defined(MBEDTLS_ECP_NO_INTERNAL_RNG)
2323 f_rng = &ecp_drbg_random;
2324#if defined(MBEDTLS_ECP_RESTARTABLE)
2325 if( rs_ctx !=
NULL && rs_ctx->rsm !=
NULL )
2326 p_rng = &rs_ctx->rsm->drbg_ctx;
2332#if defined(MBEDTLS_ECP_RESTARTABLE)
2333 if( rs_ctx ==
NULL || rs_ctx->rsm ==
NULL ||
2334 rs_ctx->rsm->drbg_seeded == 0 )
2337 const size_t m_len = ( grp->
nbits + 7 ) / 8;
2340#if defined(MBEDTLS_ECP_RESTARTABLE)
2341 if( rs_ctx !=
NULL && rs_ctx->rsm !=
NULL )
2342 rs_ctx->rsm->drbg_seeded = 1;
2348#if MBEDTLS_ECP_FIXED_POINT_OPTIM == 1
2356 w = ecp_pick_window_size( grp, p_eq_g );
2357 T_size = 1U << (
w - 1 );
2361 if( p_eq_g && grp->
T !=
NULL )
2368#if defined(MBEDTLS_ECP_RESTARTABLE)
2370 if( rs_ctx !=
NULL && rs_ctx->rsm !=
NULL && rs_ctx->rsm->T !=
NULL )
2374 rs_ctx->rsm->T =
NULL;
2375 rs_ctx->rsm->T_size = 0;
2378 T_ok = rs_ctx->rsm->state >= ecp_rsm_comb_core;
2391 for(
i = 0;
i < T_size;
i++ )
2414 f_rng, p_rng, rs_ctx ) );
2418#if !defined(MBEDTLS_ECP_NO_INTERNAL_RNG)
2419 ecp_drbg_free( &drbg_ctx );
2427#if defined(MBEDTLS_ECP_RESTARTABLE)
2431 rs_ctx->rsm->T_size = T_size;
2440 for(
i = 0;
i < T_size;
i++ )
2446#if defined(MBEDTLS_ECP_RESTARTABLE)
2453 ECP_RS_LEAVE( rsm );
2460#if defined(ECP_MONTGOMERY)
2477#if defined(MBEDTLS_ECP_NORMALIZE_MXZ_ALT)
2478 if( mbedtls_internal_ecp_grp_capable( grp ) )
2479 return( mbedtls_internal_ecp_normalize_mxz( grp,
P ) );
2499 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng )
2506#if defined(MBEDTLS_ECP_RANDOMIZE_MXZ_ALT)
2507 if( mbedtls_internal_ecp_grp_capable( grp ) )
2508 return( mbedtls_internal_ecp_randomize_mxz( grp,
P, f_rng, p_rng ) );
2511 p_size = ( grp->
pbits + 7 ) / 8;
2561#if defined(MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT)
2562 if( mbedtls_internal_ecp_grp_capable( grp ) )
2563 return( mbedtls_internal_ecp_double_add_mxz( grp,
R,
S,
P, Q,
d ) );
2603 int (*f_rng)(
void *,
unsigned char *,
size_t),
2611#if !defined(MBEDTLS_ECP_NO_INTERNAL_RNG)
2612 ecp_drbg_context drbg_ctx;
2614 ecp_drbg_init( &drbg_ctx );
2618#if !defined(MBEDTLS_ECP_NO_INTERNAL_RNG)
2621 const size_t m_len = ( grp->
nbits + 7 ) / 8;
2623 f_rng = &ecp_drbg_random;
2641#if defined(MBEDTLS_ECP_NO_INTERNAL_RNG)
2676#if defined(MBEDTLS_ECP_NO_INTERNAL_RNG)
2684#if !defined(MBEDTLS_ECP_NO_INTERNAL_RNG)
2685 ecp_drbg_free( &drbg_ctx );
2700 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng,
2704#if defined(MBEDTLS_ECP_INTERNAL_ALT)
2705 char is_grp_capable = 0;
2707 ECP_VALIDATE_RET( grp !=
NULL );
2708 ECP_VALIDATE_RET(
R !=
NULL );
2709 ECP_VALIDATE_RET(
m !=
NULL );
2710 ECP_VALIDATE_RET(
P !=
NULL );
2712#if defined(MBEDTLS_ECP_RESTARTABLE)
2714 if( rs_ctx !=
NULL && rs_ctx->depth++ == 0 )
2715 rs_ctx->ops_done = 0;
2718#if defined(MBEDTLS_ECP_INTERNAL_ALT)
2719 if( ( is_grp_capable = mbedtls_internal_ecp_grp_capable( grp ) ) )
2723#if defined(MBEDTLS_ECP_RESTARTABLE)
2725 if( rs_ctx ==
NULL || rs_ctx->rsm ==
NULL )
2737#if defined(ECP_MONTGOMERY)
2738 if( ecp_get_type( grp ) == ECP_TYPE_MONTGOMERY )
2741#if defined(ECP_SHORTWEIERSTRASS)
2742 if( ecp_get_type( grp ) == ECP_TYPE_SHORT_WEIERSTRASS )
2748#if defined(MBEDTLS_ECP_INTERNAL_ALT)
2749 if( is_grp_capable )
2750 mbedtls_internal_ecp_free( grp );
2753#if defined(MBEDTLS_ECP_RESTARTABLE)
2754 if( rs_ctx !=
NULL )
2766 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng )
2768 ECP_VALIDATE_RET( grp !=
NULL );
2769 ECP_VALIDATE_RET(
R !=
NULL );
2770 ECP_VALIDATE_RET(
m !=
NULL );
2771 ECP_VALIDATE_RET(
P !=
NULL );
2775#if defined(ECP_SHORTWEIERSTRASS)
2871#if defined(MBEDTLS_ECP_INTERNAL_ALT)
2872 char is_grp_capable = 0;
2874 ECP_VALIDATE_RET( grp !=
NULL );
2875 ECP_VALIDATE_RET(
R !=
NULL );
2876 ECP_VALIDATE_RET(
m !=
NULL );
2877 ECP_VALIDATE_RET(
P !=
NULL );
2878 ECP_VALIDATE_RET(
n !=
NULL );
2879 ECP_VALIDATE_RET( Q !=
NULL );
2881 if( ecp_get_type( grp ) != ECP_TYPE_SHORT_WEIERSTRASS )
2888#if defined(MBEDTLS_ECP_RESTARTABLE)
2889 if( rs_ctx !=
NULL && rs_ctx->ma !=
NULL )
2892 pmP = &rs_ctx->ma->mP;
2893 pR = &rs_ctx->ma->R;
2896 if( rs_ctx->ma->state == ecp_rsma_mul2 )
2898 if( rs_ctx->ma->state == ecp_rsma_add )
2900 if( rs_ctx->ma->state == ecp_rsma_norm )
2906#if defined(MBEDTLS_ECP_RESTARTABLE)
2907 if( rs_ctx !=
NULL && rs_ctx->ma !=
NULL )
2908 rs_ctx->ma->state = ecp_rsma_mul2;
2914#if defined(MBEDTLS_ECP_INTERNAL_ALT)
2915 if( ( is_grp_capable = mbedtls_internal_ecp_grp_capable( grp ) ) )
2919#if defined(MBEDTLS_ECP_RESTARTABLE)
2920 if( rs_ctx !=
NULL && rs_ctx->ma !=
NULL )
2921 rs_ctx->ma->state = ecp_rsma_add;
2927#if defined(MBEDTLS_ECP_RESTARTABLE)
2928 if( rs_ctx !=
NULL && rs_ctx->ma !=
NULL )
2929 rs_ctx->ma->state = ecp_rsma_norm;
2936#if defined(MBEDTLS_ECP_RESTARTABLE)
2937 if( rs_ctx !=
NULL && rs_ctx->ma !=
NULL )
2942#if defined(MBEDTLS_ECP_INTERNAL_ALT)
2943 if( is_grp_capable )
2944 mbedtls_internal_ecp_free( grp );
2962 ECP_VALIDATE_RET( grp !=
NULL );
2963 ECP_VALIDATE_RET(
R !=
NULL );
2964 ECP_VALIDATE_RET(
m !=
NULL );
2965 ECP_VALIDATE_RET(
P !=
NULL );
2966 ECP_VALIDATE_RET(
n !=
NULL );
2967 ECP_VALIDATE_RET( Q !=
NULL );
2971#if defined(ECP_MONTGOMERY)
2972#if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED)
2973#define ECP_MPI_INIT(s, n, p) {s, (n), (mbedtls_mpi_uint *)(p)}
2974#define ECP_MPI_INIT_ARRAY(x) \
2975 ECP_MPI_INIT(1, sizeof(x) / sizeof(mbedtls_mpi_uint), x)
2993static const mbedtls_mpi ecp_x25519_bad_point_1 = ECP_MPI_INIT_ARRAY(
2994 x25519_bad_point_1 );
2995static const mbedtls_mpi ecp_x25519_bad_point_2 = ECP_MPI_INIT_ARRAY(
2996 x25519_bad_point_2 );
3028#if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED)
3080 return( ecp_check_bad_points_mx( &
pt->X, &grp->
P, grp->
id ) );
3090 ECP_VALIDATE_RET( grp !=
NULL );
3091 ECP_VALIDATE_RET(
pt !=
NULL );
3097#if defined(ECP_MONTGOMERY)
3098 if( ecp_get_type( grp ) == ECP_TYPE_MONTGOMERY )
3099 return( ecp_check_pubkey_mx( grp,
pt ) );
3101#if defined(ECP_SHORTWEIERSTRASS)
3102 if( ecp_get_type( grp ) == ECP_TYPE_SHORT_WEIERSTRASS )
3103 return( ecp_check_pubkey_sw( grp,
pt ) );
3114 ECP_VALIDATE_RET( grp !=
NULL );
3115 ECP_VALIDATE_RET(
d !=
NULL );
3117#if defined(ECP_MONTGOMERY)
3118 if( ecp_get_type( grp ) == ECP_TYPE_MONTGOMERY )
3133#if defined(ECP_SHORTWEIERSTRASS)
3134 if( ecp_get_type( grp ) == ECP_TYPE_SHORT_WEIERSTRASS )
3153 int (*f_rng)(
void *,
unsigned char *,
size_t),
3158#if defined(ECP_SHORTWEIERSTRASS)
3164 ECP_VALIDATE_RET( grp !=
NULL );
3165 ECP_VALIDATE_RET(
d !=
NULL );
3166 ECP_VALIDATE_RET( f_rng !=
NULL );
3168 n_size = ( grp->
nbits + 7 ) / 8;
3170#if defined(ECP_MONTGOMERY)
3171 if( ecp_get_type( grp ) == ECP_TYPE_MONTGOMERY )
3191 if( grp->
nbits == 254 )
3198#if defined(ECP_SHORTWEIERSTRASS)
3199 if( ecp_get_type( grp ) == ECP_TYPE_SHORT_WEIERSTRASS )
3203 unsigned lt_lower = 1, lt_upper = 0;
3238 while( lt_lower != 0 || lt_upper == 0 );
3243#if defined(ECP_SHORTWEIERSTRASS)
3255 int (*f_rng)(
void *,
unsigned char *,
size_t),
3259 ECP_VALIDATE_RET( grp !=
NULL );
3260 ECP_VALIDATE_RET(
d !=
NULL );
3261 ECP_VALIDATE_RET(
G !=
NULL );
3262 ECP_VALIDATE_RET( Q !=
NULL );
3263 ECP_VALIDATE_RET( f_rng !=
NULL );
3277 int (*f_rng)(
void *,
unsigned char *,
size_t),
3280 ECP_VALIDATE_RET( grp !=
NULL );
3281 ECP_VALIDATE_RET(
d !=
NULL );
3282 ECP_VALIDATE_RET( Q !=
NULL );
3283 ECP_VALIDATE_RET( f_rng !=
NULL );
3292 int (*f_rng)(
void *,
unsigned char *,
size_t),
void *p_rng )
3295 ECP_VALIDATE_RET(
key !=
NULL );
3296 ECP_VALIDATE_RET( f_rng !=
NULL );
3312 ECP_VALIDATE_RET( pub !=
NULL );
3313 ECP_VALIDATE_RET( prv !=
NULL );
3348#if defined(MBEDTLS_SELF_TEST)
3350#if defined(ECP_ONE_STEP_KDF)
3360#if defined(MBEDTLS_SHA512_C)
3362static const uint8_t test_kdf_z[16] = {
3363 0x3b, 0xa9, 0x79, 0xe9, 0xbc, 0x5e, 0x3e, 0xc7,
3364 0x61, 0x30, 0x36, 0xb6, 0xf5, 0x1c, 0xd5, 0xaa,
3366static const uint8_t test_kdf_out[40] = {
3367 0x3e, 0xf6, 0xda, 0xf9, 0x51, 0x60, 0x70, 0x5f,
3368 0xdf, 0x21, 0xcd, 0xab, 0xac, 0x25, 0x7b, 0x05,
3369 0xfe, 0xc1, 0xab, 0x7c, 0xc9, 0x68, 0x43, 0x25,
3370 0x8a, 0xfc, 0x40, 0x6e, 0x5b, 0xf7, 0x98, 0x27,
3371 0x10, 0xfa, 0x7b, 0x93, 0x52, 0xd4, 0x16, 0xaa,
3374#elif defined(MBEDTLS_SHA256_C)
3376static const uint8_t test_kdf_z[16] = {
3377 0xc8, 0x3e, 0x35, 0x8e, 0x99, 0xa6, 0x89, 0xc6,
3378 0x7d, 0xb4, 0xfe, 0x39, 0xcf, 0x8f, 0x26, 0xe1,
3380static const uint8_t test_kdf_out[40] = {
3381 0x7d, 0xf6, 0x41, 0xf8, 0x3c, 0x47, 0xdc, 0x28,
3382 0x5f, 0x7f, 0xaa, 0xde, 0x05, 0x64, 0xd6, 0x25,
3383 0x00, 0x6a, 0x47, 0xd9, 0x1e, 0xa4, 0xa0, 0x8c,
3384 0xd7, 0xf7, 0x0c, 0x99, 0xaa, 0xa0, 0x72, 0x66,
3385 0x69, 0x0e, 0x25, 0xaa, 0xa1, 0x63, 0x14, 0x79,
3390static int ecp_kdf_self_test(
void )
3393 ecp_drbg_context kdf_ctx;
3397 ecp_drbg_init( &kdf_ctx );
3402 test_kdf_z,
sizeof( test_kdf_z ) ) );
3405 &scalar,
sizeof( test_kdf_z ) ) );
3413 ecp_drbg_free( &kdf_ctx );
3423int mbedtls_ecp_self_test(
int verbose )
3430 unsigned long add_c_prev, dbl_c_prev, mul_c_prev;
3432 const char *exponents[] =
3434 "000000000000000000000000000000000000000000000001",
3435 "FFFFFFFFFFFFFFFFFFFFFFFF99DEF836146BC9B1B4D22830",
3436 "5EA6F389A38B8BC81E767753B15AA5569E1782E30ABE7D25",
3437 "400000000000000000000000000000000000000000000000",
3438 "7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
3439 "555555555555555555555555555555555555555555555555",
3448#if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED)
3455 mbedtls_printf(
" ECP test #1 (constant op_count, base point G): " );
3467 for(
i = 1;
i <
sizeof( exponents ) /
sizeof( exponents[0] );
i++ )
3469 add_c_prev = add_count;
3470 dbl_c_prev = dbl_count;
3471 mul_c_prev = mul_count;
3479 if( add_count != add_c_prev ||
3480 dbl_count != dbl_c_prev ||
3481 mul_count != mul_c_prev )
3495 mbedtls_printf(
" ECP test #2 (constant op_count, other point): " );
3504 for(
i = 1;
i <
sizeof( exponents ) /
sizeof( exponents[0] );
i++ )
3506 add_c_prev = add_count;
3507 dbl_c_prev = dbl_count;
3508 mul_c_prev = mul_count;
3516 if( add_count != add_c_prev ||
3517 dbl_count != dbl_c_prev ||
3518 mul_count != mul_c_prev )
3531#if defined(ECP_ONE_STEP_KDF)
3535 ret = ecp_kdf_self_test();
_Tp _STLP_CALL norm(const complex< _Tp > &__z)
int strcmp(const char *String1, const char *String2)
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
unsigned short int uint16_t
int mbedtls_mpi_read_string(mbedtls_mpi *X, int radix, const char *s)
Import an MPI from an ASCII string.
int mbedtls_mpi_sub_mpi(mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B)
Perform a signed subtraction of MPIs: X = A - B.
int mbedtls_mpi_sub_int(mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint b)
Perform a signed subtraction of an MPI and an integer: X = A - b.
int mbedtls_mpi_add_int(mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint b)
Perform a signed addition of an MPI and an integer: X = A + b.
int mbedtls_mpi_grow(mbedtls_mpi *X, size_t nblimbs)
Enlarge an MPI to the specified number of limbs.
int mbedtls_mpi_copy(mbedtls_mpi *X, const mbedtls_mpi *Y)
Make a copy of an MPI.
int mbedtls_mpi_set_bit(mbedtls_mpi *X, size_t pos, unsigned char val)
Modify a specific bit in an MPI.
size_t mbedtls_mpi_size(const mbedtls_mpi *X)
Return the total size of an MPI value in bytes.
int mbedtls_mpi_add_mpi(mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B)
Perform a signed addition of MPIs: X = A + B.
int mbedtls_mpi_safe_cond_assign(mbedtls_mpi *X, const mbedtls_mpi *Y, unsigned char assign)
Perform a safe conditional copy of MPI which doesn't reveal whether the condition was true or not.
int mbedtls_mpi_lset(mbedtls_mpi *X, mbedtls_mpi_sint z)
Store integer value in MPI.
size_t mbedtls_mpi_bitlen(const mbedtls_mpi *X)
Return the number of bits up to and including the most significant bit of value 1.
int mbedtls_mpi_read_binary(mbedtls_mpi *X, const unsigned char *buf, size_t buflen)
Import an MPI from unsigned big endian binary data.
int mbedtls_mpi_cmp_mpi(const mbedtls_mpi *X, const mbedtls_mpi *Y)
Compare two MPIs.
int mbedtls_mpi_mod_mpi(mbedtls_mpi *R, const mbedtls_mpi *A, const mbedtls_mpi *B)
Perform a modular reduction. R = A mod B.
int mbedtls_mpi_fill_random(mbedtls_mpi *X, size_t size, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Fill an MPI with a number of random bytes.
int mbedtls_mpi_shift_l(mbedtls_mpi *X, size_t count)
Perform a left-shift on an MPI: X <<= count.
int mbedtls_mpi_safe_cond_swap(mbedtls_mpi *X, mbedtls_mpi *Y, unsigned char assign)
Perform a safe conditional swap which doesn't reveal whether the condition was true or not.
void mbedtls_mpi_init(mbedtls_mpi *X)
Initialize an MPI context.
int mbedtls_mpi_mul_mpi(mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B)
Perform a multiplication of two MPIs: X = A * B.
#define MBEDTLS_MPI_CHK(f)
int mbedtls_mpi_shrink(mbedtls_mpi *X, size_t nblimbs)
This function resizes an MPI downwards, keeping at least the specified number of limbs.
int mbedtls_mpi_inv_mod(mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *N)
Compute the modular inverse: X = A^-1 mod N.
int mbedtls_mpi_get_bit(const mbedtls_mpi *X, size_t pos)
Get a specific bit from an MPI.
void mbedtls_mpi_free(mbedtls_mpi *X)
This function frees the components of an MPI context.
int mbedtls_mpi_mul_int(mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_uint b)
Perform a multiplication of an MPI with an unsigned integer: X = A * b.
int mbedtls_mpi_lt_mpi_ct(const mbedtls_mpi *X, const mbedtls_mpi *Y, unsigned *ret)
Check if an MPI is less than the other in constant time.
int mbedtls_mpi_write_binary(const mbedtls_mpi *X, unsigned char *buf, size_t buflen)
Export an MPI into unsigned big endian binary data of fixed size.
int mbedtls_mpi_cmp_int(const mbedtls_mpi *X, mbedtls_mpi_sint z)
Compare an MPI with an integer.
int mbedtls_mpi_sub_abs(mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B)
Perform an unsigned subtraction of MPIs: X = |A| - |B|.
uint32_t mbedtls_mpi_uint
int mbedtls_mpi_shift_r(mbedtls_mpi *X, size_t count)
Perform a right-shift on an MPI: X >>= count.
#define G(r, i, a, b, c, d)
Multi-precision integer library.
#define MBEDTLS_BYTES_TO_T_UINT_8(a, b, c, d, e, f, g, h)
This file contains definitions and functions for the CTR_DRBG pseudorandom generator.
static void cleanup(void)
Function declarations for alternative implementation of elliptic curve point arithmetic.
GLint GLint GLint GLint GLint x
GLint GLint GLint GLint GLint GLint y
GLuint GLuint GLsizei count
GLboolean GLboolean GLboolean b
GLenum GLuint GLenum GLsizei const GLchar * buf
GLubyte GLubyte GLubyte GLubyte w
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
The HMAC_DRBG pseudorandom generator.
void mbedtls_hmac_drbg_init(mbedtls_hmac_drbg_context *ctx)
HMAC_DRBG context initialization.
void mbedtls_hmac_drbg_free(mbedtls_hmac_drbg_context *ctx)
This function resets HMAC_DRBG context to the state immediately after initial call of mbedtls_hmac_dr...
int mbedtls_hmac_drbg_seed_buf(mbedtls_hmac_drbg_context *ctx, const mbedtls_md_info_t *md_info, const unsigned char *data, size_t data_len)
Initilisation of simpified HMAC_DRBG (never reseeds).
int mbedtls_hmac_drbg_random(void *p_rng, unsigned char *output, size_t out_len)
This function uses HMAC_DRBG to generate random data.
#define AA(_h, _w, _x, _y, _z)
const int * mbedtls_md_list(void)
This function returns the list of digests supported by the generic digest module.
mbedtls_md_type_t
Supported message digests.
#define memcpy(s1, s2, n)
static DATA_BLOB CRYPTPROTECT_PROMPTSTRUCT DATA_BLOB *static LPWSTR DATA_BLOB CRYPTPROTECT_PROMPTSTRUCT DATA_BLOB *static char secret[]
#define mbedtls_md_info_from_type
#define mbedtls_ctr_drbg_seed
#define mbedtls_ctr_drbg_random
#define mbedtls_ctr_drbg_init
#define mbedtls_ctr_drbg_free
Configuration options (set of defines)
This file provides an API for Elliptic Curves over GF(P) (ECP).
#define MBEDTLS_ERR_ECP_ALLOC_FAILED
void mbedtls_ecp_keypair_free(mbedtls_ecp_keypair *key)
This function frees the components of a key pair.
#define MBEDTLS_ECP_PF_UNCOMPRESSED
int mbedtls_ecp_point_read_binary(const mbedtls_ecp_group *grp, mbedtls_ecp_point *P, const unsigned char *buf, size_t ilen)
This function imports a point from unsigned binary data.
int mbedtls_ecp_muladd(mbedtls_ecp_group *grp, mbedtls_ecp_point *R, const mbedtls_mpi *m, const mbedtls_ecp_point *P, const mbedtls_mpi *n, const mbedtls_ecp_point *Q)
This function performs multiplication and addition of two points by integers: R = m * P + n * Q.
int mbedtls_ecp_gen_key(mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
This function generates an ECP key.
#define MBEDTLS_ECP_WINDOW_SIZE
#define MBEDTLS_ECP_BUDGET(ops)
int mbedtls_ecp_is_zero(mbedtls_ecp_point *pt)
This function checks if a point is the point at infinity.
#define MBEDTLS_ERR_ECP_INVALID_KEY
int mbedtls_ecp_tls_write_group(const mbedtls_ecp_group *grp, size_t *olen, unsigned char *buf, size_t blen)
This function exports an elliptic curve as a TLS ECParameters record as defined in RFC 4492,...
int mbedtls_ecp_group_copy(mbedtls_ecp_group *dst, const mbedtls_ecp_group *src)
This function copies the contents of group src into group dst.
#define MBEDTLS_ECP_PF_COMPRESSED
#define MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL
#define MBEDTLS_ERR_ECP_RANDOM_FAILED
int mbedtls_ecp_mul(mbedtls_ecp_group *grp, mbedtls_ecp_point *R, const mbedtls_mpi *m, const mbedtls_ecp_point *P, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
This function performs a scalar multiplication of a point by an integer: R = m * P.
const mbedtls_ecp_group_id * mbedtls_ecp_grp_id_list(void)
This function retrieves the list of internal group identifiers of all supported curves in the order o...
void mbedtls_ecp_group_init(mbedtls_ecp_group *grp)
This function initializes an ECP group context without loading any domain parameters.
int mbedtls_ecp_gen_keypair_base(mbedtls_ecp_group *grp, const mbedtls_ecp_point *G, mbedtls_mpi *d, mbedtls_ecp_point *Q, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
This function generates a keypair with a configurable base point.
int mbedtls_ecp_check_pub_priv(const mbedtls_ecp_keypair *pub, const mbedtls_ecp_keypair *prv)
This function checks that the keypair objects pub and prv have the same group and the same public poi...
#define MBEDTLS_ECP_TLS_NAMED_CURVE
int mbedtls_ecp_mul_restartable(mbedtls_ecp_group *grp, mbedtls_ecp_point *R, const mbedtls_mpi *m, const mbedtls_ecp_point *P, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, mbedtls_ecp_restart_ctx *rs_ctx)
This function performs multiplication of a point by an integer: R = m * P in a restartable way.
int mbedtls_ecp_point_cmp(const mbedtls_ecp_point *P, const mbedtls_ecp_point *Q)
This function compares two points.
int mbedtls_ecp_check_privkey(const mbedtls_ecp_group *grp, const mbedtls_mpi *d)
This function checks that an mbedtls_mpi is a valid private key for this curve.
int mbedtls_ecp_point_read_string(mbedtls_ecp_point *P, int radix, const char *x, const char *y)
This function imports a non-zero point from two ASCII strings.
int mbedtls_ecp_group_load(mbedtls_ecp_group *grp, mbedtls_ecp_group_id id)
This function sets up an ECP group context from a standardized set of domain parameters.
#define MBEDTLS_ERR_ECP_IN_PROGRESS
void mbedtls_ecp_keypair_init(mbedtls_ecp_keypair *key)
This function initializes a key pair as an invalid one.
int mbedtls_ecp_tls_read_group_id(mbedtls_ecp_group_id *grp, const unsigned char **buf, size_t len)
This function extracts an elliptic curve group ID from a TLS ECParameters record as defined in RFC 44...
const mbedtls_ecp_curve_info * mbedtls_ecp_curve_info_from_name(const char *name)
This function retrieves curve information from a human-readable name.
void mbedtls_ecp_point_free(mbedtls_ecp_point *pt)
This function frees the components of a point.
int mbedtls_ecp_tls_read_point(const mbedtls_ecp_group *grp, mbedtls_ecp_point *pt, const unsigned char **buf, size_t len)
This function imports a point from a TLS ECPoint record.
void mbedtls_ecp_group_free(mbedtls_ecp_group *grp)
This function frees the components of an ECP group.
int mbedtls_ecp_copy(mbedtls_ecp_point *P, const mbedtls_ecp_point *Q)
This function copies the contents of point Q into point P.
int mbedtls_ecp_muladd_restartable(mbedtls_ecp_group *grp, mbedtls_ecp_point *R, const mbedtls_mpi *m, const mbedtls_ecp_point *P, const mbedtls_mpi *n, const mbedtls_ecp_point *Q, mbedtls_ecp_restart_ctx *rs_ctx)
This function performs multiplication and addition of two points by integers: R = m * P + n * Q in a ...
int mbedtls_ecp_gen_privkey(const mbedtls_ecp_group *grp, mbedtls_mpi *d, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
This function generates a private key.
#define MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE
int mbedtls_ecp_gen_keypair(mbedtls_ecp_group *grp, mbedtls_mpi *d, mbedtls_ecp_point *Q, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
This function generates an ECP keypair.
int mbedtls_ecp_tls_write_point(const mbedtls_ecp_group *grp, const mbedtls_ecp_point *pt, int format, size_t *olen, unsigned char *buf, size_t blen)
This function exports a point as a TLS ECPoint record defined in RFC 4492, Section 5....
const mbedtls_ecp_curve_info * mbedtls_ecp_curve_info_from_grp_id(mbedtls_ecp_group_id grp_id)
This function retrieves curve information from an internal group identifier.
#define MBEDTLS_ECP_MAX_BYTES
#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA
int mbedtls_ecp_set_zero(mbedtls_ecp_point *pt)
This function sets a point to the point at infinity.
int mbedtls_ecp_tls_read_group(mbedtls_ecp_group *grp, const unsigned char **buf, size_t len)
This function sets up an ECP group context from a TLS ECParameters record as defined in RFC 4492,...
const mbedtls_ecp_curve_info * mbedtls_ecp_curve_list(void)
This function retrieves the information defined in mbedtls_ecp_curve_info() for all supported curves ...
void mbedtls_ecp_point_init(mbedtls_ecp_point *pt)
This function initializes a point as zero.
int mbedtls_ecp_check_pubkey(const mbedtls_ecp_group *grp, const mbedtls_ecp_point *pt)
This function checks that a point is a valid public key on this curve.
@ MBEDTLS_ECP_DP_SECP192K1
@ MBEDTLS_ECP_DP_SECP384R1
@ MBEDTLS_ECP_DP_CURVE25519
@ MBEDTLS_ECP_DP_SECP256K1
@ MBEDTLS_ECP_DP_SECP224R1
@ MBEDTLS_ECP_DP_SECP521R1
@ MBEDTLS_ECP_DP_SECP224K1
@ MBEDTLS_ECP_DP_SECP192R1
@ MBEDTLS_ECP_DP_SECP256R1
int mbedtls_ecp_point_write_binary(const mbedtls_ecp_group *grp, const mbedtls_ecp_point *P, int format, size_t *olen, unsigned char *buf, size_t buflen)
This function exports a point into unsigned binary data.
const mbedtls_ecp_curve_info * mbedtls_ecp_curve_info_from_tls_id(uint16_t tls_id)
This function retrieves curve information from a TLS NamedCurve value.
This file contains SHA-224 and SHA-256 definitions and functions.
This file contains SHA-384 and SHA-512 definitions and functions.
The CTR_DRBG context structure.
mbedtls_ecp_group_id grp_id
int(* t_pre)(mbedtls_ecp_point *, void *)
int(* t_post)(mbedtls_ecp_point *, void *)
int(* modp)(mbedtls_mpi *)
The ECP key-pair structure.
The ECP point structure, in Jacobian coordinates.
Threading abstraction layer.