summaryrefslogtreecommitdiff
path: root/deps/openssl/openssl/crypto/ec/ec2_smpl.c
diff options
context:
space:
mode:
authorShigeki Ohtsu <ohtsu@ohtsu.org>2018-03-29 16:39:12 +0900
committerShigeki Ohtsu <ohtsu@ohtsu.org>2018-04-10 06:45:42 +0900
commit66cb29e64621fdd1aa5e377a395ff107d21a613b (patch)
treef05243a51577e04b6f1c4a2f8a6b7b2f05786079 /deps/openssl/openssl/crypto/ec/ec2_smpl.c
parent38c97f5dc7ff3fbf83982d0268fc9e93cfc00c7d (diff)
downloadandroid-node-v8-66cb29e64621fdd1aa5e377a395ff107d21a613b.tar.gz
android-node-v8-66cb29e64621fdd1aa5e377a395ff107d21a613b.tar.bz2
android-node-v8-66cb29e64621fdd1aa5e377a395ff107d21a613b.zip
deps: upgrade openssl sources to 1.1.0h
This updates all sources in deps/openssl/openssl with openssl-1.1.0h. Fixes: https://github.com/nodejs/node/issues/4270 PR-URL: https://github.com/nodejs/node/pull/19794 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rod Vagg <rod@vagg.org> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Diffstat (limited to 'deps/openssl/openssl/crypto/ec/ec2_smpl.c')
-rw-r--r--deps/openssl/openssl/crypto/ec/ec2_smpl.c266
1 files changed, 113 insertions, 153 deletions
diff --git a/deps/openssl/openssl/crypto/ec/ec2_smpl.c b/deps/openssl/openssl/crypto/ec/ec2_smpl.c
index 5b27b91fcc..cfeef5fc74 100644
--- a/deps/openssl/openssl/crypto/ec/ec2_smpl.c
+++ b/deps/openssl/openssl/crypto/ec/ec2_smpl.c
@@ -1,4 +1,12 @@
-/* crypto/ec/ec2_smpl.c */
+/*
+ * Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the OpenSSL license (the "License"). You may not use
+ * this file except in compliance with the License. You can obtain a copy
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+
/* ====================================================================
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
*
@@ -13,70 +21,14 @@
* Douglas Stebila of Sun Microsystems Laboratories.
*
*/
-/* ====================================================================
- * Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. All advertising materials mentioning features or use of this
- * software must display the following acknowledgment:
- * "This product includes software developed by the OpenSSL Project
- * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
- *
- * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
- * endorse or promote products derived from this software without
- * prior written permission. For written permission, please contact
- * openssl-core@openssl.org.
- *
- * 5. Products derived from this software may not be called "OpenSSL"
- * nor may "OpenSSL" appear in their names without prior written
- * permission of the OpenSSL Project.
- *
- * 6. Redistributions of any form whatsoever must retain the following
- * acknowledgment:
- * "This product includes software developed by the OpenSSL Project
- * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
- *
- * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
- * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE.
- * ====================================================================
- *
- * This product includes cryptographic software written by Eric Young
- * (eay@cryptsoft.com). This product includes software written by Tim
- * Hudson (tjh@cryptsoft.com).
- *
- */
#include <openssl/err.h>
+#include "internal/bn_int.h"
#include "ec_lcl.h"
#ifndef OPENSSL_NO_EC2M
-# ifdef OPENSSL_FIPS
-# include <openssl/fips.h>
-# endif
-
const EC_METHOD *EC_GF2m_simple_method(void)
{
static const EC_METHOD ret = {
@@ -89,6 +41,7 @@ const EC_METHOD *EC_GF2m_simple_method(void)
ec_GF2m_simple_group_set_curve,
ec_GF2m_simple_group_get_curve,
ec_GF2m_simple_group_get_degree,
+ ec_group_simple_order_bits,
ec_GF2m_simple_group_check_discriminant,
ec_GF2m_simple_point_init,
ec_GF2m_simple_point_finish,
@@ -121,14 +74,18 @@ const EC_METHOD *EC_GF2m_simple_method(void)
ec_GF2m_simple_field_div,
0 /* field_encode */ ,
0 /* field_decode */ ,
- 0 /* field_set_to_one */
+ 0, /* field_set_to_one */
+ ec_key_simple_priv2oct,
+ ec_key_simple_oct2priv,
+ 0, /* set private */
+ ec_key_simple_generate_key,
+ ec_key_simple_check_key,
+ ec_key_simple_generate_public_key,
+ 0, /* keycopy */
+ 0, /* keyfinish */
+ ecdh_simple_compute_key
};
-# ifdef OPENSSL_FIPS
- if (FIPS_mode())
- return fips_ec_gf2m_simple_method();
-# endif
-
return &ret;
}
@@ -138,9 +95,16 @@ const EC_METHOD *EC_GF2m_simple_method(void)
*/
int ec_GF2m_simple_group_init(EC_GROUP *group)
{
- BN_init(&group->field);
- BN_init(&group->a);
- BN_init(&group->b);
+ group->field = BN_new();
+ group->a = BN_new();
+ group->b = BN_new();
+
+ if (group->field == NULL || group->a == NULL || group->b == NULL) {
+ BN_free(group->field);
+ BN_free(group->a);
+ BN_free(group->b);
+ return 0;
+ }
return 1;
}
@@ -150,9 +114,9 @@ int ec_GF2m_simple_group_init(EC_GROUP *group)
*/
void ec_GF2m_simple_group_finish(EC_GROUP *group)
{
- BN_free(&group->field);
- BN_free(&group->a);
- BN_free(&group->b);
+ BN_free(group->field);
+ BN_free(group->a);
+ BN_free(group->b);
}
/*
@@ -161,9 +125,9 @@ void ec_GF2m_simple_group_finish(EC_GROUP *group)
*/
void ec_GF2m_simple_group_clear_finish(EC_GROUP *group)
{
- BN_clear_free(&group->field);
- BN_clear_free(&group->a);
- BN_clear_free(&group->b);
+ BN_clear_free(group->field);
+ BN_clear_free(group->a);
+ BN_clear_free(group->b);
group->poly[0] = 0;
group->poly[1] = 0;
group->poly[2] = 0;
@@ -178,12 +142,11 @@ void ec_GF2m_simple_group_clear_finish(EC_GROUP *group)
*/
int ec_GF2m_simple_group_copy(EC_GROUP *dest, const EC_GROUP *src)
{
- int i;
- if (!BN_copy(&dest->field, &src->field))
+ if (!BN_copy(dest->field, src->field))
return 0;
- if (!BN_copy(&dest->a, &src->a))
+ if (!BN_copy(dest->a, src->a))
return 0;
- if (!BN_copy(&dest->b, &src->b))
+ if (!BN_copy(dest->b, src->b))
return 0;
dest->poly[0] = src->poly[0];
dest->poly[1] = src->poly[1];
@@ -191,16 +154,14 @@ int ec_GF2m_simple_group_copy(EC_GROUP *dest, const EC_GROUP *src)
dest->poly[3] = src->poly[3];
dest->poly[4] = src->poly[4];
dest->poly[5] = src->poly[5];
- if (bn_wexpand(&dest->a, (int)(dest->poly[0] + BN_BITS2 - 1) / BN_BITS2)
- == NULL)
+ if (bn_wexpand(dest->a, (int)(dest->poly[0] + BN_BITS2 - 1) / BN_BITS2) ==
+ NULL)
return 0;
- if (bn_wexpand(&dest->b, (int)(dest->poly[0] + BN_BITS2 - 1) / BN_BITS2)
- == NULL)
+ if (bn_wexpand(dest->b, (int)(dest->poly[0] + BN_BITS2 - 1) / BN_BITS2) ==
+ NULL)
return 0;
- for (i = dest->a.top; i < dest->a.dmax; i++)
- dest->a.d[i] = 0;
- for (i = dest->b.top; i < dest->b.dmax; i++)
- dest->b.d[i] = 0;
+ bn_set_all_zero(dest->a);
+ bn_set_all_zero(dest->b);
return 1;
}
@@ -212,31 +173,29 @@ int ec_GF2m_simple_group_set_curve(EC_GROUP *group,
int ret = 0, i;
/* group->field */
- if (!BN_copy(&group->field, p))
+ if (!BN_copy(group->field, p))
goto err;
- i = BN_GF2m_poly2arr(&group->field, group->poly, 6) - 1;
+ i = BN_GF2m_poly2arr(group->field, group->poly, 6) - 1;
if ((i != 5) && (i != 3)) {
ECerr(EC_F_EC_GF2M_SIMPLE_GROUP_SET_CURVE, EC_R_UNSUPPORTED_FIELD);
goto err;
}
/* group->a */
- if (!BN_GF2m_mod_arr(&group->a, a, group->poly))
+ if (!BN_GF2m_mod_arr(group->a, a, group->poly))
goto err;
- if (bn_wexpand(&group->a, (int)(group->poly[0] + BN_BITS2 - 1) / BN_BITS2)
+ if (bn_wexpand(group->a, (int)(group->poly[0] + BN_BITS2 - 1) / BN_BITS2)
== NULL)
goto err;
- for (i = group->a.top; i < group->a.dmax; i++)
- group->a.d[i] = 0;
+ bn_set_all_zero(group->a);
/* group->b */
- if (!BN_GF2m_mod_arr(&group->b, b, group->poly))
+ if (!BN_GF2m_mod_arr(group->b, b, group->poly))
goto err;
- if (bn_wexpand(&group->b, (int)(group->poly[0] + BN_BITS2 - 1) / BN_BITS2)
+ if (bn_wexpand(group->b, (int)(group->poly[0] + BN_BITS2 - 1) / BN_BITS2)
== NULL)
goto err;
- for (i = group->b.top; i < group->b.dmax; i++)
- group->b.d[i] = 0;
+ bn_set_all_zero(group->b);
ret = 1;
err:
@@ -253,17 +212,17 @@ int ec_GF2m_simple_group_get_curve(const EC_GROUP *group, BIGNUM *p,
int ret = 0;
if (p != NULL) {
- if (!BN_copy(p, &group->field))
+ if (!BN_copy(p, group->field))
return 0;
}
if (a != NULL) {
- if (!BN_copy(a, &group->a))
+ if (!BN_copy(a, group->a))
goto err;
}
if (b != NULL) {
- if (!BN_copy(b, &group->b))
+ if (!BN_copy(b, group->b))
goto err;
}
@@ -279,7 +238,7 @@ int ec_GF2m_simple_group_get_curve(const EC_GROUP *group, BIGNUM *p,
*/
int ec_GF2m_simple_group_get_degree(const EC_GROUP *group)
{
- return BN_num_bits(&group->field) - 1;
+ return BN_num_bits(group->field) - 1;
}
/*
@@ -306,7 +265,7 @@ int ec_GF2m_simple_group_check_discriminant(const EC_GROUP *group,
if (b == NULL)
goto err;
- if (!BN_GF2m_mod_arr(b, &group->b, group->poly))
+ if (!BN_GF2m_mod_arr(b, group->b, group->poly))
goto err;
/*
@@ -321,34 +280,40 @@ int ec_GF2m_simple_group_check_discriminant(const EC_GROUP *group,
err:
if (ctx != NULL)
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
/* Initializes an EC_POINT. */
int ec_GF2m_simple_point_init(EC_POINT *point)
{
- BN_init(&point->X);
- BN_init(&point->Y);
- BN_init(&point->Z);
+ point->X = BN_new();
+ point->Y = BN_new();
+ point->Z = BN_new();
+
+ if (point->X == NULL || point->Y == NULL || point->Z == NULL) {
+ BN_free(point->X);
+ BN_free(point->Y);
+ BN_free(point->Z);
+ return 0;
+ }
return 1;
}
/* Frees an EC_POINT. */
void ec_GF2m_simple_point_finish(EC_POINT *point)
{
- BN_free(&point->X);
- BN_free(&point->Y);
- BN_free(&point->Z);
+ BN_free(point->X);
+ BN_free(point->Y);
+ BN_free(point->Z);
}
/* Clears and frees an EC_POINT. */
void ec_GF2m_simple_point_clear_finish(EC_POINT *point)
{
- BN_clear_free(&point->X);
- BN_clear_free(&point->Y);
- BN_clear_free(&point->Z);
+ BN_clear_free(point->X);
+ BN_clear_free(point->Y);
+ BN_clear_free(point->Z);
point->Z_is_one = 0;
}
@@ -358,11 +323,11 @@ void ec_GF2m_simple_point_clear_finish(EC_POINT *point)
*/
int ec_GF2m_simple_point_copy(EC_POINT *dest, const EC_POINT *src)
{
- if (!BN_copy(&dest->X, &src->X))
+ if (!BN_copy(dest->X, src->X))
return 0;
- if (!BN_copy(&dest->Y, &src->Y))
+ if (!BN_copy(dest->Y, src->Y))
return 0;
- if (!BN_copy(&dest->Z, &src->Z))
+ if (!BN_copy(dest->Z, src->Z))
return 0;
dest->Z_is_one = src->Z_is_one;
@@ -377,7 +342,7 @@ int ec_GF2m_simple_point_set_to_infinity(const EC_GROUP *group,
EC_POINT *point)
{
point->Z_is_one = 0;
- BN_zero(&point->Z);
+ BN_zero(point->Z);
return 1;
}
@@ -397,15 +362,15 @@ int ec_GF2m_simple_point_set_affine_coordinates(const EC_GROUP *group,
return 0;
}
- if (!BN_copy(&point->X, x))
+ if (!BN_copy(point->X, x))
goto err;
- BN_set_negative(&point->X, 0);
- if (!BN_copy(&point->Y, y))
+ BN_set_negative(point->X, 0);
+ if (!BN_copy(point->Y, y))
goto err;
- BN_set_negative(&point->Y, 0);
- if (!BN_copy(&point->Z, BN_value_one()))
+ BN_set_negative(point->Y, 0);
+ if (!BN_copy(point->Z, BN_value_one()))
goto err;
- BN_set_negative(&point->Z, 0);
+ BN_set_negative(point->Z, 0);
point->Z_is_one = 1;
ret = 1;
@@ -430,18 +395,18 @@ int ec_GF2m_simple_point_get_affine_coordinates(const EC_GROUP *group,
return 0;
}
- if (BN_cmp(&point->Z, BN_value_one())) {
+ if (BN_cmp(point->Z, BN_value_one())) {
ECerr(EC_F_EC_GF2M_SIMPLE_POINT_GET_AFFINE_COORDINATES,
ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
return 0;
}
if (x != NULL) {
- if (!BN_copy(x, &point->X))
+ if (!BN_copy(x, point->X))
goto err;
BN_set_negative(x, 0);
}
if (y != NULL) {
- if (!BN_copy(y, &point->Y))
+ if (!BN_copy(y, point->Y))
goto err;
BN_set_negative(y, 0);
}
@@ -493,18 +458,18 @@ int ec_GF2m_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,
goto err;
if (a->Z_is_one) {
- if (!BN_copy(x0, &a->X))
+ if (!BN_copy(x0, a->X))
goto err;
- if (!BN_copy(y0, &a->Y))
+ if (!BN_copy(y0, a->Y))
goto err;
} else {
if (!EC_POINT_get_affine_coordinates_GF2m(group, a, x0, y0, ctx))
goto err;
}
if (b->Z_is_one) {
- if (!BN_copy(x1, &b->X))
+ if (!BN_copy(x1, b->X))
goto err;
- if (!BN_copy(y1, &b->Y))
+ if (!BN_copy(y1, b->Y))
goto err;
} else {
if (!EC_POINT_get_affine_coordinates_GF2m(group, b, x1, y1, ctx))
@@ -520,7 +485,7 @@ int ec_GF2m_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,
goto err;
if (!group->meth->field_sqr(group, x2, s, ctx))
goto err;
- if (!BN_GF2m_add(x2, x2, &group->a))
+ if (!BN_GF2m_add(x2, x2, group->a))
goto err;
if (!BN_GF2m_add(x2, x2, s))
goto err;
@@ -542,7 +507,7 @@ int ec_GF2m_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,
goto err;
if (!BN_GF2m_add(x2, x2, s))
goto err;
- if (!BN_GF2m_add(x2, x2, &group->a))
+ if (!BN_GF2m_add(x2, x2, group->a))
goto err;
}
@@ -562,8 +527,7 @@ int ec_GF2m_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,
err:
BN_CTX_end(ctx);
- if (new_ctx != NULL)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
@@ -579,20 +543,20 @@ int ec_GF2m_simple_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,
int ec_GF2m_simple_invert(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx)
{
- if (EC_POINT_is_at_infinity(group, point) || BN_is_zero(&point->Y))
+ if (EC_POINT_is_at_infinity(group, point) || BN_is_zero(point->Y))
/* point is its own inverse */
return 1;
if (!EC_POINT_make_affine(group, point, ctx))
return 0;
- return BN_GF2m_add(&point->Y, &point->X, &point->Y);
+ return BN_GF2m_add(point->Y, point->X, point->Y);
}
/* Indicates whether the given point is the point at infinity. */
int ec_GF2m_simple_is_at_infinity(const EC_GROUP *group,
const EC_POINT *point)
{
- return BN_is_zero(&point->Z);
+ return BN_is_zero(point->Z);
}
/*-
@@ -638,17 +602,17 @@ int ec_GF2m_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point,
* <=> x^3 + a*x^2 + x*y + b + y^2 = 0
* <=> ((x + a) * x + y ) * x + b + y^2 = 0
*/
- if (!BN_GF2m_add(lh, &point->X, &group->a))
+ if (!BN_GF2m_add(lh, point->X, group->a))
goto err;
- if (!field_mul(group, lh, lh, &point->X, ctx))
+ if (!field_mul(group, lh, lh, point->X, ctx))
goto err;
- if (!BN_GF2m_add(lh, lh, &point->Y))
+ if (!BN_GF2m_add(lh, lh, point->Y))
goto err;
- if (!field_mul(group, lh, lh, &point->X, ctx))
+ if (!field_mul(group, lh, lh, point->X, ctx))
goto err;
- if (!BN_GF2m_add(lh, lh, &group->b))
+ if (!BN_GF2m_add(lh, lh, group->b))
goto err;
- if (!field_sqr(group, y2, &point->Y, ctx))
+ if (!field_sqr(group, y2, point->Y, ctx))
goto err;
if (!BN_GF2m_add(lh, lh, y2))
goto err;
@@ -656,8 +620,7 @@ int ec_GF2m_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point,
err:
if (ctx)
BN_CTX_end(ctx);
- if (new_ctx)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
@@ -683,8 +646,7 @@ int ec_GF2m_simple_cmp(const EC_GROUP *group, const EC_POINT *a,
return 1;
if (a->Z_is_one && b->Z_is_one) {
- return ((BN_cmp(&a->X, &b->X) == 0)
- && BN_cmp(&a->Y, &b->Y) == 0) ? 0 : 1;
+ return ((BN_cmp(a->X, b->X) == 0) && BN_cmp(a->Y, b->Y) == 0) ? 0 : 1;
}
if (ctx == NULL) {
@@ -710,8 +672,7 @@ int ec_GF2m_simple_cmp(const EC_GROUP *group, const EC_POINT *a,
err:
if (ctx)
BN_CTX_end(ctx);
- if (new_ctx)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
@@ -740,11 +701,11 @@ int ec_GF2m_simple_make_affine(const EC_GROUP *group, EC_POINT *point,
if (!EC_POINT_get_affine_coordinates_GF2m(group, point, x, y, ctx))
goto err;
- if (!BN_copy(&point->X, x))
+ if (!BN_copy(point->X, x))
goto err;
- if (!BN_copy(&point->Y, y))
+ if (!BN_copy(point->Y, y))
goto err;
- if (!BN_one(&point->Z))
+ if (!BN_one(point->Z))
goto err;
point->Z_is_one = 1;
@@ -753,8 +714,7 @@ int ec_GF2m_simple_make_affine(const EC_GROUP *group, EC_POINT *point,
err:
if (ctx)
BN_CTX_end(ctx);
- if (new_ctx)
- BN_CTX_free(new_ctx);
+ BN_CTX_free(new_ctx);
return ret;
}
@@ -792,7 +752,7 @@ int ec_GF2m_simple_field_sqr(const EC_GROUP *group, BIGNUM *r,
int ec_GF2m_simple_field_div(const EC_GROUP *group, BIGNUM *r,
const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
{
- return BN_GF2m_mod_div(r, a, b, &group->field, ctx);
+ return BN_GF2m_mod_div(r, a, b, group->field, ctx);
}
#endif