blob: bc1afbbed1e8ce19bbf60fe5996d5a36699605f8 [file] [log] [blame]
Manuel Pégourié-Gonnard2aea1412013-01-26 16:33:44 +01001/**
2 * \file ecdsa.h
3 *
4 * \brief Elliptic curve DSA
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_ECDSA_H
28#define POLARSSL_ECDSA_H
29
30#include "polarssl/ecp.h"
31
Manuel Pégourié-Gonnardbec2f452013-06-27 10:17:07 +020032/**
33 * \brief ECDSA context structure
34 */
35typedef struct
36{
37 ecp_group grp; /*!< ellipitic curve used */
38 mpi d; /*!< secret signature key */
39 ecp_point Q; /*!< public signature key */
40 mpi r; /*!< first integer from signature */
41 mpi s; /*!< second integer from signature */
Manuel Pégourié-Gonnardbec2f452013-06-27 10:17:07 +020042}
43ecdsa_context;
44
Manuel Pégourié-Gonnard2aea1412013-01-26 16:33:44 +010045#ifdef __cplusplus
46extern "C" {
47#endif
48
49/**
Manuel Pégourié-Gonnardb309ab22013-01-26 17:24:59 +010050 * \brief Compute ECDSA signature of a previously hashed message
51 *
52 * \param grp ECP group
53 * \param r First output integer
54 * \param s Second output integer
55 * \param d Private signing key
56 * \param buf Message hash
57 * \param blen Length of buf
58 * \param f_rng RNG function
59 * \param p_rng RNG parameter
60 *
61 * \return 0 if successful,
62 * or a POLARSSL_ERR_ECP_XXX or POLARSSL_MPI_XXX error code
63 */
64int ecdsa_sign( const ecp_group *grp, mpi *r, mpi *s,
65 const mpi *d, const unsigned char *buf, size_t blen,
66 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
67
68/**
Manuel Pégourié-Gonnard3aeb5a72013-01-26 18:05:50 +010069 * \brief Verify ECDSA signature of a previously hashed message
70 *
71 * \param grp ECP group
72 * \param buf Message hash
73 * \param blen Length of buf
74 * \param Q Public key to use for verification
75 * \param r First integer of the signature
76 * \param s Second integer of the signature
77 *
78 * \return 0 if successful,
79 * POLARSSL_ERR_ECP_BAD_INPUT_DATA if signature is invalid
80 * or a POLARSSL_ERR_ECP_XXX or POLARSSL_MPI_XXX error code
81 */
82int ecdsa_verify( const ecp_group *grp,
83 const unsigned char *buf, size_t blen,
84 const ecp_point *Q, const mpi *r, const mpi *s);
85
86/**
Manuel Pégourié-Gonnard7c8934e2013-06-27 12:54:02 +020087 * \brief Initialize context
88 *
89 * \param ctx Context to initialize
90 */
91void ecdsa_init( ecdsa_context *ctx );
92
93/**
94 * \brief Free context
95 *
96 * \param ctx Context to free
97 */
98void ecdsa_free( ecdsa_context *ctx );
99
100/**
Manuel Pégourié-Gonnard2aea1412013-01-26 16:33:44 +0100101 * \brief Checkup routine
102 *
103 * \return 0 if successful, or 1 if the test failed
104 */
105int ecdsa_self_test( int verbose );
106
107#ifdef __cplusplus
108}
109#endif
110
111#endif