Botan  1.10.9
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
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 (DataSource &input)
 
 PBE_PKCS5v20 (BlockCipher *cipher, HashFunction *hash)
 
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 (const byte in[], size_t length)
 
void send (byte in)
 
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

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  }
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.

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

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  }
std::invalid_argument Invalid_Argument
Definition: exceptn.h:20
virtual std::string name() const =0
static bool known_cipher(const std::string &cipher)
Definition: pbes2.cpp:193
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

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::SecureQueue, and Botan::DataSink.

Definition at line 50 of file filter.h.

50 { return true; }
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.

References Botan::Pipe::end_msg(), and Botan::Pipe::reset().

56  {
57  pipe.end_msg();
58  flush_pipe(false);
59  pipe.reset();
60  }
void reset()
Definition: pipe.cpp:76
void end_msg()
Definition: pipe.cpp:166
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.

Referenced by PBE_PKCS5v20().

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  }
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.

References Botan::Algorithm::name().

203  {
204  return "PBE-PKCS5v20(" + block_cipher->name() + "," +
205  hash_function->name() + ")";
206  }
virtual std::string name() const =0
void Botan::Filter::send ( const byte  in[],
size_t  length 
)
protectedinherited
Parameters
insome input for the filter
lengththe length of in

Definition at line 28 of file filter.cpp.

References Botan::MemoryRegion< T >::clear(), Botan::MemoryRegion< T >::size(), and Botan::Filter::write().

Referenced by Botan::PK_Encryptor_Filter::end_msg(), Botan::Zlib_Compression::end_msg(), Botan::Bzip_Compression::end_msg(), Botan::Hex_Encoder::end_msg(), Botan::Base64_Encoder::end_msg(), Botan::PK_Decryptor_Filter::end_msg(), Botan::Bzip_Decompression::end_msg(), Botan::Zlib_Decompression::end_msg(), Botan::PK_Signer_Filter::end_msg(), Botan::Hex_Decoder::end_msg(), Botan::Base64_Decoder::end_msg(), Botan::PK_Verifier_Filter::end_msg(), Botan::Hash_Filter::end_msg(), Botan::MAC_Filter::end_msg(), Botan::Bzip_Compression::flush(), Botan::Zlib_Compression::flush(), Botan::Bzip_Compression::write(), Botan::Zlib_Compression::write(), Botan::StreamCipher_Filter::write(), Botan::Bzip_Decompression::write(), Botan::Zlib_Decompression::write(), Botan::Hex_Decoder::write(), and Botan::Base64_Decoder::write().

29  {
30  bool nothing_attached = true;
31  for(size_t j = 0; j != total_ports(); ++j)
32  if(next[j])
33  {
34  if(write_queue.size())
35  next[j]->write(&write_queue[0], write_queue.size());
36  next[j]->write(input, length);
37  nothing_attached = false;
38  }
39 
40  if(nothing_attached)
41  write_queue += std::make_pair(input, length);
42  else
43  write_queue.clear();
44  }
virtual void write(const byte input[], size_t length)=0
size_t size() const
Definition: secmem.h:29
void Botan::Filter::send ( byte  in)
inlineprotectedinherited
Parameters
insome input for the filter

Definition at line 63 of file filter.h.

References Botan::Filter::send().

Referenced by Botan::Filter::send().

63 { send(&in, 1); }
void send(const byte in[], size_t length)
Definition: filter.cpp:28
void Botan::Filter::send ( const MemoryRegion< byte > &  in)
inlineprotectedinherited
Parameters
insome input for the filter

Definition at line 68 of file filter.h.

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

Referenced by Botan::Filter::send().

68 { send(&in[0], in.size()); }
void send(const byte in[], size_t length)
Definition: filter.cpp:28
size_t size() const
Definition: secmem.h:29
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  }
void send(const byte in[], size_t length)
Definition: filter.cpp:28
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.

References Botan::Pipe::append(), Botan::BlockCipher::clone(), Botan::Pipe::default_msg(), Botan::ENCRYPTION, Botan::Pipe::message_count(), Botan::Pipe::set_default_msg(), and Botan::Pipe::start_msg().

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  }
void start_msg()
Definition: pipe.cpp:152
void append(Filter *filt)
Definition: pipe.cpp:215
virtual BlockCipher * clone() const =0
size_t default_msg() const
Definition: pipe.h:206
void set_default_msg(message_id msg)
Definition: pipe.cpp:106
message_id message_count() const
Definition: pipe.cpp:282
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.

References Botan::Pipe::write().

28  {
29  pipe.write(input, length);
30  flush_pipe(true);
31  }
void write(const byte in[], size_t length)
Definition: pipe_rw.cpp:34

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