1656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* crypto/ecdsa/ecdsa.h */
2656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/**
3656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * \file   crypto/ecdsa/ecdsa.h Include file for the OpenSSL ECDSA functions
4656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * \author Written by Nils Larsch for the OpenSSL project
5656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project */
6656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* ====================================================================
7221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom * Copyright (c) 2000-2005 The OpenSSL Project.  All rights reserved.
8656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *
9656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * Redistribution and use in source and binary forms, with or without
10656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * modification, are permitted provided that the following conditions
11656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * are met:
12656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *
13656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 1. Redistributions of source code must retain the above copyright
14656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *    notice, this list of conditions and the following disclaimer.
15656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *
16656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 2. Redistributions in binary form must reproduce the above copyright
17656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *    notice, this list of conditions and the following disclaimer in
18656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *    the documentation and/or other materials provided with the
19656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *    distribution.
20656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *
21656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 3. All advertising materials mentioning features or use of this
22656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *    software must display the following acknowledgment:
23656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *    "This product includes software developed by the OpenSSL Project
24656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *
26656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *    endorse or promote products derived from this software without
28656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *    prior written permission. For written permission, please contact
29656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *    licensing@OpenSSL.org.
30656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *
31656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 5. Products derived from this software may not be called "OpenSSL"
32656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *    nor may "OpenSSL" appear in their names without prior written
33656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *    permission of the OpenSSL Project.
34656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *
35656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * 6. Redistributions of any form whatsoever must retain the following
36656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *    acknowledgment:
37656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *    "This product includes software developed by the OpenSSL Project
38656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *
40656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
44656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * OF THE POSSIBILITY OF SUCH DAMAGE.
52656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * ====================================================================
53656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *
54656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * This product includes cryptographic software written by Eric Young
55656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * (eay@cryptsoft.com).  This product includes software written by Tim
56656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * Hudson (tjh@cryptsoft.com).
57656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project *
58656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project */
59656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#ifndef HEADER_ECDSA_H
60656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#define HEADER_ECDSA_H
61656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
62656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#include <openssl/opensslconf.h>
63656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
64656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#ifdef OPENSSL_NO_ECDSA
65656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#error ECDSA is disabled.
66656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#endif
67656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
68656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#include <openssl/ec.h>
69656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#include <openssl/ossl_typ.h>
70656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#ifndef OPENSSL_NO_DEPRECATED
71656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#include <openssl/bn.h>
72656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#endif
73656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
74656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#ifdef __cplusplus
75656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectextern "C" {
76656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#endif
77656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
78656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projecttypedef struct ECDSA_SIG_st
79656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	{
80656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	BIGNUM *r;
81656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	BIGNUM *s;
82656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project	} ECDSA_SIG;
83656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
84221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom/** Allocates and initialize a ECDSA_SIG structure
85221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \return pointer to a ECDSA_SIG structure or NULL if an error occurred
86656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project */
87656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source ProjectECDSA_SIG *ECDSA_SIG_new(void);
88656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
89221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom/** frees a ECDSA_SIG structure
90221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  sig  pointer to the ECDSA_SIG structure
91656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project */
92221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromvoid	  ECDSA_SIG_free(ECDSA_SIG *sig);
93656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
94221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom/** DER encode content of ECDSA_SIG object (note: this function modifies *pp
95221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  (*pp += length of the DER encoded signature)).
96221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  sig  pointer to the ECDSA_SIG object
97221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  pp   pointer to a unsigned char pointer for the output or NULL
98221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \return the length of the DER encoded ECDSA_SIG object or 0
99656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project */
100221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstromint	  i2d_ECDSA_SIG(const ECDSA_SIG *sig, unsigned char **pp);
101656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
102221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom/** Decodes a DER encoded ECDSA signature (note: this function changes *pp
103221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  (*pp += len)).
104221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  sig  pointer to ECDSA_SIG pointer (may be NULL)
105221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  pp   memory buffer with the DER encoded signature
106221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  len  length of the buffer
107221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \return pointer to the decoded ECDSA_SIG structure (or NULL)
108656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project */
109221304ee937bc0910948a8be1320cb8cc4eb6d36Brian CarlstromECDSA_SIG *d2i_ECDSA_SIG(ECDSA_SIG **sig, const unsigned char **pp, long len);
110656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
111221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom/** Computes the ECDSA signature of the given hash value using
112221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  the supplied private key and returns the created signature.
113221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  dgst      pointer to the hash value
114221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  dgst_len  length of the hash value
115221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  eckey     EC_KEY object containing a private EC key
116221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \return pointer to a ECDSA_SIG structure or NULL if an error occurred
117656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project */
118656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source ProjectECDSA_SIG *ECDSA_do_sign(const unsigned char *dgst,int dgst_len,EC_KEY *eckey);
119656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
120221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom/** Computes ECDSA signature of a given hash value using the supplied
121221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  private key (note: sig must point to ECDSA_size(eckey) bytes of memory).
122221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  dgst     pointer to the hash value to sign
123221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  dgstlen  length of the hash value
124221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  kinv     BIGNUM with a pre-computed inverse k (optional)
125221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  rp       BIGNUM with a pre-computed rp value (optioanl),
126221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *                   see ECDSA_sign_setup
127221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  eckey    EC_KEY object containing a private EC key
128221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \return pointer to a ECDSA_SIG structure or NULL if an error occurred
129656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project */
130656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source ProjectECDSA_SIG *ECDSA_do_sign_ex(const unsigned char *dgst, int dgstlen,
131656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project		const BIGNUM *kinv, const BIGNUM *rp, EC_KEY *eckey);
132656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
133221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom/** Verifies that the supplied signature is a valid ECDSA
134221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  signature of the supplied hash value using the supplied public key.
135221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  dgst      pointer to the hash value
136221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  dgst_len  length of the hash value
137221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  sig       ECDSA_SIG structure
138221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  eckey     EC_KEY object containing a public EC key
139221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \return 1 if the signature is valid, 0 if the signature is invalid
140221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *          and -1 on error
141656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project */
142656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectint	  ECDSA_do_verify(const unsigned char *dgst, int dgst_len,
143656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project		const ECDSA_SIG *sig, EC_KEY* eckey);
144656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
145656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectconst ECDSA_METHOD *ECDSA_OpenSSL(void);
146656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
147221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom/** Sets the default ECDSA method
148221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  meth  new default ECDSA_METHOD
149656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project */
150656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectvoid	  ECDSA_set_default_method(const ECDSA_METHOD *meth);
151656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
152221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom/** Returns the default ECDSA method
153221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \return pointer to ECDSA_METHOD structure containing the default method
154656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project */
155656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectconst ECDSA_METHOD *ECDSA_get_default_method(void);
156656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
157221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom/** Sets method to be used for the ECDSA operations
158221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  eckey  EC_KEY object
159221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  meth   new method
160221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \return 1 on success and 0 otherwise
161656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project */
162656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectint 	  ECDSA_set_method(EC_KEY *eckey, const ECDSA_METHOD *meth);
163656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
164221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom/** Returns the maximum length of the DER encoded signature
165221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  eckey  EC_KEY object
166221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \return numbers of bytes required for the DER encoded signature
167656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project */
168656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectint	  ECDSA_size(const EC_KEY *eckey);
169656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
170221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom/** Precompute parts of the signing operation
171221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  eckey  EC_KEY object containing a private EC key
172221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  ctx    BN_CTX object (optional)
173221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  kinv   BIGNUM pointer for the inverse of k
174221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  rp     BIGNUM pointer for x coordinate of k * generator
175221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \return 1 on success and 0 otherwise
176656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project */
177656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectint 	  ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx, BIGNUM **kinv,
178656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project		BIGNUM **rp);
179656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
180221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom/** Computes ECDSA signature of a given hash value using the supplied
181221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  private key (note: sig must point to ECDSA_size(eckey) bytes of memory).
182221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  type     this parameter is ignored
183221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  dgst     pointer to the hash value to sign
184221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  dgstlen  length of the hash value
185221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  sig      memory for the DER encoded created signature
186221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  siglen   pointer to the length of the returned signature
187221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  eckey    EC_KEY object containing a private EC key
188221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \return 1 on success and 0 otherwise
189656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project */
190656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectint	  ECDSA_sign(int type, const unsigned char *dgst, int dgstlen,
191656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project		unsigned char *sig, unsigned int *siglen, EC_KEY *eckey);
192656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
193656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
194221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom/** Computes ECDSA signature of a given hash value using the supplied
195221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  private key (note: sig must point to ECDSA_size(eckey) bytes of memory).
196221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  type     this parameter is ignored
197221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  dgst     pointer to the hash value to sign
198221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  dgstlen  length of the hash value
199221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  sig      buffer to hold the DER encoded signature
200221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  siglen   pointer to the length of the returned signature
201221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  kinv     BIGNUM with a pre-computed inverse k (optional)
202221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  rp       BIGNUM with a pre-computed rp value (optioanl),
203221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *                   see ECDSA_sign_setup
204221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  eckey    EC_KEY object containing a private EC key
205221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \return 1 on success and 0 otherwise
206656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project */
207656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectint	  ECDSA_sign_ex(int type, const unsigned char *dgst, int dgstlen,
208656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project		unsigned char *sig, unsigned int *siglen, const BIGNUM *kinv,
209656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project		const BIGNUM *rp, EC_KEY *eckey);
210656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
211221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom/** Verifies that the given signature is valid ECDSA signature
212221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  of the supplied hash value using the specified public key.
213221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  type     this parameter is ignored
214221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  dgst     pointer to the hash value
215221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  dgstlen  length of the hash value
216221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  sig      pointer to the DER encoded signature
217221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  siglen   length of the DER encoded signature
218221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \param  eckey    EC_KEY object containing a public EC key
219221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *  \return 1 if the signature is valid, 0 if the signature is invalid
220221304ee937bc0910948a8be1320cb8cc4eb6d36Brian Carlstrom *          and -1 on error
221656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project */
222656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectint 	  ECDSA_verify(int type, const unsigned char *dgst, int dgstlen,
223656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project		const unsigned char *sig, int siglen, EC_KEY *eckey);
224656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
225656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* the standard ex_data functions */
226656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectint 	  ECDSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new
227656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project		*new_func, CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
228656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectint 	  ECDSA_set_ex_data(EC_KEY *d, int idx, void *arg);
229656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectvoid 	  *ECDSA_get_ex_data(EC_KEY *d, int idx);
230656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
231656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
232656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* BEGIN ERROR CODES */
233656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* The following lines are auto generated by the script mkerr.pl. Any changes
234656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project * made after this point may be overwritten when the script is next run.
235656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project */
236656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Projectvoid ERR_load_ECDSA_strings(void);
237656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
238656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* Error codes for the ECDSA functions. */
239656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
240656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* Function codes. */
241392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom#define ECDSA_F_ECDSA_CHECK				 104
242656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#define ECDSA_F_ECDSA_DATA_NEW_METHOD			 100
243656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#define ECDSA_F_ECDSA_DO_SIGN				 101
244656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#define ECDSA_F_ECDSA_DO_VERIFY				 102
245656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#define ECDSA_F_ECDSA_SIGN_SETUP			 103
246656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
247656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project/* Reason codes. */
248656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#define ECDSA_R_BAD_SIGNATURE				 100
249656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#define ECDSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE		 101
250656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#define ECDSA_R_ERR_EC_LIB				 102
251656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#define ECDSA_R_MISSING_PARAMETERS			 103
252656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#define ECDSA_R_NEED_NEW_SETUP_VALUES			 106
25323b9568fd705172c870175f42556ae21861da399Adam Langley#define ECDSA_R_NONCE_CANNOT_BE_PRECOMPUTED		 108
254392aa7cc7d2b122614c5393c3e357da07fd07af3Brian Carlstrom#define ECDSA_R_NON_FIPS_METHOD				 107
255656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#define ECDSA_R_RANDOM_NUMBER_GENERATION_FAILED		 104
256656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#define ECDSA_R_SIGNATURE_MALLOC_FAILED			 105
257656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project
258656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#ifdef  __cplusplus
259656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project}
260656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#endif
261656d9c7f52f88b3a3daccafa7655dec086c4756eThe Android Open Source Project#endif
262