blob: 2f1e51dd46ec8672d12a53318c308dfede864822 [file] [log] [blame]
Manuel Pégourié-Gonnard0bad5c22013-01-26 15:30:46 +01001/**
2 * \file ecdh.h
3 *
4 * \brief Elliptic curve Diffie-Hellman
5 *
6 * Copyright (C) 2006-2013, Brainspark B.V.
7 *
8 * This file is part of PolarSSL (http://www.polarssl.org)
9 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
10 *
11 * All rights reserved.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 */
27#ifndef POLARSSL_ECDH_H
28#define POLARSSL_ECDH_H
29
30#include "polarssl/ecp.h"
31
Manuel Pégourié-Gonnard63533e42013-02-10 14:21:04 +010032/**
33 * \brief ECDH context structure
34 */
35typedef struct
36{
37 ecp_group grp; /*!< ellipitic curve used */
38 mpi d; /*!< our secret value */
39 ecp_point Q; /*!< our public value */
40 ecp_point Qp; /*!< peer's public value */
41 mpi z; /*!< shared secret */
42}
43ecdh_context;
44
Manuel Pégourié-Gonnard0bad5c22013-01-26 15:30:46 +010045#ifdef __cplusplus
46extern "C" {
47#endif
48
Manuel Pégourié-Gonnard6545ca72013-01-26 16:05:22 +010049/**
50 * \brief Generate a public key
51 *
52 * \param grp ECP group
53 * \param d Destination MPI (secret exponent)
54 * \param Q Destination point (public key)
55 * \param f_rng RNG function
56 * \param p_rng RNG parameter
57 *
58 * \return 0 if successful,
59 * or a POLARSSL_ERR_ECP_XXX or POLARSSL_MPI_XXX error code
60 */
61int ecdh_gen_public( const ecp_group *grp, mpi *d, ecp_point *Q,
62 int (*f_rng)(void *, unsigned char *, size_t),
63 void *p_rng );
64
65/**
66 * \brief Compute shared secret
67 *
68 * \param grp ECP group
69 * \param z Destination MPI (shared secret)
70 * \param Q Public key from other party
71 * \param d Our secret exponent
72 *
73 * \return 0 if successful,
74 * or a POLARSSL_ERR_ECP_XXX or POLARSSL_MPI_XXX error code
75 */
76int ecdh_compute_shared( const ecp_group *grp, mpi *z,
77 const ecp_point *Q, const mpi *d );
Manuel Pégourié-Gonnard0bad5c22013-01-26 15:30:46 +010078
79/**
Manuel Pégourié-Gonnard63533e42013-02-10 14:21:04 +010080 * \brief Initialize context
81 *
82 * \param ctx Context to initialize
83 */
84void ecdh_init( ecdh_context *ctx );
85
86/**
87 * \brief Free context
88 *
89 * \param ctx Context to free
90 */
91void ecdh_free( ecdh_context *ctx );
92
93/**
Manuel Pégourié-Gonnard0bad5c22013-01-26 15:30:46 +010094 * \brief Checkup routine
95 *
96 * \return 0 if successful, or 1 if the test failed
97 */
98int ecdh_self_test( int verbose );
99
Manuel Pégourié-Gonnard6545ca72013-01-26 16:05:22 +0100100#ifdef __cplusplus
101}
102#endif
103
Manuel Pégourié-Gonnard0bad5c22013-01-26 15:30:46 +0100104#endif