aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/pubkey
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/pubkey')
-rw-r--r--src/lib/pubkey/ec_group/ec_group.cpp5
-rw-r--r--src/lib/pubkey/ec_group/ec_group.h5
-rw-r--r--src/lib/pubkey/ecc_key/ecc_key.cpp2
-rw-r--r--src/lib/pubkey/ecdsa/ecdsa.cpp2
-rw-r--r--src/lib/pubkey/ecgdsa/ecgdsa.cpp2
-rw-r--r--src/lib/pubkey/eckcdsa/eckcdsa.cpp2
-rw-r--r--src/lib/pubkey/sm2/sm2.cpp2
-rw-r--r--src/lib/pubkey/sm2/sm2_enc.cpp2
8 files changed, 16 insertions, 6 deletions
diff --git a/src/lib/pubkey/ec_group/ec_group.cpp b/src/lib/pubkey/ec_group/ec_group.cpp
index 623c79cc8..45aef6c2f 100644
--- a/src/lib/pubkey/ec_group/ec_group.cpp
+++ b/src/lib/pubkey/ec_group/ec_group.cpp
@@ -505,6 +505,11 @@ BigInt EC_Group::blinded_base_point_multiply_x(const BigInt& k,
return data().blinded_base_point_multiply(k, rng, ws).get_affine_x();
}
+BigInt EC_Group::random_scalar(RandomNumberGenerator& rng) const
+ {
+ return BigInt::random_integer(rng, 1, get_order());
+ }
+
PointGFp EC_Group::blinded_var_point_multiply(const PointGFp& point,
const BigInt& k,
RandomNumberGenerator& rng,
diff --git a/src/lib/pubkey/ec_group/ec_group.h b/src/lib/pubkey/ec_group/ec_group.h
index 32c115432..031e5cc34 100644
--- a/src/lib/pubkey/ec_group/ec_group.h
+++ b/src/lib/pubkey/ec_group/ec_group.h
@@ -273,6 +273,11 @@ class BOTAN_PUBLIC_API(2,0) EC_Group final
std::vector<BigInt>& ws) const;
/**
+ * Return a random scalar ie an integer in [1,order)
+ */
+ BigInt random_scalar(RandomNumberGenerator& rng) const;
+
+ /**
* Return the zero (or infinite) point on this curve
*/
PointGFp zero_point() const;
diff --git a/src/lib/pubkey/ecc_key/ecc_key.cpp b/src/lib/pubkey/ecc_key/ecc_key.cpp
index 7b00d3209..7c46a2fa0 100644
--- a/src/lib/pubkey/ecc_key/ecc_key.cpp
+++ b/src/lib/pubkey/ecc_key/ecc_key.cpp
@@ -122,7 +122,7 @@ EC_PrivateKey::EC_PrivateKey(RandomNumberGenerator& rng,
if(x == 0)
{
- m_private_key = BigInt::random_integer(rng, 1, order);
+ m_private_key = ec_group.random_scalar(rng);
}
else
{
diff --git a/src/lib/pubkey/ecdsa/ecdsa.cpp b/src/lib/pubkey/ecdsa/ecdsa.cpp
index f35693189..03f5e57ab 100644
--- a/src/lib/pubkey/ecdsa/ecdsa.cpp
+++ b/src/lib/pubkey/ecdsa/ecdsa.cpp
@@ -86,7 +86,7 @@ ECDSA_Signature_Operation::raw_sign(const uint8_t msg[], size_t msg_len,
#if defined(BOTAN_HAS_RFC6979_GENERATOR)
const BigInt k = generate_rfc6979_nonce(m_x, m_group.get_order(), m, m_rfc6979_hash);
#else
- const BigInt k = BigInt::random_integer(rng, 1, m_group.get_order());
+ const BigInt k = m_group.random_scalar(rng);
#endif
const BigInt k_inv = inverse_mod(k, m_group.get_order());
diff --git a/src/lib/pubkey/ecgdsa/ecgdsa.cpp b/src/lib/pubkey/ecgdsa/ecgdsa.cpp
index 12962d18c..062bb524d 100644
--- a/src/lib/pubkey/ecgdsa/ecgdsa.cpp
+++ b/src/lib/pubkey/ecgdsa/ecgdsa.cpp
@@ -59,7 +59,7 @@ ECGDSA_Signature_Operation::raw_sign(const uint8_t msg[], size_t msg_len,
{
const BigInt m(msg, msg_len, m_group.get_order_bits());
- BigInt k = BigInt::random_integer(rng, 1, m_group.get_order());
+ const BigInt k = m_group.random_scalar(rng);
const BigInt r = m_group.mod_order(
m_group.blinded_base_point_multiply_x(k, rng, m_ws));
diff --git a/src/lib/pubkey/eckcdsa/eckcdsa.cpp b/src/lib/pubkey/eckcdsa/eckcdsa.cpp
index f9d9b2f60..f16fb027e 100644
--- a/src/lib/pubkey/eckcdsa/eckcdsa.cpp
+++ b/src/lib/pubkey/eckcdsa/eckcdsa.cpp
@@ -76,7 +76,7 @@ secure_vector<uint8_t>
ECKCDSA_Signature_Operation::raw_sign(const uint8_t msg[], size_t,
RandomNumberGenerator& rng)
{
- const BigInt k = BigInt::random_integer(rng, 1, m_group.get_order());
+ const BigInt k = m_group.random_scalar(rng);
const BigInt k_times_P_x = m_group.blinded_base_point_multiply_x(k, rng, m_ws);
secure_vector<uint8_t> to_be_hashed(k_times_P_x.bytes());
diff --git a/src/lib/pubkey/sm2/sm2.cpp b/src/lib/pubkey/sm2/sm2.cpp
index cec9eaa38..4b5610c85 100644
--- a/src/lib/pubkey/sm2/sm2.cpp
+++ b/src/lib/pubkey/sm2/sm2.cpp
@@ -114,7 +114,7 @@ SM2_Signature_Operation::sign(RandomNumberGenerator& rng)
{
const BigInt e = BigInt::decode(m_hash->final());
- const BigInt k = BigInt::random_integer(rng, 1, m_group.get_order());
+ const BigInt k = m_group.random_scalar(rng);
const BigInt r = m_group.mod_order(
m_group.blinded_base_point_multiply_x(k, rng, m_ws) + e);
diff --git a/src/lib/pubkey/sm2/sm2_enc.cpp b/src/lib/pubkey/sm2/sm2_enc.cpp
index 4a6aa2b6e..e3553d5b3 100644
--- a/src/lib/pubkey/sm2/sm2_enc.cpp
+++ b/src/lib/pubkey/sm2/sm2_enc.cpp
@@ -67,7 +67,7 @@ class SM2_Encryption_Operation final : public PK_Ops::Encryption
const size_t p_bytes = m_group.get_p_bytes();
- const BigInt k = BigInt::random_integer(rng, 1, m_group.get_order());
+ const BigInt k = m_group.random_scalar(rng);
const PointGFp C1 = m_group.blinded_base_point_multiply(k, rng, m_ws);
const BigInt x1 = C1.get_affine_x();