blob: 37aff6c68a2fdfad1ea54570c54a12599ce842d4 [file] [log] [blame]
Manuel Pégourié-Gonnard4d8685b2015-08-05 15:44:42 +02001/**
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
30extern "C" {
31#endif
32
Manuel Pégourié-Gonnard7af8bc12015-08-12 16:58:50 +020033typedef 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) */
45} mbedtls_ecjpake_context;
46
47/*
48 * \brief Initialize a context
49 * (just makes it ready for setup() or free()).
50 *
51 * \param ctx context to initialize
52 */
53void mbedtls_ecjpake_init( mbedtls_ecjpake_context *ctx );
54
55/*
Manuel Pégourié-Gonnard7af8bc12015-08-12 16:58:50 +020056 * \brief Set up a context for use
57 *
58 * \note Currently the only values for hash/curve allowed by the
59 * standard are MBEDTLS_MD_SHA256/MBEDTLS_ECP_DP_SECP256R1.
60 *
61 * \param ctx context to set up
62 * \param hash hash function to use (MBEDTLS_MD_XXX)
63 * \param curve elliptic curve identifier (MBEDTLS_ECP_DP_XXX)
64 *
65 * \return 0 if successfull,
66 * a negative error code otherwise
67 */
68int mbedtls_ecjpake_setup( mbedtls_ecjpake_context *ctx,
69 mbedtls_md_type_t hash,
70 mbedtls_ecp_group_id curve );
71
Manuel Pégourié-Gonnard4e8bc782015-08-12 20:50:31 +020072/*
73 * \brief Generate and write contents of ClientHello extension
74 * (excluding extension type and length bytes)
75 *
76 * \param ctx Context to use
77 * \param buf Buffer to write the contents to
78 * \param len Buffer size
79 * \param olen Will be updated with the number of bytes written
80 * \param f_rng RNG function
81 * \param p_rng RNG parameter
82 *
83 * \return 0 if successfull,
84 * a negative error code otherwise
85 */
86int mbedtls_ecjpake_tls_write_client_ext( mbedtls_ecjpake_context *ctx,
87 unsigned char *buf, size_t len, size_t *olen,
88 int (*f_rng)(void *, unsigned char *, size_t),
89 void *p_rng );
90/*
91 * \brief Read and process contents of the ClientHello extension
92 * (excluding extension type and length bytes)
93 *
94 * \param ctx Context to use
95 * \param buf Pointer to extension contents
96 * \param len Extension length
97 *
98 * \return 0 if successfull,
99 * a negative error code otherwise
100 */
101int mbedtls_ecjpake_tls_read_client_ext( mbedtls_ecjpake_context *ctx,
102 const unsigned char *buf,
103 size_t len );
104
105/*
106 * \brief Generate and write contents of ServerHello extension
107 * (excluding extension type and length bytes)
108 *
109 * \param ctx Context to use
110 * \param buf Buffer to write the contents to
111 * \param len Buffer size
112 * \param olen Will be updated with the number of bytes written
113 * \param f_rng RNG function
114 * \param p_rng RNG parameter
115 *
116 * \return 0 if successfull,
117 * a negative error code otherwise
118 */
119int mbedtls_ecjpake_tls_write_server_ext( mbedtls_ecjpake_context *ctx,
120 unsigned char *buf, size_t len, size_t *olen,
121 int (*f_rng)(void *, unsigned char *, size_t),
122 void *p_rng );
123/*
124 * \brief Read and process contents of the ServerHello extension
125 * (excluding extension type and length bytes)
126 *
127 * \param ctx Context to use
128 * \param buf Pointer to extension contents
129 * \param len Extension length
130 *
131 * \return 0 if successfull,
132 * a negative error code otherwise
133 */
134int mbedtls_ecjpake_tls_read_server_ext( mbedtls_ecjpake_context *ctx,
135 const unsigned char *buf,
136 size_t len );
137
138/*
139 * \brief Free a context's content
140 *
141 * \param ctx context to free
142 */
143void mbedtls_ecjpake_free( mbedtls_ecjpake_context *ctx );
144
Manuel Pégourié-Gonnard4d8685b2015-08-05 15:44:42 +0200145#if defined(MBEDTLS_SELF_TEST)
146/**
147 * \brief Checkup routine
148 *
149 * \return 0 if successful, or 1 if a test failed
150 */
151int mbedtls_ecjpake_self_test( int verbose );
152#endif
153
154#ifdef __cplusplus
155}
156#endif
157
158#endif /* ecjpake.h */