summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/ec/ecp_oct.c
diff options
context:
space:
mode:
authortb <>2024-11-02 15:50:50 +0000
committertb <>2024-11-02 15:50:50 +0000
commit04277a8a70494b7b35dc16881dea60c36382073c (patch)
treeafddf8953e07c4b922c56d9d930051ace171ebfe /src/lib/libcrypto/ec/ecp_oct.c
parent7ac9d79f59c8680854d47ab54d8cb8d38183a391 (diff)
downloadopenbsd-04277a8a70494b7b35dc16881dea60c36382073c.tar.gz
openbsd-04277a8a70494b7b35dc16881dea60c36382073c.tar.bz2
openbsd-04277a8a70494b7b35dc16881dea60c36382073c.zip
Merge compressed coordinate setting back into ecp_smpl and ec_lib
The reason these were in separate files was FIPS. Not our problem.
Diffstat (limited to 'src/lib/libcrypto/ec/ecp_oct.c')
-rw-r--r--src/lib/libcrypto/ec/ecp_oct.c169
1 files changed, 0 insertions, 169 deletions
diff --git a/src/lib/libcrypto/ec/ecp_oct.c b/src/lib/libcrypto/ec/ecp_oct.c
deleted file mode 100644
index 85467a4143..0000000000
--- a/src/lib/libcrypto/ec/ecp_oct.c
+++ /dev/null
@@ -1,169 +0,0 @@
1/* $OpenBSD: ecp_oct.c,v 1.32 2024/11/02 09:21:04 tb Exp $ */
2/* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de>
3 * for the OpenSSL project.
4 * Includes code written by Bodo Moeller for the OpenSSL project.
5*/
6/* ====================================================================
7 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * 3. All advertising materials mentioning features or use of this
22 * software must display the following acknowledgment:
23 * "This product includes software developed by the OpenSSL Project
24 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
25 *
26 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27 * endorse or promote products derived from this software without
28 * prior written permission. For written permission, please contact
29 * openssl-core@openssl.org.
30 *
31 * 5. Products derived from this software may not be called "OpenSSL"
32 * nor may "OpenSSL" appear in their names without prior written
33 * permission of the OpenSSL Project.
34 *
35 * 6. Redistributions of any form whatsoever must retain the following
36 * acknowledgment:
37 * "This product includes software developed by the OpenSSL Project
38 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51 * OF THE POSSIBILITY OF SUCH DAMAGE.
52 * ====================================================================
53 *
54 * This product includes cryptographic software written by Eric Young
55 * (eay@cryptsoft.com). This product includes software written by Tim
56 * Hudson (tjh@cryptsoft.com).
57 *
58 */
59/* ====================================================================
60 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
61 * Portions of this software developed by SUN MICROSYSTEMS, INC.,
62 * and contributed to the OpenSSL project.
63 */
64
65#include <stddef.h>
66
67#include <openssl/bn.h>
68#include <openssl/ec.h>
69#include <openssl/err.h>
70
71#include "ec_local.h"
72
73int
74ec_GFp_simple_set_compressed_coordinates(const EC_GROUP *group,
75 EC_POINT *point, const BIGNUM *in_x, int y_bit, BN_CTX *ctx)
76{
77 const BIGNUM *p = &group->field, *a = &group->a, *b = &group->b;
78 BIGNUM *w, *x, *y;
79 int ret = 0;
80
81 y_bit = (y_bit != 0);
82
83 BN_CTX_start(ctx);
84
85 if ((w = BN_CTX_get(ctx)) == NULL)
86 goto err;
87 if ((x = BN_CTX_get(ctx)) == NULL)
88 goto err;
89 if ((y = BN_CTX_get(ctx)) == NULL)
90 goto err;
91
92 /*
93 * Weierstrass equation: y^2 = x^3 + ax + b, so y is one of the
94 * square roots of x^3 + ax + b. The y-bit indicates which one.
95 */
96
97 /* XXX - should we not insist on 0 <= x < p instead? */
98 if (!BN_nnmod(x, in_x, p, ctx))
99 goto err;
100
101 if (group->meth->field_encode != NULL) {
102 if (!group->meth->field_encode(group, x, x, ctx))
103 goto err;
104 }
105
106 /* y = x^3 */
107 if (!group->meth->field_sqr(group, y, x, ctx))
108 goto err;
109 if (!group->meth->field_mul(group, y, y, x, ctx))
110 goto err;
111
112 /* y += ax */
113 if (group->a_is_minus3) {
114 if (!BN_mod_lshift1_quick(w, x, p))
115 goto err;
116 if (!BN_mod_add_quick(w, w, x, p))
117 goto err;
118 if (!BN_mod_sub_quick(y, y, w, p))
119 goto err;
120 } else {
121 if (!group->meth->field_mul(group, w, a, x, ctx))
122 goto err;
123 if (!BN_mod_add_quick(y, y, w, p))
124 goto err;
125 }
126
127 /* y += b */
128 if (!BN_mod_add_quick(y, y, b, p))
129 goto err;
130
131 if (group->meth->field_decode != NULL) {
132 if (!group->meth->field_decode(group, x, x, ctx))
133 goto err;
134 if (!group->meth->field_decode(group, y, y, ctx))
135 goto err;
136 }
137
138 if (!BN_mod_sqrt(y, y, p, ctx)) {
139 ECerror(EC_R_INVALID_COMPRESSED_POINT);
140 goto err;
141 }
142
143 if (y_bit == BN_is_odd(y))
144 goto done;
145
146 if (BN_is_zero(y)) {
147 ECerror(EC_R_INVALID_COMPRESSION_BIT);
148 goto err;
149 }
150 if (!BN_usub(y, &group->field, y))
151 goto err;
152
153 if (y_bit != BN_is_odd(y)) {
154 /* Can only happen if p is even and should not be reachable. */
155 ECerror(ERR_R_INTERNAL_ERROR);
156 goto err;
157 }
158
159 done:
160 if (!EC_POINT_set_affine_coordinates(group, point, x, y, ctx))
161 goto err;
162
163 ret = 1;
164
165 err:
166 BN_CTX_end(ctx);
167
168 return ret;
169}