Latest update.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#! /usr/bin/env perl
|
||||
# Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
# Copyright 2015-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
# this file except in compliance with the License. You can obtain a copy
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#! /usr/bin/env perl
|
||||
# Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
# Copyright 2015-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
# this file except in compliance with the License. You can obtain a copy
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#! /usr/bin/env perl
|
||||
# Copyright 2014-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
# Copyright 2014-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
# Copyright (c) 2014, Intel Corporation. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#! /usr/bin/env perl
|
||||
# Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
# Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
# this file except in compliance with the License. You can obtain a copy
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#! /usr/bin/env perl
|
||||
# Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
# Copyright 2015-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
# this file except in compliance with the License. You can obtain a copy
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#! /usr/bin/env perl
|
||||
# Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
# Copyright 2015-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
# this file except in compliance with the License. You can obtain a copy
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#! /usr/bin/env perl
|
||||
# Copyright 2014-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
# Copyright 2014-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
# Copyright (c) 2014, Intel Corporation. All Rights Reserved.
|
||||
# Copyright (c) 2015 CloudFlare, Inc.
|
||||
#
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#! /usr/bin/env perl
|
||||
# Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
# Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
# this file except in compliance with the License. You can obtain a copy
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env perl
|
||||
# Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
# Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
# this file except in compliance with the License. You can obtain a copy
|
||||
|
||||
@@ -18,7 +18,7 @@ IF[{- !$disabled{asm} -}]
|
||||
$ECASM_mips32=
|
||||
$ECASM_mips64=
|
||||
|
||||
$ECASM_s390x=ecp_s390x_nistp.c
|
||||
$ECASM_s390x=ecp_s390x_nistp.c ecx_s390x.c
|
||||
$ECDEF_s390x=S390X_EC_ASM
|
||||
|
||||
$ECASM_armv4=ecp_nistz256.c ecp_nistz256-armv4.S
|
||||
@@ -44,14 +44,18 @@ IF[{- !$disabled{asm} -}]
|
||||
ENDIF
|
||||
|
||||
$COMMON=ec_lib.c ecp_smpl.c ecp_mont.c ecp_nist.c ec_cvt.c ec_mult.c \
|
||||
ec_curve.c ec_check.c ec_print.c ec_key.c ec_asn1.c \
|
||||
ec_curve.c ec_check.c ec_print.c ec_key.c ecx_key.c ec_asn1.c \
|
||||
ec2_smpl.c \
|
||||
ecp_nistp224.c ecp_nistp256.c ecp_nistp521.c ecp_nistputil.c \
|
||||
ecp_oct.c ec2_oct.c ec_oct.c ec_kmeth.c ecdh_ossl.c \
|
||||
ecdsa_ossl.c ecdsa_sign.c ecdsa_vrf.c curve25519.c \
|
||||
curve448/arch_32/f_impl.c curve448/f_generic.c curve448/scalar.c \
|
||||
curve448/curve448_tables.c curve448/eddsa.c curve448/curve448.c \
|
||||
$ECASM ec_backend.c ecx_backend.c
|
||||
|
||||
IF[{- !$disabled{'ec_nistp_64_gcc_128'} -}]
|
||||
$COMMON=$COMMON ecp_nistp224.c ecp_nistp256.c ecp_nistp521.c ecp_nistputil.c
|
||||
ENDIF
|
||||
|
||||
SOURCE[../../libcrypto]=$COMMON ec_ameth.c ec_pmeth.c ecx_meth.c ecx_key.c \
|
||||
ec_err.c ecdh_kdf.c eck_prn.c ec_ctrl.c
|
||||
SOURCE[../../providers/libfips.a]=$COMMON
|
||||
@@ -72,6 +76,7 @@ GENERATE[ecp_nistz256-sparcv9.S]=asm/ecp_nistz256-sparcv9.pl
|
||||
INCLUDE[ecp_nistz256-sparcv9.o]=..
|
||||
|
||||
INCLUDE[ecp_s390x_nistp.o]=..
|
||||
INCLUDE[ecx_s390x.o]=..
|
||||
INCLUDE[ecx_meth.o]=..
|
||||
|
||||
GENERATE[ecp_nistz256-armv4.S]=asm/ecp_nistz256-armv4.pl
|
||||
|
||||
+15
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -5577,13 +5577,23 @@ err:
|
||||
return res;
|
||||
}
|
||||
|
||||
void ED25519_public_from_private(uint8_t out_public_key[32],
|
||||
const uint8_t private_key[32])
|
||||
int ED25519_public_from_private(OPENSSL_CTX *ctx, uint8_t out_public_key[32],
|
||||
const uint8_t private_key[32])
|
||||
{
|
||||
uint8_t az[SHA512_DIGEST_LENGTH];
|
||||
ge_p3 A;
|
||||
int r;
|
||||
EVP_MD *sha512 = NULL;
|
||||
|
||||
SHA512(private_key, 32, az);
|
||||
sha512 = EVP_MD_fetch(ctx, SN_sha512, NULL);
|
||||
if (sha512 == NULL)
|
||||
return 0;
|
||||
r = EVP_Digest(private_key, 32, az, NULL, sha512, NULL);
|
||||
EVP_MD_free(sha512);
|
||||
if (!r) {
|
||||
OPENSSL_cleanse(az, sizeof(az));
|
||||
return 0;
|
||||
}
|
||||
|
||||
az[0] &= 248;
|
||||
az[31] &= 63;
|
||||
@@ -5593,6 +5603,7 @@ void ED25519_public_from_private(uint8_t out_public_key[32],
|
||||
ge_p3_tobytes(out_public_key, &A);
|
||||
|
||||
OPENSSL_cleanse(az, sizeof(az));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int X25519(uint8_t out_shared_key[32], const uint8_t private_key[32],
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2017-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2015-2016 Cryptography Research, Inc.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2017-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -18,7 +18,4 @@ int ED448ph_verify(OPENSSL_CTX *ctx, const uint8_t hash[64],
|
||||
const uint8_t signature[114], const uint8_t public_key[57],
|
||||
const uint8_t *context, size_t context_len);
|
||||
|
||||
int ED448_public_from_private(OPENSSL_CTX *ctx, uint8_t out_public_key[57],
|
||||
const uint8_t private_key[57]);
|
||||
|
||||
#endif /* OSSL_CRYPTO_EC_CURVE448_LOCAL_H */
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2017-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2015-2016 Cryptography Research, Inc.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2011-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2002-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
@@ -956,8 +956,6 @@ const EC_METHOD *EC_GF2m_simple_method(void)
|
||||
ec_GF2m_simple_point_clear_finish,
|
||||
ec_GF2m_simple_point_copy,
|
||||
ec_GF2m_simple_point_set_to_infinity,
|
||||
0, /* set_Jprojective_coordinates_GFp */
|
||||
0, /* get_Jprojective_coordinates_GFp */
|
||||
ec_GF2m_simple_point_set_affine_coordinates,
|
||||
ec_GF2m_simple_point_get_affine_coordinates,
|
||||
0, /* point_set_compressed_coordinates */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2006-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -758,10 +758,11 @@ int ec_pkey_export_to(const EVP_PKEY *from, void *to_keydata,
|
||||
return rv;
|
||||
}
|
||||
|
||||
static int ec_pkey_import_from(const OSSL_PARAM params[], void *key)
|
||||
static int ec_pkey_import_from(const OSSL_PARAM params[], void *vpctx)
|
||||
{
|
||||
EVP_PKEY *pkey = key;
|
||||
EC_KEY *ec = EC_KEY_new();
|
||||
EVP_PKEY_CTX *pctx = vpctx;
|
||||
EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(pctx);
|
||||
EC_KEY *ec = EC_KEY_new_ex(pctx->libctx);
|
||||
|
||||
if (ec == NULL) {
|
||||
ERR_raise(ERR_LIB_DH, ERR_R_MALLOC_FAILURE);
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2002-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2002-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2002-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2001-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2001-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
|
||||
+3
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Generated by util/mkerr.pl DO NOT EDIT
|
||||
* Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -34,6 +34,8 @@ static const ERR_STRING_DATA EC_str_reasons[] = {
|
||||
"discriminant is zero"},
|
||||
{ERR_PACK(ERR_LIB_EC, 0, EC_R_EC_GROUP_NEW_BY_NAME_FAILURE),
|
||||
"ec group new by name failure"},
|
||||
{ERR_PACK(ERR_LIB_EC, 0, EC_R_FAILED_MAKING_PUBLIC_KEY),
|
||||
"failed making public key"},
|
||||
{ERR_PACK(ERR_LIB_EC, 0, EC_R_FIELD_TOO_LARGE), "field too large"},
|
||||
{ERR_PACK(ERR_LIB_EC, 0, EC_R_GF2M_NOT_SUPPORTED), "gf2m not supported"},
|
||||
{ERR_PACK(ERR_LIB_EC, 0, EC_R_GROUP2PKPARAMETERS_FAILURE),
|
||||
|
||||
+1
-1
@@ -688,7 +688,7 @@ int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *priv_key)
|
||||
* This is important also because `BN_dup()` (and `BN_copy()`) do not
|
||||
* propagate the `BN_FLG_CONSTTIME` flag from the source `BIGNUM`, and
|
||||
* this brings an extra risk of inadvertently losing the flag, even when
|
||||
* the called specifically set it.
|
||||
* the caller specifically set it.
|
||||
*
|
||||
* The propagation has been turned on and off a few times in the past
|
||||
* years because in some conditions has shown unintended consequences in
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2015-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
|
||||
+7
-7
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2001-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2001-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
@@ -796,12 +796,13 @@ int EC_POINT_set_to_infinity(const EC_GROUP *group, EC_POINT *point)
|
||||
return group->meth->point_set_to_infinity(group, point);
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_DEPRECATED_3_0
|
||||
int EC_POINT_set_Jprojective_coordinates_GFp(const EC_GROUP *group,
|
||||
EC_POINT *point, const BIGNUM *x,
|
||||
const BIGNUM *y, const BIGNUM *z,
|
||||
BN_CTX *ctx)
|
||||
{
|
||||
if (group->meth->point_set_Jprojective_coordinates_GFp == 0) {
|
||||
if (group->meth->field_type != NID_X9_62_prime_field) {
|
||||
ECerr(EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP,
|
||||
ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
|
||||
return 0;
|
||||
@@ -811,8 +812,7 @@ int EC_POINT_set_Jprojective_coordinates_GFp(const EC_GROUP *group,
|
||||
EC_R_INCOMPATIBLE_OBJECTS);
|
||||
return 0;
|
||||
}
|
||||
return group->meth->point_set_Jprojective_coordinates_GFp(group, point, x,
|
||||
y, z, ctx);
|
||||
return ec_GFp_simple_set_Jprojective_coordinates_GFp(group, point, x, y, z, ctx);
|
||||
}
|
||||
|
||||
int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *group,
|
||||
@@ -820,7 +820,7 @@ int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *group,
|
||||
BIGNUM *y, BIGNUM *z,
|
||||
BN_CTX *ctx)
|
||||
{
|
||||
if (group->meth->point_get_Jprojective_coordinates_GFp == 0) {
|
||||
if (group->meth->field_type != NID_X9_62_prime_field) {
|
||||
ECerr(EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP,
|
||||
ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
|
||||
return 0;
|
||||
@@ -830,9 +830,9 @@ int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *group,
|
||||
EC_R_INCOMPATIBLE_OBJECTS);
|
||||
return 0;
|
||||
}
|
||||
return group->meth->point_get_Jprojective_coordinates_GFp(group, point, x,
|
||||
y, z, ctx);
|
||||
return ec_GFp_simple_get_Jprojective_coordinates_GFp(group, point, x, y, z, ctx);
|
||||
}
|
||||
#endif
|
||||
|
||||
int EC_POINT_set_affine_coordinates(const EC_GROUP *group, EC_POINT *point,
|
||||
const BIGNUM *x, const BIGNUM *y,
|
||||
|
||||
+1
-11
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2001-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2001-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
@@ -76,14 +76,6 @@ struct ec_method_st {
|
||||
* EC_POINT_set_compressed_coordinates:
|
||||
*/
|
||||
int (*point_set_to_infinity) (const EC_GROUP *, EC_POINT *);
|
||||
int (*point_set_Jprojective_coordinates_GFp) (const EC_GROUP *,
|
||||
EC_POINT *, const BIGNUM *x,
|
||||
const BIGNUM *y,
|
||||
const BIGNUM *z, BN_CTX *);
|
||||
int (*point_get_Jprojective_coordinates_GFp) (const EC_GROUP *,
|
||||
const EC_POINT *, BIGNUM *x,
|
||||
BIGNUM *y, BIGNUM *z,
|
||||
BN_CTX *);
|
||||
int (*point_set_affine_coordinates) (const EC_GROUP *, EC_POINT *,
|
||||
const BIGNUM *x, const BIGNUM *y,
|
||||
BN_CTX *);
|
||||
@@ -679,8 +671,6 @@ ECDSA_SIG *ecdsa_simple_sign_sig(const unsigned char *dgst, int dgst_len,
|
||||
int ecdsa_simple_verify_sig(const unsigned char *dgst, int dgst_len,
|
||||
const ECDSA_SIG *sig, EC_KEY *eckey);
|
||||
|
||||
void ED25519_public_from_private(uint8_t out_public_key[32],
|
||||
const uint8_t private_key[32]);
|
||||
|
||||
/*-
|
||||
* This functions computes a single point multiplication over the EC group,
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2001-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2001-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2011-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2006-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2002-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2015-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2002-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2002-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2015-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2002-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2001-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2001-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
@@ -37,8 +37,6 @@ const EC_METHOD *EC_GFp_mont_method(void)
|
||||
ec_GFp_simple_point_clear_finish,
|
||||
ec_GFp_simple_point_copy,
|
||||
ec_GFp_simple_point_set_to_infinity,
|
||||
ec_GFp_simple_set_Jprojective_coordinates_GFp,
|
||||
ec_GFp_simple_get_Jprojective_coordinates_GFp,
|
||||
ec_GFp_simple_point_set_affine_coordinates,
|
||||
ec_GFp_simple_point_get_affine_coordinates,
|
||||
0, 0, 0,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2001-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2001-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
@@ -39,8 +39,6 @@ const EC_METHOD *EC_GFp_nist_method(void)
|
||||
ec_GFp_simple_point_clear_finish,
|
||||
ec_GFp_simple_point_copy,
|
||||
ec_GFp_simple_point_set_to_infinity,
|
||||
ec_GFp_simple_set_Jprojective_coordinates_GFp,
|
||||
ec_GFp_simple_get_Jprojective_coordinates_GFp,
|
||||
ec_GFp_simple_point_set_affine_coordinates,
|
||||
ec_GFp_simple_point_get_affine_coordinates,
|
||||
0, 0, 0,
|
||||
|
||||
+12
-20
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2010-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -37,22 +37,19 @@
|
||||
*/
|
||||
|
||||
#include <openssl/opensslconf.h>
|
||||
#ifdef OPENSSL_NO_EC_NISTP_64_GCC_128
|
||||
NON_EMPTY_TRANSLATION_UNIT
|
||||
#else
|
||||
|
||||
# include <stdint.h>
|
||||
# include <string.h>
|
||||
# include <openssl/err.h>
|
||||
# include "ec_local.h"
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <openssl/err.h>
|
||||
#include "ec_local.h"
|
||||
|
||||
# if defined(__SIZEOF_INT128__) && __SIZEOF_INT128__==16
|
||||
#if defined(__SIZEOF_INT128__) && __SIZEOF_INT128__==16
|
||||
/* even with gcc, the typedef won't work for 32-bit platforms */
|
||||
typedef __uint128_t uint128_t; /* nonstandard; implemented by gcc on 64-bit
|
||||
* platforms */
|
||||
# else
|
||||
# error "Your compiler doesn't appear to support 128-bit integer types"
|
||||
# endif
|
||||
#else
|
||||
# error "Your compiler doesn't appear to support 128-bit integer types"
|
||||
#endif
|
||||
|
||||
typedef uint8_t u8;
|
||||
typedef uint64_t u64;
|
||||
@@ -264,8 +261,6 @@ const EC_METHOD *EC_GFp_nistp224_method(void)
|
||||
ec_GFp_simple_point_clear_finish,
|
||||
ec_GFp_simple_point_copy,
|
||||
ec_GFp_simple_point_set_to_infinity,
|
||||
ec_GFp_simple_set_Jprojective_coordinates_GFp,
|
||||
ec_GFp_simple_get_Jprojective_coordinates_GFp,
|
||||
ec_GFp_simple_point_set_affine_coordinates,
|
||||
ec_GFp_nistp224_point_get_affine_coordinates,
|
||||
0 /* point_set_compressed_coordinates */ ,
|
||||
@@ -1468,9 +1463,8 @@ int ec_GFp_nistp224_points_mul(const EC_GROUP *group, EC_POINT *r,
|
||||
ECerr(EC_F_EC_GFP_NISTP224_POINTS_MUL, ERR_R_BN_LIB);
|
||||
goto err;
|
||||
}
|
||||
if (!EC_POINT_set_Jprojective_coordinates_GFp(group,
|
||||
generator, x, y, z,
|
||||
ctx))
|
||||
if (!ec_GFp_simple_set_Jprojective_coordinates_GFp(group, generator, x,
|
||||
y, z, ctx))
|
||||
goto err;
|
||||
if (0 == EC_POINT_cmp(group, generator, group->generator, ctx))
|
||||
/* precomputation matches generator */
|
||||
@@ -1604,7 +1598,7 @@ int ec_GFp_nistp224_points_mul(const EC_GROUP *group, EC_POINT *r,
|
||||
ECerr(EC_F_EC_GFP_NISTP224_POINTS_MUL, ERR_R_BN_LIB);
|
||||
goto err;
|
||||
}
|
||||
ret = EC_POINT_set_Jprojective_coordinates_GFp(group, r, x, y, z, ctx);
|
||||
ret = ec_GFp_simple_set_Jprojective_coordinates_GFp(group, r, x, y, z, ctx);
|
||||
|
||||
err:
|
||||
BN_CTX_end(ctx);
|
||||
@@ -1755,5 +1749,3 @@ int ec_GFp_nistp224_have_precompute_mult(const EC_GROUP *group)
|
||||
{
|
||||
return HAVEPRECOMP(group, nistp224);
|
||||
}
|
||||
|
||||
#endif
|
||||
+26
-33
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2011-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -38,23 +38,20 @@
|
||||
*/
|
||||
|
||||
#include <openssl/opensslconf.h>
|
||||
#ifdef OPENSSL_NO_EC_NISTP_64_GCC_128
|
||||
NON_EMPTY_TRANSLATION_UNIT
|
||||
#else
|
||||
|
||||
# include <stdint.h>
|
||||
# include <string.h>
|
||||
# include <openssl/err.h>
|
||||
# include "ec_local.h"
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <openssl/err.h>
|
||||
#include "ec_local.h"
|
||||
|
||||
# if defined(__SIZEOF_INT128__) && __SIZEOF_INT128__==16
|
||||
#if defined(__SIZEOF_INT128__) && __SIZEOF_INT128__==16
|
||||
/* even with gcc, the typedef won't work for 32-bit platforms */
|
||||
typedef __uint128_t uint128_t; /* nonstandard; implemented by gcc on 64-bit
|
||||
* platforms */
|
||||
typedef __int128_t int128_t;
|
||||
# else
|
||||
# error "Your compiler doesn't appear to support 128-bit integer types"
|
||||
# endif
|
||||
#else
|
||||
# error "Your compiler doesn't appear to support 128-bit integer types"
|
||||
#endif
|
||||
|
||||
typedef uint8_t u8;
|
||||
typedef uint32_t u32;
|
||||
@@ -116,7 +113,7 @@ static const felem_bytearray nistp256_curve_params[5] = {
|
||||
* values are used as intermediate values before multiplication.
|
||||
*/
|
||||
|
||||
# define NLIMBS 4
|
||||
#define NLIMBS 4
|
||||
|
||||
typedef uint128_t limb;
|
||||
typedef limb felem[NLIMBS];
|
||||
@@ -248,9 +245,9 @@ static void longfelem_scalar(longfelem out, const u64 scalar)
|
||||
out[7] *= scalar;
|
||||
}
|
||||
|
||||
# define two105m41m9 (((limb)1) << 105) - (((limb)1) << 41) - (((limb)1) << 9)
|
||||
# define two105 (((limb)1) << 105)
|
||||
# define two105m41p9 (((limb)1) << 105) - (((limb)1) << 41) + (((limb)1) << 9)
|
||||
#define two105m41m9 (((limb)1) << 105) - (((limb)1) << 41) - (((limb)1) << 9)
|
||||
#define two105 (((limb)1) << 105)
|
||||
#define two105m41p9 (((limb)1) << 105) - (((limb)1) << 41) + (((limb)1) << 9)
|
||||
|
||||
/* zero105 is 0 mod p */
|
||||
static const felem zero105 =
|
||||
@@ -293,9 +290,9 @@ static void felem_diff(felem out, const felem in)
|
||||
out[3] -= in[3];
|
||||
}
|
||||
|
||||
# define two107m43m11 (((limb)1) << 107) - (((limb)1) << 43) - (((limb)1) << 11)
|
||||
# define two107 (((limb)1) << 107)
|
||||
# define two107m43p11 (((limb)1) << 107) - (((limb)1) << 43) + (((limb)1) << 11)
|
||||
#define two107m43m11 (((limb)1) << 107) - (((limb)1) << 43) - (((limb)1) << 11)
|
||||
#define two107 (((limb)1) << 107)
|
||||
#define two107m43p11 (((limb)1) << 107) - (((limb)1) << 43) + (((limb)1) << 11)
|
||||
|
||||
/* zero107 is 0 mod p */
|
||||
static const felem zero107 =
|
||||
@@ -364,10 +361,10 @@ static void longfelem_diff(longfelem out, const longfelem in)
|
||||
out[7] -= in[7];
|
||||
}
|
||||
|
||||
# define two64m0 (((limb)1) << 64) - 1
|
||||
# define two110p32m0 (((limb)1) << 110) + (((limb)1) << 32) - 1
|
||||
# define two64m46 (((limb)1) << 64) - (((limb)1) << 46)
|
||||
# define two64m32 (((limb)1) << 64) - (((limb)1) << 32)
|
||||
#define two64m0 (((limb)1) << 64) - 1
|
||||
#define two110p32m0 (((limb)1) << 110) + (((limb)1) << 32) - 1
|
||||
#define two64m46 (((limb)1) << 64) - (((limb)1) << 46)
|
||||
#define two64m32 (((limb)1) << 64) - (((limb)1) << 32)
|
||||
|
||||
/* zero110 is 0 mod p */
|
||||
static const felem zero110 = { two64m0, two110p32m0, two64m46, two64m32 };
|
||||
@@ -717,9 +714,9 @@ static void felem_small_mul(longfelem out, const smallfelem small1,
|
||||
smallfelem_mul(out, small1, small2);
|
||||
}
|
||||
|
||||
# define two100m36m4 (((limb)1) << 100) - (((limb)1) << 36) - (((limb)1) << 4)
|
||||
# define two100 (((limb)1) << 100)
|
||||
# define two100m36p4 (((limb)1) << 100) - (((limb)1) << 36) + (((limb)1) << 4)
|
||||
#define two100m36m4 (((limb)1) << 100) - (((limb)1) << 36) - (((limb)1) << 4)
|
||||
#define two100 (((limb)1) << 100)
|
||||
#define two100m36p4 (((limb)1) << 100) - (((limb)1) << 36) + (((limb)1) << 4)
|
||||
/* zero100 is 0 mod p */
|
||||
static const felem zero100 =
|
||||
{ two100m36m4, two100, two100m36p4, two100m36p4 };
|
||||
@@ -1801,8 +1798,6 @@ const EC_METHOD *EC_GFp_nistp256_method(void)
|
||||
ec_GFp_simple_point_clear_finish,
|
||||
ec_GFp_simple_point_copy,
|
||||
ec_GFp_simple_point_set_to_infinity,
|
||||
ec_GFp_simple_set_Jprojective_coordinates_GFp,
|
||||
ec_GFp_simple_get_Jprojective_coordinates_GFp,
|
||||
ec_GFp_simple_point_set_affine_coordinates,
|
||||
ec_GFp_nistp256_point_get_affine_coordinates,
|
||||
0 /* point_set_compressed_coordinates */ ,
|
||||
@@ -2083,9 +2078,8 @@ int ec_GFp_nistp256_points_mul(const EC_GROUP *group, EC_POINT *r,
|
||||
ECerr(EC_F_EC_GFP_NISTP256_POINTS_MUL, ERR_R_BN_LIB);
|
||||
goto err;
|
||||
}
|
||||
if (!EC_POINT_set_Jprojective_coordinates_GFp(group,
|
||||
generator, x, y, z,
|
||||
ctx))
|
||||
if (!ec_GFp_simple_set_Jprojective_coordinates_GFp(group, generator, x,
|
||||
y, z, ctx))
|
||||
goto err;
|
||||
if (0 == EC_POINT_cmp(group, generator, group->generator, ctx))
|
||||
/* precomputation matches generator */
|
||||
@@ -2225,7 +2219,7 @@ int ec_GFp_nistp256_points_mul(const EC_GROUP *group, EC_POINT *r,
|
||||
ECerr(EC_F_EC_GFP_NISTP256_POINTS_MUL, ERR_R_BN_LIB);
|
||||
goto err;
|
||||
}
|
||||
ret = EC_POINT_set_Jprojective_coordinates_GFp(group, r, x, y, z, ctx);
|
||||
ret = ec_GFp_simple_set_Jprojective_coordinates_GFp(group, r, x, y, z, ctx);
|
||||
|
||||
err:
|
||||
BN_CTX_end(ctx);
|
||||
@@ -2387,4 +2381,3 @@ int ec_GFp_nistp256_have_precompute_mult(const EC_GROUP *group)
|
||||
{
|
||||
return HAVEPRECOMP(group, nistp256);
|
||||
}
|
||||
#endif
|
||||
+12
-20
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2011-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -38,21 +38,18 @@
|
||||
*/
|
||||
|
||||
#include <openssl/e_os2.h>
|
||||
#ifdef OPENSSL_NO_EC_NISTP_64_GCC_128
|
||||
NON_EMPTY_TRANSLATION_UNIT
|
||||
#else
|
||||
|
||||
# include <string.h>
|
||||
# include <openssl/err.h>
|
||||
# include "ec_local.h"
|
||||
#include <string.h>
|
||||
#include <openssl/err.h>
|
||||
#include "ec_local.h"
|
||||
|
||||
# if defined(__SIZEOF_INT128__) && __SIZEOF_INT128__==16
|
||||
#if defined(__SIZEOF_INT128__) && __SIZEOF_INT128__==16
|
||||
/* even with gcc, the typedef won't work for 32-bit platforms */
|
||||
typedef __uint128_t uint128_t; /* nonstandard; implemented by gcc on 64-bit
|
||||
* platforms */
|
||||
# else
|
||||
# error "Your compiler doesn't appear to support 128-bit integer types"
|
||||
# endif
|
||||
#else
|
||||
# error "Your compiler doesn't appear to support 128-bit integer types"
|
||||
#endif
|
||||
|
||||
typedef uint8_t u8;
|
||||
typedef uint64_t u64;
|
||||
@@ -131,7 +128,7 @@ static const felem_bytearray nistp521_curve_params[5] = {
|
||||
* A field element with 64-bit limbs is an 'felem'. One with 128-bit limbs is a
|
||||
* 'largefelem' */
|
||||
|
||||
# define NLIMBS 9
|
||||
#define NLIMBS 9
|
||||
|
||||
typedef uint64_t limb;
|
||||
typedef limb felem[NLIMBS];
|
||||
@@ -1641,8 +1638,6 @@ const EC_METHOD *EC_GFp_nistp521_method(void)
|
||||
ec_GFp_simple_point_clear_finish,
|
||||
ec_GFp_simple_point_copy,
|
||||
ec_GFp_simple_point_set_to_infinity,
|
||||
ec_GFp_simple_set_Jprojective_coordinates_GFp,
|
||||
ec_GFp_simple_get_Jprojective_coordinates_GFp,
|
||||
ec_GFp_simple_point_set_affine_coordinates,
|
||||
ec_GFp_nistp521_point_get_affine_coordinates,
|
||||
0 /* point_set_compressed_coordinates */ ,
|
||||
@@ -1922,9 +1917,8 @@ int ec_GFp_nistp521_points_mul(const EC_GROUP *group, EC_POINT *r,
|
||||
ECerr(EC_F_EC_GFP_NISTP521_POINTS_MUL, ERR_R_BN_LIB);
|
||||
goto err;
|
||||
}
|
||||
if (!EC_POINT_set_Jprojective_coordinates_GFp(group,
|
||||
generator, x, y, z,
|
||||
ctx))
|
||||
if (!ec_GFp_simple_set_Jprojective_coordinates_GFp(group, generator, x,
|
||||
y, z, ctx))
|
||||
goto err;
|
||||
if (0 == EC_POINT_cmp(group, generator, group->generator, ctx))
|
||||
/* precomputation matches generator */
|
||||
@@ -2062,7 +2056,7 @@ int ec_GFp_nistp521_points_mul(const EC_GROUP *group, EC_POINT *r,
|
||||
ECerr(EC_F_EC_GFP_NISTP521_POINTS_MUL, ERR_R_BN_LIB);
|
||||
goto err;
|
||||
}
|
||||
ret = EC_POINT_set_Jprojective_coordinates_GFp(group, r, x, y, z, ctx);
|
||||
ret = ec_GFp_simple_set_Jprojective_coordinates_GFp(group, r, x, y, z, ctx);
|
||||
|
||||
err:
|
||||
BN_CTX_end(ctx);
|
||||
@@ -2193,5 +2187,3 @@ int ec_GFp_nistp521_have_precompute_mult(const EC_GROUP *group)
|
||||
{
|
||||
return HAVEPRECOMP(group, nistp521);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2011-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -30,16 +30,13 @@
|
||||
#include "internal/deprecated.h"
|
||||
|
||||
#include <openssl/opensslconf.h>
|
||||
#ifdef OPENSSL_NO_EC_NISTP_64_GCC_128
|
||||
NON_EMPTY_TRANSLATION_UNIT
|
||||
#else
|
||||
|
||||
/*
|
||||
* Common utility functions for ecp_nistp224.c, ecp_nistp256.c, ecp_nistp521.c.
|
||||
*/
|
||||
|
||||
# include <stddef.h>
|
||||
# include "ec_local.h"
|
||||
#include <stddef.h>
|
||||
#include "ec_local.h"
|
||||
|
||||
/*
|
||||
* Convert an array of points into affine coordinates. (If the point at
|
||||
@@ -80,10 +77,10 @@ void ec_GFp_nistp_points_make_affine_internal(size_t num, void *point_array,
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
# define tmp_felem(I) (&((char *)tmp_felems)[(I) * felem_size])
|
||||
# define X(I) (&((char *)point_array)[3*(I) * felem_size])
|
||||
# define Y(I) (&((char *)point_array)[(3*(I) + 1) * felem_size])
|
||||
# define Z(I) (&((char *)point_array)[(3*(I) + 2) * felem_size])
|
||||
#define tmp_felem(I) (&((char *)tmp_felems)[(I) * felem_size])
|
||||
#define X(I) (&((char *)point_array)[3*(I) * felem_size])
|
||||
#define Y(I) (&((char *)point_array)[(3*(I) + 1) * felem_size])
|
||||
#define Z(I) (&((char *)point_array)[(3*(I) + 2) * felem_size])
|
||||
|
||||
if (!felem_is_zero(Z(0)))
|
||||
felem_assign(tmp_felem(0), Z(0));
|
||||
@@ -226,4 +223,3 @@ void ec_GFp_nistp_recode_scalar_bits(unsigned char *sign,
|
||||
*sign = s & 1;
|
||||
*digit = d;
|
||||
}
|
||||
#endif
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2014-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright (c) 2014, Intel Corporation. All Rights Reserved.
|
||||
* Copyright (c) 2015, CloudFlare, Inc.
|
||||
*
|
||||
@@ -1694,8 +1694,6 @@ const EC_METHOD *EC_GFp_nistz256_method(void)
|
||||
ec_GFp_simple_point_clear_finish,
|
||||
ec_GFp_simple_point_copy,
|
||||
ec_GFp_simple_point_set_to_infinity,
|
||||
ec_GFp_simple_set_Jprojective_coordinates_GFp,
|
||||
ec_GFp_simple_get_Jprojective_coordinates_GFp,
|
||||
ec_GFp_simple_point_set_affine_coordinates,
|
||||
ecp_nistz256_get_affine,
|
||||
0, 0, 0,
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2011-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -332,8 +332,6 @@ const EC_METHOD *EC_GFp_s390x_nistp##bits##_method(void) \
|
||||
ec_GFp_simple_point_clear_finish, \
|
||||
ec_GFp_simple_point_copy, \
|
||||
ec_GFp_simple_point_set_to_infinity, \
|
||||
ec_GFp_simple_set_Jprojective_coordinates_GFp, \
|
||||
ec_GFp_simple_get_Jprojective_coordinates_GFp, \
|
||||
ec_GFp_simple_point_set_affine_coordinates, \
|
||||
ec_GFp_simple_point_get_affine_coordinates, \
|
||||
NULL, /* point_set_compressed_coordinates */ \
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2001-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2001-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
@@ -38,8 +38,6 @@ const EC_METHOD *EC_GFp_simple_method(void)
|
||||
ec_GFp_simple_point_clear_finish,
|
||||
ec_GFp_simple_point_copy,
|
||||
ec_GFp_simple_point_set_to_infinity,
|
||||
ec_GFp_simple_set_Jprojective_coordinates_GFp,
|
||||
ec_GFp_simple_get_Jprojective_coordinates_GFp,
|
||||
ec_GFp_simple_point_set_affine_coordinates,
|
||||
ec_GFp_simple_point_get_affine_coordinates,
|
||||
0, 0, 0,
|
||||
|
||||
+50
-232
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2006-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -35,7 +35,8 @@ typedef enum {
|
||||
|
||||
/* Setup EVP_PKEY using public, private or generation */
|
||||
static int ecx_key_op(EVP_PKEY *pkey, int id, const X509_ALGOR *palg,
|
||||
const unsigned char *p, int plen, ecx_key_op_t op)
|
||||
const unsigned char *p, int plen, ecx_key_op_t op,
|
||||
OPENSSL_CTX *libctx, const char *propq)
|
||||
{
|
||||
ECX_KEY *key = NULL;
|
||||
unsigned char *privkey, *pubkey;
|
||||
@@ -92,17 +93,19 @@ static int ecx_key_op(EVP_PKEY *pkey, int id, const X509_ALGOR *palg,
|
||||
X25519_public_from_private(pubkey, privkey);
|
||||
break;
|
||||
case EVP_PKEY_ED25519:
|
||||
ED25519_public_from_private(pubkey, privkey);
|
||||
if (!ED25519_public_from_private(libctx, pubkey, privkey)) {
|
||||
ECerr(EC_F_ECX_KEY_OP, EC_R_FAILED_MAKING_PUBLIC_KEY);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case EVP_PKEY_X448:
|
||||
X448_public_from_private(pubkey, privkey);
|
||||
break;
|
||||
case EVP_PKEY_ED448:
|
||||
/*
|
||||
* TODO(3.0): We set the library context to NULL for now. This will
|
||||
* need to change.
|
||||
*/
|
||||
ED448_public_from_private(NULL, pubkey, privkey);
|
||||
if (!ED448_public_from_private(libctx, pubkey, privkey)) {
|
||||
ECerr(EC_F_ECX_KEY_OP, EC_R_FAILED_MAKING_PUBLIC_KEY);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -148,7 +151,7 @@ static int ecx_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey)
|
||||
if (!X509_PUBKEY_get0_param(NULL, &p, &pklen, &palg, pubkey))
|
||||
return 0;
|
||||
return ecx_key_op(pkey, pkey->ameth->pkey_id, palg, p, pklen,
|
||||
KEY_OP_PUBLIC);
|
||||
KEY_OP_PUBLIC, NULL, NULL);
|
||||
}
|
||||
|
||||
static int ecx_pub_cmp(const EVP_PKEY *a, const EVP_PKEY *b)
|
||||
@@ -162,7 +165,9 @@ static int ecx_pub_cmp(const EVP_PKEY *a, const EVP_PKEY *b)
|
||||
return CRYPTO_memcmp(akey->pubkey, bkey->pubkey, KEYLEN(a)) == 0;
|
||||
}
|
||||
|
||||
static int ecx_priv_decode(EVP_PKEY *pkey, const PKCS8_PRIV_KEY_INFO *p8)
|
||||
static int ecx_priv_decode_with_libctx(EVP_PKEY *pkey,
|
||||
const PKCS8_PRIV_KEY_INFO *p8,
|
||||
OPENSSL_CTX *libctx, const char *propq)
|
||||
{
|
||||
const unsigned char *p;
|
||||
int plen;
|
||||
@@ -182,7 +187,8 @@ static int ecx_priv_decode(EVP_PKEY *pkey, const PKCS8_PRIV_KEY_INFO *p8)
|
||||
plen = ASN1_STRING_length(oct);
|
||||
}
|
||||
|
||||
rv = ecx_key_op(pkey, pkey->ameth->pkey_id, palg, p, plen, KEY_OP_PRIVATE);
|
||||
rv = ecx_key_op(pkey, pkey->ameth->pkey_id, palg, p, plen, KEY_OP_PRIVATE,
|
||||
libctx, propq);
|
||||
ASN1_STRING_clear_free(oct);
|
||||
return rv;
|
||||
}
|
||||
@@ -310,7 +316,7 @@ static int ecx_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2)
|
||||
|
||||
case ASN1_PKEY_CTRL_SET1_TLS_ENCPT:
|
||||
return ecx_key_op(pkey, pkey->ameth->pkey_id, NULL, arg2, arg1,
|
||||
KEY_OP_PUBLIC);
|
||||
KEY_OP_PUBLIC, NULL, NULL);
|
||||
|
||||
case ASN1_PKEY_CTRL_GET1_TLS_ENCPT:
|
||||
if (pkey->pkey.ecx != NULL) {
|
||||
@@ -345,14 +351,15 @@ static int ecd_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2)
|
||||
static int ecx_set_priv_key(EVP_PKEY *pkey, const unsigned char *priv,
|
||||
size_t len)
|
||||
{
|
||||
/* TODO(3.0): We should pass a libctx here */
|
||||
return ecx_key_op(pkey, pkey->ameth->pkey_id, NULL, priv, len,
|
||||
KEY_OP_PRIVATE);
|
||||
KEY_OP_PRIVATE, NULL, NULL);
|
||||
}
|
||||
|
||||
static int ecx_set_pub_key(EVP_PKEY *pkey, const unsigned char *pub, size_t len)
|
||||
{
|
||||
return ecx_key_op(pkey, pkey->ameth->pkey_id, NULL, pub, len,
|
||||
KEY_OP_PUBLIC);
|
||||
KEY_OP_PUBLIC, NULL, NULL);
|
||||
}
|
||||
|
||||
static int ecx_get_priv_key(const EVP_PKEY *pkey, unsigned char *priv,
|
||||
@@ -443,10 +450,11 @@ static int ecx_pkey_export_to(const EVP_PKEY *from, void *to_keydata,
|
||||
return rv;
|
||||
}
|
||||
|
||||
static int ecx_generic_import_from(const OSSL_PARAM params[], void *key,
|
||||
static int ecx_generic_import_from(const OSSL_PARAM params[], void *vpctx,
|
||||
int keytype)
|
||||
{
|
||||
EVP_PKEY *pkey = key;
|
||||
EVP_PKEY_CTX *pctx = vpctx;
|
||||
EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(pctx);
|
||||
ECX_KEY *ecx = ecx_key_new(KEYNID2TYPE(keytype), 0);
|
||||
|
||||
if (ecx == NULL) {
|
||||
@@ -462,9 +470,9 @@ static int ecx_generic_import_from(const OSSL_PARAM params[], void *key,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int x25519_import_from(const OSSL_PARAM params[], void *key)
|
||||
static int x25519_import_from(const OSSL_PARAM params[], void *vpctx)
|
||||
{
|
||||
return ecx_generic_import_from(params, key, EVP_PKEY_X25519);
|
||||
return ecx_generic_import_from(params, vpctx, EVP_PKEY_X25519);
|
||||
}
|
||||
|
||||
const EVP_PKEY_ASN1_METHOD ecx25519_asn1_meth = {
|
||||
@@ -479,7 +487,7 @@ const EVP_PKEY_ASN1_METHOD ecx25519_asn1_meth = {
|
||||
ecx_pub_cmp,
|
||||
ecx_pub_print,
|
||||
|
||||
ecx_priv_decode,
|
||||
NULL,
|
||||
ecx_priv_encode,
|
||||
ecx_priv_print,
|
||||
|
||||
@@ -510,12 +518,14 @@ const EVP_PKEY_ASN1_METHOD ecx25519_asn1_meth = {
|
||||
ecx_get_pub_key,
|
||||
ecx_pkey_dirty_cnt,
|
||||
ecx_pkey_export_to,
|
||||
x25519_import_from
|
||||
x25519_import_from,
|
||||
|
||||
ecx_priv_decode_with_libctx
|
||||
};
|
||||
|
||||
static int x448_import_from(const OSSL_PARAM params[], void *key)
|
||||
static int x448_import_from(const OSSL_PARAM params[], void *vpctx)
|
||||
{
|
||||
return ecx_generic_import_from(params, key, EVP_PKEY_X448);
|
||||
return ecx_generic_import_from(params, vpctx, EVP_PKEY_X448);
|
||||
}
|
||||
|
||||
const EVP_PKEY_ASN1_METHOD ecx448_asn1_meth = {
|
||||
@@ -530,7 +540,7 @@ const EVP_PKEY_ASN1_METHOD ecx448_asn1_meth = {
|
||||
ecx_pub_cmp,
|
||||
ecx_pub_print,
|
||||
|
||||
ecx_priv_decode,
|
||||
NULL,
|
||||
ecx_priv_encode,
|
||||
ecx_priv_print,
|
||||
|
||||
@@ -561,7 +571,9 @@ const EVP_PKEY_ASN1_METHOD ecx448_asn1_meth = {
|
||||
ecx_get_pub_key,
|
||||
ecx_pkey_dirty_cnt,
|
||||
ecx_pkey_export_to,
|
||||
x448_import_from
|
||||
x448_import_from,
|
||||
|
||||
ecx_priv_decode_with_libctx
|
||||
};
|
||||
|
||||
static int ecd_size25519(const EVP_PKEY *pkey)
|
||||
@@ -636,9 +648,9 @@ static int ecd_sig_info_set448(X509_SIG_INFO *siginf, const X509_ALGOR *alg,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int ed25519_import_from(const OSSL_PARAM params[], void *key)
|
||||
static int ed25519_import_from(const OSSL_PARAM params[], void *vpctx)
|
||||
{
|
||||
return ecx_generic_import_from(params, key, EVP_PKEY_ED25519);
|
||||
return ecx_generic_import_from(params, vpctx, EVP_PKEY_ED25519);
|
||||
}
|
||||
|
||||
const EVP_PKEY_ASN1_METHOD ed25519_asn1_meth = {
|
||||
@@ -653,7 +665,7 @@ const EVP_PKEY_ASN1_METHOD ed25519_asn1_meth = {
|
||||
ecx_pub_cmp,
|
||||
ecx_pub_print,
|
||||
|
||||
ecx_priv_decode,
|
||||
NULL,
|
||||
ecx_priv_encode,
|
||||
ecx_priv_print,
|
||||
|
||||
@@ -683,12 +695,14 @@ const EVP_PKEY_ASN1_METHOD ed25519_asn1_meth = {
|
||||
ecx_get_pub_key,
|
||||
ecx_pkey_dirty_cnt,
|
||||
ecx_pkey_export_to,
|
||||
ed25519_import_from
|
||||
ed25519_import_from,
|
||||
|
||||
ecx_priv_decode_with_libctx
|
||||
};
|
||||
|
||||
static int ed448_import_from(const OSSL_PARAM params[], void *key)
|
||||
static int ed448_import_from(const OSSL_PARAM params[], void *vpctx)
|
||||
{
|
||||
return ecx_generic_import_from(params, key, EVP_PKEY_ED448);
|
||||
return ecx_generic_import_from(params, vpctx, EVP_PKEY_ED448);
|
||||
}
|
||||
|
||||
const EVP_PKEY_ASN1_METHOD ed448_asn1_meth = {
|
||||
@@ -703,7 +717,7 @@ const EVP_PKEY_ASN1_METHOD ed448_asn1_meth = {
|
||||
ecx_pub_cmp,
|
||||
ecx_pub_print,
|
||||
|
||||
ecx_priv_decode,
|
||||
NULL,
|
||||
ecx_priv_encode,
|
||||
ecx_priv_print,
|
||||
|
||||
@@ -733,12 +747,15 @@ const EVP_PKEY_ASN1_METHOD ed448_asn1_meth = {
|
||||
ecx_get_pub_key,
|
||||
ecx_pkey_dirty_cnt,
|
||||
ecx_pkey_export_to,
|
||||
ed448_import_from
|
||||
ed448_import_from,
|
||||
|
||||
ecx_priv_decode_with_libctx
|
||||
};
|
||||
|
||||
static int pkey_ecx_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
|
||||
{
|
||||
return ecx_key_op(pkey, ctx->pmeth->pkey_id, NULL, NULL, 0, KEY_OP_KEYGEN);
|
||||
return ecx_key_op(pkey, ctx->pmeth->pkey_id, NULL, NULL, 0, KEY_OP_KEYGEN,
|
||||
NULL, NULL);
|
||||
}
|
||||
|
||||
static int validate_ecx_derive(EVP_PKEY_CTX *ctx, unsigned char *key,
|
||||
@@ -938,205 +955,6 @@ static const EVP_PKEY_METHOD ed448_pkey_meth = {
|
||||
|
||||
#ifdef S390X_EC_ASM
|
||||
# include "s390x_arch.h"
|
||||
# include "internal/constant_time.h"
|
||||
|
||||
static void s390x_x25519_mod_p(unsigned char u[32])
|
||||
{
|
||||
unsigned char u_red[32];
|
||||
unsigned int c = 0;
|
||||
int i;
|
||||
|
||||
memcpy(u_red, u, sizeof(u_red));
|
||||
|
||||
c += (unsigned int)u_red[31] + 19;
|
||||
u_red[31] = (unsigned char)c;
|
||||
c >>= 8;
|
||||
|
||||
for (i = 30; i >= 0; i--) {
|
||||
c += (unsigned int)u_red[i];
|
||||
u_red[i] = (unsigned char)c;
|
||||
c >>= 8;
|
||||
}
|
||||
|
||||
c = (u_red[0] & 0x80) >> 7;
|
||||
u_red[0] &= 0x7f;
|
||||
constant_time_cond_swap_buff(0 - (unsigned char)c,
|
||||
u, u_red, sizeof(u_red));
|
||||
}
|
||||
|
||||
static void s390x_x448_mod_p(unsigned char u[56])
|
||||
{
|
||||
unsigned char u_red[56];
|
||||
unsigned int c = 0;
|
||||
int i;
|
||||
|
||||
memcpy(u_red, u, sizeof(u_red));
|
||||
|
||||
c += (unsigned int)u_red[55] + 1;
|
||||
u_red[55] = (unsigned char)c;
|
||||
c >>= 8;
|
||||
|
||||
for (i = 54; i >= 28; i--) {
|
||||
c += (unsigned int)u_red[i];
|
||||
u_red[i] = (unsigned char)c;
|
||||
c >>= 8;
|
||||
}
|
||||
|
||||
c += (unsigned int)u_red[27] + 1;
|
||||
u_red[27] = (unsigned char)c;
|
||||
c >>= 8;
|
||||
|
||||
for (i = 26; i >= 0; i--) {
|
||||
c += (unsigned int)u_red[i];
|
||||
u_red[i] = (unsigned char)c;
|
||||
c >>= 8;
|
||||
}
|
||||
|
||||
constant_time_cond_swap_buff(0 - (unsigned char)c,
|
||||
u, u_red, sizeof(u_red));
|
||||
}
|
||||
|
||||
int s390x_x25519_mul(unsigned char u_dst[32],
|
||||
const unsigned char u_src[32],
|
||||
const unsigned char d_src[32])
|
||||
{
|
||||
union {
|
||||
struct {
|
||||
unsigned char u_dst[32];
|
||||
unsigned char u_src[32];
|
||||
unsigned char d_src[32];
|
||||
} x25519;
|
||||
unsigned long long buff[512];
|
||||
} param;
|
||||
int rc;
|
||||
|
||||
memset(¶m, 0, sizeof(param));
|
||||
|
||||
s390x_flip_endian32(param.x25519.u_src, u_src);
|
||||
param.x25519.u_src[0] &= 0x7f;
|
||||
s390x_x25519_mod_p(param.x25519.u_src);
|
||||
|
||||
s390x_flip_endian32(param.x25519.d_src, d_src);
|
||||
param.x25519.d_src[31] &= 248;
|
||||
param.x25519.d_src[0] &= 127;
|
||||
param.x25519.d_src[0] |= 64;
|
||||
|
||||
rc = s390x_pcc(S390X_SCALAR_MULTIPLY_X25519, ¶m.x25519) ? 0 : 1;
|
||||
if (rc == 1)
|
||||
s390x_flip_endian32(u_dst, param.x25519.u_dst);
|
||||
|
||||
OPENSSL_cleanse(param.x25519.d_src, sizeof(param.x25519.d_src));
|
||||
return rc;
|
||||
}
|
||||
|
||||
int s390x_x448_mul(unsigned char u_dst[56],
|
||||
const unsigned char u_src[56],
|
||||
const unsigned char d_src[56])
|
||||
{
|
||||
union {
|
||||
struct {
|
||||
unsigned char u_dst[64];
|
||||
unsigned char u_src[64];
|
||||
unsigned char d_src[64];
|
||||
} x448;
|
||||
unsigned long long buff[512];
|
||||
} param;
|
||||
int rc;
|
||||
|
||||
memset(¶m, 0, sizeof(param));
|
||||
|
||||
memcpy(param.x448.u_src, u_src, 56);
|
||||
memcpy(param.x448.d_src, d_src, 56);
|
||||
|
||||
s390x_flip_endian64(param.x448.u_src, param.x448.u_src);
|
||||
s390x_x448_mod_p(param.x448.u_src + 8);
|
||||
|
||||
s390x_flip_endian64(param.x448.d_src, param.x448.d_src);
|
||||
param.x448.d_src[63] &= 252;
|
||||
param.x448.d_src[8] |= 128;
|
||||
|
||||
rc = s390x_pcc(S390X_SCALAR_MULTIPLY_X448, ¶m.x448) ? 0 : 1;
|
||||
if (rc == 1) {
|
||||
s390x_flip_endian64(param.x448.u_dst, param.x448.u_dst);
|
||||
memcpy(u_dst, param.x448.u_dst, 56);
|
||||
}
|
||||
|
||||
OPENSSL_cleanse(param.x448.d_src, sizeof(param.x448.d_src));
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int s390x_ed25519_mul(unsigned char x_dst[32],
|
||||
unsigned char y_dst[32],
|
||||
const unsigned char x_src[32],
|
||||
const unsigned char y_src[32],
|
||||
const unsigned char d_src[32])
|
||||
{
|
||||
union {
|
||||
struct {
|
||||
unsigned char x_dst[32];
|
||||
unsigned char y_dst[32];
|
||||
unsigned char x_src[32];
|
||||
unsigned char y_src[32];
|
||||
unsigned char d_src[32];
|
||||
} ed25519;
|
||||
unsigned long long buff[512];
|
||||
} param;
|
||||
int rc;
|
||||
|
||||
memset(¶m, 0, sizeof(param));
|
||||
|
||||
s390x_flip_endian32(param.ed25519.x_src, x_src);
|
||||
s390x_flip_endian32(param.ed25519.y_src, y_src);
|
||||
s390x_flip_endian32(param.ed25519.d_src, d_src);
|
||||
|
||||
rc = s390x_pcc(S390X_SCALAR_MULTIPLY_ED25519, ¶m.ed25519) ? 0 : 1;
|
||||
if (rc == 1) {
|
||||
s390x_flip_endian32(x_dst, param.ed25519.x_dst);
|
||||
s390x_flip_endian32(y_dst, param.ed25519.y_dst);
|
||||
}
|
||||
|
||||
OPENSSL_cleanse(param.ed25519.d_src, sizeof(param.ed25519.d_src));
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int s390x_ed448_mul(unsigned char x_dst[57],
|
||||
unsigned char y_dst[57],
|
||||
const unsigned char x_src[57],
|
||||
const unsigned char y_src[57],
|
||||
const unsigned char d_src[57])
|
||||
{
|
||||
union {
|
||||
struct {
|
||||
unsigned char x_dst[64];
|
||||
unsigned char y_dst[64];
|
||||
unsigned char x_src[64];
|
||||
unsigned char y_src[64];
|
||||
unsigned char d_src[64];
|
||||
} ed448;
|
||||
unsigned long long buff[512];
|
||||
} param;
|
||||
int rc;
|
||||
|
||||
memset(¶m, 0, sizeof(param));
|
||||
|
||||
memcpy(param.ed448.x_src, x_src, 57);
|
||||
memcpy(param.ed448.y_src, y_src, 57);
|
||||
memcpy(param.ed448.d_src, d_src, 57);
|
||||
s390x_flip_endian64(param.ed448.x_src, param.ed448.x_src);
|
||||
s390x_flip_endian64(param.ed448.y_src, param.ed448.y_src);
|
||||
s390x_flip_endian64(param.ed448.d_src, param.ed448.d_src);
|
||||
|
||||
rc = s390x_pcc(S390X_SCALAR_MULTIPLY_ED448, ¶m.ed448) ? 0 : 1;
|
||||
if (rc == 1) {
|
||||
s390x_flip_endian64(param.ed448.x_dst, param.ed448.x_dst);
|
||||
s390x_flip_endian64(param.ed448.y_dst, param.ed448.y_dst);
|
||||
memcpy(x_dst, param.ed448.x_dst, 57);
|
||||
memcpy(y_dst, param.ed448.y_dst, 57);
|
||||
}
|
||||
|
||||
OPENSSL_cleanse(param.ed448.d_src, sizeof(param.ed448.d_src));
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int s390x_pkey_ecx_keygen25519(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,217 @@
|
||||
/*
|
||||
* Copyright 2006-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (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
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "internal/cryptlib.h"
|
||||
#include <openssl/ec.h>
|
||||
#include <openssl/rand.h>
|
||||
#include "crypto/ecx.h"
|
||||
#include "ec_local.h"
|
||||
#include "curve448/curve448_local.h"
|
||||
#include "ecx_backend.h"
|
||||
#include "s390x_arch.h"
|
||||
#include "internal/constant_time.h"
|
||||
|
||||
static void s390x_x25519_mod_p(unsigned char u[32])
|
||||
{
|
||||
unsigned char u_red[32];
|
||||
unsigned int c = 0;
|
||||
int i;
|
||||
|
||||
memcpy(u_red, u, sizeof(u_red));
|
||||
|
||||
c += (unsigned int)u_red[31] + 19;
|
||||
u_red[31] = (unsigned char)c;
|
||||
c >>= 8;
|
||||
|
||||
for (i = 30; i >= 0; i--) {
|
||||
c += (unsigned int)u_red[i];
|
||||
u_red[i] = (unsigned char)c;
|
||||
c >>= 8;
|
||||
}
|
||||
|
||||
c = (u_red[0] & 0x80) >> 7;
|
||||
u_red[0] &= 0x7f;
|
||||
constant_time_cond_swap_buff(0 - (unsigned char)c,
|
||||
u, u_red, sizeof(u_red));
|
||||
}
|
||||
|
||||
static void s390x_x448_mod_p(unsigned char u[56])
|
||||
{
|
||||
unsigned char u_red[56];
|
||||
unsigned int c = 0;
|
||||
int i;
|
||||
|
||||
memcpy(u_red, u, sizeof(u_red));
|
||||
|
||||
c += (unsigned int)u_red[55] + 1;
|
||||
u_red[55] = (unsigned char)c;
|
||||
c >>= 8;
|
||||
|
||||
for (i = 54; i >= 28; i--) {
|
||||
c += (unsigned int)u_red[i];
|
||||
u_red[i] = (unsigned char)c;
|
||||
c >>= 8;
|
||||
}
|
||||
|
||||
c += (unsigned int)u_red[27] + 1;
|
||||
u_red[27] = (unsigned char)c;
|
||||
c >>= 8;
|
||||
|
||||
for (i = 26; i >= 0; i--) {
|
||||
c += (unsigned int)u_red[i];
|
||||
u_red[i] = (unsigned char)c;
|
||||
c >>= 8;
|
||||
}
|
||||
|
||||
constant_time_cond_swap_buff(0 - (unsigned char)c,
|
||||
u, u_red, sizeof(u_red));
|
||||
}
|
||||
|
||||
int s390x_x25519_mul(unsigned char u_dst[32],
|
||||
const unsigned char u_src[32],
|
||||
const unsigned char d_src[32])
|
||||
{
|
||||
union {
|
||||
struct {
|
||||
unsigned char u_dst[32];
|
||||
unsigned char u_src[32];
|
||||
unsigned char d_src[32];
|
||||
} x25519;
|
||||
unsigned long long buff[512];
|
||||
} param;
|
||||
int rc;
|
||||
|
||||
memset(¶m, 0, sizeof(param));
|
||||
|
||||
s390x_flip_endian32(param.x25519.u_src, u_src);
|
||||
param.x25519.u_src[0] &= 0x7f;
|
||||
s390x_x25519_mod_p(param.x25519.u_src);
|
||||
|
||||
s390x_flip_endian32(param.x25519.d_src, d_src);
|
||||
param.x25519.d_src[31] &= 248;
|
||||
param.x25519.d_src[0] &= 127;
|
||||
param.x25519.d_src[0] |= 64;
|
||||
|
||||
rc = s390x_pcc(S390X_SCALAR_MULTIPLY_X25519, ¶m.x25519) ? 0 : 1;
|
||||
if (rc == 1)
|
||||
s390x_flip_endian32(u_dst, param.x25519.u_dst);
|
||||
|
||||
OPENSSL_cleanse(param.x25519.d_src, sizeof(param.x25519.d_src));
|
||||
return rc;
|
||||
}
|
||||
|
||||
int s390x_x448_mul(unsigned char u_dst[56],
|
||||
const unsigned char u_src[56],
|
||||
const unsigned char d_src[56])
|
||||
{
|
||||
union {
|
||||
struct {
|
||||
unsigned char u_dst[64];
|
||||
unsigned char u_src[64];
|
||||
unsigned char d_src[64];
|
||||
} x448;
|
||||
unsigned long long buff[512];
|
||||
} param;
|
||||
int rc;
|
||||
|
||||
memset(¶m, 0, sizeof(param));
|
||||
|
||||
memcpy(param.x448.u_src, u_src, 56);
|
||||
memcpy(param.x448.d_src, d_src, 56);
|
||||
|
||||
s390x_flip_endian64(param.x448.u_src, param.x448.u_src);
|
||||
s390x_x448_mod_p(param.x448.u_src + 8);
|
||||
|
||||
s390x_flip_endian64(param.x448.d_src, param.x448.d_src);
|
||||
param.x448.d_src[63] &= 252;
|
||||
param.x448.d_src[8] |= 128;
|
||||
|
||||
rc = s390x_pcc(S390X_SCALAR_MULTIPLY_X448, ¶m.x448) ? 0 : 1;
|
||||
if (rc == 1) {
|
||||
s390x_flip_endian64(param.x448.u_dst, param.x448.u_dst);
|
||||
memcpy(u_dst, param.x448.u_dst, 56);
|
||||
}
|
||||
|
||||
OPENSSL_cleanse(param.x448.d_src, sizeof(param.x448.d_src));
|
||||
return rc;
|
||||
}
|
||||
|
||||
int s390x_ed25519_mul(unsigned char x_dst[32],
|
||||
unsigned char y_dst[32],
|
||||
const unsigned char x_src[32],
|
||||
const unsigned char y_src[32],
|
||||
const unsigned char d_src[32])
|
||||
{
|
||||
union {
|
||||
struct {
|
||||
unsigned char x_dst[32];
|
||||
unsigned char y_dst[32];
|
||||
unsigned char x_src[32];
|
||||
unsigned char y_src[32];
|
||||
unsigned char d_src[32];
|
||||
} ed25519;
|
||||
unsigned long long buff[512];
|
||||
} param;
|
||||
int rc;
|
||||
|
||||
memset(¶m, 0, sizeof(param));
|
||||
|
||||
s390x_flip_endian32(param.ed25519.x_src, x_src);
|
||||
s390x_flip_endian32(param.ed25519.y_src, y_src);
|
||||
s390x_flip_endian32(param.ed25519.d_src, d_src);
|
||||
|
||||
rc = s390x_pcc(S390X_SCALAR_MULTIPLY_ED25519, ¶m.ed25519) ? 0 : 1;
|
||||
if (rc == 1) {
|
||||
s390x_flip_endian32(x_dst, param.ed25519.x_dst);
|
||||
s390x_flip_endian32(y_dst, param.ed25519.y_dst);
|
||||
}
|
||||
|
||||
OPENSSL_cleanse(param.ed25519.d_src, sizeof(param.ed25519.d_src));
|
||||
return rc;
|
||||
}
|
||||
|
||||
int s390x_ed448_mul(unsigned char x_dst[57],
|
||||
unsigned char y_dst[57],
|
||||
const unsigned char x_src[57],
|
||||
const unsigned char y_src[57],
|
||||
const unsigned char d_src[57])
|
||||
{
|
||||
union {
|
||||
struct {
|
||||
unsigned char x_dst[64];
|
||||
unsigned char y_dst[64];
|
||||
unsigned char x_src[64];
|
||||
unsigned char y_src[64];
|
||||
unsigned char d_src[64];
|
||||
} ed448;
|
||||
unsigned long long buff[512];
|
||||
} param;
|
||||
int rc;
|
||||
|
||||
memset(¶m, 0, sizeof(param));
|
||||
|
||||
memcpy(param.ed448.x_src, x_src, 57);
|
||||
memcpy(param.ed448.y_src, y_src, 57);
|
||||
memcpy(param.ed448.d_src, d_src, 57);
|
||||
s390x_flip_endian64(param.ed448.x_src, param.ed448.x_src);
|
||||
s390x_flip_endian64(param.ed448.y_src, param.ed448.y_src);
|
||||
s390x_flip_endian64(param.ed448.d_src, param.ed448.d_src);
|
||||
|
||||
rc = s390x_pcc(S390X_SCALAR_MULTIPLY_ED448, ¶m.ed448) ? 0 : 1;
|
||||
if (rc == 1) {
|
||||
s390x_flip_endian64(param.ed448.x_dst, param.ed448.x_dst);
|
||||
s390x_flip_endian64(param.ed448.y_dst, param.ed448.y_dst);
|
||||
memcpy(x_dst, param.ed448.x_dst, 57);
|
||||
memcpy(y_dst, param.ed448.y_dst, 57);
|
||||
}
|
||||
|
||||
OPENSSL_cleanse(param.ed448.d_src, sizeof(param.ed448.d_src));
|
||||
return rc;
|
||||
}
|
||||
Reference in New Issue
Block a user