/src/mbedtls/3rdparty/everest/library/everest.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Interface to code from Project Everest |
3 | | * |
4 | | * Copyright 2016-2018 INRIA and Microsoft Corporation |
5 | | * SPDX-License-Identifier: Apache-2.0 |
6 | | * |
7 | | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
8 | | * not use this file except in compliance with the License. |
9 | | * You may obtain a copy of the License at |
10 | | * |
11 | | * http://www.apache.org/licenses/LICENSE-2.0 |
12 | | * |
13 | | * Unless required by applicable law or agreed to in writing, software |
14 | | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
15 | | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | | * See the License for the specific language governing permissions and |
17 | | * limitations under the License. |
18 | | * |
19 | | * This file is part of Mbed TLS (https://tls.mbed.org). |
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 | | #include "mbedtls/platform.h" |
32 | | |
33 | | #if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED) |
34 | | |
35 | | int mbedtls_everest_setup( mbedtls_ecdh_context_everest *ctx, int grp_id ) |
36 | 0 | { |
37 | 0 | if( grp_id != MBEDTLS_ECP_DP_CURVE25519 ) |
38 | 0 | return MBEDTLS_ERR_ECP_BAD_INPUT_DATA; |
39 | 0 | mbedtls_x25519_init( &ctx->ctx ); |
40 | 0 | return 0; |
41 | 0 | } |
42 | | |
43 | | void mbedtls_everest_free( mbedtls_ecdh_context_everest *ctx ) |
44 | 0 | { |
45 | 0 | mbedtls_x25519_free( &ctx->ctx ); |
46 | 0 | } |
47 | | |
48 | | int mbedtls_everest_make_params( mbedtls_ecdh_context_everest *ctx, size_t *olen, |
49 | | unsigned char *buf, size_t blen, |
50 | | int( *f_rng )( void *, unsigned char *, size_t ), |
51 | | void *p_rng ) |
52 | 0 | { |
53 | 0 | mbedtls_x25519_context *x25519_ctx = &ctx->ctx; |
54 | 0 | return mbedtls_x25519_make_params( x25519_ctx, olen, buf, blen, f_rng, p_rng ); |
55 | 0 | } |
56 | | |
57 | | int mbedtls_everest_read_params( mbedtls_ecdh_context_everest *ctx, |
58 | | const unsigned char **buf, |
59 | | const unsigned char *end ) |
60 | 0 | { |
61 | 0 | mbedtls_x25519_context *x25519_ctx = &ctx->ctx; |
62 | 0 | return mbedtls_x25519_read_params( x25519_ctx, buf, end ); |
63 | 0 | } |
64 | | |
65 | | int mbedtls_everest_get_params( mbedtls_ecdh_context_everest *ctx, |
66 | | const mbedtls_ecp_keypair *key, |
67 | | mbedtls_everest_ecdh_side side ) |
68 | 0 | { |
69 | 0 | mbedtls_x25519_context *x25519_ctx = &ctx->ctx; |
70 | 0 | mbedtls_x25519_ecdh_side s = side == MBEDTLS_EVEREST_ECDH_OURS ? |
71 | 0 | MBEDTLS_X25519_ECDH_OURS : |
72 | 0 | MBEDTLS_X25519_ECDH_THEIRS; |
73 | 0 | return mbedtls_x25519_get_params( x25519_ctx, key, s ); |
74 | 0 | } |
75 | | |
76 | | int mbedtls_everest_make_public( mbedtls_ecdh_context_everest *ctx, size_t *olen, |
77 | | unsigned char *buf, size_t blen, |
78 | | int( *f_rng )( void *, unsigned char *, size_t ), |
79 | | void *p_rng ) |
80 | 0 | { |
81 | 0 | mbedtls_x25519_context *x25519_ctx = &ctx->ctx; |
82 | 0 | return mbedtls_x25519_make_public( x25519_ctx, olen, buf, blen, f_rng, p_rng ); |
83 | 0 | } |
84 | | |
85 | | int mbedtls_everest_read_public( mbedtls_ecdh_context_everest *ctx, |
86 | | const unsigned char *buf, size_t blen ) |
87 | 0 | { |
88 | 0 | mbedtls_x25519_context *x25519_ctx = &ctx->ctx; |
89 | 0 | return mbedtls_x25519_read_public ( x25519_ctx, buf, blen ); |
90 | 0 | } |
91 | | |
92 | | int mbedtls_everest_calc_secret( mbedtls_ecdh_context_everest *ctx, size_t *olen, |
93 | | unsigned char *buf, size_t blen, |
94 | | int( *f_rng )( void *, unsigned char *, size_t ), |
95 | | void *p_rng ) |
96 | 0 | { |
97 | 0 | mbedtls_x25519_context *x25519_ctx = &ctx->ctx; |
98 | 0 | return mbedtls_x25519_calc_secret( x25519_ctx, olen, buf, blen, f_rng, p_rng ); |
99 | 0 | } |
100 | | |
101 | | #endif /* MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED */ |
102 | | |