Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

ofb.cpp
Go to the documentation of this file.
1 /*
2 * OFB Mode
3 * (C) 1999-2007,2014 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7
8 #include <botan/ofb.h>
9
10 namespace Botan {
11
12 OFB::OFB(BlockCipher* cipher) :
13 m_cipher(cipher),
14 m_buffer(m_cipher->block_size()),
15 m_buf_pos(0)
16 {
17 }
18
19 void OFB::clear()
20 {
21 m_cipher->clear();
22 zeroise(m_buffer);
23 m_buf_pos = 0;
24 }
25
26 void OFB::key_schedule(const uint8_t key[], size_t key_len)
27 {
28 m_cipher->set_key(key, key_len);
29
30 // Set a default all-zeros IV
31 set_iv(nullptr, 0);
32 }
33
34 std::string OFB::name() const
35 {
36 return "OFB(" + m_cipher->name() + ")";
37 }
38
39 void OFB::cipher(const uint8_t in[], uint8_t out[], size_t length)
40 {
41 while(length >= m_buffer.size() - m_buf_pos)
42 {
43 xor_buf(out, in, &m_buffer[m_buf_pos], m_buffer.size() - m_buf_pos);
44 length -= (m_buffer.size() - m_buf_pos);
45 in += (m_buffer.size() - m_buf_pos);
46 out += (m_buffer.size() - m_buf_pos);
47 m_cipher->encrypt(m_buffer);
48 m_buf_pos = 0;
49 }
50 xor_buf(out, in, &m_buffer[m_buf_pos], length);
51 m_buf_pos += length;
52 }
53
54 void OFB::set_iv(const uint8_t iv[], size_t iv_len)
55 {
56 if(!valid_iv_length(iv_len))
57 throw Invalid_IV_Length(name(), iv_len);
58
59 zeroise(m_buffer);
60 buffer_insert(m_buffer, 0, iv, iv_len);
61
62 m_cipher->encrypt(m_buffer);
63 m_buf_pos = 0;
64 }
65
66
67 void OFB::seek(uint64_t)
68 {
69 throw Exception("OFB does not support seeking");
70 }
71 }
Botan::xor_buf
void xor_buf(T out[], const T in[], size_t length)
Definition: mem_ops.h:115
Botan::OFB::set_iv
void set_iv(const uint8_t iv[], size_t iv_len) override
Definition: ofb.cpp:54
Botan::Exception
Definition: exceptn.h:21
Botan::OFB::cipher
void cipher(const uint8_t in[], uint8_t out[], size_t length) override
Definition: ofb.cpp:39
Botan::OFB::clear
void clear() override
Definition: ofb.cpp:19
Botan::Invalid_IV_Length
Definition: exceptn.h:109
Botan
Definition: alg_id.cpp:13
Botan::OFB::valid_iv_length
bool valid_iv_length(size_t iv_len) const override
Definition: ofb.h:26
Botan::OFB::name
std::string name() const override
Definition: ofb.cpp:34
Botan::OFB::seek
void seek(uint64_t offset) override
Definition: ofb.cpp:67
Botan::buffer_insert
size_t buffer_insert(std::vector< T, Alloc > &buf, size_t buf_offset, const T input[], size_t input_length)
Definition: secmem.h:133
Botan::OFB::OFB
OFB(BlockCipher *cipher)
Definition: ofb.cpp:12
Botan::BlockCipher
Definition: block_cipher.h:19
Botan::zeroise
void zeroise(std::vector< T, Alloc > &vec)
Definition: secmem.h:211