Update 1.1.1-pre8

This commit is contained in:
2018-06-24 20:52:36 +09:00
parent 5d513892b8
commit 4c4004fa50
48 changed files with 288 additions and 298 deletions
-8
View File
@@ -23,10 +23,6 @@
# include "internal/bn_int.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* These preprocessor symbols control various aspects of the bignum headers
* and library code. They're not defined by any "normal" configuration, as
@@ -659,8 +655,4 @@ static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)
return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);
}
#ifdef __cplusplus
}
#endif
#endif
+13 -15
View File
@@ -154,19 +154,21 @@ int BN_is_prime_fasttest_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed,
int i, j, ret = -1;
int k;
BN_CTX *ctx = NULL;
BIGNUM *A1, *A1_odd, *check; /* taken from ctx */
BIGNUM *A1, *A1_odd, *A3, *check; /* taken from ctx */
BN_MONT_CTX *mont = NULL;
if (BN_cmp(a, BN_value_one()) <= 0)
/* Take care of the really small primes 2 & 3 */
if (BN_is_word(a, 2) || BN_is_word(a, 3))
return 1;
/* Check odd and bigger than 1 */
if (!BN_is_odd(a) || BN_cmp(a, BN_value_one()) <= 0)
return 0;
if (checks == BN_prime_checks)
checks = BN_prime_checks_for_size(BN_num_bits(a));
/* first look for small factors */
if (!BN_is_odd(a))
/* a is even => a is prime if and only if a == 2 */
return BN_is_word(a, 2);
if (do_trial_division) {
for (i = 1; i < NUMPRIMES; i++) {
BN_ULONG mod = BN_mod_word(a, primes[i]);
@@ -186,20 +188,18 @@ int BN_is_prime_fasttest_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed,
BN_CTX_start(ctx);
A1 = BN_CTX_get(ctx);
A3 = BN_CTX_get(ctx);
A1_odd = BN_CTX_get(ctx);
check = BN_CTX_get(ctx);
if (check == NULL)
goto err;
/* compute A1 := a - 1 */
if (!BN_copy(A1, a))
if (!BN_copy(A1, a) || !BN_sub_word(A1, 1))
goto err;
if (!BN_sub_word(A1, 1))
/* compute A3 := a - 3 */
if (!BN_copy(A3, a) || !BN_sub_word(A3, 3))
goto err;
if (BN_is_zero(A1)) {
ret = 0;
goto err;
}
/* write A1 as A1_odd * 2^k */
k = 1;
@@ -216,11 +216,9 @@ int BN_is_prime_fasttest_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed,
goto err;
for (i = 0; i < checks; i++) {
if (!BN_priv_rand_range(check, A1))
/* 1 < check < a-1 */
if (!BN_priv_rand_range(check, A3) || !BN_add_word(check, 2))
goto err;
if (!BN_add_word(check, 1))
goto err;
/* now 1 <= check < a */
j = witness(check, a, A1, A1_odd, k, ctx, mont);
if (j == -1)
-7
View File
@@ -10,10 +10,6 @@
#ifndef HEADER_CMS_LCL_H
# define HEADER_CMS_LCL_H
#ifdef __cplusplus
extern "C" {
#endif
# include <openssl/x509.h>
/*
@@ -438,7 +434,4 @@ DECLARE_ASN1_ITEM(CMS_RevocationInfoChoice)
DECLARE_ASN1_ITEM(CMS_SignedData)
DECLARE_ASN1_ITEM(CMS_CompressedData)
#ifdef __cplusplus
}
#endif
#endif
+1 -1
View File
@@ -46,7 +46,7 @@ typedef struct ctlog_store_load_ctx_st {
* Creates an empty context for loading a CT log store.
* It should be populated before use.
*/
static CTLOG_STORE_LOAD_CTX *ctlog_store_load_ctx_new();
static CTLOG_STORE_LOAD_CTX *ctlog_store_load_ctx_new(void);
/*
* Deletes a CT log store load context.
+1 -1
View File
@@ -150,7 +150,7 @@ void x25519_fe51_mul121666(fe51 h, fe51 f);
typedef uint64_t fe64[4];
int x25519_fe64_eligible();
int x25519_fe64_eligible(void);
/*
* There are no reference C implementations for this radix.
+4 -4
View File
@@ -174,8 +174,8 @@ struct ec_method_st {
int (*ecdh_compute_key)(unsigned char **pout, size_t *poutlen,
const EC_POINT *pub_key, const EC_KEY *ecdh);
/* Inverse modulo order */
int (*field_inverse_mod_ord)(const EC_GROUP *, BIGNUM *r, BIGNUM *x,
BN_CTX *ctx);
int (*field_inverse_mod_ord)(const EC_GROUP *, BIGNUM *r,
const BIGNUM *x, BN_CTX *);
int (*blind_coordinates)(const EC_GROUP *group, EC_POINT *p, BN_CTX *ctx);
};
@@ -636,7 +636,7 @@ int X25519(uint8_t out_shared_key[32], const uint8_t private_key[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);
int ec_group_do_inverse_ord(const EC_GROUP *group, BIGNUM *res,
const BIGNUM *x, BN_CTX *ctx);
int ec_point_blind_coordinates(const EC_GROUP *group, EC_POINT *p, BN_CTX *ctx);
+57 -3
View File
@@ -1017,13 +1017,67 @@ int ec_group_simple_order_bits(const EC_GROUP *group)
return BN_num_bits(group->order);
}
int EC_GROUP_do_inverse_ord(const EC_GROUP *group, BIGNUM *res,
BIGNUM *x, BN_CTX *ctx)
static int ec_field_inverse_mod_ord(const EC_GROUP *group, BIGNUM *r,
const BIGNUM *x, BN_CTX *ctx)
{
BIGNUM *e = NULL;
BN_CTX *new_ctx = NULL;
int ret = 0;
if (group->mont_data == NULL)
return 0;
if (ctx == NULL && (ctx = new_ctx = BN_CTX_secure_new()) == NULL)
return 0;
BN_CTX_start(ctx);
if ((e = BN_CTX_get(ctx)) == NULL)
goto err;
/*-
* We want inverse in constant time, therefore we utilize the fact
* order must be prime and use Fermats Little Theorem instead.
*/
if (!BN_set_word(e, 2))
goto err;
if (!BN_sub(e, group->order, e))
goto err;
/*-
* Exponent e is public.
* No need for scatter-gather or BN_FLG_CONSTTIME.
*/
if (!BN_mod_exp_mont(r, x, e, group->order, ctx, group->mont_data))
goto err;
ret = 1;
err:
if (ctx != NULL)
BN_CTX_end(ctx);
BN_CTX_free(new_ctx);
return ret;
}
/*-
* Default behavior, if group->meth->field_inverse_mod_ord is NULL:
* - When group->order is even, this function returns an error.
* - When group->order is otherwise composite, the correctness
* of the output is not guaranteed.
* - When x is outside the range [1, group->order), the correctness
* of the output is not guaranteed.
* - Otherwise, this function returns the multiplicative inverse in the
* range [1, group->order).
*
* EC_METHODs must implement their own field_inverse_mod_ord for
* other functionality.
*/
int ec_group_do_inverse_ord(const EC_GROUP *group, BIGNUM *res,
const BIGNUM *x, BN_CTX *ctx)
{
if (group->meth->field_inverse_mod_ord != NULL)
return group->meth->field_inverse_mod_ord(group, res, x, ctx);
else
return 0;
return ec_field_inverse_mod_ord(group, res, x, ctx);
}
/*-
+9 -35
View File
@@ -136,34 +136,10 @@ static int ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in,
}
while (BN_is_zero(r));
/* Check if optimized inverse is implemented */
if (EC_GROUP_do_inverse_ord(group, k, k, ctx) == 0) {
/* compute the inverse of k */
if (group->mont_data != NULL) {
/*
* We want inverse in constant time, therefore we utilize the fact
* order must be prime and use Fermats Little Theorem instead.
*/
if (!BN_set_word(X, 2)) {
ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_BN_LIB);
goto err;
}
if (!BN_mod_sub(X, order, X, order, ctx)) {
ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_BN_LIB);
goto err;
}
BN_set_flags(X, BN_FLG_CONSTTIME);
if (!BN_mod_exp_mont_consttime(k, k, X, order, ctx,
group->mont_data)) {
ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_BN_LIB);
goto err;
}
} else {
if (!BN_mod_inverse(k, k, order, ctx)) {
ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_BN_LIB);
goto err;
}
}
/* compute the inverse of k */
if (!ec_group_do_inverse_ord(group, k, k, ctx)) {
ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_BN_LIB);
goto err;
}
/* clear old values if necessary */
@@ -360,7 +336,8 @@ ECDSA_SIG *ossl_ecdsa_sign_sig(const unsigned char *dgst, int dgst_len,
ECDSA_SIG_free(ret);
ret = NULL;
}
BN_CTX_end(ctx);
if (ctx != NULL)
BN_CTX_end(ctx);
BN_CTX_free(ctx);
BN_clear_free(kinv);
return ret;
@@ -449,12 +426,9 @@ int ossl_ecdsa_verify_sig(const unsigned char *dgst, int dgst_len,
goto err;
}
/* calculate tmp1 = inv(S) mod order */
/* Check if optimized inverse is implemented */
if (EC_GROUP_do_inverse_ord(group, u2, sig->s, ctx) == 0) {
if (!BN_mod_inverse(u2, sig->s, order, ctx)) {
ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_BN_LIB);
goto err;
}
if (!ec_group_do_inverse_ord(group, u2, sig->s, ctx)) {
ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_BN_LIB);
goto err;
}
/* digest -> m */
i = BN_num_bits(order);
+1 -1
View File
@@ -1212,7 +1212,7 @@ static void batch_mul(felem x_out, felem y_out, felem z_out,
* FUNCTIONS TO MANAGE PRECOMPUTATION
*/
static NISTP224_PRE_COMP *nistp224_pre_comp_new()
static NISTP224_PRE_COMP *nistp224_pre_comp_new(void)
{
NISTP224_PRE_COMP *ret = OPENSSL_zalloc(sizeof(*ret));
+1 -1
View File
@@ -1832,7 +1832,7 @@ const EC_METHOD *EC_GFp_nistp256_method(void)
* FUNCTIONS TO MANAGE PRECOMPUTATION
*/
static NISTP256_PRE_COMP *nistp256_pre_comp_new()
static NISTP256_PRE_COMP *nistp256_pre_comp_new(void)
{
NISTP256_PRE_COMP *ret = OPENSSL_zalloc(sizeof(*ret));
+1 -1
View File
@@ -1671,7 +1671,7 @@ const EC_METHOD *EC_GFp_nistp521_method(void)
* FUNCTIONS TO MANAGE PRECOMPUTATION
*/
static NISTP521_PRE_COMP *nistp521_pre_comp_new()
static NISTP521_PRE_COMP *nistp521_pre_comp_new(void)
{
NISTP521_PRE_COMP *ret = OPENSSL_zalloc(sizeof(*ret));
+1 -1
View File
@@ -1512,7 +1512,7 @@ void ecp_nistz256_ord_sqr_mont(BN_ULONG res[P256_LIMBS],
int rep);
static int ecp_nistz256_inv_mod_ord(const EC_GROUP *group, BIGNUM *r,
BIGNUM *x, BN_CTX *ctx)
const BIGNUM *x, BN_CTX *ctx)
{
/* RR = 2^512 mod ord(p256) */
static const BN_ULONG RR[P256_LIMBS] = {
-8
View File
@@ -16,10 +16,6 @@
# include "internal/thread_once.h"
# include "internal/refcount.h"
#ifdef __cplusplus
extern "C" {
#endif
extern CRYPTO_RWLOCK *global_engine_lock;
/*
@@ -172,8 +168,4 @@ typedef struct st_engine_pile ENGINE_PILE;
DEFINE_LHASH_OF(ENGINE_PILE);
#ifdef __cplusplus
}
#endif
#endif /* HEADER_ENGINE_INT_H */
-11
View File
@@ -10,13 +10,6 @@
#ifndef HEADER_HMAC_LCL_H
# define HEADER_HMAC_LCL_H
#ifdef __cplusplus
extern "C" {
#endif
#if 0 /* emacs indentation fix */
}
#endif
struct hmac_ctx_st {
const EVP_MD *md;
EVP_MD_CTX *md_ctx;
@@ -26,8 +19,4 @@ struct hmac_ctx_st {
unsigned char key[HMAC_MAX_MD_CBLOCK];
};
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif
-8
View File
@@ -25,10 +25,6 @@
# define ARIA_BLOCK_SIZE 16 /* Size of each encryption/decryption block */
# define ARIA_MAX_KEYS 17 /* Number of keys needed in the worst case */
# ifdef __cplusplus
extern "C" {
# endif
typedef union {
unsigned char c[ARIA_BLOCK_SIZE];
unsigned int u[ARIA_BLOCK_SIZE / sizeof(unsigned int)];
@@ -51,8 +47,4 @@ int aria_set_decrypt_key(const unsigned char *userKey, const int bits,
void aria_encrypt(const unsigned char *in, unsigned char *out,
const ARIA_KEY *key);
# ifdef __cplusplus
}
# endif
#endif
-8
View File
@@ -13,10 +13,6 @@
# include <openssl/bn.h>
# include <limits.h>
#ifdef __cplusplus
extern "C" {
#endif
BIGNUM *bn_wexpand(BIGNUM *a, int words);
BIGNUM *bn_expand2(BIGNUM *a, int words);
@@ -64,8 +60,4 @@ void bn_set_static_words(BIGNUM *a, BN_ULONG *words, int size);
*/
int bn_set_words(BIGNUM *a, BN_ULONG *words, int num_words);
#ifdef __cplusplus
}
#endif
#endif
-7
View File
@@ -12,10 +12,6 @@
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* ChaCha20_ctr32 encrypts |len| bytes from |inp| with the given key and
* nonce and writes the result to |out|, which may be equal to |inp|.
@@ -43,7 +39,4 @@ void ChaCha20_ctr32(unsigned char *out, const unsigned char *inp,
#define CHACHA_CTR_SIZE 16
#define CHACHA_BLK_SIZE 64
#ifdef __cplusplus
}
#endif
#endif
-8
View File
@@ -15,10 +15,6 @@
# ifndef OPENSSL_NO_SM2
# ifdef __cplusplus
extern "C" {
# endif
# include <openssl/ec.h>
/* The default user id as specified in GM/T 0009-2012 */
@@ -74,9 +70,5 @@ int sm2_decrypt(const EC_KEY *key,
const uint8_t *ciphertext,
size_t ciphertext_len, uint8_t *ptext_buf, size_t *ptext_len);
# ifdef __cplusplus
}
# endif
# endif /* OPENSSL_NO_SM2 */
#endif
-3
View File
@@ -15,9 +15,6 @@
# ifndef OPENSSL_NO_SM2
# ifdef __cplusplus
extern "C"
# endif
int ERR_load_SM2_strings(void);
/*
-7
View File
@@ -14,10 +14,6 @@
# include <openssl/store.h>
# include <openssl/ui.h>
# ifdef __cplusplus
extern "C" {
# endif
/*
* Two functions to read PEM data off an already opened BIO. To be used
* instead of OSSLSTORE_open() and OSSLSTORE_close(). Everything is done
@@ -27,7 +23,4 @@ OSSL_STORE_CTX *ossl_store_attach_pem_bio(BIO *bp, const UI_METHOD *ui_method,
void *ui_data);
int ossl_store_detach_pem_bio(OSSL_STORE_CTX *ctx);
# ifdef __cplusplus
}
# endif
#endif
-8
View File
@@ -45,10 +45,6 @@ typedef unsigned int seed_word;
# endif
#ifdef __cplusplus
extern "C" {
#endif
# define char2word(c, i) \
(i) = ((((seed_word)(c)[0]) << 24) | (((seed_word)(c)[1]) << 16) | (((seed_word)(c)[2]) << 8) | ((seed_word)(c)[3]))
@@ -113,8 +109,4 @@ extern "C" {
(X1) ^= (T0); \
(X2) ^= (T1)
#ifdef __cplusplus
}
#endif
#endif /* HEADER_SEED_LOCL_H */
+1 -1
View File
@@ -254,7 +254,7 @@ for($i=0;$i<16;$i++) { &BODY_00_15($i,@V); unshift(@V,pop(@V)); }
$code.=".Lrounds_16_xx:\n";
for (;$i<32;$i++) { &BODY_16_XX($i,@V); unshift(@V,pop(@V)); }
$code.=<<___;
#if __ARM_ARCH__>=7
#ifdef __thumb2__
ite eq @ Thumb2 thing, sanity check in ARM
#endif
ldreq $t3,[sp,#16*4] @ pull ctx
+2 -2
View File
@@ -157,7 +157,7 @@ $code.=<<___;
teq $t0,#$magic
ldr $t3,[sp,#$Coff+0] @ c.lo
#if __ARM_ARCH__>=7
#ifdef __thumb2__
it eq @ Thumb2 thing, sanity check in ARM
#endif
orreq $Ktbl,$Ktbl,#1
@@ -411,7 +411,7 @@ $code.=<<___;
___
&BODY_00_15(0x17);
$code.=<<___;
#if __ARM_ARCH__>=7
#ifdef __thumb2__
ittt eq @ Thumb2 thing, sanity check in ARM
#endif
ldreq $t0,[sp,#`$Xoff+8*(16-1)`+0]
-7
View File
@@ -10,10 +10,6 @@
#ifndef HEADER_V3_ADMISSION_H
# define HEADER_V3_ADMISSION_H
#ifdef __cplusplus
extern "C" {
#endif
struct NamingAuthority_st {
ASN1_OBJECT* namingAuthorityId;
ASN1_IA5STRING* namingAuthorityUrl;
@@ -39,7 +35,4 @@ struct AdmissionSyntax_st {
STACK_OF(ADMISSIONS)* contentsOfAdmissions;
};
#ifdef __cplusplus
}
#endif
#endif