Latest update.
This commit is contained in:
@@ -19,7 +19,7 @@ IF[{- !$disabled{asm} -}]
|
||||
$ECASM_mips64=
|
||||
|
||||
$ECASM_s390x=ecp_s390x_nistp.c
|
||||
$ECDEF_s390x=S390X_NISTP_ASM
|
||||
$ECDEF_s390x=S390X_EC_ASM
|
||||
|
||||
$ECASM_armv4=ecp_nistz256.c ecp_nistz256-armv4.S
|
||||
$ECDEF_armv4=ECP_NISTZ256_ASM
|
||||
@@ -56,9 +56,13 @@ $COMMON=ec_lib.c ecp_smpl.c ecp_mont.c ecp_nist.c ec_cvt.c ec_mult.c \
|
||||
$ECASM
|
||||
SOURCE[../../libcrypto]=$COMMON ec_ameth.c ec_pmeth.c ecx_meth.c ec_err.c \
|
||||
ecdh_kdf.c eck_prn.c
|
||||
SOURCE[../../providers/libfips.a]=$COMMON
|
||||
|
||||
# Implementations are now spread across several libraries, so the defines
|
||||
# need to be applied to all affected libraries and modules.
|
||||
DEFINE[../../libcrypto]=$ECDEF
|
||||
SOURCE[../../providers/fips]=$COMMON
|
||||
DEFINE[../../providers/fips]=$ECDEF
|
||||
DEFINE[../../providers/libfips.a]=$ECDEF
|
||||
DEFINE[../../providers/libimplementations.a]=$ECDEF
|
||||
|
||||
GENERATE[ecp_nistz256-x86.s]=asm/ecp_nistz256-x86.pl
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "ec_lcl.h"
|
||||
#include "ec_local.h"
|
||||
#include <openssl/sha.h>
|
||||
|
||||
#if defined(X25519_ASM) && (defined(__x86_64) || defined(__x86_64__) || \
|
||||
|
||||
@@ -10,10 +10,10 @@
|
||||
* Originally written by Mike Hamburg
|
||||
*/
|
||||
|
||||
#ifndef HEADER_ARCH_32_ARCH_INTRINSICS_H
|
||||
# define HEADER_ARCH_32_ARCH_INTRINSICS_H
|
||||
#ifndef OSSL_CRYPTO_EC_CURVE448_ARCH_32_INTRINSICS_H
|
||||
# define OSSL_CRYPTO_EC_CURVE448_ARCH_32_INTRINSICS_H
|
||||
|
||||
#include "internal/constant_time_locl.h"
|
||||
#include "internal/constant_time.h"
|
||||
|
||||
# define ARCH_WORD_BITS 32
|
||||
|
||||
@@ -24,4 +24,4 @@ static ossl_inline uint64_t widemul(uint32_t a, uint32_t b)
|
||||
return ((uint64_t)a) * b;
|
||||
}
|
||||
|
||||
#endif /* HEADER_ARCH_32_ARCH_INTRINSICS_H */
|
||||
#endif /* OSSL_CRYPTO_EC_CURVE448_ARCH_32_INTRINSICS_H */
|
||||
@@ -10,8 +10,8 @@
|
||||
* Originally written by Mike Hamburg
|
||||
*/
|
||||
|
||||
#ifndef HEADER_ARCH_32_F_IMPL_H
|
||||
# define HEADER_ARCH_32_F_IMPL_H
|
||||
#ifndef OSSL_CRYPTO_EC_CURVE448_ARCH_32_F_IMPL_H
|
||||
# define OSSL_CRYPTO_EC_CURVE448_ARCH_32_F_IMPL_H
|
||||
|
||||
# define GF_HEADROOM 2
|
||||
# define LIMB(x) ((x) & ((1 << 28) - 1)), ((x) >> 28)
|
||||
@@ -57,4 +57,4 @@ void gf_weak_reduce(gf a)
|
||||
a->limb[0] = (a->limb[0] & mask) + tmp;
|
||||
}
|
||||
|
||||
#endif /* HEADER_ARCH_32_F_IMPL_H */
|
||||
#endif /* OSSL_CRYPTO_EC_CURVE448_ARCH_32_F_IMPL_H */
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
#include "point_448.h"
|
||||
#include "ed448.h"
|
||||
#include "curve448_lcl.h"
|
||||
#include "curve448_local.h"
|
||||
|
||||
#define COFACTOR 4
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
#ifndef HEADER_CURVE448_LCL_H
|
||||
# define HEADER_CURVE448_LCL_H
|
||||
#ifndef OSSL_CRYPTO_EC_CURVE448_LOCAL_H
|
||||
# define OSSL_CRYPTO_EC_CURVE448_LOCAL_H
|
||||
# include "curve448utils.h"
|
||||
|
||||
int X448(uint8_t out_shared_key[56], const uint8_t private_key[56],
|
||||
@@ -36,4 +36,4 @@ int ED448ph_verify(OPENSSL_CTX *ctx, const uint8_t hash[64],
|
||||
int ED448_public_from_private(OPENSSL_CTX *ctx, uint8_t out_public_key[57],
|
||||
const uint8_t private_key[57]);
|
||||
|
||||
#endif /* HEADER_CURVE448_LCL_H */
|
||||
#endif /* OSSL_CRYPTO_EC_CURVE448_LOCAL_H */
|
||||
@@ -10,8 +10,8 @@
|
||||
* Originally written by Mike Hamburg
|
||||
*/
|
||||
|
||||
#ifndef HEADER_CURVE448UTILS_H
|
||||
# define HEADER_CURVE448UTILS_H
|
||||
#ifndef OSSL_CRYPTO_EC_CURVE448UTILS_H
|
||||
# define OSSL_CRYPTO_EC_CURVE448UTILS_H
|
||||
|
||||
# include <openssl/e_os2.h>
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
* Originally written by Mike Hamburg
|
||||
*/
|
||||
|
||||
#ifndef HEADER_ED448_H
|
||||
# define HEADER_ED448_H
|
||||
#ifndef OSSL_CRYPTO_EC_CURVE448_ED448_H
|
||||
# define OSSL_CRYPTO_EC_CURVE448_ED448_H
|
||||
|
||||
# include "point_448.h"
|
||||
|
||||
@@ -198,4 +198,4 @@ c448_error_t c448_ed448_convert_private_key_to_x448(
|
||||
uint8_t x[X448_PRIVATE_BYTES],
|
||||
const uint8_t ed[EDDSA_448_PRIVATE_BYTES]);
|
||||
|
||||
#endif /* HEADER_ED448_H */
|
||||
#endif /* OSSL_CRYPTO_EC_CURVE448_ED448_H */
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <string.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/evp.h>
|
||||
#include "curve448_lcl.h"
|
||||
#include "curve448_local.h"
|
||||
#include "word.h"
|
||||
#include "ed448.h"
|
||||
#include "internal/numbers.h"
|
||||
|
||||
@@ -10,10 +10,10 @@
|
||||
* Originally written by Mike Hamburg
|
||||
*/
|
||||
|
||||
#ifndef HEADER_FIELD_H
|
||||
# define HEADER_FIELD_H
|
||||
#ifndef OSSL_CRYPTO_EC_CURVE448_FIELD_H
|
||||
# define OSSL_CRYPTO_EC_CURVE448_FIELD_H
|
||||
|
||||
# include "internal/constant_time_locl.h"
|
||||
# include "internal/constant_time.h"
|
||||
# include <string.h>
|
||||
# include <assert.h>
|
||||
# include "word.h"
|
||||
@@ -165,4 +165,4 @@ static ossl_inline void gf_cond_swap(gf x, gf_s * RESTRICT y, mask_t swap)
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* HEADER_FIELD_H */
|
||||
#endif /* OSSL_CRYPTO_EC_CURVE448_FIELD_H */
|
||||
@@ -10,8 +10,8 @@
|
||||
* Originally written by Mike Hamburg
|
||||
*/
|
||||
|
||||
#ifndef HEADER_POINT_448_H
|
||||
# define HEADER_POINT_448_H
|
||||
#ifndef OSSL_CRYPTO_EC_CURVE448_POINT_448_H
|
||||
# define OSSL_CRYPTO_EC_CURVE448_POINT_448_H
|
||||
|
||||
# include "curve448utils.h"
|
||||
# include "field.h"
|
||||
@@ -298,4 +298,4 @@ void curve448_scalar_destroy(curve448_scalar_t scalar);
|
||||
/* Overwrite point with zeros. */
|
||||
void curve448_point_destroy(curve448_point_t point);
|
||||
|
||||
#endif /* HEADER_POINT_448_H */
|
||||
#endif /* OSSL_CRYPTO_EC_CURVE448_POINT_448_H */
|
||||
@@ -10,8 +10,8 @@
|
||||
* Originally written by Mike Hamburg
|
||||
*/
|
||||
|
||||
#ifndef HEADER_WORD_H
|
||||
# define HEADER_WORD_H
|
||||
#ifndef OSSL_CRYPTO_EC_CURVE448_WORD_H
|
||||
# define OSSL_CRYPTO_EC_CURVE448_WORD_H
|
||||
|
||||
# include <string.h>
|
||||
# include <assert.h>
|
||||
@@ -78,4 +78,4 @@ static ossl_inline mask_t bool_to_mask(c448_bool_t m)
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* HEADER_WORD_H */
|
||||
#endif /* OSSL_CRYPTO_EC_CURVE448_WORD_H */
|
||||
+1
-1
@@ -10,7 +10,7 @@
|
||||
|
||||
#include <openssl/err.h>
|
||||
|
||||
#include "ec_lcl.h"
|
||||
#include "ec_local.h"
|
||||
|
||||
#ifndef OPENSSL_NO_EC2M
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
|
||||
#include <openssl/err.h>
|
||||
|
||||
#include "internal/bn_int.h"
|
||||
#include "ec_lcl.h"
|
||||
#include "crypto/bn.h"
|
||||
#include "ec_local.h"
|
||||
|
||||
#ifndef OPENSSL_NO_EC2M
|
||||
|
||||
|
||||
@@ -14,9 +14,9 @@
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/cms.h>
|
||||
#include <openssl/asn1t.h>
|
||||
#include "internal/asn1_int.h"
|
||||
#include "internal/evp_int.h"
|
||||
#include "ec_lcl.h"
|
||||
#include "crypto/asn1.h"
|
||||
#include "crypto/evp.h"
|
||||
#include "ec_local.h"
|
||||
|
||||
#ifndef OPENSSL_NO_CMS
|
||||
static int ecdh_cms_decrypt(CMS_RecipientInfo *ri);
|
||||
@@ -196,7 +196,7 @@ static int eckey_priv_decode(EVP_PKEY *pkey, const PKCS8_PRIV_KEY_INFO *p8)
|
||||
|
||||
eckey = eckey_type2param(ptype, pval);
|
||||
|
||||
if (!eckey)
|
||||
if (eckey == NULL)
|
||||
goto ecliberr;
|
||||
|
||||
/* We have parameters now set private key */
|
||||
@@ -650,7 +650,7 @@ static int ecdh_cms_set_peerkey(EVP_PKEY_CTX *pctx,
|
||||
const EC_GROUP *grp;
|
||||
EVP_PKEY *pk;
|
||||
pk = EVP_PKEY_CTX_get0_pkey(pctx);
|
||||
if (!pk)
|
||||
if (pk == NULL)
|
||||
goto err;
|
||||
grp = EC_KEY_get0_group(pk->pkey.ec);
|
||||
ecpeer = EC_KEY_new();
|
||||
@@ -666,7 +666,7 @@ static int ecdh_cms_set_peerkey(EVP_PKEY_CTX *pctx,
|
||||
/* We have parameters now set public key */
|
||||
plen = ASN1_STRING_length(pubkey);
|
||||
p = ASN1_STRING_get0_data(pubkey);
|
||||
if (!p || !plen)
|
||||
if (p == NULL || plen == 0)
|
||||
goto err;
|
||||
if (!o2i_ECPublicKey(&ecpeer, &p, plen))
|
||||
goto err;
|
||||
|
||||
+27
-10
@@ -8,12 +8,12 @@
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "ec_lcl.h"
|
||||
#include "ec_local.h"
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/objects.h>
|
||||
#include "internal/nelem.h"
|
||||
#include "internal/asn1_dsa.h"
|
||||
#include "crypto/asn1_dsa.h"
|
||||
|
||||
#ifndef FIPS_MODE
|
||||
|
||||
@@ -581,8 +581,9 @@ EC_GROUP *EC_GROUP_new_from_ecparameters(const ECPARAMETERS *params)
|
||||
int curve_name = NID_undef;
|
||||
BN_CTX *ctx = NULL;
|
||||
|
||||
if (!params->fieldID || !params->fieldID->fieldType ||
|
||||
!params->fieldID->p.ptr) {
|
||||
if (params->fieldID == NULL
|
||||
|| params->fieldID->fieldType == NULL
|
||||
|| params->fieldID->p.ptr == NULL) {
|
||||
ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, EC_R_ASN1_ERROR);
|
||||
goto err;
|
||||
}
|
||||
@@ -593,9 +594,9 @@ EC_GROUP *EC_GROUP_new_from_ecparameters(const ECPARAMETERS *params)
|
||||
* encoded them incorrectly, so we must accept any length for backwards
|
||||
* compatibility.
|
||||
*/
|
||||
if (!params->curve || !params->curve->a ||
|
||||
!params->curve->a->data || !params->curve->b ||
|
||||
!params->curve->b->data) {
|
||||
if (params->curve == NULL
|
||||
|| params->curve->a == NULL || params->curve->a->data == NULL
|
||||
|| params->curve->b == NULL || params->curve->b->data == NULL) {
|
||||
ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, EC_R_ASN1_ERROR);
|
||||
goto err;
|
||||
}
|
||||
@@ -665,7 +666,7 @@ EC_GROUP *EC_GROUP_new_from_ecparameters(const ECPARAMETERS *params)
|
||||
X9_62_PENTANOMIAL *penta;
|
||||
|
||||
penta = char_two->p.ppBasis;
|
||||
if (!penta) {
|
||||
if (penta == NULL) {
|
||||
ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, EC_R_ASN1_ERROR);
|
||||
goto err;
|
||||
}
|
||||
@@ -705,7 +706,7 @@ EC_GROUP *EC_GROUP_new_from_ecparameters(const ECPARAMETERS *params)
|
||||
else if (tmp == NID_X9_62_prime_field) {
|
||||
/* we have a curve over a prime field */
|
||||
/* extract the prime number */
|
||||
if (!params->fieldID->p.prime) {
|
||||
if (params->fieldID->p.prime == NULL) {
|
||||
ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, EC_R_ASN1_ERROR);
|
||||
goto err;
|
||||
}
|
||||
@@ -750,7 +751,9 @@ EC_GROUP *EC_GROUP_new_from_ecparameters(const ECPARAMETERS *params)
|
||||
ret->seed_len = params->curve->seed->length;
|
||||
}
|
||||
|
||||
if (!params->order || !params->base || !params->base->data) {
|
||||
if (params->order == NULL
|
||||
|| params->base == NULL
|
||||
|| params->base->data == NULL) {
|
||||
ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, EC_R_ASN1_ERROR);
|
||||
goto err;
|
||||
}
|
||||
@@ -852,6 +855,20 @@ EC_GROUP *EC_GROUP_new_from_ecparameters(const ECPARAMETERS *params)
|
||||
* serialized using explicit parameters by default.
|
||||
*/
|
||||
EC_GROUP_set_asn1_flag(ret, OPENSSL_EC_EXPLICIT_CURVE);
|
||||
|
||||
/*
|
||||
* If the input params do not contain the optional seed field we make
|
||||
* sure it is not added to the returned group.
|
||||
*
|
||||
* The seed field is not really used inside libcrypto anyway, and
|
||||
* adding it to parsed explicit parameter keys would alter their DER
|
||||
* encoding output (because of the extra field) which could impact
|
||||
* applications fingerprinting keys by their DER encoding.
|
||||
*/
|
||||
if (params->curve->seed == NULL) {
|
||||
if (EC_GROUP_set_seed(ret, NULL, 0) != 1)
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
ok = 1;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include "ec_lcl.h"
|
||||
#include "ec_local.h"
|
||||
#include <openssl/err.h>
|
||||
|
||||
int EC_GROUP_check_named_curve(const EC_GROUP *group, int nist_only,
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "ec_lcl.h"
|
||||
#include "ec_local.h"
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/obj_mac.h>
|
||||
#include <openssl/opensslconf.h>
|
||||
@@ -2829,7 +2829,7 @@ static const ec_list_element curve_list[] = {
|
||||
# endif
|
||||
/* SECG secp256r1 is the same as X9.62 prime256v1 and hence omitted */
|
||||
{NID_secp384r1, &_EC_NIST_PRIME_384.h,
|
||||
# if defined(S390X_NISTP_ASM)
|
||||
# if defined(S390X_EC_ASM)
|
||||
EC_GFp_s390x_nistp384_method,
|
||||
# else
|
||||
0,
|
||||
@@ -2837,7 +2837,7 @@ static const ec_list_element curve_list[] = {
|
||||
"NIST/SECG curve over a 384 bit prime field"},
|
||||
|
||||
{NID_secp521r1, &_EC_NIST_PRIME_521.h,
|
||||
# if defined(S390X_NISTP_ASM)
|
||||
# if defined(S390X_EC_ASM)
|
||||
EC_GFp_s390x_nistp521_method,
|
||||
# elif !defined(OPENSSL_NO_EC_NISTP_64_GCC_128)
|
||||
EC_GFp_nistp521_method,
|
||||
@@ -2852,7 +2852,7 @@ static const ec_list_element curve_list[] = {
|
||||
{NID_X9_62_prime256v1, &_EC_X9_62_PRIME_256V1.h,
|
||||
# if defined(ECP_NISTZ256_ASM)
|
||||
EC_GFp_nistz256_method,
|
||||
# elif defined(S390X_NISTP_ASM)
|
||||
# elif defined(S390X_EC_ASM)
|
||||
EC_GFp_s390x_nistp256_method,
|
||||
# elif !defined(OPENSSL_NO_EC_NISTP_64_GCC_128)
|
||||
EC_GFp_nistp256_method,
|
||||
@@ -2922,14 +2922,14 @@ static const ec_list_element curve_list[] = {
|
||||
"SECG curve over a 256 bit prime field"},
|
||||
/* SECG secp256r1 is the same as X9.62 prime256v1 and hence omitted */
|
||||
{NID_secp384r1, &_EC_NIST_PRIME_384.h,
|
||||
# if defined(S390X_NISTP_ASM)
|
||||
# if defined(S390X_EC_ASM)
|
||||
EC_GFp_s390x_nistp384_method,
|
||||
# else
|
||||
0,
|
||||
# endif
|
||||
"NIST/SECG curve over a 384 bit prime field"},
|
||||
{NID_secp521r1, &_EC_NIST_PRIME_521.h,
|
||||
# if defined(S390X_NISTP_ASM)
|
||||
# if defined(S390X_EC_ASM)
|
||||
EC_GFp_s390x_nistp521_method,
|
||||
# elif !defined(OPENSSL_NO_EC_NISTP_64_GCC_128)
|
||||
EC_GFp_nistp521_method,
|
||||
@@ -2953,7 +2953,7 @@ static const ec_list_element curve_list[] = {
|
||||
{NID_X9_62_prime256v1, &_EC_X9_62_PRIME_256V1.h,
|
||||
# if defined(ECP_NISTZ256_ASM)
|
||||
EC_GFp_nistz256_method,
|
||||
# elif defined(S390X_NISTP_ASM)
|
||||
# elif defined(S390X_EC_ASM)
|
||||
EC_GFp_s390x_nistp256_method,
|
||||
# elif !defined(OPENSSL_NO_EC_NISTP_64_GCC_128)
|
||||
EC_GFp_nistp256_method,
|
||||
|
||||
+2
-2
@@ -9,8 +9,8 @@
|
||||
*/
|
||||
|
||||
#include <openssl/err.h>
|
||||
#include "internal/bn_int.h"
|
||||
#include "ec_lcl.h"
|
||||
#include "crypto/bn.h"
|
||||
#include "ec_local.h"
|
||||
|
||||
EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a,
|
||||
const BIGNUM *b, BN_CTX *ctx)
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@
|
||||
|
||||
#include "internal/cryptlib.h"
|
||||
#include <string.h>
|
||||
#include "ec_lcl.h"
|
||||
#include "ec_local.h"
|
||||
#include "internal/refcount.h"
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/engine.h>
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <openssl/ec.h>
|
||||
#include <openssl/engine.h>
|
||||
#include <openssl/err.h>
|
||||
#include "ec_lcl.h"
|
||||
#include "ec_local.h"
|
||||
|
||||
|
||||
static const EC_KEY_METHOD openssl_ec_key_method = {
|
||||
|
||||
+3
-3
@@ -13,7 +13,7 @@
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/opensslv.h>
|
||||
|
||||
#include "ec_lcl.h"
|
||||
#include "ec_local.h"
|
||||
|
||||
/* functions for EC_GROUP objects */
|
||||
|
||||
@@ -710,7 +710,7 @@ EC_POINT *EC_POINT_new(const EC_GROUP *group)
|
||||
|
||||
void EC_POINT_free(EC_POINT *point)
|
||||
{
|
||||
if (!point)
|
||||
if (point == NULL)
|
||||
return;
|
||||
|
||||
if (point->meth->point_finish != 0)
|
||||
@@ -720,7 +720,7 @@ void EC_POINT_free(EC_POINT *point)
|
||||
|
||||
void EC_POINT_clear_free(EC_POINT *point)
|
||||
{
|
||||
if (!point)
|
||||
if (point == NULL)
|
||||
return;
|
||||
|
||||
if (point->meth->point_clear_finish != 0)
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#include <openssl/ec.h>
|
||||
#include <openssl/bn.h>
|
||||
#include "internal/refcount.h"
|
||||
#include "internal/ec_int.h"
|
||||
#include "crypto/ec.h"
|
||||
|
||||
#if defined(__SUNPRO_C)
|
||||
# if __SUNPRO_C >= 0x520
|
||||
@@ -597,7 +597,7 @@ int ec_group_simple_order_bits(const EC_GROUP *group);
|
||||
*/
|
||||
const EC_METHOD *EC_GFp_nistz256_method(void);
|
||||
#endif
|
||||
#ifdef S390X_NISTP_ASM
|
||||
#ifdef S390X_EC_ASM
|
||||
const EC_METHOD *EC_GFp_s390x_nistp256_method(void);
|
||||
const EC_METHOD *EC_GFp_s390x_nistp384_method(void);
|
||||
const EC_METHOD *EC_GFp_s390x_nistp521_method(void);
|
||||
+2
-2
@@ -12,8 +12,8 @@
|
||||
#include <openssl/err.h>
|
||||
|
||||
#include "internal/cryptlib.h"
|
||||
#include "internal/bn_int.h"
|
||||
#include "ec_lcl.h"
|
||||
#include "crypto/bn.h"
|
||||
#include "ec_local.h"
|
||||
#include "internal/refcount.h"
|
||||
|
||||
/*
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/opensslv.h>
|
||||
|
||||
#include "ec_lcl.h"
|
||||
#include "ec_local.h"
|
||||
|
||||
int EC_POINT_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *point,
|
||||
const BIGNUM *x, int y_bit, BN_CTX *ctx)
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/ec.h>
|
||||
#include "ec_lcl.h"
|
||||
#include "ec_local.h"
|
||||
#include <openssl/evp.h>
|
||||
#include "internal/evp_int.h"
|
||||
#include "crypto/evp.h"
|
||||
|
||||
/* EC pkey context structure */
|
||||
|
||||
@@ -437,7 +437,7 @@ static int pkey_ec_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
|
||||
return ret ? EC_KEY_generate_key(ec) : 0;
|
||||
}
|
||||
|
||||
const EVP_PKEY_METHOD ec_pkey_meth = {
|
||||
static const EVP_PKEY_METHOD ec_pkey_meth = {
|
||||
EVP_PKEY_EC,
|
||||
0,
|
||||
pkey_ec_init,
|
||||
@@ -475,3 +475,8 @@ const EVP_PKEY_METHOD ec_pkey_meth = {
|
||||
pkey_ec_ctrl,
|
||||
pkey_ec_ctrl_str
|
||||
};
|
||||
|
||||
const EVP_PKEY_METHOD *ec_pkey_method(void)
|
||||
{
|
||||
return &ec_pkey_meth;
|
||||
}
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/err.h>
|
||||
#include "ec_lcl.h"
|
||||
#include "ec_local.h"
|
||||
|
||||
BIGNUM *EC_POINT_point2bn(const EC_GROUP *group,
|
||||
const EC_POINT *point,
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <openssl/ec.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/kdf.h>
|
||||
#include "ec_lcl.h"
|
||||
#include "ec_local.h"
|
||||
|
||||
/* Key derivation function from X9.63/SECG */
|
||||
int ecdh_KDF_X9_63(unsigned char *out, size_t outlen,
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/objects.h>
|
||||
#include <openssl/ec.h>
|
||||
#include "ec_lcl.h"
|
||||
#include "ec_local.h"
|
||||
|
||||
int ossl_ecdh_compute_key(unsigned char **psec, size_t *pseclen,
|
||||
const EC_POINT *pub_key, const EC_KEY *ecdh)
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/obj_mac.h>
|
||||
#include <openssl/rand.h>
|
||||
#include "internal/bn_int.h"
|
||||
#include "ec_lcl.h"
|
||||
#include "crypto/bn.h"
|
||||
#include "ec_local.h"
|
||||
|
||||
int ossl_ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp,
|
||||
BIGNUM **rp)
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
#include <openssl/ec.h>
|
||||
#include "ec_lcl.h"
|
||||
#include "ec_local.h"
|
||||
#include <openssl/err.h>
|
||||
|
||||
ECDSA_SIG *ECDSA_do_sign(const unsigned char *dgst, int dlen, EC_KEY *eckey)
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
#include <openssl/ec.h>
|
||||
#include "ec_lcl.h"
|
||||
#include "ec_local.h"
|
||||
#include <openssl/err.h>
|
||||
|
||||
/*-
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
#include <openssl/err.h>
|
||||
|
||||
#include "ec_lcl.h"
|
||||
#include "ec_local.h"
|
||||
|
||||
const EC_METHOD *EC_GFp_mont_method(void)
|
||||
{
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/obj_mac.h>
|
||||
#include "ec_lcl.h"
|
||||
#include "ec_local.h"
|
||||
|
||||
const EC_METHOD *EC_GFp_nist_method(void)
|
||||
{
|
||||
|
||||
@@ -38,7 +38,7 @@ NON_EMPTY_TRANSLATION_UNIT
|
||||
# include <stdint.h>
|
||||
# include <string.h>
|
||||
# include <openssl/err.h>
|
||||
# include "ec_lcl.h"
|
||||
# include "ec_local.h"
|
||||
|
||||
# if defined(__SIZEOF_INT128__) && __SIZEOF_INT128__==16
|
||||
/* even with gcc, the typedef won't work for 32-bit platforms */
|
||||
|
||||
@@ -39,7 +39,7 @@ NON_EMPTY_TRANSLATION_UNIT
|
||||
# include <stdint.h>
|
||||
# include <string.h>
|
||||
# include <openssl/err.h>
|
||||
# include "ec_lcl.h"
|
||||
# include "ec_local.h"
|
||||
|
||||
# if defined(__SIZEOF_INT128__) && __SIZEOF_INT128__==16
|
||||
/* even with gcc, the typedef won't work for 32-bit platforms */
|
||||
|
||||
@@ -38,7 +38,7 @@ NON_EMPTY_TRANSLATION_UNIT
|
||||
|
||||
# include <string.h>
|
||||
# include <openssl/err.h>
|
||||
# include "ec_lcl.h"
|
||||
# include "ec_local.h"
|
||||
|
||||
# if defined(__SIZEOF_INT128__) && __SIZEOF_INT128__==16
|
||||
/* even with gcc, the typedef won't work for 32-bit platforms */
|
||||
|
||||
@@ -33,7 +33,7 @@ NON_EMPTY_TRANSLATION_UNIT
|
||||
*/
|
||||
|
||||
# include <stddef.h>
|
||||
# include "ec_lcl.h"
|
||||
# include "ec_local.h"
|
||||
|
||||
/*
|
||||
* Convert an array of points into affine coordinates. (If the point at
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "internal/cryptlib.h"
|
||||
#include "internal/bn_int.h"
|
||||
#include "ec_lcl.h"
|
||||
#include "crypto/bn.h"
|
||||
#include "ec_local.h"
|
||||
#include "internal/refcount.h"
|
||||
|
||||
#if BN_BITS2 != 64
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/symhacks.h>
|
||||
|
||||
#include "ec_lcl.h"
|
||||
#include "ec_local.h"
|
||||
|
||||
int ec_GFp_simple_set_compressed_coordinates(const EC_GROUP *group,
|
||||
EC_POINT *point,
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <string.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/rand.h>
|
||||
#include "ec_lcl.h"
|
||||
#include "ec_local.h"
|
||||
#include "s390x_arch.h"
|
||||
|
||||
/* Size of parameter blocks */
|
||||
@@ -110,7 +110,7 @@ ret:
|
||||
/* Otherwise use default. */
|
||||
if (rc == -1)
|
||||
rc = ec_wNAF_mul(group, r, scalar, num, points, scalars, ctx);
|
||||
OPENSSL_cleanse(param, sizeof(param));
|
||||
OPENSSL_cleanse(param + S390X_OFF_SCALAR(len), len);
|
||||
BN_CTX_end(ctx);
|
||||
BN_CTX_free(new_ctx);
|
||||
return rc;
|
||||
@@ -203,7 +203,7 @@ static ECDSA_SIG *ecdsa_s390x_nistp_sign_sig(const unsigned char *dgst,
|
||||
|
||||
ok = 1;
|
||||
ret:
|
||||
OPENSSL_cleanse(param, sizeof(param));
|
||||
OPENSSL_cleanse(param + S390X_OFF_K(len), 2 * len);
|
||||
if (ok != 1) {
|
||||
ECDSA_SIG_free(sig);
|
||||
sig = NULL;
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/symhacks.h>
|
||||
|
||||
#include "ec_lcl.h"
|
||||
#include "ec_local.h"
|
||||
|
||||
const EC_METHOD *EC_GFp_simple_method(void)
|
||||
{
|
||||
|
||||
+672
-8
@@ -12,10 +12,10 @@
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/ec.h>
|
||||
#include <openssl/rand.h>
|
||||
#include "internal/asn1_int.h"
|
||||
#include "internal/evp_int.h"
|
||||
#include "ec_lcl.h"
|
||||
#include "curve448/curve448_lcl.h"
|
||||
#include "crypto/asn1.h"
|
||||
#include "crypto/evp.h"
|
||||
#include "ec_local.h"
|
||||
#include "curve448/curve448_local.h"
|
||||
|
||||
#define X25519_BITS 253
|
||||
#define X25519_SECURITY_BITS 128
|
||||
@@ -719,7 +719,7 @@ static int pkey_ecx_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
|
||||
return -2;
|
||||
}
|
||||
|
||||
const EVP_PKEY_METHOD ecx25519_pkey_meth = {
|
||||
static const EVP_PKEY_METHOD ecx25519_pkey_meth = {
|
||||
EVP_PKEY_X25519,
|
||||
0, 0, 0, 0, 0, 0, 0,
|
||||
pkey_ecx_keygen,
|
||||
@@ -729,7 +729,7 @@ const EVP_PKEY_METHOD ecx25519_pkey_meth = {
|
||||
0
|
||||
};
|
||||
|
||||
const EVP_PKEY_METHOD ecx448_pkey_meth = {
|
||||
static const EVP_PKEY_METHOD ecx448_pkey_meth = {
|
||||
EVP_PKEY_X448,
|
||||
0, 0, 0, 0, 0, 0, 0,
|
||||
pkey_ecx_keygen,
|
||||
@@ -830,7 +830,7 @@ static int pkey_ecd_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
|
||||
return -2;
|
||||
}
|
||||
|
||||
const EVP_PKEY_METHOD ed25519_pkey_meth = {
|
||||
static const EVP_PKEY_METHOD ed25519_pkey_meth = {
|
||||
EVP_PKEY_ED25519, EVP_PKEY_FLAG_SIGCTX_CUSTOM,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
pkey_ecx_keygen,
|
||||
@@ -841,7 +841,7 @@ const EVP_PKEY_METHOD ed25519_pkey_meth = {
|
||||
pkey_ecd_digestverify25519
|
||||
};
|
||||
|
||||
const EVP_PKEY_METHOD ed448_pkey_meth = {
|
||||
static const EVP_PKEY_METHOD ed448_pkey_meth = {
|
||||
EVP_PKEY_ED448, EVP_PKEY_FLAG_SIGCTX_CUSTOM,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
pkey_ecx_keygen,
|
||||
@@ -851,3 +851,667 @@ const EVP_PKEY_METHOD ed448_pkey_meth = {
|
||||
pkey_ecd_digestsign448,
|
||||
pkey_ecd_digestverify448
|
||||
};
|
||||
|
||||
#ifdef S390X_EC_ASM
|
||||
# include "s390x_arch.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; c > 0 && i >= 0; i--) {
|
||||
c += (unsigned int)u_red[i];
|
||||
u_red[i] = (unsigned char)c;
|
||||
c >>= 8;
|
||||
}
|
||||
|
||||
if (u_red[0] & 0x80) {
|
||||
u_red[0] &= 0x7f;
|
||||
memcpy(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; c > 0 && i >= 0; i--) {
|
||||
c += (unsigned int)u_red[i];
|
||||
u_red[i] = (unsigned char)c;
|
||||
c >>= 8;
|
||||
}
|
||||
|
||||
if (u_red[0] & 0x80) {
|
||||
u_red[0] &= 0x7f;
|
||||
memcpy(u, u_red, sizeof(u_red));
|
||||
}
|
||||
}
|
||||
|
||||
static 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;
|
||||
}
|
||||
|
||||
static 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);
|
||||
|
||||
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)
|
||||
{
|
||||
static const unsigned char generator[] = {
|
||||
0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
ECX_KEY *key;
|
||||
unsigned char *privkey = NULL, *pubkey;
|
||||
|
||||
key = OPENSSL_zalloc(sizeof(*key));
|
||||
if (key == NULL) {
|
||||
ECerr(EC_F_S390X_PKEY_ECX_KEYGEN25519, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
pubkey = key->pubkey;
|
||||
|
||||
privkey = key->privkey = OPENSSL_secure_malloc(X25519_KEYLEN);
|
||||
if (privkey == NULL) {
|
||||
ECerr(EC_F_S390X_PKEY_ECX_KEYGEN25519, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (RAND_priv_bytes(privkey, X25519_KEYLEN) <= 0)
|
||||
goto err;
|
||||
|
||||
privkey[0] &= 248;
|
||||
privkey[31] &= 127;
|
||||
privkey[31] |= 64;
|
||||
|
||||
if (s390x_x25519_mul(pubkey, generator, privkey) != 1)
|
||||
goto err;
|
||||
|
||||
EVP_PKEY_assign(pkey, ctx->pmeth->pkey_id, key);
|
||||
return 1;
|
||||
err:
|
||||
OPENSSL_secure_clear_free(privkey, X25519_KEYLEN);
|
||||
key->privkey = NULL;
|
||||
OPENSSL_free(key);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int s390x_pkey_ecx_keygen448(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
|
||||
{
|
||||
static const unsigned char generator[] = {
|
||||
0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
ECX_KEY *key;
|
||||
unsigned char *privkey = NULL, *pubkey;
|
||||
|
||||
key = OPENSSL_zalloc(sizeof(*key));
|
||||
if (key == NULL) {
|
||||
ECerr(EC_F_S390X_PKEY_ECX_KEYGEN448, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
pubkey = key->pubkey;
|
||||
|
||||
privkey = key->privkey = OPENSSL_secure_malloc(X448_KEYLEN);
|
||||
if (privkey == NULL) {
|
||||
ECerr(EC_F_S390X_PKEY_ECX_KEYGEN448, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (RAND_priv_bytes(privkey, X448_KEYLEN) <= 0)
|
||||
goto err;
|
||||
|
||||
privkey[0] &= 252;
|
||||
privkey[55] |= 128;
|
||||
|
||||
if (s390x_x448_mul(pubkey, generator, privkey) != 1)
|
||||
goto err;
|
||||
|
||||
EVP_PKEY_assign(pkey, ctx->pmeth->pkey_id, key);
|
||||
return 1;
|
||||
err:
|
||||
OPENSSL_secure_clear_free(privkey, X448_KEYLEN);
|
||||
key->privkey = NULL;
|
||||
OPENSSL_free(key);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int s390x_pkey_ecd_keygen25519(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
|
||||
{
|
||||
static const unsigned char generator_x[] = {
|
||||
0x1a, 0xd5, 0x25, 0x8f, 0x60, 0x2d, 0x56, 0xc9, 0xb2, 0xa7, 0x25, 0x95,
|
||||
0x60, 0xc7, 0x2c, 0x69, 0x5c, 0xdc, 0xd6, 0xfd, 0x31, 0xe2, 0xa4, 0xc0,
|
||||
0xfe, 0x53, 0x6e, 0xcd, 0xd3, 0x36, 0x69, 0x21
|
||||
};
|
||||
static const unsigned char generator_y[] = {
|
||||
0x58, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
|
||||
0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
|
||||
0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
|
||||
};
|
||||
unsigned char x_dst[32], buff[SHA512_DIGEST_LENGTH];
|
||||
ECX_KEY *key;
|
||||
unsigned char *privkey = NULL, *pubkey;
|
||||
|
||||
key = OPENSSL_zalloc(sizeof(*key));
|
||||
if (key == NULL) {
|
||||
ECerr(EC_F_S390X_PKEY_ECD_KEYGEN25519, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
pubkey = key->pubkey;
|
||||
|
||||
privkey = key->privkey = OPENSSL_secure_malloc(ED25519_KEYLEN);
|
||||
if (privkey == NULL) {
|
||||
ECerr(EC_F_S390X_PKEY_ECD_KEYGEN25519, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (RAND_priv_bytes(privkey, ED25519_KEYLEN) <= 0)
|
||||
goto err;
|
||||
|
||||
SHA512(privkey, 32, buff);
|
||||
buff[0] &= 248;
|
||||
buff[31] &= 63;
|
||||
buff[31] |= 64;
|
||||
|
||||
if (s390x_ed25519_mul(x_dst, pubkey,
|
||||
generator_x, generator_y, buff) != 1)
|
||||
goto err;
|
||||
|
||||
pubkey[31] |= ((x_dst[0] & 0x01) << 7);
|
||||
|
||||
EVP_PKEY_assign(pkey, ctx->pmeth->pkey_id, key);
|
||||
return 1;
|
||||
err:
|
||||
OPENSSL_secure_clear_free(privkey, ED25519_KEYLEN);
|
||||
key->privkey = NULL;
|
||||
OPENSSL_free(key);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int s390x_pkey_ecd_keygen448(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
|
||||
{
|
||||
static const unsigned char generator_x[] = {
|
||||
0x5e, 0xc0, 0x0c, 0xc7, 0x2b, 0xa8, 0x26, 0x26, 0x8e, 0x93, 0x00, 0x8b,
|
||||
0xe1, 0x80, 0x3b, 0x43, 0x11, 0x65, 0xb6, 0x2a, 0xf7, 0x1a, 0xae, 0x12,
|
||||
0x64, 0xa4, 0xd3, 0xa3, 0x24, 0xe3, 0x6d, 0xea, 0x67, 0x17, 0x0f, 0x47,
|
||||
0x70, 0x65, 0x14, 0x9e, 0xda, 0x36, 0xbf, 0x22, 0xa6, 0x15, 0x1d, 0x22,
|
||||
0xed, 0x0d, 0xed, 0x6b, 0xc6, 0x70, 0x19, 0x4f, 0x00
|
||||
};
|
||||
static const unsigned char generator_y[] = {
|
||||
0x14, 0xfa, 0x30, 0xf2, 0x5b, 0x79, 0x08, 0x98, 0xad, 0xc8, 0xd7, 0x4e,
|
||||
0x2c, 0x13, 0xbd, 0xfd, 0xc4, 0x39, 0x7c, 0xe6, 0x1c, 0xff, 0xd3, 0x3a,
|
||||
0xd7, 0xc2, 0xa0, 0x05, 0x1e, 0x9c, 0x78, 0x87, 0x40, 0x98, 0xa3, 0x6c,
|
||||
0x73, 0x73, 0xea, 0x4b, 0x62, 0xc7, 0xc9, 0x56, 0x37, 0x20, 0x76, 0x88,
|
||||
0x24, 0xbc, 0xb6, 0x6e, 0x71, 0x46, 0x3f, 0x69, 0x00
|
||||
};
|
||||
unsigned char x_dst[57], buff[114];
|
||||
ECX_KEY *key;
|
||||
unsigned char *privkey = NULL, *pubkey;
|
||||
EVP_MD_CTX *hashctx = NULL;
|
||||
|
||||
key = OPENSSL_zalloc(sizeof(*key));
|
||||
if (key == NULL) {
|
||||
ECerr(EC_F_S390X_PKEY_ECD_KEYGEN448, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
pubkey = key->pubkey;
|
||||
|
||||
privkey = key->privkey = OPENSSL_secure_malloc(ED448_KEYLEN);
|
||||
if (privkey == NULL) {
|
||||
ECerr(EC_F_S390X_PKEY_ECD_KEYGEN448, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (RAND_priv_bytes(privkey, ED448_KEYLEN) <= 0)
|
||||
goto err;
|
||||
|
||||
hashctx = EVP_MD_CTX_new();
|
||||
if (hashctx == NULL)
|
||||
goto err;
|
||||
if (EVP_DigestInit_ex(hashctx, EVP_shake256(), NULL) != 1)
|
||||
goto err;
|
||||
if (EVP_DigestUpdate(hashctx, privkey, 57) != 1)
|
||||
goto err;
|
||||
if (EVP_DigestFinalXOF(hashctx, buff, sizeof(buff)) != 1)
|
||||
goto err;
|
||||
|
||||
buff[0] &= -4;
|
||||
buff[55] |= 0x80;
|
||||
buff[56] = 0;
|
||||
|
||||
if (s390x_ed448_mul(x_dst, pubkey,
|
||||
generator_x, generator_y, buff) != 1)
|
||||
goto err;
|
||||
|
||||
pubkey[56] |= ((x_dst[0] & 0x01) << 7);
|
||||
|
||||
EVP_PKEY_assign(pkey, ctx->pmeth->pkey_id, key);
|
||||
EVP_MD_CTX_free(hashctx);
|
||||
return 1;
|
||||
err:
|
||||
OPENSSL_secure_clear_free(privkey, ED448_KEYLEN);
|
||||
key->privkey = NULL;
|
||||
OPENSSL_free(key);
|
||||
EVP_MD_CTX_free(hashctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int s390x_pkey_ecx_derive25519(EVP_PKEY_CTX *ctx, unsigned char *key,
|
||||
size_t *keylen)
|
||||
{
|
||||
const unsigned char *privkey, *pubkey;
|
||||
|
||||
if (!validate_ecx_derive(ctx, key, keylen, &privkey, &pubkey))
|
||||
return 0;
|
||||
|
||||
if (key != NULL)
|
||||
return s390x_x25519_mul(key, pubkey, privkey);
|
||||
|
||||
*keylen = X25519_KEYLEN;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int s390x_pkey_ecx_derive448(EVP_PKEY_CTX *ctx, unsigned char *key,
|
||||
size_t *keylen)
|
||||
{
|
||||
const unsigned char *privkey, *pubkey;
|
||||
|
||||
if (!validate_ecx_derive(ctx, key, keylen, &privkey, &pubkey))
|
||||
return 0;
|
||||
|
||||
if (key != NULL)
|
||||
return s390x_x448_mul(key, pubkey, privkey);
|
||||
|
||||
*keylen = X448_KEYLEN;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int s390x_pkey_ecd_digestsign25519(EVP_MD_CTX *ctx,
|
||||
unsigned char *sig, size_t *siglen,
|
||||
const unsigned char *tbs,
|
||||
size_t tbslen)
|
||||
{
|
||||
union {
|
||||
struct {
|
||||
unsigned char sig[64];
|
||||
unsigned char priv[32];
|
||||
} ed25519;
|
||||
unsigned long long buff[512];
|
||||
} param;
|
||||
const ECX_KEY *edkey = EVP_MD_CTX_pkey_ctx(ctx)->pkey->pkey.ecx;
|
||||
int rc;
|
||||
|
||||
if (sig == NULL) {
|
||||
*siglen = ED25519_SIGSIZE;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (*siglen < ED25519_SIGSIZE) {
|
||||
ECerr(EC_F_S390X_PKEY_ECD_DIGESTSIGN25519, EC_R_BUFFER_TOO_SMALL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
memset(¶m, 0, sizeof(param));
|
||||
memcpy(param.ed25519.priv, edkey->privkey, sizeof(param.ed25519.priv));
|
||||
|
||||
rc = s390x_kdsa(S390X_EDDSA_SIGN_ED25519, ¶m.ed25519, tbs, tbslen);
|
||||
OPENSSL_cleanse(param.ed25519.priv, sizeof(param.ed25519.priv));
|
||||
if (rc != 0)
|
||||
return 0;
|
||||
|
||||
s390x_flip_endian32(sig, param.ed25519.sig);
|
||||
s390x_flip_endian32(sig + 32, param.ed25519.sig + 32);
|
||||
|
||||
*siglen = ED25519_SIGSIZE;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int s390x_pkey_ecd_digestsign448(EVP_MD_CTX *ctx,
|
||||
unsigned char *sig, size_t *siglen,
|
||||
const unsigned char *tbs,
|
||||
size_t tbslen)
|
||||
{
|
||||
union {
|
||||
struct {
|
||||
unsigned char sig[128];
|
||||
unsigned char priv[64];
|
||||
} ed448;
|
||||
unsigned long long buff[512];
|
||||
} param;
|
||||
const ECX_KEY *edkey = EVP_MD_CTX_pkey_ctx(ctx)->pkey->pkey.ecx;
|
||||
int rc;
|
||||
|
||||
if (sig == NULL) {
|
||||
*siglen = ED448_SIGSIZE;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (*siglen < ED448_SIGSIZE) {
|
||||
ECerr(EC_F_S390X_PKEY_ECD_DIGESTSIGN448, EC_R_BUFFER_TOO_SMALL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
memset(¶m, 0, sizeof(param));
|
||||
memcpy(param.ed448.priv + 64 - 57, edkey->privkey, 57);
|
||||
|
||||
rc = s390x_kdsa(S390X_EDDSA_SIGN_ED448, ¶m.ed448, tbs, tbslen);
|
||||
OPENSSL_cleanse(param.ed448.priv, sizeof(param.ed448.priv));
|
||||
if (rc != 0)
|
||||
return 0;
|
||||
|
||||
s390x_flip_endian64(param.ed448.sig, param.ed448.sig);
|
||||
s390x_flip_endian64(param.ed448.sig + 64, param.ed448.sig + 64);
|
||||
memcpy(sig, param.ed448.sig, 57);
|
||||
memcpy(sig + 57, param.ed448.sig + 64, 57);
|
||||
|
||||
*siglen = ED448_SIGSIZE;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int s390x_pkey_ecd_digestverify25519(EVP_MD_CTX *ctx,
|
||||
const unsigned char *sig,
|
||||
size_t siglen,
|
||||
const unsigned char *tbs,
|
||||
size_t tbslen)
|
||||
{
|
||||
union {
|
||||
struct {
|
||||
unsigned char sig[64];
|
||||
unsigned char pub[32];
|
||||
} ed25519;
|
||||
unsigned long long buff[512];
|
||||
} param;
|
||||
const ECX_KEY *edkey = EVP_MD_CTX_pkey_ctx(ctx)->pkey->pkey.ecx;
|
||||
|
||||
if (siglen != ED25519_SIGSIZE)
|
||||
return 0;
|
||||
|
||||
memset(¶m, 0, sizeof(param));
|
||||
s390x_flip_endian32(param.ed25519.sig, sig);
|
||||
s390x_flip_endian32(param.ed25519.sig + 32, sig + 32);
|
||||
s390x_flip_endian32(param.ed25519.pub, edkey->pubkey);
|
||||
|
||||
return s390x_kdsa(S390X_EDDSA_VERIFY_ED25519,
|
||||
¶m.ed25519, tbs, tbslen) == 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
static int s390x_pkey_ecd_digestverify448(EVP_MD_CTX *ctx,
|
||||
const unsigned char *sig,
|
||||
size_t siglen,
|
||||
const unsigned char *tbs,
|
||||
size_t tbslen)
|
||||
{
|
||||
union {
|
||||
struct {
|
||||
unsigned char sig[128];
|
||||
unsigned char pub[64];
|
||||
} ed448;
|
||||
unsigned long long buff[512];
|
||||
} param;
|
||||
const ECX_KEY *edkey = EVP_MD_CTX_pkey_ctx(ctx)->pkey->pkey.ecx;
|
||||
|
||||
if (siglen != ED448_SIGSIZE)
|
||||
return 0;
|
||||
|
||||
memset(¶m, 0, sizeof(param));
|
||||
memcpy(param.ed448.sig, sig, 57);
|
||||
s390x_flip_endian64(param.ed448.sig, param.ed448.sig);
|
||||
memcpy(param.ed448.sig + 64, sig + 57, 57);
|
||||
s390x_flip_endian64(param.ed448.sig + 64, param.ed448.sig + 64);
|
||||
memcpy(param.ed448.pub, edkey->pubkey, 57);
|
||||
s390x_flip_endian64(param.ed448.pub, param.ed448.pub);
|
||||
|
||||
return s390x_kdsa(S390X_EDDSA_VERIFY_ED448,
|
||||
¶m.ed448, tbs, tbslen) == 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
static const EVP_PKEY_METHOD ecx25519_s390x_pkey_meth = {
|
||||
EVP_PKEY_X25519,
|
||||
0, 0, 0, 0, 0, 0, 0,
|
||||
s390x_pkey_ecx_keygen25519,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
s390x_pkey_ecx_derive25519,
|
||||
pkey_ecx_ctrl,
|
||||
0
|
||||
};
|
||||
|
||||
static const EVP_PKEY_METHOD ecx448_s390x_pkey_meth = {
|
||||
EVP_PKEY_X448,
|
||||
0, 0, 0, 0, 0, 0, 0,
|
||||
s390x_pkey_ecx_keygen448,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
s390x_pkey_ecx_derive448,
|
||||
pkey_ecx_ctrl,
|
||||
0
|
||||
};
|
||||
static const EVP_PKEY_METHOD ed25519_s390x_pkey_meth = {
|
||||
EVP_PKEY_ED25519, EVP_PKEY_FLAG_SIGCTX_CUSTOM,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
s390x_pkey_ecd_keygen25519,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
pkey_ecd_ctrl,
|
||||
0,
|
||||
s390x_pkey_ecd_digestsign25519,
|
||||
s390x_pkey_ecd_digestverify25519
|
||||
};
|
||||
|
||||
static const EVP_PKEY_METHOD ed448_s390x_pkey_meth = {
|
||||
EVP_PKEY_ED448, EVP_PKEY_FLAG_SIGCTX_CUSTOM,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
s390x_pkey_ecd_keygen448,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
pkey_ecd_ctrl,
|
||||
0,
|
||||
s390x_pkey_ecd_digestsign448,
|
||||
s390x_pkey_ecd_digestverify448
|
||||
};
|
||||
#endif
|
||||
|
||||
const EVP_PKEY_METHOD *ecx25519_pkey_method(void)
|
||||
{
|
||||
#ifdef S390X_EC_ASM
|
||||
if (OPENSSL_s390xcap_P.pcc[1] & S390X_CAPBIT(S390X_SCALAR_MULTIPLY_X25519))
|
||||
return &ecx25519_s390x_pkey_meth;
|
||||
#endif
|
||||
return &ecx25519_pkey_meth;
|
||||
}
|
||||
|
||||
const EVP_PKEY_METHOD *ecx448_pkey_method(void)
|
||||
{
|
||||
#ifdef S390X_EC_ASM
|
||||
if (OPENSSL_s390xcap_P.pcc[1] & S390X_CAPBIT(S390X_SCALAR_MULTIPLY_X448))
|
||||
return &ecx448_s390x_pkey_meth;
|
||||
#endif
|
||||
return &ecx448_pkey_meth;
|
||||
}
|
||||
|
||||
const EVP_PKEY_METHOD *ed25519_pkey_method(void)
|
||||
{
|
||||
#ifdef S390X_EC_ASM
|
||||
if (OPENSSL_s390xcap_P.pcc[1] & S390X_CAPBIT(S390X_SCALAR_MULTIPLY_ED25519)
|
||||
&& OPENSSL_s390xcap_P.kdsa[0] & S390X_CAPBIT(S390X_EDDSA_SIGN_ED25519)
|
||||
&& OPENSSL_s390xcap_P.kdsa[0]
|
||||
& S390X_CAPBIT(S390X_EDDSA_VERIFY_ED25519))
|
||||
return &ed25519_s390x_pkey_meth;
|
||||
#endif
|
||||
return &ed25519_pkey_meth;
|
||||
}
|
||||
|
||||
const EVP_PKEY_METHOD *ed448_pkey_method(void)
|
||||
{
|
||||
#ifdef S390X_EC_ASM
|
||||
if (OPENSSL_s390xcap_P.pcc[1] & S390X_CAPBIT(S390X_SCALAR_MULTIPLY_ED448)
|
||||
&& OPENSSL_s390xcap_P.kdsa[0] & S390X_CAPBIT(S390X_EDDSA_SIGN_ED448)
|
||||
&& OPENSSL_s390xcap_P.kdsa[0] & S390X_CAPBIT(S390X_EDDSA_VERIFY_ED448))
|
||||
return &ed448_s390x_pkey_meth;
|
||||
#endif
|
||||
return &ed448_pkey_meth;
|
||||
}
|
||||
Reference in New Issue
Block a user