| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#include "common.h" |
| 23 |
|
| 24 |
#include <string.h> |
| 25 |
|
| 26 |
#include "mbedtls/ecdh.h" |
| 27 |
|
| 28 |
#include "everest/x25519.h" |
| 29 |
#include "everest/everest.h" |
| 30 |
|
| 31 |
#if defined(MBEDTLS_PLATFORM_C) |
| 32 |
#include "mbedtls/platform.h" |
| 33 |
#else |
| 34 |
#define mbedtls_calloc calloc |
| 35 |
#define mbedtls_free free |
| 36 |
#endif |
| 37 |
|
| 38 |
#if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED) |
| 39 |
|
| 40 |
int mbedtls_everest_setup( mbedtls_ecdh_context_everest *ctx, int grp_id ) |
| 41 |
{ |
| 42 |
if( grp_id != MBEDTLS_ECP_DP_CURVE25519 ) |
| 43 |
return MBEDTLS_ERR_ECP_BAD_INPUT_DATA; |
| 44 |
mbedtls_x25519_init( &ctx->ctx ); |
| 45 |
return 0; |
| 46 |
} |
| 47 |
|
| 48 |
void mbedtls_everest_free( mbedtls_ecdh_context_everest *ctx ) |
| 49 |
{ |
| 50 |
mbedtls_x25519_free( &ctx->ctx ); |
| 51 |
} |
| 52 |
|
| 53 |
int mbedtls_everest_make_params( mbedtls_ecdh_context_everest *ctx, size_t *olen, |
| 54 |
unsigned char *buf, size_t blen, |
| 55 |
int( *f_rng )( void *, unsigned char *, size_t ), |
| 56 |
void *p_rng ) |
| 57 |
{ |
| 58 |
mbedtls_x25519_context *x25519_ctx = &ctx->ctx; |
| 59 |
return mbedtls_x25519_make_params( x25519_ctx, olen, buf, blen, f_rng, p_rng ); |
| 60 |
} |
| 61 |
|
| 62 |
int mbedtls_everest_read_params( mbedtls_ecdh_context_everest *ctx, |
| 63 |
const unsigned char **buf, |
| 64 |
const unsigned char *end ) |
| 65 |
{ |
| 66 |
mbedtls_x25519_context *x25519_ctx = &ctx->ctx; |
| 67 |
return mbedtls_x25519_read_params( x25519_ctx, buf, end ); |
| 68 |
} |
| 69 |
|
| 70 |
int mbedtls_everest_get_params( mbedtls_ecdh_context_everest *ctx, |
| 71 |
const mbedtls_ecp_keypair *key, |
| 72 |
mbedtls_everest_ecdh_side side ) |
| 73 |
{ |
| 74 |
mbedtls_x25519_context *x25519_ctx = &ctx->ctx; |
| 75 |
mbedtls_x25519_ecdh_side s = side == MBEDTLS_EVEREST_ECDH_OURS ? |
| 76 |
MBEDTLS_X25519_ECDH_OURS : |
| 77 |
MBEDTLS_X25519_ECDH_THEIRS; |
| 78 |
return mbedtls_x25519_get_params( x25519_ctx, key, s ); |
| 79 |
} |
| 80 |
|
| 81 |
int mbedtls_everest_make_public( mbedtls_ecdh_context_everest *ctx, size_t *olen, |
| 82 |
unsigned char *buf, size_t blen, |
| 83 |
int( *f_rng )( void *, unsigned char *, size_t ), |
| 84 |
void *p_rng ) |
| 85 |
{ |
| 86 |
mbedtls_x25519_context *x25519_ctx = &ctx->ctx; |
| 87 |
return mbedtls_x25519_make_public( x25519_ctx, olen, buf, blen, f_rng, p_rng ); |
| 88 |
} |
| 89 |
|
| 90 |
int mbedtls_everest_read_public( mbedtls_ecdh_context_everest *ctx, |
| 91 |
const unsigned char *buf, size_t blen ) |
| 92 |
{ |
| 93 |
mbedtls_x25519_context *x25519_ctx = &ctx->ctx; |
| 94 |
return mbedtls_x25519_read_public ( x25519_ctx, buf, blen ); |
| 95 |
} |
| 96 |
|
| 97 |
int mbedtls_everest_calc_secret( mbedtls_ecdh_context_everest *ctx, size_t *olen, |
| 98 |
unsigned char *buf, size_t blen, |
| 99 |
int( *f_rng )( void *, unsigned char *, size_t ), |
| 100 |
void *p_rng ) |
| 101 |
{ |
| 102 |
mbedtls_x25519_context *x25519_ctx = &ctx->ctx; |
| 103 |
return mbedtls_x25519_calc_secret( x25519_ctx, olen, buf, blen, f_rng, p_rng ); |
| 104 |
} |
| 105 |
|
| 106 |
#endif |
| 107 |
|