summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/ec/ec_local.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/ec/ec_local.h')
-rw-r--r--src/lib/libcrypto/ec/ec_local.h254
1 files changed, 0 insertions, 254 deletions
diff --git a/src/lib/libcrypto/ec/ec_local.h b/src/lib/libcrypto/ec/ec_local.h
deleted file mode 100644
index c7a54d3a2b..0000000000
--- a/src/lib/libcrypto/ec/ec_local.h
+++ /dev/null
@@ -1,254 +0,0 @@
1/* $OpenBSD: ec_local.h,v 1.67 2025/03/24 13:07:04 jsing Exp $ */
2/*
3 * Originally written by Bodo Moeller for the OpenSSL project.
4 */
5/* ====================================================================
6 * Copyright (c) 1998-2010 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58/* ====================================================================
59 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
60 *
61 * Portions of the attached software ("Contribution") are developed by
62 * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
63 *
64 * The Contribution is licensed pursuant to the OpenSSL open source
65 * license provided above.
66 *
67 * The elliptic curve binary polynomial software is originally written by
68 * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories.
69 *
70 */
71
72#include <stdlib.h>
73
74#include <openssl/bn.h>
75#include <openssl/ec.h>
76#include <openssl/objects.h>
77
78#include "bn_local.h"
79
80__BEGIN_HIDDEN_DECLS
81
82typedef struct ec_method_st {
83 int (*group_set_curve)(EC_GROUP *, const BIGNUM *p, const BIGNUM *a,
84 const BIGNUM *b, BN_CTX *);
85 int (*group_get_curve)(const EC_GROUP *, BIGNUM *p, BIGNUM *a,
86 BIGNUM *b, BN_CTX *);
87
88 int (*point_is_on_curve)(const EC_GROUP *, const EC_POINT *, BN_CTX *);
89 int (*point_cmp)(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b,
90 BN_CTX *);
91
92 int (*point_set_affine_coordinates)(const EC_GROUP *, EC_POINT *,
93 const BIGNUM *x, const BIGNUM *y, BN_CTX *);
94 int (*point_get_affine_coordinates)(const EC_GROUP *, const EC_POINT *,
95 BIGNUM *x, BIGNUM *y, BN_CTX *);
96
97 /* Only used by the wNAF code. */
98 int (*points_make_affine)(const EC_GROUP *, size_t num, EC_POINT **,
99 BN_CTX *);
100
101 int (*add)(const EC_GROUP *, EC_POINT *r, const EC_POINT *a,
102 const EC_POINT *b, BN_CTX *);
103 int (*dbl)(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *);
104 int (*invert)(const EC_GROUP *, EC_POINT *, BN_CTX *);
105
106 int (*mul_single_ct)(const EC_GROUP *group, EC_POINT *r,
107 const BIGNUM *scalar, const EC_POINT *point, BN_CTX *);
108 int (*mul_double_nonct)(const EC_GROUP *group, EC_POINT *r,
109 const BIGNUM *scalar1, const EC_POINT *point1,
110 const BIGNUM *scalar2, const EC_POINT *point2, BN_CTX *);
111
112 /*
113 * These can be used by 'add' and 'dbl' so that the same implementations
114 * of point operations can be used with different optimized versions of
115 * expensive field operations.
116 */
117 int (*field_mul)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
118 const BIGNUM *b, BN_CTX *);
119 int (*field_sqr)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
120 BN_CTX *);
121
122 /* Encode to and decode from other forms (e.g. Montgomery). */
123 int (*field_encode)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
124 BN_CTX *);
125 int (*field_decode)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
126 BN_CTX *);
127} EC_METHOD;
128
129struct ec_group_st {
130 const EC_METHOD *meth;
131
132 EC_POINT *generator; /* Optional */
133 BIGNUM *order;
134 BIGNUM *cofactor;
135
136 int nid; /* Optional NID for named curve. */
137
138 /* ASN.1 encoding controls. */
139 int asn1_flag;
140 point_conversion_form_t asn1_form;
141
142 /* Optional seed for parameters (appears in ASN.1). */
143 unsigned char *seed;
144 size_t seed_len;
145
146 /*
147 * Coefficients of the Weierstrass equation y^2 = x^3 + a*x + b (mod p).
148 */
149 BIGNUM *p;
150 BIGNUM *a;
151 BIGNUM *b;
152
153 /* Enables optimized point arithmetics for special case. */
154 int a_is_minus3;
155
156 /* Montgomery context used by EC_GFp_mont_method. */
157 BN_MONT_CTX *mont_ctx;
158} /* EC_GROUP */;
159
160struct ec_point_st {
161 const EC_METHOD *meth;
162
163 /*
164 * Jacobian projective coordinates: (X, Y, Z) represents (X/Z^2, Y/Z^3)
165 * if Z != 0
166 */
167 BIGNUM *X;
168 BIGNUM *Y;
169 BIGNUM *Z;
170 int Z_is_one; /* enable optimized point arithmetics for special case */
171} /* EC_POINT */;
172
173const EC_METHOD *EC_GFp_simple_method(void);
174const EC_METHOD *EC_GFp_mont_method(void);
175
176/* Compute r = scalar1 * point1 + scalar2 * point2 in non-constant time. */
177int ec_wnaf_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar1,
178 const EC_POINT *point1, const BIGNUM *scalar2, const EC_POINT *point2,
179 BN_CTX *ctx);
180
181int ec_group_is_builtin_curve(const EC_GROUP *group, int *out_nid);
182
183/*
184 * Wrappers around the unergonomic EC_POINT_{oct2point,point2oct}().
185 */
186int ec_point_from_octets(const EC_GROUP *group, const unsigned char *buf,
187 size_t buf_len, EC_POINT **out_point, uint8_t *out_form, BN_CTX *ctx_in);
188int ec_point_to_octets(const EC_GROUP *group, const EC_POINT *point, int form,
189 unsigned char **out_buf, size_t *len, BN_CTX *ctx_in);
190
191/* Public API in OpenSSL */
192const BIGNUM *EC_GROUP_get0_cofactor(const EC_GROUP *group);
193const BIGNUM *EC_GROUP_get0_order(const EC_GROUP *group);
194
195struct ec_key_method_st {
196 const char *name;
197 int32_t flags;
198 int (*init)(EC_KEY *key);
199 void (*finish)(EC_KEY *key);
200 int (*copy)(EC_KEY *dest, const EC_KEY *src);
201 int (*set_group)(EC_KEY *key, const EC_GROUP *grp);
202 int (*set_private)(EC_KEY *key, const BIGNUM *priv_key);
203 int (*set_public)(EC_KEY *key, const EC_POINT *pub_key);
204 int (*keygen)(EC_KEY *key);
205 int (*compute_key)(unsigned char **out, size_t *out_len,
206 const EC_POINT *pub_key, const EC_KEY *ecdh);
207 int (*sign)(int type, const unsigned char *dgst, int dlen, unsigned char
208 *sig, unsigned int *siglen, const BIGNUM *kinv,
209 const BIGNUM *r, EC_KEY *eckey);
210 int (*sign_setup)(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp,
211 BIGNUM **rp);
212 ECDSA_SIG *(*sign_sig)(const unsigned char *dgst, int dgst_len,
213 const BIGNUM *in_kinv, const BIGNUM *in_r,
214 EC_KEY *eckey);
215 int (*verify)(int type, const unsigned char *dgst, int dgst_len,
216 const unsigned char *sigbuf, int sig_len, EC_KEY *eckey);
217 int (*verify_sig)(const unsigned char *dgst, int dgst_len,
218 const ECDSA_SIG *sig, EC_KEY *eckey);
219} /* EC_KEY_METHOD */;
220
221struct ec_key_st {
222 const EC_KEY_METHOD *meth;
223
224 int version;
225
226 EC_GROUP *group;
227
228 EC_POINT *pub_key;
229 BIGNUM *priv_key;
230
231 unsigned int enc_flag;
232 point_conversion_form_t conv_form;
233
234 int references;
235 int flags;
236
237 CRYPTO_EX_DATA ex_data;
238} /* EC_KEY */;
239
240int eckey_compute_pubkey(EC_KEY *eckey);
241int ecdh_compute_key(unsigned char **out, size_t *out_len,
242 const EC_POINT *pub_key, const EC_KEY *ecdh);
243int ecdsa_verify(int type, const unsigned char *dgst, int dgst_len,
244 const unsigned char *sigbuf, int sig_len, EC_KEY *eckey);
245int ecdsa_verify_sig(const unsigned char *dgst, int dgst_len,
246 const ECDSA_SIG *sig, EC_KEY *eckey);
247
248/*
249 * ECDH Key Derivation Function as defined in ANSI X9.63.
250 */
251int ecdh_KDF_X9_63(unsigned char *out, size_t outlen, const unsigned char *Z,
252 size_t Zlen, const unsigned char *sinfo, size_t sinfolen, const EVP_MD *md);
253
254__END_HIDDEN_DECLS