#include "common.h"
#if defined(MBEDTLS_ECJPAKE_C)
#include "mbedtls/ecjpake.h"
#include "mbedtls/platform_util.h"
#include "mbedtls/error.h"
#include <string.h>
#if !defined(MBEDTLS_ECJPAKE_ALT)
static const char * const ecjpake_id[] = …;
#define ID_MINE …
#define ID_PEER …
static int mbedtls_ecjpake_compute_hash(mbedtls_md_type_t md_type,
const unsigned char *input, size_t ilen,
unsigned char *output)
{ … }
void mbedtls_ecjpake_init(mbedtls_ecjpake_context *ctx)
{ … }
void mbedtls_ecjpake_free(mbedtls_ecjpake_context *ctx)
{ … }
int mbedtls_ecjpake_setup(mbedtls_ecjpake_context *ctx,
mbedtls_ecjpake_role role,
mbedtls_md_type_t hash,
mbedtls_ecp_group_id curve,
const unsigned char *secret,
size_t len)
{ … }
int mbedtls_ecjpake_set_point_format(mbedtls_ecjpake_context *ctx,
int point_format)
{ … }
int mbedtls_ecjpake_check(const mbedtls_ecjpake_context *ctx)
{ … }
static int ecjpake_write_len_point(unsigned char **p,
const unsigned char *end,
const mbedtls_ecp_group *grp,
const int pf,
const mbedtls_ecp_point *P)
{ … }
#define ECJPAKE_HASH_BUF_LEN …
static int ecjpake_hash(const mbedtls_md_type_t md_type,
const mbedtls_ecp_group *grp,
const int pf,
const mbedtls_ecp_point *G,
const mbedtls_ecp_point *V,
const mbedtls_ecp_point *X,
const char *id,
mbedtls_mpi *h)
{ … }
static int ecjpake_zkp_read(const mbedtls_md_type_t md_type,
const mbedtls_ecp_group *grp,
const int pf,
const mbedtls_ecp_point *G,
const mbedtls_ecp_point *X,
const char *id,
const unsigned char **p,
const unsigned char *end)
{ … }
static int ecjpake_zkp_write(const mbedtls_md_type_t md_type,
const mbedtls_ecp_group *grp,
const int pf,
const mbedtls_ecp_point *G,
const mbedtls_mpi *x,
const mbedtls_ecp_point *X,
const char *id,
unsigned char **p,
const unsigned char *end,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng)
{ … }
static int ecjpake_kkp_read(const mbedtls_md_type_t md_type,
const mbedtls_ecp_group *grp,
const int pf,
const mbedtls_ecp_point *G,
mbedtls_ecp_point *X,
const char *id,
const unsigned char **p,
const unsigned char *end)
{ … }
static int ecjpake_kkp_write(const mbedtls_md_type_t md_type,
const mbedtls_ecp_group *grp,
const int pf,
const mbedtls_ecp_point *G,
mbedtls_mpi *x,
mbedtls_ecp_point *X,
const char *id,
unsigned char **p,
const unsigned char *end,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng)
{ … }
static int ecjpake_kkpp_read(const mbedtls_md_type_t md_type,
const mbedtls_ecp_group *grp,
const int pf,
const mbedtls_ecp_point *G,
mbedtls_ecp_point *Xa,
mbedtls_ecp_point *Xb,
const char *id,
const unsigned char *buf,
size_t len)
{ … }
static int ecjpake_kkpp_write(const mbedtls_md_type_t md_type,
const mbedtls_ecp_group *grp,
const int pf,
const mbedtls_ecp_point *G,
mbedtls_mpi *xm1,
mbedtls_ecp_point *Xa,
mbedtls_mpi *xm2,
mbedtls_ecp_point *Xb,
const char *id,
unsigned char *buf,
size_t len,
size_t *olen,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng)
{ … }
int mbedtls_ecjpake_read_round_one(mbedtls_ecjpake_context *ctx,
const unsigned char *buf,
size_t len)
{ … }
int mbedtls_ecjpake_write_round_one(mbedtls_ecjpake_context *ctx,
unsigned char *buf, size_t len, size_t *olen,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng)
{ … }
static int ecjpake_ecp_add3(mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
const mbedtls_ecp_point *A,
const mbedtls_ecp_point *B,
const mbedtls_ecp_point *C)
{ … }
int mbedtls_ecjpake_read_round_two(mbedtls_ecjpake_context *ctx,
const unsigned char *buf,
size_t len)
{ … }
static int ecjpake_mul_secret(mbedtls_mpi *R, int sign,
const mbedtls_mpi *X,
const mbedtls_mpi *S,
const mbedtls_mpi *N,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng)
{ … }
int mbedtls_ecjpake_write_round_two(mbedtls_ecjpake_context *ctx,
unsigned char *buf, size_t len, size_t *olen,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng)
{ … }
static int mbedtls_ecjpake_derive_k(mbedtls_ecjpake_context *ctx,
mbedtls_ecp_point *K,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng)
{ … }
int mbedtls_ecjpake_derive_secret(mbedtls_ecjpake_context *ctx,
unsigned char *buf, size_t len, size_t *olen,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng)
{ … }
int mbedtls_ecjpake_write_shared_key(mbedtls_ecjpake_context *ctx,
unsigned char *buf, size_t len, size_t *olen,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng)
{ … }
#undef ID_MINE
#undef ID_PEER
#endif
#if defined(MBEDTLS_SELF_TEST)
#include "mbedtls/platform.h"
#if !defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) || \
!defined(MBEDTLS_MD_CAN_SHA256)
int mbedtls_ecjpake_self_test(int verbose)
{
(void) verbose;
return 0;
}
#else
static const unsigned char ecjpake_test_password[] = …;
#if !defined(MBEDTLS_ECJPAKE_ALT)
static const unsigned char ecjpake_test_x1[] = …;
static const unsigned char ecjpake_test_x2[] = …;
static const unsigned char ecjpake_test_x3[] = …;
static const unsigned char ecjpake_test_x4[] = …;
static const unsigned char ecjpake_test_cli_one[] = …;
static const unsigned char ecjpake_test_srv_one[] = …;
static const unsigned char ecjpake_test_srv_two[] = …;
static const unsigned char ecjpake_test_cli_two[] = …;
static const unsigned char ecjpake_test_shared_key[] = …;
static const unsigned char ecjpake_test_pms[] = …;
static int self_test_rng(void *ctx, unsigned char *out, size_t len)
{ … }
static int ecjpake_test_load(mbedtls_ecjpake_context *ctx,
const unsigned char *xm1, size_t len1,
const unsigned char *xm2, size_t len2)
{ … }
#endif
static int ecjpake_lgc(void *p, unsigned char *out, size_t len)
{ … }
#define TEST_ASSERT …
int mbedtls_ecjpake_self_test(int verbose)
{ … }
#undef TEST_ASSERT
#endif
#endif
#endif