aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/pubkey/sm2/sm2.cpp6
-rw-r--r--src/lib/pubkey/sm2/sm2_enc.cpp22
2 files changed, 14 insertions, 14 deletions
diff --git a/src/lib/pubkey/sm2/sm2.cpp b/src/lib/pubkey/sm2/sm2.cpp
index e2bc5d92d..2af888bbc 100644
--- a/src/lib/pubkey/sm2/sm2.cpp
+++ b/src/lib/pubkey/sm2/sm2.cpp
@@ -83,13 +83,13 @@ class SM2_Signature_Operation final : public PK_Ops::Signature
const std::string& ident,
const std::string& hash) :
m_group(sm2.domain()),
- m_base_point(sm2.domain().get_base_point(), sm2.domain().get_order()),
+ m_base_point(m_group.get_base_point(), m_group.get_order()),
m_x(sm2.private_value()),
m_da_inv(sm2.get_da_inv()),
m_hash(HashFunction::create_or_throw(hash))
{
// ZA=H256(ENTLA || IDA || a || b || xG || yG || xA || yA)
- m_za = sm2_compute_za(*m_hash, ident, sm2.domain(), sm2.public_point());
+ m_za = sm2_compute_za(*m_hash, ident, m_group, sm2.public_point());
m_hash->update(m_za);
}
@@ -141,7 +141,7 @@ class SM2_Verification_Operation final : public PK_Ops::Verification
m_hash(HashFunction::create_or_throw(hash))
{
// ZA=H256(ENTLA || IDA || a || b || xG || yG || xA || yA)
- m_za = sm2_compute_za(*m_hash, ident, sm2.domain(), sm2.public_point());
+ m_za = sm2_compute_za(*m_hash, ident, m_group, m_public_point);
m_hash->update(m_za);
}
diff --git a/src/lib/pubkey/sm2/sm2_enc.cpp b/src/lib/pubkey/sm2/sm2_enc.cpp
index 9ba278060..462c4b968 100644
--- a/src/lib/pubkey/sm2/sm2_enc.cpp
+++ b/src/lib/pubkey/sm2/sm2_enc.cpp
@@ -46,10 +46,9 @@ class SM2_Encryption_Operation final : public PK_Ops::Encryption
{
public:
SM2_Encryption_Operation(const SM2_Encryption_PublicKey& key, const std::string& kdf_hash) :
- m_p_bytes(key.domain().get_p_bytes()),
- m_order(key.domain().get_order()),
- m_base_point(key.domain().get_base_point(), m_order),
- m_public_point(key.public_point(), m_order),
+ m_group(key.domain()),
+ m_base_point(m_group.get_base_point(), m_group.get_order()),
+ m_public_point(key.public_point(), m_group.get_order()),
m_kdf_hash(kdf_hash)
{}
@@ -66,13 +65,15 @@ class SM2_Encryption_Operation final : public PK_Ops::Encryption
std::unique_ptr<HashFunction> hash = HashFunction::create_or_throw(m_kdf_hash);
std::unique_ptr<KDF> kdf = KDF::create_or_throw("KDF2(" + m_kdf_hash + ")");
- const BigInt k = BigInt::random_integer(rng, 1, m_order);
+ const size_t p_bytes = m_group.get_p_bytes();
+
+ const BigInt k = BigInt::random_integer(rng, 1, m_group.get_order());
const PointGFp C1 = m_base_point.blinded_multiply(k, rng);
const BigInt x1 = C1.get_affine_x();
const BigInt y1 = C1.get_affine_y();
- std::vector<uint8_t> x1_bytes(m_p_bytes);
- std::vector<uint8_t> y1_bytes(m_p_bytes);
+ std::vector<uint8_t> x1_bytes(p_bytes);
+ std::vector<uint8_t> y1_bytes(p_bytes);
BigInt::encode_1363(x1_bytes.data(), x1_bytes.size(), x1);
BigInt::encode_1363(y1_bytes.data(), y1_bytes.size(), y1);
@@ -80,8 +81,8 @@ class SM2_Encryption_Operation final : public PK_Ops::Encryption
const BigInt x2 = kPB.get_affine_x();
const BigInt y2 = kPB.get_affine_y();
- std::vector<uint8_t> x2_bytes(m_p_bytes);
- std::vector<uint8_t> y2_bytes(m_p_bytes);
+ std::vector<uint8_t> x2_bytes(p_bytes);
+ std::vector<uint8_t> y2_bytes(p_bytes);
BigInt::encode_1363(x2_bytes.data(), x2_bytes.size(), x2);
BigInt::encode_1363(y2_bytes.data(), y2_bytes.size(), y2);
@@ -112,8 +113,7 @@ class SM2_Encryption_Operation final : public PK_Ops::Encryption
}
private:
- size_t m_p_bytes;
- const BigInt& m_order;
+ const EC_Group m_group;
Blinded_Point_Multiply m_base_point;
Blinded_Point_Multiply m_public_point;
const std::string m_kdf_hash;