X-Git-Url: https://git.openssl.org/gitweb/?a=blobdiff_plain;f=crypto%2Fec%2Fec_lcl.h;h=421cd470e2e9bf4fa7aa7976dec5e6b86b5baa74;hb=4ea41daa073af5fb45dacc7e380248e3a108c63d;hp=5b79340a141f162deab51d3ca415421e7f6482a6;hpb=25d57dc71b7b2d024588eb3831a73cb32fc069bf;p=openssl.git diff --git a/crypto/ec/ec_lcl.h b/crypto/ec/ec_lcl.h index 5b79340a14..421cd470e2 100644 --- a/crypto/ec/ec_lcl.h +++ b/crypto/ec/ec_lcl.h @@ -1,5 +1,6 @@ /* - * Copyright 2001-2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2001-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -7,27 +8,12 @@ * https://www.openssl.org/source/license.html */ -/* ==================================================================== - * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. - * - * Portions of the attached software ("Contribution") are developed by - * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project. - * - * The Contribution is licensed pursuant to the OpenSSL open source - * license provided above. - * - * The elliptic curve binary polynomial software is originally written by - * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories. - * - */ - #include #include #include #include - -#include "e_os.h" +#include "internal/refcount.h" #if defined(__SUNPRO_C) # if __SUNPRO_C >= 0x520 @@ -169,7 +155,10 @@ struct ec_method_st { /* custom ECDH operation */ int (*ecdh_compute_key)(unsigned char **pout, size_t *poutlen, const EC_POINT *pub_key, const EC_KEY *ecdh); -} /* EC_METHOD */ ; + /* Inverse modulo order */ + int (*field_inverse_mod_ord)(const EC_GROUP *, BIGNUM *r, BIGNUM *x, + BN_CTX *ctx); +}; /* * Types and functions to manipulate pre-computed values. @@ -228,11 +217,16 @@ struct ec_group_st { /* data for ECDSA inverse */ BN_MONT_CTX *mont_data; - /* precomputed values for speed. */ + /* + * Precomputed values for speed. The PCT_xxx names match the + * pre_comp.xxx union names; see the SETPRECOMP and HAVEPRECOMP + * macros, below. + */ enum { - pct_none, - pct_nistp224, pct_nistp256, pct_nistp521, pct_nistz256, - pct_ec } pre_comp_type; + PCT_none, + PCT_nistp224, PCT_nistp256, PCT_nistp521, PCT_nistz256, + PCT_ec + } pre_comp_type; union { NISTP224_PRE_COMP *nistp224; NISTP256_PRE_COMP *nistp256; @@ -240,12 +234,12 @@ struct ec_group_st { NISTZ256_PRE_COMP *nistz256; EC_PRE_COMP *ec; } pre_comp; -} /* EC_GROUP */ ; +}; #define SETPRECOMP(g, type, pre) \ - g->pre_comp_type = pct_##type, g->pre_comp.type = pre + g->pre_comp_type = PCT_##type, g->pre_comp.type = pre #define HAVEPRECOMP(g, type) \ - g->pre_comp_type == pct_##type && g->pre_comp.type != NULL + g->pre_comp_type == PCT_##type && g->pre_comp.type != NULL struct ec_key_st { const EC_KEY_METHOD *meth; @@ -254,19 +248,13 @@ struct ec_key_st { EC_GROUP *group; EC_POINT *pub_key; BIGNUM *priv_key; - /* - * Arbitrary extra data. - * For example in X25519 this contains the raw private key in a 32 byte - * buffer. - */ - void *custom_data; unsigned int enc_flag; point_conversion_form_t conv_form; - int references; + CRYPTO_REF_COUNT references; int flags; CRYPTO_EX_DATA ex_data; CRYPTO_RWLOCK *lock; -} /* EC_KEY */ ; +}; struct ec_point_st { const EC_METHOD *meth; @@ -280,12 +268,7 @@ struct ec_point_st { * Z) represents (X/Z^2, Y/Z^3) if Z != 0 */ int Z_is_one; /* enable optimized point arithmetics for * special case */ - /* - * Arbitrary extra data. - * For example in X25519 this contains the public key in a 32 byte buffer. - */ - void *custom_data; -} /* EC_POINT */ ; +}; NISTP224_PRE_COMP *EC_nistp224_pre_comp_dup(NISTP224_PRE_COMP *); NISTP256_PRE_COMP *EC_nistp256_pre_comp_dup(NISTP256_PRE_COMP *); @@ -540,7 +523,6 @@ void ec_GFp_nistp_points_make_affine_internal(size_t num, void *point_array, void ec_GFp_nistp_recode_scalar_bits(unsigned char *sign, unsigned char *digit, unsigned char in); #endif -int ec_precompute_mont_data(EC_GROUP *); int ec_group_simple_order_bits(const EC_GROUP *group); #ifdef ECP_NISTZ256_ASM @@ -585,7 +567,7 @@ struct ec_key_method_st { const unsigned char *sigbuf, int sig_len, EC_KEY *eckey); int (*verify_sig)(const unsigned char *dgst, int dgst_len, const ECDSA_SIG *sig, EC_KEY *eckey); -} /* EC_KEY_METHOD */ ; +}; #define EC_KEY_METHOD_DYNAMIC 1 @@ -613,9 +595,17 @@ int ossl_ecdsa_verify(int type, const unsigned char *dgst, int dgst_len, int ossl_ecdsa_verify_sig(const unsigned char *dgst, int dgst_len, const ECDSA_SIG *sig, EC_KEY *eckey); -const EC_METHOD *ec_x25519_meth(void); +int ED25519_sign(uint8_t *out_sig, const uint8_t *message, size_t message_len, + const uint8_t public_key[32], const uint8_t private_key[32]); +int ED25519_verify(const uint8_t *message, size_t message_len, + const uint8_t signature[64], const uint8_t public_key[32]); +void ED25519_public_from_private(uint8_t out_public_key[32], + const uint8_t private_key[32]); int X25519(uint8_t out_shared_key[32], const uint8_t private_key[32], const uint8_t peer_public_value[32]); void X25519_public_from_private(uint8_t out_public_value[32], const uint8_t private_key[32]); + +int EC_GROUP_do_inverse_ord(const EC_GROUP *group, BIGNUM *res, + BIGNUM *x, BN_CTX *ctx);