blob: e709b405c5d5ad72682b4f8980b478cf4d6ce369 [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 */
42 int point_format; /*!< format for point export */
43}
44ecdsa_context;
45
Manuel Pégourié-Gonnard2aea1412013-01-26 16:33:44 +010046#ifdef __cplusplus
47extern "C" {
48#endif
49
50/**
Manuel Pégourié-Gonnardb309ab22013-01-26 17:24:59 +010051 * \brief Compute ECDSA signature of a previously hashed message
52 *
53 * \param grp ECP group
54 * \param r First output integer
55 * \param s Second output integer
56 * \param d Private signing key
57 * \param buf Message hash
58 * \param blen Length of buf
59 * \param f_rng RNG function
60 * \param p_rng RNG parameter
61 *
62 * \return 0 if successful,
63 * or a POLARSSL_ERR_ECP_XXX or POLARSSL_MPI_XXX error code
64 */
65int ecdsa_sign( const ecp_group *grp, mpi *r, mpi *s,
66 const mpi *d, const unsigned char *buf, size_t blen,
67 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
68
69/**
Manuel Pégourié-Gonnard3aeb5a72013-01-26 18:05:50 +010070 * \brief Verify ECDSA signature of a previously hashed message
71 *
72 * \param grp ECP group
73 * \param buf Message hash
74 * \param blen Length of buf
75 * \param Q Public key to use for verification
76 * \param r First integer of the signature
77 * \param s Second integer of the signature
78 *
79 * \return 0 if successful,
80 * POLARSSL_ERR_ECP_BAD_INPUT_DATA if signature is invalid
81 * or a POLARSSL_ERR_ECP_XXX or POLARSSL_MPI_XXX error code
82 */
83int ecdsa_verify( const ecp_group *grp,
84 const unsigned char *buf, size_t blen,
85 const ecp_point *Q, const mpi *r, const mpi *s);
86
87/**
Manuel Pégourié-Gonnard7c8934e2013-06-27 12:54:02 +020088 * \brief Initialize context
89 *
90 * \param ctx Context to initialize
91 */
92void ecdsa_init( ecdsa_context *ctx );
93
94/**
95 * \brief Free context
96 *
97 * \param ctx Context to free
98 */
99void ecdsa_free( ecdsa_context *ctx );
100
101/**
Manuel Pégourié-Gonnard2aea1412013-01-26 16:33:44 +0100102 * \brief Checkup routine
103 *
104 * \return 0 if successful, or 1 if the test failed
105 */
106int ecdsa_self_test( int verbose );
107
108#ifdef __cplusplus
109}
110#endif
111
112#endif