diff options
author | Matthias Gierlings <[email protected]> | 2017-10-09 23:23:28 +0200 |
---|---|---|
committer | Matthias Gierlings <[email protected]> | 2017-11-21 21:03:16 +0100 |
commit | 306a665f07e21eefa19f1f9c047ed9e5bd9ba224 (patch) | |
tree | e799a0b9d41ad4d853f1988f588132e5de86b914 /src/lib/pubkey/xmss/xmss_wots_privatekey.h | |
parent | f1b1c6e3506fea734bc41cdb7794bf26666d293a (diff) |
Implements multithreading support for XMSS
Diffstat (limited to 'src/lib/pubkey/xmss/xmss_wots_privatekey.h')
-rw-r--r-- | src/lib/pubkey/xmss/xmss_wots_privatekey.h | 117 |
1 files changed, 103 insertions, 14 deletions
diff --git a/src/lib/pubkey/xmss/xmss_wots_privatekey.h b/src/lib/pubkey/xmss/xmss_wots_privatekey.h index 686162911..b0cb427c9 100644 --- a/src/lib/pubkey/xmss/xmss_wots_privatekey.h +++ b/src/lib/pubkey/xmss/xmss_wots_privatekey.h @@ -24,7 +24,7 @@ namespace Botan { * Signatures. **/ class BOTAN_PUBLIC_API(2,0) XMSS_WOTS_PrivateKey final : public virtual XMSS_WOTS_PublicKey, - public virtual Private_Key + public virtual Private_Key { public: /** @@ -65,7 +65,7 @@ class BOTAN_PUBLIC_API(2,0) XMSS_WOTS_PrivateKey final : public virtual XMSS_WOT **/ XMSS_WOTS_PrivateKey(XMSS_WOTS_Parameters::ots_algorithm_t oid, const secure_vector<uint8_t>& public_seed, - RandomNumberGenerator &rng) + RandomNumberGenerator& rng) : XMSS_WOTS_PublicKey(oid, public_seed), m_private_seed(rng.random_vec(m_wots_params.element_size())) { @@ -111,31 +111,61 @@ class BOTAN_PUBLIC_API(2,0) XMSS_WOTS_PrivateKey final : public virtual XMSS_WOT * Retrieves the i-th WOTS private key using pseudo random key * (re-)generation. * + * This overload is used in multithreaded scenarios, where it is + * required to provide seperate instances of XMSS_Hash to each + * thread. + * * @param i Index of the key to retrieve. + * @param hash Instance of XMSS_Hash, that may only be used by the + * thead executing at. * * @return WOTS secret key. **/ - wots_keysig_t operator[](size_t i) + wots_keysig_t at(size_t i, XMSS_Hash& hash) { secure_vector<uint8_t> idx_bytes; XMSS_Tools::concat(idx_bytes, i, m_wots_params.element_size()); - m_hash.h(idx_bytes, m_private_seed, idx_bytes); - return generate(idx_bytes); + hash.h(idx_bytes, m_private_seed, idx_bytes); + return generate(idx_bytes, hash); + } + + /** + * Retrieves the i-th WOTS private key using pseudo random key + * (re-)generation. + * + * @param i Index of the key to retrieve. + * + * @return WOTS secret key. + **/ + inline wots_keysig_t operator[](size_t i) + { + return this->at(i, m_hash); } /** * Retrieves the i-th WOTS private key using pseudo random key * (re-)generation. * + * This overload is used in multithreaded scenarios, where it is + * required to provide seperate instances of XMSS_Hash to each + * thread. + * * @param adrs The address of the key to retrieve. + * @param hash Instance of XMSS_Hash, that may only be used by the + * thead executing at. * * @return WOTS secret key. **/ - wots_keysig_t operator[](const XMSS_Address& adrs) + wots_keysig_t at(const XMSS_Address& adrs, XMSS_Hash& hash) { secure_vector<uint8_t> result; - m_hash.prf(result, m_private_seed, adrs.bytes()); - return generate(result); + hash.prf(result, m_private_seed, adrs.bytes()); + return generate(result, hash); + } + + inline wots_keysig_t operator[](const XMSS_Address& adrs) + { + return this->at(adrs, m_hash); } wots_keysig_t generate_private_key(const secure_vector<uint8_t>& priv_seed); @@ -158,15 +188,40 @@ class BOTAN_PUBLIC_API(2,0) XMSS_WOTS_PrivateKey final : public virtual XMSS_WOT * key_data() member, with data derived from in_key_data using the * WOTS chaining function. * + * This overload is used in multithreaded scenarios, where it is + * required to provide seperate instances of XMSS_Hash to each + * thread. + * * @param[out] pub_key Public key to initialize key_data() member on. * @param in_key_data Input key material from private key used for * public key generation. * @param adrs Hash function address encoding the address of * the WOTS+ key pair within a greater structure. + * @param hash Instance of XMSS_Hash, that may only by the thead + * executing generate_public_key. **/ void generate_public_key(XMSS_WOTS_PublicKey& pub_key, wots_keysig_t&& in_key_data, - XMSS_Address& adrs); + XMSS_Address& adrs, + XMSS_Hash& hash); + /** + * Algorithm 4: "WOTS_genPK" + * Initializes a Winternitz One Time Signature+ (WOTS+) Public Key's + * key_data() member, with data derived from in_key_data using the + * WOTS chaining function. + * + * @param[out] pub_key Public key to initialize key_data() member on. + * @param in_key_data Input key material from private key used for + * public key generation. + * @param adrs Hash function address encoding the address of + * the WOTS+ key pair within a greater structure. + **/ + inline void generate_public_key(XMSS_WOTS_PublicKey& pub_key, + wots_keysig_t&& in_key_data, + XMSS_Address& adrs) + { + generate_public_key(pub_key, std::forward<wots_keysig_t>(in_key_data), adrs, m_hash); + } /** * Algorithm 5: "WOTS_sign" @@ -178,8 +233,31 @@ class BOTAN_PUBLIC_API(2,0) XMSS_WOTS_PrivateKey final : public virtual XMSS_WOT * * @return signature for msg. **/ + inline wots_keysig_t sign(const secure_vector<uint8_t>& msg, + XMSS_Address& adrs) + { + return sign(msg, adrs, m_hash); + } + + /** + * Algorithm 5: "WOTS_sign" + * Generates a signature from a private key and a message. + * + * This overload is used in multithreaded scenarios, where it is + * required to provide seperate instances of XMSS_Hash to each + * thread. + * + * @param msg A message to sign. + * @param adrs An OTS hash address identifying the WOTS+ key pair + * used for signing. + * @param hash Instance of XMSS_Hash, that may only be used by the + * thead executing sign. + * + * @return signature for msg. + **/ wots_keysig_t sign(const secure_vector<uint8_t>& msg, - XMSS_Address& adrs); + XMSS_Address& adrs, + XMSS_Hash& hash); /** * Retrieves the secret seed used to generate WOTS+ chains. The seed @@ -221,9 +299,9 @@ class BOTAN_PUBLIC_API(2,0) XMSS_WOTS_PrivateKey final : public virtual XMSS_WOT } std::unique_ptr<PK_Ops::Signature> - create_signature_op(RandomNumberGenerator&, - const std::string&, - const std::string& provider) const override; + create_signature_op(RandomNumberGenerator&, + const std::string&, + const std::string& provider) const override; secure_vector<uint8_t> private_key_bits() const override { @@ -235,12 +313,23 @@ class BOTAN_PUBLIC_API(2,0) XMSS_WOTS_PrivateKey final : public virtual XMSS_WOT * Algorithm 3: "Generating a WOTS+ Private Key". * Generates a private key. * + * This overload is used in multithreaded scenarios, where it is + * required to provide seperate instances of XMSS_Hash to each thread. + * * @param private_seed Uniformly random n-byte value. + * @param[in] hash Instance of XMSS_Hash, that may only be used by the + * thead executing generate. * * @returns a vector of length key_size() of vectors of n bytes length * containing uniformly random data. **/ - wots_keysig_t generate(const secure_vector<uint8_t>& private_seed); + wots_keysig_t generate(const secure_vector<uint8_t>& private_seed, + XMSS_Hash& hash); + + inline wots_keysig_t generate(const secure_vector<uint8_t>& private_seed) + { + return generate(private_seed, m_hash); + } secure_vector<uint8_t> m_private_seed; }; |