Loading...
Searching...
No Matches
ecjpake.h
Go to the documentation of this file.
/*
* Copyright The Mbed TLS Contributors
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
*/
#ifndef MBEDTLS_ECJPAKE_H
#define MBEDTLS_ECJPAKE_H
#include "mbedtls/private_access.h"
/*
* J-PAKE is a password-authenticated key exchange that allows deriving a
* strong shared secret from a (potentially low entropy) pre-shared
* passphrase, with forward secrecy and mutual authentication.
* https://en.wikipedia.org/wiki/Password_Authenticated_Key_Exchange_by_Juggling
*
* This file implements the Elliptic Curve variant of J-PAKE,
* as defined in Chapter 7.4 of the Thread v1.0 Specification,
* available to members of the Thread Group http://threadgroup.org/
*
* As the J-PAKE algorithm is inherently symmetric, so is our API.
* Each party needs to send its first round message, in any order, to the
* other party, then each sends its second round message, in any order.
* The payloads are serialized in a way suitable for use in TLS, but could
* also be use outside TLS.
*/
#include "mbedtls/build_info.h"
#include "mbedtls/ecp.h"
#include "mbedtls/md.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
MBEDTLS_ECJPAKE_CLIENT = 0,
MBEDTLS_ECJPAKE_SERVER,
MBEDTLS_ECJPAKE_NONE,
} mbedtls_ecjpake_role;
#if !defined(MBEDTLS_ECJPAKE_ALT)
typedef struct mbedtls_ecjpake_context {
mbedtls_md_type_t MBEDTLS_PRIVATE(md_type);
mbedtls_ecp_group MBEDTLS_PRIVATE(grp);
mbedtls_ecjpake_role MBEDTLS_PRIVATE(role);
int MBEDTLS_PRIVATE(point_format);
mbedtls_ecp_point MBEDTLS_PRIVATE(Xm1);
mbedtls_ecp_point MBEDTLS_PRIVATE(Xm2);
mbedtls_ecp_point MBEDTLS_PRIVATE(Xp1);
mbedtls_ecp_point MBEDTLS_PRIVATE(Xp2);
mbedtls_ecp_point MBEDTLS_PRIVATE(Xp);
mbedtls_mpi MBEDTLS_PRIVATE(xm1);
mbedtls_mpi MBEDTLS_PRIVATE(xm2);
mbedtls_mpi MBEDTLS_PRIVATE(s);
} mbedtls_ecjpake_context;
#else /* MBEDTLS_ECJPAKE_ALT */
#include "ecjpake_alt.h"
#endif /* MBEDTLS_ECJPAKE_ALT */
void mbedtls_ecjpake_init(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);
int mbedtls_ecjpake_write_round_one(mbedtls_ecjpake_context *ctx,
unsigned char *buf, size_t len, size_t *olen,
mbedtls_f_rng_t *f_rng,
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_two(mbedtls_ecjpake_context *ctx,
unsigned char *buf, size_t len, size_t *olen,
mbedtls_f_rng_t *f_rng,
void *p_rng);
int mbedtls_ecjpake_read_round_two(mbedtls_ecjpake_context *ctx,
const unsigned char *buf,
size_t len);
int mbedtls_ecjpake_derive_secret(mbedtls_ecjpake_context *ctx,
unsigned char *buf, size_t len, size_t *olen,
mbedtls_f_rng_t *f_rng,
void *p_rng);
int mbedtls_ecjpake_write_shared_key(mbedtls_ecjpake_context *ctx,
unsigned char *buf, size_t len, size_t *olen,
mbedtls_f_rng_t *f_rng,
void *p_rng);
void mbedtls_ecjpake_free(mbedtls_ecjpake_context *ctx);
#if defined(MBEDTLS_SELF_TEST)
int mbedtls_ecjpake_self_test(int verbose);
#endif /* MBEDTLS_SELF_TEST */
#ifdef __cplusplus
}
#endif
#endif /* ecjpake.h */
mbedtls_ecjpake_read_round_two
int mbedtls_ecjpake_read_round_two(mbedtls_ecjpake_context *ctx, const unsigned char *buf, size_t len)
Read and process the second round message (TLS: contents of the Client/ServerKeyExchange).
mbedtls_ecjpake_role
mbedtls_ecjpake_role
Definition ecjpake.h:42
MBEDTLS_ECJPAKE_NONE
@ MBEDTLS_ECJPAKE_NONE
Definition ecjpake.h:45
MBEDTLS_ECJPAKE_CLIENT
@ MBEDTLS_ECJPAKE_CLIENT
Definition ecjpake.h:43
MBEDTLS_ECJPAKE_SERVER
@ MBEDTLS_ECJPAKE_SERVER
Definition ecjpake.h:44
mbedtls_ecjpake_set_point_format
int mbedtls_ecjpake_set_point_format(mbedtls_ecjpake_context *ctx, int point_format)
Set the point format for future reads and writes.
mbedtls_ecjpake_write_round_two
int mbedtls_ecjpake_write_round_two(mbedtls_ecjpake_context *ctx, unsigned char *buf, size_t len, size_t *olen, mbedtls_f_rng_t *f_rng, void *p_rng)
Generate and write the second round message (TLS: contents of the Client/ServerKeyExchange).
mbedtls_ecjpake_setup
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)
Set up an ECJPAKE context for use.
mbedtls_ecjpake_derive_secret
int mbedtls_ecjpake_derive_secret(mbedtls_ecjpake_context *ctx, unsigned char *buf, size_t len, size_t *olen, mbedtls_f_rng_t *f_rng, void *p_rng)
Derive the shared secret (TLS: Pre-Master Secret).
mbedtls_ecjpake_write_round_one
int mbedtls_ecjpake_write_round_one(mbedtls_ecjpake_context *ctx, unsigned char *buf, size_t len, size_t *olen, mbedtls_f_rng_t *f_rng, void *p_rng)
Generate and write the first round message (TLS: contents of the Client/ServerHello extension,...
mbedtls_ecjpake_init
void mbedtls_ecjpake_init(mbedtls_ecjpake_context *ctx)
Initialize an ECJPAKE context.
mbedtls_ecjpake_self_test
int mbedtls_ecjpake_self_test(int verbose)
Checkup routine.
mbedtls_ecjpake_check
int mbedtls_ecjpake_check(const mbedtls_ecjpake_context *ctx)
Check if an ECJPAKE context is ready for use.
mbedtls_ecjpake_read_round_one
int mbedtls_ecjpake_read_round_one(mbedtls_ecjpake_context *ctx, const unsigned char *buf, size_t len)
Read and process the first round message (TLS: contents of the Client/ServerHello extension,...
mbedtls_ecjpake_write_shared_key
int mbedtls_ecjpake_write_shared_key(mbedtls_ecjpake_context *ctx, unsigned char *buf, size_t len, size_t *olen, mbedtls_f_rng_t *f_rng, void *p_rng)
Write the shared key material to be passed to a Key Derivation Function as described in RFC8236.
mbedtls_ecjpake_free
void mbedtls_ecjpake_free(mbedtls_ecjpake_context *ctx)
This clears an ECJPAKE context and frees any embedded data structure.
ecjpake_alt.h
ecp.h
This file provides an API for Elliptic Curves over GF(P) (ECP).
mbedtls_ecp_group_id
mbedtls_ecp_group_id
Definition ecp.h:102
build_info.h
Build-time configuration info.
md.h
This file contains the generic functions for message-digest (hashing) and HMAC.
mbedtls_md_type_t
mbedtls_md_type_t
Supported message digests.
Definition md.h:47
mbedtls_f_rng_t
int mbedtls_f_rng_t(void *p_rng, unsigned char *output, size_t output_size)
The type of custom random generator (RNG) callbacks.
Definition platform_util.h:209
private_access.h
Macro wrapper for struct's members.
MBEDTLS_PRIVATE
#define MBEDTLS_PRIVATE(member)
Definition private_access.h:15
mbedtls_ecjpake_context
Definition ecjpake.h:60
mbedtls_ecp_group
The ECP group structure.
Definition ecp.h:233
mbedtls_ecp_point
The ECP point structure, in Jacobian coordinates.
Definition ecp.h:158
mbedtls_mpi
MPI structure.
Definition bignum.h:208