9#include <botan/internal/ml_dsa_impl.h>
11#include <botan/asn1_obj.h>
12#include <botan/ber_dec.h>
13#include <botan/der_enc.h>
14#include <botan/exceptn.h>
15#include <botan/mem_ops.h>
16#include <botan/internal/dilithium_algos.h>
17#include <botan/internal/dilithium_types.h>
38 if(expanded.size() != mode.private_key_bytes()) {
39 throw Decoding_Error(
"invalid length of ML-DSA (or Dilithium) expanded private key byte string");
54 if(expanded.size() != mode.private_key_bytes()) {
55 throw Decoding_Error(
"invalid length of ML-DSA expanded private key byte string");
64 throw Decoding_Error(
"seed and expanded key in ML-DSA serialized key do not match");
66 return key_pair_from_seed;
74 const auto& seed = keypair.second->seed();
76 throw Encoding_Error(
"ML-DSA private key does not contain the seed, cannot encode it in the requested format");
137 .keypair = decode_seed_only(private_key_bits, std::move(mode)),
144 .keypair = decode_expanded_only(private_key_bits, std::move(mode)),
149 .keypair = decode_seed_plus_expanded(private_key_bits, std::move(mode)),
#define BOTAN_ASSERT_NONNULL(ptr)
const BER_Object & peek_next_object()
BER_Decoder & decode(bool &out)
BER_Decoder & verify_end()
BER_Decoder start_sequence()
DER_Encoder & start_sequence()
DER_Encoder & encode(bool b)
static constexpr size_t SEED_RANDOMNESS_BYTES
size_t private_key_bytes() const
byte length of the encoded private key
secure_vector< uint8_t > encode_keypair(const DilithiumInternalKeypair &keypair, MlPrivateKeyFormat format) const override
DilithiumDecodedKeypair decode_keypair(std::span< const uint8_t > private_key, DilithiumConstants mode) const override
DilithiumInternalKeypair expand_keypair(DilithiumSeedRandomness xi, DilithiumConstants mode)
DilithiumSerializedPrivateKey encode_keypair(const DilithiumInternalKeypair &keypair)
DilithiumInternalKeypair decode_keypair(StrongSpan< const DilithiumSerializedPrivateKey > sk, DilithiumConstants mode)
Strong< secure_vector< uint8_t >, struct DilithiumSeedRandomness_ > DilithiumSeedRandomness
Principal seed used to generate Dilithium key pairs.
Strong< secure_vector< uint8_t >, struct DilithiumSerializedPrivateKey_ > DilithiumSerializedPrivateKey
Serialized private key data.
std::vector< T, secure_allocator< T > > secure_vector
bool constant_time_compare(std::span< const uint8_t > x, std::span< const uint8_t > y)
std::pair< std::shared_ptr< const Dilithium_PublicKeyInternal >, std::shared_ptr< const Dilithium_PrivateKeyInternal > > DilithiumInternalKeypair
Internal representation of a Dilithium key pair.
A decoded private key together with the encoding format it was found in.