Commit c11dead1 authored by Ulf Möller's avatar Ulf Möller
Browse files

Don't set the two top bits to one when generating a random number < q.:wq

parent 40411564
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -84,7 +84,7 @@ int DSA_generate_key(DSA *dsa)
	i=BN_num_bits(dsa->q);
	i=BN_num_bits(dsa->q);
	for (;;)
	for (;;)
		{
		{
		if (!BN_rand(priv_key,i,1,0))
		if (!BN_rand(priv_key,i,0,0))
			goto err;
			goto err;
		if (BN_cmp(priv_key,dsa->q) >= 0)
		if (BN_cmp(priv_key,dsa->q) >= 0)
			BN_sub(priv_key,priv_key,dsa->q);
			BN_sub(priv_key,priv_key,dsa->q);
+1 −1
Original line number Original line Diff line number Diff line
@@ -181,7 +181,7 @@ static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
	/* Get random k */
	/* Get random k */
	for (;;)
	for (;;)
		{
		{
		if (!BN_rand(&k, BN_num_bits(dsa->q), 1, 0)) goto err;
		if (!BN_rand(&k, BN_num_bits(dsa->q), 0, 0)) goto err;
		if (BN_cmp(&k,dsa->q) >= 0)
		if (BN_cmp(&k,dsa->q) >= 0)
			BN_sub(&k,&k,dsa->q);
			BN_sub(&k,&k,dsa->q);
		if (!BN_is_zero(&k)) break;
		if (!BN_is_zero(&k)) break;