monotone

monotone Mtn Source Tree

Root/botan/modebase.cpp

1/*************************************************
2* Block Cipher Mode Source File *
3* (C) 1999-2007 The Botan Project *
4*************************************************/
5
6#include <botan/modebase.h>
7#include <botan/lookup.h>
8
9namespace Botan {
10
11/*************************************************
12* Block Cipher Mode Constructor *
13*************************************************/
14BlockCipherMode::BlockCipherMode(const std::string& cipher_name,
15 const std::string& cipher_mode_name,
16 u32bit iv_size, u32bit iv_meth,
17 u32bit buf_mult) :
18 BLOCK_SIZE(block_size_of(cipher_name)), BUFFER_SIZE(buf_mult * BLOCK_SIZE),
19 IV_METHOD(iv_meth), mode_name(cipher_mode_name)
20 {
21 base_ptr = cipher = get_block_cipher(cipher_name);
22 buffer.create(BUFFER_SIZE);
23 state.create(iv_size);
24 position = 0;
25 }
26
27/*************************************************
28* Return the name of this type *
29*************************************************/
30std::string BlockCipherMode::name() const
31 {
32 return (cipher->name() + "/" + mode_name);
33 }
34
35/*************************************************
36* Set the IV *
37*************************************************/
38void BlockCipherMode::set_iv(const InitializationVector& new_iv)
39 {
40 if(new_iv.length() != state.size())
41 throw Invalid_IV_Length(name(), new_iv.length());
42
43 state = new_iv.bits_of();
44 buffer.clear();
45 position = 0;
46
47 if(IV_METHOD == 1)
48 cipher->encrypt(state, buffer);
49 else if(IV_METHOD == 2)
50 cipher->encrypt(state);
51 }
52
53}

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status