Botan 3.14.1
Crypto and TLS for C&
Botan::PSS_Params Class Referencefinal

#include <pss_params.h>

Inheritance diagram for Botan::PSS_Params:
Botan::ASN1_Object

Public Member Functions

std::vector< uint8_t > BER_encode () const
void encode_into (DER_Encoder &to) const override
const AlgorithmIdentifier & hash_algid () const
std::string hash_function () const
const AlgorithmIdentifier & mgf_algid () const
std::string mgf_function () const
const AlgorithmIdentifier & mgf_hash_algid () const
BOTAN_FUTURE_EXPLICIT PSS_Params (std::span< const uint8_t > der)
 PSS_Params (std::string_view hash_fn, size_t salt_len)
size_t salt_length () const
std::vector< uint8_t > serialize () const
size_t trailer_field () const

Static Public Member Functions

static PSS_Params from_emsa_name (std::string_view padding_name)
static PSS_Params from_padding_name (std::string_view padding_name)

Detailed Description

PSS parameters type

Handles encoding/decoding of RSASSA-PSS-params from RFC 3447

Only MGF1 is supported, and the trailer field must 1 (ie the variant from IEEE 1363a using a hash identifier is not supported)

Definition at line 24 of file pss_params.h.

Constructor & Destructor Documentation

◆ PSS_Params() [1/2]

Botan::PSS_Params::PSS_Params ( std::string_view hash_fn,
size_t salt_len )

Create PSS parameters using MGF1 with the same hash as the message hash

Parameters
hash_fnthe name of the hash function to use
salt_lenthe salt length in bytes

Definition at line 30 of file pss_params.cpp.

30 :
32 m_mgf("MGF1", m_hash.BER_encode()),
33 m_mgf_hash(m_hash),
34 m_salt_len(salt_len),
35 m_trailer_field(1) {}

References Botan::ASN1_Object::BER_encode().

Referenced by from_emsa_name(), and from_padding_name().

◆ PSS_Params() [2/2]

Botan::PSS_Params::PSS_Params ( std::span< const uint8_t > der)

Decode an encoded RSASSA-PSS-params

Definition at line 37 of file pss_params.cpp.

37 : m_salt_len(0), m_trailer_field(1) {
38 BER_Decoder decoder(der, BER_Decoder::Limits::DER());
39 this->decode_from(decoder);
40 decoder.verify_end();
41}
static Limits DER()
Definition ber_dec.h:44

References Botan::BER_Decoder::Limits::DER(), and Botan::BER_Decoder::verify_end().

Member Function Documentation

◆ BER_encode()

std::vector< uint8_t > Botan::ASN1_Object::BER_encode ( ) const
inherited

Return the encoding of this object. This is a convenience method when just one object needs to be serialized. Use DER_Encoder for complicated encodings.

Definition at line 21 of file asn1_obj.cpp.

21 {
22 std::vector<uint8_t> output;
23 DER_Encoder der(output);
24 this->encode_into(der);
25 return output;
26}
virtual void encode_into(DER_Encoder &to) const =0

References encode_into().

Referenced by decode_from(), Botan::PKCS12::export_to(), Botan::Certificate_Store_In_SQL::find_all_certs(), Botan::Certificate_Store_In_SQL::find_cert(), Botan::X509_Certificate::fingerprint(), Botan::Certificate_Store_In_SQL::insert_cert(), Botan::X509_Object::PEM_encode(), and Botan::PSS_Params::PSS_Params().

◆ encode_into()

void Botan::PSS_Params::encode_into ( DER_Encoder & to) const
overridevirtual

Encode whatever this object is into to

Parameters
tothe DER_Encoder that will be written to

Implements Botan::ASN1_Object.

Definition at line 49 of file pss_params.cpp.

49 {
50 to.start_sequence()
51 .start_context_specific(0)
52 .encode(m_hash)
53 .end_cons()
54 .start_context_specific(1)
55 .encode(m_mgf)
56 .end_cons()
57 .start_context_specific(2)
58 .encode(m_salt_len)
59 .end_cons()
60 .end_cons();
61}

References Botan::DER_Encoder::encode(), Botan::DER_Encoder::end_cons(), Botan::DER_Encoder::start_context_specific(), and Botan::DER_Encoder::start_sequence().

◆ from_emsa_name()

PSS_Params Botan::PSS_Params::from_emsa_name ( std::string_view padding_name)
inlinestatic

Note that the only valid strings you can pass to this function are values returned by SignaturePaddingScheme::name() and these may change in a minor release.

Definition at line 39 of file pss_params.h.

39 {
40 return PSS_Params::from_padding_name(padding_name);
41 }
static PSS_Params from_padding_name(std::string_view padding_name)

References from_emsa_name(), from_padding_name(), and PSS_Params().

Referenced by from_emsa_name().

◆ from_padding_name()

PSS_Params Botan::PSS_Params::from_padding_name ( std::string_view padding_name)
static

Note that the only valid strings you can pass to this function are values returned by SignaturePaddingScheme::name() and these may change in a minor release.

Definition at line 19 of file pss_params.cpp.

19 {
20 const AlgorithmSpec spec(padding_name);
21
22 const auto m = spec.match("PSS|PSS_Raw({hash},MGF1,{salt_len:int})");
23 if(!m) {
24 throw Invalid_Argument(fmt("PSS_Params::from_padding_name unexpected param '{}'", padding_name));
25 }
26
27 return PSS_Params(m->str("hash"), m->integer("salt_len"));
28}
PSS_Params(std::string_view hash_fn, size_t salt_len)
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53

References Botan::fmt(), Botan::AlgorithmSpec::match(), and PSS_Params().

Referenced by from_emsa_name().

◆ hash_algid()

const AlgorithmIdentifier & Botan::PSS_Params::hash_algid ( ) const
inline

Return the AlgorithmIdentifier of the hash used to hash the message

Definition at line 59 of file pss_params.h.

59{ return m_hash; }

Referenced by hash_function().

◆ hash_function()

std::string Botan::PSS_Params::hash_function ( ) const
inline

Return the name of the hash used to hash the message

Definition at line 84 of file pss_params.h.

84{ return hash_algid().oid().to_formatted_string(); }
const OID & oid() const
Definition asn1_obj.h:688
std::string to_formatted_string() const
Definition asn1_oid.cpp:137
const AlgorithmIdentifier & hash_algid() const
Definition pss_params.h:59

References hash_algid().

◆ mgf_algid()

const AlgorithmIdentifier & Botan::PSS_Params::mgf_algid ( ) const
inline

Return the AlgorithmIdentifier of the mask generation function

Definition at line 64 of file pss_params.h.

64{ return m_mgf; }

Referenced by mgf_function().

◆ mgf_function()

std::string Botan::PSS_Params::mgf_function ( ) const
inline

Return the name of the mask generation function; only MGF1 is supported

Definition at line 89 of file pss_params.h.

89{ return mgf_algid().oid().to_formatted_string(); }
const AlgorithmIdentifier & mgf_algid() const
Definition pss_params.h:64

References mgf_algid().

◆ mgf_hash_algid()

const AlgorithmIdentifier & Botan::PSS_Params::mgf_hash_algid ( ) const
inline

Return the AlgorithmIdentifier of the hash used within the mask generation function

Definition at line 69 of file pss_params.h.

69{ return m_mgf_hash; }

◆ salt_length()

size_t Botan::PSS_Params::salt_length ( ) const
inline

Return the salt length in bytes

Definition at line 74 of file pss_params.h.

74{ return m_salt_len; }

◆ serialize()

std::vector< uint8_t > Botan::PSS_Params::serialize ( ) const

Return the DER encoding of these RSASSA-PSS-params

Definition at line 43 of file pss_params.cpp.

43 {
44 std::vector<uint8_t> output;
45 DER_Encoder(output).encode(*this);
46 return output;
47}

References Botan::DER_Encoder::encode().

◆ trailer_field()

size_t Botan::PSS_Params::trailer_field ( ) const
inline

Return the trailer field; only a value of 1 is supported

Definition at line 79 of file pss_params.h.

79{ return m_trailer_field; }

The documentation for this class was generated from the following files: