33 #if !defined(POLARSSL_CONFIG_FILE) 36 #include POLARSSL_CONFIG_FILE 39 #if defined(POLARSSL_ECDH_C) 47 int (*f_rng)(
void *,
unsigned char *,
size_t),
58 int (*f_rng)(
void *,
unsigned char *,
size_t),
121 unsigned char *buf,
size_t blen,
122 int (*f_rng)(
void *,
unsigned char *,
size_t),
126 size_t grp_len, pt_len;
128 if( ctx == NULL || ctx->
grp.
pbits == 0 )
143 &pt_len, buf, blen ) ) != 0 )
146 *olen = grp_len + pt_len;
158 const unsigned char **buf,
const unsigned char *end )
191 if( ( ret =
ecp_copy( &ctx->
Q, &key->
Q ) ) != 0 ||
202 unsigned char *buf,
size_t blen,
203 int (*f_rng)(
void *,
unsigned char *,
size_t),
208 if( ctx == NULL || ctx->
grp.
pbits == 0 )
223 const unsigned char *buf,
size_t blen )
226 const unsigned char *p = buf;
234 if( (
size_t)( p - buf ) != blen )
244 unsigned char *buf,
size_t blen,
245 int (*f_rng)(
void *,
unsigned char *,
size_t),
254 f_rng, p_rng ) ) != 0 )
267 #if defined(POLARSSL_SELF_TEST) int ecdh_make_params(ecdh_context *ctx, size_t *olen, unsigned char *buf, size_t blen, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Generate a public key and a TLS ServerKeyExchange payload.
int ecdh_make_public(ecdh_context *ctx, size_t *olen, unsigned char *buf, size_t blen, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Generate a public key and a TLS ClientKeyExchange payload.
#define POLARSSL_ERR_ECP_BAD_INPUT_DATA
Bad input parameters to function.
int ecp_group_copy(ecp_group *dst, const ecp_group *src)
Copy the contents of a group object.
int ecdh_calc_secret(ecdh_context *ctx, size_t *olen, unsigned char *buf, size_t blen, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Derive and export the shared secret.
int ecdh_read_public(ecdh_context *ctx, const unsigned char *buf, size_t blen)
Parse and process a TLS ClientKeyExchange payload.
int ecdh_compute_shared(ecp_group *grp, mpi *z, const ecp_point *Q, const mpi *d, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Compute shared secret Raw function that only does the core computation.
int ecdh_gen_public(ecp_group *grp, mpi *d, ecp_point *Q, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Generate a public key.
Configuration options (set of defines)
int ecdh_get_params(ecdh_context *ctx, const ecp_keypair *key, ecdh_side side)
Setup an ECDH context from an EC key.
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) ...
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)
void mpi_free(mpi *X)
Unallocate one MPI.
void ecp_group_free(ecp_group *grp)
Free the components of an ECP group.
ecdh_side
When importing from an EC key, select if it is our key or the peer's key.
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 ecdh_read_params(ecdh_context *ctx, const unsigned char **buf, const unsigned char *end)
Parse and procress a TLS ServerKeyExhange payload.
Elliptic curve Diffie-Hellman.
int ecp_copy(ecp_point *P, const ecp_point *Q)
Copy the contents of point Q into P.
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.
size_t mpi_size(const mpi *X)
Return the total size in bytes.
int mpi_copy(mpi *X, const mpi *Y)
Copy the contents of Y into X.
int mpi_write_binary(const mpi *X, unsigned char *buf, size_t buflen)
Export X into unsigned binary data, big endian.
int ecp_tls_read_group(ecp_group *grp, const unsigned char **buf, size_t len)
Set a group from a TLS ECParameters record.
void ecdh_init(ecdh_context *ctx)
Initialize context.
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 ecdh_self_test(int verbose)
Checkup routine.
void ecdh_free(ecdh_context *ctx)
Free context.
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.
void ecp_point_free(ecp_point *pt)
Free the components of a point.