Commit 6ec8e63a authored by Dr. Stephen Henson's avatar Dr. Stephen Henson
Browse files

Port BN_MONT_CTX_set_locked() from stable branch.

The function rsa_eay_mont_helper() has been removed because it is no longer
needed after this change.
parent 465b9f6b
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -794,6 +794,11 @@

 Changes between 0.9.7g and 0.9.7h  [XX xxx XXXX]

  *) New function BN_MONT_CTX_set_locked() to set montgomery parameters in
     a threadsafe manner. Modify rsa code to use new function and add calls
     to dsa and dh code (which had race conditions before).
     [Steve Henson]

  *) Include the fixed error library code in the C error file definitions
     instead of fixing them up at runtime. This keeps the error code
     structures constant.
+0 −28
Original line number Diff line number Diff line
@@ -837,31 +837,3 @@ be added to the end of this file.

	Enable shared link on HP-UX.
2005-04-22 07:17  steve

	Changed:
		CHANGES (1.977.2.156), "Exp", lines: +5 -0
		crypto/bn/bn.h (1.66.2.4), "Exp", lines: +2 -0
		crypto/bn/bn_mont.c (1.30.2.3), "Exp", lines: +20 -0
		crypto/dh/dh_key.c (1.16.2.4), "Exp", lines: +14 -10
		crypto/dsa/dsa_ossl.c (1.12.2.7), "Exp", lines: +12 -9
		crypto/rsa/rsa_eay.c (1.28.2.10), "Exp", lines: +16 -90
		fips/fipshashes.c (1.1.2.5), "Exp", lines: +3 -3
		fips/dh/fips_dh_key.c (1.1.2.4), "Exp", lines: +13 -10
		fips/dsa/fips_dsa_ossl.c (1.1.2.8), "Exp", lines: +12 -9
		fips/rsa/fips_rsa_eay.c (1.1.4.5), "Exp", lines: +17 -90

	New function BN_MONT_CTX_set_locked, to set montgomery parameters
	in a threadsafe manner.

		Modify or add calls to use it in rsa, dsa and dh
	algorithms.

2005-04-23 06:46  nils

	Changed:
		crypto/dsa/dsa_ossl.c (1.12.2.8), "Exp", lines: +1 -1
		crypto/rsa/rsa_eay.c (1.28.2.11), "Exp", lines: +4 -4

	fix typo
+2 −0
Original line number Diff line number Diff line
@@ -510,6 +510,8 @@ int BN_from_montgomery(BIGNUM *r,const BIGNUM *a,
void BN_MONT_CTX_free(BN_MONT_CTX *mont);
int BN_MONT_CTX_set(BN_MONT_CTX *mont,const BIGNUM *mod,BN_CTX *ctx);
BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to,BN_MONT_CTX *from);
BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, int lock,
					const BIGNUM *mod, BN_CTX *ctx);

/* BN_BLINDING flags */
#define	BN_BLINDING_NO_UPDATE	0x00000001
+18 −0
Original line number Diff line number Diff line
@@ -350,3 +350,21 @@ BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to, BN_MONT_CTX *from)
	return(to);
	}

BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, int lock,
					const BIGNUM *mod, BN_CTX *ctx)
	{
	if (*pmont)
		return *pmont;
	CRYPTO_w_lock(lock);
	if (!*pmont)
		{
		*pmont = BN_MONT_CTX_new();
		if (*pmont && !BN_MONT_CTX_set(*pmont, mod, ctx))
			{
			BN_MONT_CTX_free(*pmont);
			*pmont = NULL;
			}
		}
	CRYPTO_w_unlock(lock);
	return *pmont;
	}
+14 −10
Original line number Diff line number Diff line
@@ -127,13 +127,15 @@ static int generate_key(DH *dh)
	else
		pub_key=dh->pub_key;

	if ((dh->method_mont_p == NULL) && (dh->flags & DH_FLAG_CACHE_MONT_P))

	if (dh->flags & DH_FLAG_CACHE_MONT_P)
		{
		if ((dh->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)
			if (!BN_MONT_CTX_set((BN_MONT_CTX *)dh->method_mont_p,
				dh->p,ctx)) goto err;
		mont = BN_MONT_CTX_set_locked(
				(BN_MONT_CTX **)&dh->method_mont_p,
				CRYPTO_LOCK_DH, dh->p, ctx);
		if (!mont)
			goto err;
		}
	mont=(BN_MONT_CTX *)dh->method_mont_p;

	if (generate_new_key)
		{
@@ -173,14 +175,16 @@ static int compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
		DHerr(DH_F_COMPUTE_KEY,DH_R_NO_PRIVATE_VALUE);
		goto err;
		}
	if ((dh->method_mont_p == NULL) && (dh->flags & DH_FLAG_CACHE_MONT_P))

	if (dh->flags & DH_FLAG_CACHE_MONT_P)
		{
		if ((dh->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)
			if (!BN_MONT_CTX_set((BN_MONT_CTX *)dh->method_mont_p,
				dh->p,ctx)) goto err;
		mont = BN_MONT_CTX_set_locked(
				(BN_MONT_CTX **)&dh->method_mont_p,
				CRYPTO_LOCK_DH, dh->p, ctx);
		if (!mont)
			goto err;
		}

	mont=(BN_MONT_CTX *)dh->method_mont_p;
	if (!dh->meth->bn_mod_exp(dh, tmp, pub_key, dh->priv_key,dh->p,ctx,mont))
		{
		DHerr(DH_F_COMPUTE_KEY,ERR_R_BN_LIB);
Loading