/* * XMSS WOTS Private Key * A Winternitz One Time Signature private key for use with Extended Hash-Based * Signatures. * * (C) 2016,2017 Matthias Gierlings * * Botan is released under the Simplified BSD License (see license.txt) **/ #include #include namespace Botan { wots_keysig_t XMSS_WOTS_PrivateKey::generate(const secure_vector& priv_seed, XMSS_Hash& hash) { wots_keysig_t priv_key(m_wots_params.len(), secure_vector(0)); for(size_t i = 0; i < m_wots_params.len(); i++) { XMSS_Tools::concat(priv_key[i], i, 32); hash.prf(priv_key[i], priv_seed, priv_key[i]); } return priv_key; } XMSS_WOTS_PublicKey XMSS_WOTS_PrivateKey::generate_public_key(XMSS_Address& adrs) { XMSS_WOTS_PublicKey pub_key(m_wots_params.oid(), public_seed()); generate_public_key(pub_key, wots_keysig_t((*this)[adrs]), adrs); return pub_key; } void XMSS_WOTS_PrivateKey::generate_public_key(XMSS_WOTS_PublicKey& pub_key, wots_keysig_t&& in_key_data, XMSS_Address& adrs, XMSS_Hash& hash) { BOTAN_ASSERT(wots_parameters() == pub_key.wots_parameters() && public_seed() == pub_key.public_seed(), "Conflicting public key data."); pub_key.set_key_data(std::move(in_key_data)); for(size_t i = 0; i < m_wots_params.len(); i++) { adrs.set_chain_address(i); chain(pub_key[i], 0, m_wots_params.wots_parameter() - 1, adrs, public_seed(), hash); } } wots_keysig_t XMSS_WOTS_PrivateKey::sign(const secure_vector& msg, XMSS_Address& adrs, XMSS_Hash& hash) { secure_vector msg_digest { m_wots_params.base_w(msg, m_wots_params.len_1()) }; m_wots_params.append_checksum(msg_digest); wots_keysig_t sig(this->at(adrs, hash)); for(size_t i = 0; i < m_wots_params.len(); i++) { adrs.set_chain_address(i); chain(sig[i], 0 , msg_digest[i], adrs, m_public_seed, hash); } return sig; } std::unique_ptr XMSS_WOTS_PrivateKey::create_signature_op(RandomNumberGenerator&, const std::string&, const std::string& provider) const { if(provider == "base" || provider.empty()) return std::unique_ptr( new XMSS_WOTS_Signature_Operation(*this)); throw Provider_Not_Found(algo_name(), provider); } }