aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/pubkey/sm2
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-06-20 18:47:00 -0400
committerJack Lloyd <[email protected]>2018-06-20 18:47:00 -0400
commit4288e3be60ed1af49f9295252a7ca086b1d7ef4a (patch)
treea90140f7d5c783d726a6fe20b991b2c44e2c1bf5 /src/lib/pubkey/sm2
parent9fe8f70e8f028b20788d79ccabf943818d6339f0 (diff)
Changes to allow masked lookups for variable point mult
Diffstat (limited to 'src/lib/pubkey/sm2')
-rw-r--r--src/lib/pubkey/sm2/sm2_enc.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/lib/pubkey/sm2/sm2_enc.cpp b/src/lib/pubkey/sm2/sm2_enc.cpp
index e3553d5b3..587cad44f 100644
--- a/src/lib/pubkey/sm2/sm2_enc.cpp
+++ b/src/lib/pubkey/sm2/sm2_enc.cpp
@@ -46,10 +46,13 @@ namespace {
class SM2_Encryption_Operation final : public PK_Ops::Encryption
{
public:
- SM2_Encryption_Operation(const SM2_Encryption_PublicKey& key, const std::string& kdf_hash) :
+ SM2_Encryption_Operation(const SM2_Encryption_PublicKey& key,
+ RandomNumberGenerator& rng,
+ const std::string& kdf_hash) :
m_group(key.domain()),
- m_mul_public_point(key.public_point()),
- m_kdf_hash(kdf_hash)
+ m_kdf_hash(kdf_hash),
+ m_ws(PointGFp::WORKSPACE_SIZE),
+ m_mul_public_point(key.public_point(), rng, m_ws)
{}
size_t max_input_bits() const override
@@ -114,9 +117,10 @@ class SM2_Encryption_Operation final : public PK_Ops::Encryption
private:
const EC_Group m_group;
- PointGFp_Var_Point_Precompute m_mul_public_point;
const std::string m_kdf_hash;
+
std::vector<BigInt> m_ws;
+ PointGFp_Var_Point_Precompute m_mul_public_point;
};
class SM2_Decryption_Operation final : public PK_Ops::Decryption
@@ -213,14 +217,14 @@ class SM2_Decryption_Operation final : public PK_Ops::Decryption
}
std::unique_ptr<PK_Ops::Encryption>
-SM2_Encryption_PublicKey::create_encryption_op(RandomNumberGenerator& /*rng*/,
+SM2_Encryption_PublicKey::create_encryption_op(RandomNumberGenerator& rng,
const std::string& params,
const std::string& provider) const
{
if(provider == "base" || provider.empty())
{
const std::string kdf_hash = (params.empty() ? "SM3" : params);
- return std::unique_ptr<PK_Ops::Encryption>(new SM2_Encryption_Operation(*this, kdf_hash));
+ return std::unique_ptr<PK_Ops::Encryption>(new SM2_Encryption_Operation(*this, rng, kdf_hash));
}
throw Provider_Not_Found(algo_name(), provider);