Manuel Pégourié-Gonnard | 4d8685b | 2015-08-05 15:44:42 +0200 | [diff] [blame] | 1 | /** |
| 2 | * \file ecjpake.h |
| 3 | * |
| 4 | * \brief Elliptic curve J-PAKE |
| 5 | * |
| 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved |
| 7 | * SPDX-License-Identifier: Apache-2.0 |
| 8 | * |
| 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 10 | * not use this file except in compliance with the License. |
| 11 | * You may obtain a copy of the License at |
| 12 | * |
| 13 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | * |
| 15 | * Unless required by applicable law or agreed to in writing, software |
| 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | * See the License for the specific language governing permissions and |
| 19 | * limitations under the License. |
| 20 | * |
| 21 | * This file is part of mbed TLS (https://tls.mbed.org) |
| 22 | */ |
| 23 | #ifndef MBEDTLS_ECJPAKE_H |
| 24 | #define MBEDTLS_ECJPAKE_H |
| 25 | |
| 26 | #include "ecp.h" |
| 27 | #include "md.h" |
| 28 | |
| 29 | #ifdef __cplusplus |
| 30 | extern "C" { |
| 31 | #endif |
| 32 | |
Manuel Pégourié-Gonnard | 7af8bc1 | 2015-08-12 16:58:50 +0200 | [diff] [blame] | 33 | typedef struct |
| 34 | { |
| 35 | const mbedtls_md_info_t *md_info; /**< Hash to use */ |
| 36 | mbedtls_ecp_group grp; /**< Elliptic curve */ |
| 37 | |
| 38 | mbedtls_ecp_point X1; /**< Public key one */ |
| 39 | mbedtls_ecp_point X2; /**< Public key two */ |
| 40 | mbedtls_ecp_point X3; /**< Public key three */ |
| 41 | mbedtls_ecp_point X4; /**< Public key four */ |
| 42 | |
| 43 | mbedtls_mpi xa; /**< Our first secret (x1 or x3) */ |
| 44 | mbedtls_mpi xb; /**< Our second secret (x2 or x4) */ |
Manuel Pégourié-Gonnard | 23dcbe3 | 2015-08-13 09:37:00 +0200 | [diff] [blame^] | 45 | |
| 46 | mbedtls_mpi s; /**< Pre-shared secret */ |
Manuel Pégourié-Gonnard | 7af8bc1 | 2015-08-12 16:58:50 +0200 | [diff] [blame] | 47 | } mbedtls_ecjpake_context; |
| 48 | |
| 49 | /* |
| 50 | * \brief Initialize a context |
| 51 | * (just makes it ready for setup() or free()). |
| 52 | * |
| 53 | * \param ctx context to initialize |
| 54 | */ |
| 55 | void mbedtls_ecjpake_init( mbedtls_ecjpake_context *ctx ); |
| 56 | |
| 57 | /* |
Manuel Pégourié-Gonnard | 7af8bc1 | 2015-08-12 16:58:50 +0200 | [diff] [blame] | 58 | * \brief Set up a context for use |
| 59 | * |
| 60 | * \note Currently the only values for hash/curve allowed by the |
| 61 | * standard are MBEDTLS_MD_SHA256/MBEDTLS_ECP_DP_SECP256R1. |
| 62 | * |
| 63 | * \param ctx context to set up |
| 64 | * \param hash hash function to use (MBEDTLS_MD_XXX) |
| 65 | * \param curve elliptic curve identifier (MBEDTLS_ECP_DP_XXX) |
Manuel Pégourié-Gonnard | 23dcbe3 | 2015-08-13 09:37:00 +0200 | [diff] [blame^] | 66 | * \param secret shared secret |
| 67 | * \param len length of the shared secret |
Manuel Pégourié-Gonnard | 7af8bc1 | 2015-08-12 16:58:50 +0200 | [diff] [blame] | 68 | * |
| 69 | * \return 0 if successfull, |
| 70 | * a negative error code otherwise |
| 71 | */ |
| 72 | int mbedtls_ecjpake_setup( mbedtls_ecjpake_context *ctx, |
| 73 | mbedtls_md_type_t hash, |
Manuel Pégourié-Gonnard | 23dcbe3 | 2015-08-13 09:37:00 +0200 | [diff] [blame^] | 74 | mbedtls_ecp_group_id curve, |
| 75 | const unsigned char *secret, |
| 76 | size_t len ); |
Manuel Pégourié-Gonnard | 7af8bc1 | 2015-08-12 16:58:50 +0200 | [diff] [blame] | 77 | |
Manuel Pégourié-Gonnard | 4e8bc78 | 2015-08-12 20:50:31 +0200 | [diff] [blame] | 78 | /* |
| 79 | * \brief Generate and write contents of ClientHello extension |
| 80 | * (excluding extension type and length bytes) |
| 81 | * |
| 82 | * \param ctx Context to use |
| 83 | * \param buf Buffer to write the contents to |
| 84 | * \param len Buffer size |
| 85 | * \param olen Will be updated with the number of bytes written |
| 86 | * \param f_rng RNG function |
| 87 | * \param p_rng RNG parameter |
| 88 | * |
| 89 | * \return 0 if successfull, |
| 90 | * a negative error code otherwise |
| 91 | */ |
| 92 | int mbedtls_ecjpake_tls_write_client_ext( mbedtls_ecjpake_context *ctx, |
| 93 | unsigned char *buf, size_t len, size_t *olen, |
| 94 | int (*f_rng)(void *, unsigned char *, size_t), |
| 95 | void *p_rng ); |
| 96 | /* |
| 97 | * \brief Read and process contents of the ClientHello extension |
| 98 | * (excluding extension type and length bytes) |
| 99 | * |
| 100 | * \param ctx Context to use |
| 101 | * \param buf Pointer to extension contents |
| 102 | * \param len Extension length |
| 103 | * |
| 104 | * \return 0 if successfull, |
| 105 | * a negative error code otherwise |
| 106 | */ |
| 107 | int mbedtls_ecjpake_tls_read_client_ext( mbedtls_ecjpake_context *ctx, |
| 108 | const unsigned char *buf, |
| 109 | size_t len ); |
| 110 | |
| 111 | /* |
| 112 | * \brief Generate and write contents of ServerHello extension |
| 113 | * (excluding extension type and length bytes) |
| 114 | * |
| 115 | * \param ctx Context to use |
| 116 | * \param buf Buffer to write the contents to |
| 117 | * \param len Buffer size |
| 118 | * \param olen Will be updated with the number of bytes written |
| 119 | * \param f_rng RNG function |
| 120 | * \param p_rng RNG parameter |
| 121 | * |
| 122 | * \return 0 if successfull, |
| 123 | * a negative error code otherwise |
| 124 | */ |
| 125 | int mbedtls_ecjpake_tls_write_server_ext( mbedtls_ecjpake_context *ctx, |
| 126 | unsigned char *buf, size_t len, size_t *olen, |
| 127 | int (*f_rng)(void *, unsigned char *, size_t), |
| 128 | void *p_rng ); |
| 129 | /* |
| 130 | * \brief Read and process contents of the ServerHello extension |
| 131 | * (excluding extension type and length bytes) |
| 132 | * |
| 133 | * \param ctx Context to use |
| 134 | * \param buf Pointer to extension contents |
| 135 | * \param len Extension length |
| 136 | * |
| 137 | * \return 0 if successfull, |
| 138 | * a negative error code otherwise |
| 139 | */ |
| 140 | int mbedtls_ecjpake_tls_read_server_ext( mbedtls_ecjpake_context *ctx, |
| 141 | const unsigned char *buf, |
| 142 | size_t len ); |
| 143 | |
| 144 | /* |
| 145 | * \brief Free a context's content |
| 146 | * |
| 147 | * \param ctx context to free |
| 148 | */ |
| 149 | void mbedtls_ecjpake_free( mbedtls_ecjpake_context *ctx ); |
| 150 | |
Manuel Pégourié-Gonnard | 4d8685b | 2015-08-05 15:44:42 +0200 | [diff] [blame] | 151 | #if defined(MBEDTLS_SELF_TEST) |
| 152 | /** |
| 153 | * \brief Checkup routine |
| 154 | * |
| 155 | * \return 0 if successful, or 1 if a test failed |
| 156 | */ |
| 157 | int mbedtls_ecjpake_self_test( int verbose ); |
| 158 | #endif |
| 159 | |
| 160 | #ifdef __cplusplus |
| 161 | } |
| 162 | #endif |
| 163 | |
| 164 | #endif /* ecjpake.h */ |