1d9e397b599b13d642138480a28c14db7a136bf0Adam Langley/* Originally written by Bodo Moeller for the OpenSSL project.
2d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * ====================================================================
3d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * Copyright (c) 1998-2005 The OpenSSL Project.  All rights reserved.
4d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *
5d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * Redistribution and use in source and binary forms, with or without
6d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * modification, are permitted provided that the following conditions
7d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * are met:
8d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *
9d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * 1. Redistributions of source code must retain the above copyright
10d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *    notice, this list of conditions and the following disclaimer.
11d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *
12d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * 2. Redistributions in binary form must reproduce the above copyright
13d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *    notice, this list of conditions and the following disclaimer in
14d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *    the documentation and/or other materials provided with the
15d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *    distribution.
16d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *
17d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * 3. All advertising materials mentioning features or use of this
18d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *    software must display the following acknowledgment:
19d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *    "This product includes software developed by the OpenSSL Project
20d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *
22d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *    endorse or promote products derived from this software without
24d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *    prior written permission. For written permission, please contact
25d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *    openssl-core@openssl.org.
26d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *
27d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * 5. Products derived from this software may not be called "OpenSSL"
28d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *    nor may "OpenSSL" appear in their names without prior written
29d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *    permission of the OpenSSL Project.
30d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *
31d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * 6. Redistributions of any form whatsoever must retain the following
32d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *    acknowledgment:
33d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *    "This product includes software developed by the OpenSSL Project
34d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *
36d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
40d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * OF THE POSSIBILITY OF SUCH DAMAGE.
48d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * ====================================================================
49d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *
50d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * This product includes cryptographic software written by Eric Young
51d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * (eay@cryptsoft.com).  This product includes software written by Tim
52d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * Hudson (tjh@cryptsoft.com).
53d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *
54d9e397b599b13d642138480a28c14db7a136bf0Adam Langley */
55d9e397b599b13d642138480a28c14db7a136bf0Adam Langley/* ====================================================================
56d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
57d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *
58d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * Portions of the attached software ("Contribution") are developed by
59d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
60d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *
61d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * The Contribution is licensed pursuant to the OpenSSL open source
62d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * license provided above.
63d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *
64d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * The elliptic curve binary polynomial software is originally written by
65d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems
66d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * Laboratories. */
67d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
68d9e397b599b13d642138480a28c14db7a136bf0Adam Langley#ifndef OPENSSL_HEADER_EC_KEY_H
69d9e397b599b13d642138480a28c14db7a136bf0Adam Langley#define OPENSSL_HEADER_EC_KEY_H
70d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
71d9e397b599b13d642138480a28c14db7a136bf0Adam Langley#include <openssl/base.h>
72d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
73d9e397b599b13d642138480a28c14db7a136bf0Adam Langley#include <openssl/ec.h>
74d9e397b599b13d642138480a28c14db7a136bf0Adam Langley#include <openssl/engine.h>
75d9e397b599b13d642138480a28c14db7a136bf0Adam Langley#include <openssl/ex_data.h>
76d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
77d9e397b599b13d642138480a28c14db7a136bf0Adam Langley#if defined(__cplusplus)
78d9e397b599b13d642138480a28c14db7a136bf0Adam Langleyextern "C" {
79d9e397b599b13d642138480a28c14db7a136bf0Adam Langley#endif
80d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
81d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
82e9ada863a7b3e81f5d2b1e3bdd2305da902a87f5Adam Langley/* ec_key.h contains functions that handle elliptic-curve points that are
83d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * public/private keys. */
84d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
85d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
86d9e397b599b13d642138480a28c14db7a136bf0Adam Langley/* EC key objects. */
87d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
88d9e397b599b13d642138480a28c14db7a136bf0Adam Langley/* EC_KEY_new returns a fresh |EC_KEY| object or NULL on error. */
89d9e397b599b13d642138480a28c14db7a136bf0Adam LangleyOPENSSL_EXPORT EC_KEY *EC_KEY_new(void);
90d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
91d9e397b599b13d642138480a28c14db7a136bf0Adam Langley/* EC_KEY_new_method acts the same as |EC_KEY_new|, but takes an explicit
92d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * |ENGINE|. */
93d9e397b599b13d642138480a28c14db7a136bf0Adam LangleyOPENSSL_EXPORT EC_KEY *EC_KEY_new_method(const ENGINE *engine);
94d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
95d9e397b599b13d642138480a28c14db7a136bf0Adam Langley/* EC_KEY_new_by_curve_name returns a fresh EC_KEY for group specified by |nid|
96d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * or NULL on error. */
97d9e397b599b13d642138480a28c14db7a136bf0Adam LangleyOPENSSL_EXPORT EC_KEY *EC_KEY_new_by_curve_name(int nid);
98d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
99d9e397b599b13d642138480a28c14db7a136bf0Adam Langley/* EC_KEY_free frees all the data owned by |key| and |key| itself. */
100d9e397b599b13d642138480a28c14db7a136bf0Adam LangleyOPENSSL_EXPORT void EC_KEY_free(EC_KEY *key);
101d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
102d9e397b599b13d642138480a28c14db7a136bf0Adam Langley/* EC_KEY_copy sets |dst| equal to |src| and returns |dst| or NULL on error. */
103d9e397b599b13d642138480a28c14db7a136bf0Adam LangleyOPENSSL_EXPORT EC_KEY *EC_KEY_copy(EC_KEY *dst, const EC_KEY *src);
104d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
105d9e397b599b13d642138480a28c14db7a136bf0Adam Langley/* EC_KEY_dup returns a fresh copy of |src| or NULL on error. */
106d9e397b599b13d642138480a28c14db7a136bf0Adam LangleyOPENSSL_EXPORT EC_KEY *EC_KEY_dup(const EC_KEY *src);
107d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
108d9e397b599b13d642138480a28c14db7a136bf0Adam Langley/* EC_KEY_up_ref increases the reference count of |key|. It returns one on
109d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * success and zero otherwise. */
110d9e397b599b13d642138480a28c14db7a136bf0Adam LangleyOPENSSL_EXPORT int EC_KEY_up_ref(EC_KEY *key);
111d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
112d9e397b599b13d642138480a28c14db7a136bf0Adam Langley/* EC_KEY_is_opaque returns one if |key| is opaque and doesn't expose its key
113d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * material. Otherwise it return zero. */
114d9e397b599b13d642138480a28c14db7a136bf0Adam LangleyOPENSSL_EXPORT int EC_KEY_is_opaque(const EC_KEY *key);
115d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
116d9e397b599b13d642138480a28c14db7a136bf0Adam Langley/* EC_KEY_get0_group returns a pointer to the |EC_GROUP| object inside |key|. */
117d9e397b599b13d642138480a28c14db7a136bf0Adam LangleyOPENSSL_EXPORT const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key);
118d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
119d9e397b599b13d642138480a28c14db7a136bf0Adam Langley/* EC_KEY_set_group sets the |EC_GROUP| object that |key| will use to |group|.
120d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * It returns one on success and zero otherwise. */
121d9e397b599b13d642138480a28c14db7a136bf0Adam LangleyOPENSSL_EXPORT int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group);
122d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
123d9e397b599b13d642138480a28c14db7a136bf0Adam Langley/* EC_KEY_get0_private_key returns a pointer to the private key inside |key|. */
124d9e397b599b13d642138480a28c14db7a136bf0Adam LangleyOPENSSL_EXPORT const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *key);
125d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
126d9e397b599b13d642138480a28c14db7a136bf0Adam Langley/* EC_KEY_set_private_key sets the private key of |key| to |priv|. It returns
127d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * one on success and zero otherwise. */
128d9e397b599b13d642138480a28c14db7a136bf0Adam LangleyOPENSSL_EXPORT int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *prv);
129d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
130d9e397b599b13d642138480a28c14db7a136bf0Adam Langley/* EC_KEY_get0_public_key returns a pointer to the public key point inside
131d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * |key|. */
132d9e397b599b13d642138480a28c14db7a136bf0Adam LangleyOPENSSL_EXPORT const EC_POINT *EC_KEY_get0_public_key(const EC_KEY *key);
133d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
134d9e397b599b13d642138480a28c14db7a136bf0Adam Langley/* EC_KEY_set_public_key sets the public key of |key| to |pub|, by copying it.
135d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * It returns one on success and zero otherwise. */
136d9e397b599b13d642138480a28c14db7a136bf0Adam LangleyOPENSSL_EXPORT int EC_KEY_set_public_key(EC_KEY *key, const EC_POINT *pub);
137d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
138d9e397b599b13d642138480a28c14db7a136bf0Adam Langley#define EC_PKEY_NO_PARAMETERS 0x001
139d9e397b599b13d642138480a28c14db7a136bf0Adam Langley#define EC_PKEY_NO_PUBKEY 0x002
140d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
141d9e397b599b13d642138480a28c14db7a136bf0Adam Langley/* EC_KEY_get_enc_flags returns the encoding flags for |key|, which is a
142d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * bitwise-OR of |EC_PKEY_*| values. */
143d9e397b599b13d642138480a28c14db7a136bf0Adam LangleyOPENSSL_EXPORT unsigned EC_KEY_get_enc_flags(const EC_KEY *key);
144d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
145d9e397b599b13d642138480a28c14db7a136bf0Adam Langley/* EC_KEY_set_enc_flags sets the encoding flags for |key|, which is a
146d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * bitwise-OR of |EC_PKEY_*| values. */
147d9e397b599b13d642138480a28c14db7a136bf0Adam LangleyOPENSSL_EXPORT void EC_KEY_set_enc_flags(EC_KEY *key, unsigned flags);
148d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
149d9e397b599b13d642138480a28c14db7a136bf0Adam Langley/* EC_KEY_get_conv_form returns the conversation form that will be used by
150d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * |key|. */
151d9e397b599b13d642138480a28c14db7a136bf0Adam LangleyOPENSSL_EXPORT point_conversion_form_t EC_KEY_get_conv_form(const EC_KEY *key);
152d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
153d9e397b599b13d642138480a28c14db7a136bf0Adam Langley/* EC_KEY_set_conv_form sets the conversion form to be used by |key|. */
154d9e397b599b13d642138480a28c14db7a136bf0Adam LangleyOPENSSL_EXPORT void EC_KEY_set_conv_form(EC_KEY *key,
155d9e397b599b13d642138480a28c14db7a136bf0Adam Langley                                         point_conversion_form_t cform);
156d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
157d9e397b599b13d642138480a28c14db7a136bf0Adam Langley/* EC_KEY_check_key performs several checks on |key| (possibly including an
158d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * expensive check that the public key is in the primary subgroup). It returns
159d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * one if all checks pass and zero otherwise. If it returns zero then detail
160d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * about the problem can be found on the error stack. */
161d9e397b599b13d642138480a28c14db7a136bf0Adam LangleyOPENSSL_EXPORT int EC_KEY_check_key(const EC_KEY *key);
162d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
163d9e397b599b13d642138480a28c14db7a136bf0Adam Langley/* EC_KEY_set_public_key_affine_coordinates sets the public key in |key| to
164d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * (|x|, |y|). It returns one on success and zero otherwise. */
165d9e397b599b13d642138480a28c14db7a136bf0Adam LangleyOPENSSL_EXPORT int EC_KEY_set_public_key_affine_coordinates(EC_KEY *key,
166d9e397b599b13d642138480a28c14db7a136bf0Adam Langley                                                            BIGNUM *x,
167d9e397b599b13d642138480a28c14db7a136bf0Adam Langley                                                            BIGNUM *y);
168d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
169d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
170d9e397b599b13d642138480a28c14db7a136bf0Adam Langley/* Key generation. */
171d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
172d9e397b599b13d642138480a28c14db7a136bf0Adam Langley/* EC_KEY_generate_key generates a random, private key, calculates the
173d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * corresponding public key and stores both in |key|. It returns one on success
174d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * or zero otherwise. */
175d9e397b599b13d642138480a28c14db7a136bf0Adam LangleyOPENSSL_EXPORT int EC_KEY_generate_key(EC_KEY *key);
176d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
177d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
178d9e397b599b13d642138480a28c14db7a136bf0Adam Langley/* Serialisation. */
179d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
180d9e397b599b13d642138480a28c14db7a136bf0Adam Langley/* d2i_ECPrivateKey parses an ASN.1, DER-encoded, private key from |len| bytes
181d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * at |*inp|. If |out_key| is not NULL then, on exit, a pointer to the result
182d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * is in |*out_key|. If |*out_key| is already non-NULL on entry then the result
183d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * is written directly into |*out_key|, otherwise a fresh |EC_KEY| is
184d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * allocated. On successful exit, |*inp| is advanced past the DER structure. It
185d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * returns the result or NULL on error. */
186d9e397b599b13d642138480a28c14db7a136bf0Adam LangleyOPENSSL_EXPORT EC_KEY *d2i_ECPrivateKey(EC_KEY **out_key, const uint8_t **inp,
187d9e397b599b13d642138480a28c14db7a136bf0Adam Langley                                        long len);
188d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
189b8494591d1b1a143f3b192d845c238bbf3bc629dKenny Root/* i2d_ECPrivateKey marshals an EC private key from |key| to an ASN.1, DER
190d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * structure. If |outp| is not NULL then the result is written to |*outp| and
191d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * |*outp| is advanced just past the output. It returns the number of bytes in
192d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * the result, whether written or not, or a negative value on error. */
193d9e397b599b13d642138480a28c14db7a136bf0Adam LangleyOPENSSL_EXPORT int i2d_ECPrivateKey(const EC_KEY *key, uint8_t **outp);
194d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
195d9e397b599b13d642138480a28c14db7a136bf0Adam Langley/* d2i_ECParameters parses an ASN.1, DER-encoded, set of EC parameters from
196d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * |len| bytes at |*inp|. If |out_key| is not NULL then, on exit, a pointer to
197d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * the result is in |*out_key|. If |*out_key| is already non-NULL on entry then
198d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * the result is written directly into |*out_key|, otherwise a fresh |EC_KEY|
199d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * is allocated. On successful exit, |*inp| is advanced past the DER structure.
200d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * It returns the result or NULL on error. */
201d9e397b599b13d642138480a28c14db7a136bf0Adam LangleyOPENSSL_EXPORT EC_KEY *d2i_ECParameters(EC_KEY **out_key, const uint8_t **inp,
202d9e397b599b13d642138480a28c14db7a136bf0Adam Langley                                        long len);
203d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
204d9e397b599b13d642138480a28c14db7a136bf0Adam Langley/* i2d_ECParameters marshals EC parameters from |key| to an ASN.1, DER
205d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * structure. If |outp| is not NULL then the result is written to |*outp| and
206d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * |*outp| is advanced just past the output. It returns the number of bytes in
207d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * the result, whether written or not, or a negative value on error. */
208d9e397b599b13d642138480a28c14db7a136bf0Adam LangleyOPENSSL_EXPORT int i2d_ECParameters(const EC_KEY *key, uint8_t **outp);
209d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
210d9e397b599b13d642138480a28c14db7a136bf0Adam Langley/* o2i_ECPublicKey parses an EC point from |len| bytes at |*inp| into
211d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * |*out_key|. Note that this differs from the d2i format in that |*out_key|
212b8494591d1b1a143f3b192d845c238bbf3bc629dKenny Root * must be non-NULL with a group set. On successful exit, |*inp| is advanced by
213b8494591d1b1a143f3b192d845c238bbf3bc629dKenny Root * |len| bytes. It returns |*out_key| or NULL on error. */
214d9e397b599b13d642138480a28c14db7a136bf0Adam LangleyOPENSSL_EXPORT EC_KEY *o2i_ECPublicKey(EC_KEY **out_key, const uint8_t **inp,
215d9e397b599b13d642138480a28c14db7a136bf0Adam Langley                                       long len);
216d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
217d9e397b599b13d642138480a28c14db7a136bf0Adam Langley/* i2o_ECPublicKey marshals an EC point from |key|. If |outp| is not NULL then
218d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * the result is written to |*outp| and |*outp| is advanced just past the
219d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * output. It returns the number of bytes in the result, whether written or
220d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * not, or a negative value on error. */
221d9e397b599b13d642138480a28c14db7a136bf0Adam LangleyOPENSSL_EXPORT int i2o_ECPublicKey(const EC_KEY *key, unsigned char **outp);
222d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
223d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
224d9e397b599b13d642138480a28c14db7a136bf0Adam Langley/* ex_data functions.
225d9e397b599b13d642138480a28c14db7a136bf0Adam Langley *
226d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * These functions are wrappers. See |ex_data.h| for details. */
227d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
228d9e397b599b13d642138480a28c14db7a136bf0Adam LangleyOPENSSL_EXPORT int EC_KEY_get_ex_new_index(long argl, void *argp,
2294139edb02e59e7ad48e0a8f4c02e45923bc8a344Adam Langley                                           CRYPTO_EX_unused *unused,
230d9e397b599b13d642138480a28c14db7a136bf0Adam Langley                                           CRYPTO_EX_dup *dup_func,
231d9e397b599b13d642138480a28c14db7a136bf0Adam Langley                                           CRYPTO_EX_free *free_func);
232d9e397b599b13d642138480a28c14db7a136bf0Adam LangleyOPENSSL_EXPORT int EC_KEY_set_ex_data(EC_KEY *r, int idx, void *arg);
233d9e397b599b13d642138480a28c14db7a136bf0Adam LangleyOPENSSL_EXPORT void *EC_KEY_get_ex_data(const EC_KEY *r, int idx);
234d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
235d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
236d9e397b599b13d642138480a28c14db7a136bf0Adam Langley/* ECDSA method. */
237d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
238d9e397b599b13d642138480a28c14db7a136bf0Adam Langley/* ECDSA_FLAG_OPAQUE specifies that this ECDSA_METHOD does not expose its key
239d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * material. This may be set if, for instance, it is wrapping some other crypto
240d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * API, like a platform key store. */
241d9e397b599b13d642138480a28c14db7a136bf0Adam Langley#define ECDSA_FLAG_OPAQUE 1
242d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
243d9e397b599b13d642138480a28c14db7a136bf0Adam Langley/* ecdsa_method_st is a structure of function pointers for implementing ECDSA.
244d9e397b599b13d642138480a28c14db7a136bf0Adam Langley * See engine.h. */
245d9e397b599b13d642138480a28c14db7a136bf0Adam Langleystruct ecdsa_method_st {
246d9e397b599b13d642138480a28c14db7a136bf0Adam Langley  struct openssl_method_common_st common;
247d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
248d9e397b599b13d642138480a28c14db7a136bf0Adam Langley  void *app_data;
249d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
250d9e397b599b13d642138480a28c14db7a136bf0Adam Langley  int (*init)(EC_KEY *key);
251d9e397b599b13d642138480a28c14db7a136bf0Adam Langley  int (*finish)(EC_KEY *key);
252d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
253d9e397b599b13d642138480a28c14db7a136bf0Adam Langley  /* group_order_size returns the number of bytes needed to represent the order
254d9e397b599b13d642138480a28c14db7a136bf0Adam Langley   * of the group. This is used to calculate the maximum size of an ECDSA
255d9e397b599b13d642138480a28c14db7a136bf0Adam Langley   * signature in |ECDSA_size|. */
256d9e397b599b13d642138480a28c14db7a136bf0Adam Langley  size_t (*group_order_size)(const EC_KEY *key);
257d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
258d9e397b599b13d642138480a28c14db7a136bf0Adam Langley  /* sign matches the arguments and behaviour of |ECDSA_sign|. */
259d9e397b599b13d642138480a28c14db7a136bf0Adam Langley  int (*sign)(const uint8_t *digest, size_t digest_len, uint8_t *sig,
260d9e397b599b13d642138480a28c14db7a136bf0Adam Langley              unsigned int *sig_len, EC_KEY *eckey);
261d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
262d9e397b599b13d642138480a28c14db7a136bf0Adam Langley  /* verify matches the arguments and behaviour of |ECDSA_verify|. */
263d9e397b599b13d642138480a28c14db7a136bf0Adam Langley  int (*verify)(const uint8_t *digest, size_t digest_len, const uint8_t *sig,
264d9e397b599b13d642138480a28c14db7a136bf0Adam Langley                size_t sig_len, EC_KEY *eckey);
265d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
266d9e397b599b13d642138480a28c14db7a136bf0Adam Langley  int flags;
267d9e397b599b13d642138480a28c14db7a136bf0Adam Langley};
268d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
269d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
270f7e890d94bfb2ecad87621eed301e1897b5a6aefAdam Langley/* Deprecated functions. */
271f7e890d94bfb2ecad87621eed301e1897b5a6aefAdam Langley
272f7e890d94bfb2ecad87621eed301e1897b5a6aefAdam Langley/* EC_KEY_set_asn1_flag does nothing. */
273f7e890d94bfb2ecad87621eed301e1897b5a6aefAdam LangleyOPENSSL_EXPORT void EC_KEY_set_asn1_flag(EC_KEY *key, int flag);
274f7e890d94bfb2ecad87621eed301e1897b5a6aefAdam Langley
275f7e890d94bfb2ecad87621eed301e1897b5a6aefAdam Langley
276d9e397b599b13d642138480a28c14db7a136bf0Adam Langley#if defined(__cplusplus)
277d9e397b599b13d642138480a28c14db7a136bf0Adam Langley}  /* extern C */
278d9e397b599b13d642138480a28c14db7a136bf0Adam Langley#endif
279d9e397b599b13d642138480a28c14db7a136bf0Adam Langley
280d9e397b599b13d642138480a28c14db7a136bf0Adam Langley#endif  /* OPENSSL_HEADER_EC_KEY_H */
281