Botan 1.10.17
Botan::PBE_PKCS5v20 Class Reference

#include <pbes2.h>

Inheritance diagram for Botan::PBE_PKCS5v20:
Botan::PBE Botan::Filter

Public Member Functions

virtual bool attachable ()
void end_msg ()
std::string name () const
 PBE_PKCS5v20 (BlockCipher *cipher, HashFunction *hash)
 PBE_PKCS5v20 (DataSource &input)
void start_msg ()
void write (const byte[], size_t)
 ~PBE_PKCS5v20 ()

Static Public Member Functions

static bool known_cipher (const std::string &cipher)

Protected Member Functions

void send (byte in)
void send (const byte in[], size_t length)
void send (const MemoryRegion< byte > &in)
void send (const MemoryRegion< byte > &in, size_t length)

Detailed Description

PKCS #5 v2.0 PBE

Definition at line 21 of file pbes2.h.

Constructor & Destructor Documentation

◆ PBE_PKCS5v20() [1/2]

Botan::PBE_PKCS5v20::PBE_PKCS5v20 ( DataSource & input)

Load a PKCS #5 v2.0 encrypted stream

Parameters
inputis the input source

Definition at line 228 of file pbes2.cpp.

228 : direction(DECRYPTION)
229 {
230 hash_function = 0;
231 block_cipher = 0;
232 decode_params(params);
233 }
@ DECRYPTION
Definition sym_algo.h:87

References Botan::DECRYPTION.

Referenced by Botan::get_pbe(), and Botan::get_pbe().

◆ PBE_PKCS5v20() [2/2]

Botan::PBE_PKCS5v20::PBE_PKCS5v20 ( BlockCipher * cipher,
HashFunction * hash )
Parameters
cipherthe block cipher to use
hashthe hash function to use

Definition at line 211 of file pbes2.cpp.

212 :
213 direction(ENCRYPTION),
214 block_cipher(cipher),
215 hash_function(digest),
216 iterations(0),
217 key_length(0)
218 {
219 if(!known_cipher(block_cipher->name()))
220 throw Invalid_Argument("PBE-PKCS5 v2.0: Invalid cipher " + cipher->name());
221 if(hash_function->name() != "SHA-160")
222 throw Invalid_Argument("PBE-PKCS5 v2.0: Invalid digest " + digest->name());
223 }
static bool known_cipher(const std::string &cipher)
Definition pbes2.cpp:193
std::invalid_argument Invalid_Argument
Definition exceptn.h:20
@ ENCRYPTION
Definition sym_algo.h:87

References Botan::ENCRYPTION, known_cipher(), and Botan::Algorithm::name().

◆ ~PBE_PKCS5v20()

Botan::PBE_PKCS5v20::~PBE_PKCS5v20 ( )

Definition at line 235 of file pbes2.cpp.

236 {
237 delete hash_function;
238 delete block_cipher;
239 }

Member Function Documentation

◆ attachable()

virtual bool Botan::Filter::attachable ( )
inlinevirtualinherited

Check whether this filter is an attachable filter.

Returns
true if this filter is attachable, false otherwise

Reimplemented in Botan::DataSink, and Botan::SecureQueue.

Definition at line 50 of file filter.h.

50{ return true; }

◆ end_msg()

void Botan::PBE_PKCS5v20::end_msg ( )
virtual

Notify that the current message is finished; flush buffers and do end-of-message processing (if any).

Reimplemented from Botan::Filter.

Definition at line 55 of file pbes2.cpp.

56 {
57 pipe.end_msg();
58 flush_pipe(false);
59 pipe.reset();
60 }

◆ known_cipher()

bool Botan::PBE_PKCS5v20::known_cipher ( const std::string & cipher)
static
Parameters
ciphernames a block cipher
Returns
true iff PKCS #5 knows how to use this cipher

Definition at line 193 of file pbes2.cpp.

194 {
195 if(algo == "AES-128" || algo == "AES-192" || algo == "AES-256")
196 return true;
197 if(algo == "DES" || algo == "TripleDES")
198 return true;
199 return false;
200 }

Referenced by PBE_PKCS5v20().

◆ name()

std::string Botan::PBE_PKCS5v20::name ( ) const
virtual
Returns
descriptive name for this filter

Implements Botan::Filter.

Definition at line 202 of file pbes2.cpp.

203 {
204 return "PBE-PKCS5v20(" + block_cipher->name() + "," +
205 hash_function->name() + ")";
206 }

◆ send() [1/4]

void Botan::Filter::send ( byte in)
inlineprotectedinherited
Parameters
insome input for the filter

Definition at line 63 of file filter.h.

63{ send(&in, 1); }
void send(const byte in[], size_t length)
Definition filter.cpp:28

References send().

Referenced by send().

◆ send() [2/4]

void Botan::Filter::send ( const byte in[],
size_t length )
protectedinherited

◆ send() [3/4]

void Botan::Filter::send ( const MemoryRegion< byte > & in)
inlineprotectedinherited
Parameters
insome input for the filter

Definition at line 68 of file filter.h.

68{ send(&in[0], in.size()); }

References send(), and Botan::MemoryRegion< T >::size().

Referenced by send().

◆ send() [4/4]

void Botan::Filter::send ( const MemoryRegion< byte > & in,
size_t length )
inlineprotectedinherited
Parameters
insome input for the filter
lengththe number of bytes of in to send

Definition at line 74 of file filter.h.

75 {
76 send(&in[0], length);
77 }

References send().

◆ start_msg()

void Botan::PBE_PKCS5v20::start_msg ( )
virtual

Start a new message. Must be closed by end_msg() before another message can be started.

Reimplemented from Botan::Filter.

Definition at line 36 of file pbes2.cpp.

37 {
38 if(direction == ENCRYPTION)
39 pipe.append(new CBC_Encryption(block_cipher->clone(),
40 new PKCS7_Padding,
41 key, iv));
42 else
43 pipe.append(new CBC_Decryption(block_cipher->clone(),
44 new PKCS7_Padding,
45 key, iv));
46
47 pipe.start_msg();
48 if(pipe.message_count() > 1)
49 pipe.set_default_msg(pipe.default_msg() + 1);
50 }
CBC_Decryption(BlockCipher *cipher, BlockCipherModePaddingMethod *padding)
Definition cbc.cpp:115
CBC_Encryption(BlockCipher *cipher, BlockCipherModePaddingMethod *padding)
Definition cbc.cpp:17

References Botan::CBC_Decryption::CBC_Decryption(), Botan::CBC_Encryption::CBC_Encryption(), and Botan::ENCRYPTION.

◆ write()

void Botan::PBE_PKCS5v20::write ( const byte input[],
size_t length )
virtual

Write a portion of a message to this filter.

Parameters
inputthe input as a byte array
lengththe length of the byte array input

Implements Botan::Filter.

Definition at line 27 of file pbes2.cpp.

28 {
29 pipe.write(input, length);
30 flush_pipe(true);
31 }

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