Botan 2.13.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 #include <botan/exceptn.h>
10
11 namespace Botan {
12
13 OFB::OFB(BlockCipher* cipher) :
14 m_cipher(cipher),
15 m_buffer(m_cipher->block_size()),
16 m_buf_pos(0)
17 {
18 }
19
20 void OFB::clear()
21 {
22 m_cipher->clear();
23 zeroise(m_buffer);
24 m_buf_pos = 0;
25 }
26
27 void OFB::key_schedule(const uint8_t key[], size_t key_len)
28 {
29 m_cipher->set_key(key, key_len);
30
31 // Set a default all-zeros IV
32 set_iv(nullptr, 0);
33 }
34
35 std::string OFB::name() const
36 {
37 return "OFB(" + m_cipher->name() + ")";
38 }
39
40 size_t OFB::default_iv_length() const
41 {
42 return m_cipher->block_size();
43 }
44
45 bool OFB::valid_iv_length(size_t iv_len) const
46 {
47 return (iv_len <= m_cipher->block_size());
48 }
49
50 Key_Length_Specification OFB::key_spec() const
51 {
52 return m_cipher->key_spec();
53 }
54
55 OFB* OFB::clone() const
56 {
57 return new OFB(m_cipher->clone());
58 }
59
60 void OFB::cipher(const uint8_t in[], uint8_t out[], size_t length)
61 {
62 while(length >= m_buffer.size() - m_buf_pos)
63 {
64 xor_buf(out, in, &m_buffer[m_buf_pos], m_buffer.size() - m_buf_pos);
65 length -= (m_buffer.size() - m_buf_pos);
66 in += (m_buffer.size() - m_buf_pos);
67 out += (m_buffer.size() - m_buf_pos);
68 m_cipher->encrypt(m_buffer);
69 m_buf_pos = 0;
70 }
71 xor_buf(out, in, &m_buffer[m_buf_pos], length);
72 m_buf_pos += length;
73 }
74
75 void OFB::set_iv(const uint8_t iv[], size_t iv_len)
76 {
77 if(!valid_iv_length(iv_len))
78 throw Invalid_IV_Length(name(), iv_len);
79
80 zeroise(m_buffer);
81 buffer_insert(m_buffer, 0, iv, iv_len);
82
83 m_cipher->encrypt(m_buffer);
84 m_buf_pos = 0;
85 }
86
87
88 void OFB::seek(uint64_t)
89 {
90 throw Not_Implemented("OFB does not support seeking");
91 }
92 }
Botan::OFB::set_iv
void set_iv(const uint8_t iv[], size_t iv_len) override
Definition: ofb.cpp:75
Botan::OFB::default_iv_length
size_t default_iv_length() const override
Definition: ofb.cpp:40
m_cipher
CCCryptorRef m_cipher
Definition: commoncrypto_mode.cpp:50
Botan::OFB::cipher
void cipher(const uint8_t in[], uint8_t out[], size_t length) override
Definition: ofb.cpp:60
Botan::Invalid_IV_Length
Definition: exceptn.h:161
Botan::OFB::clear
void clear() override
Definition: ofb.cpp:20
Botan::OFB
Definition: ofb.h:21
Botan::Key_Length_Specification
Definition: key_spec.h:18
Botan::Not_Implemented
Definition: exceptn.h:355
Botan::OFB::key_spec
Key_Length_Specification key_spec() const override
Definition: ofb.cpp:50
Botan::xor_buf
void xor_buf(uint8_t out[], const uint8_t in[], size_t length)
Definition: mem_ops.h:232
Botan
Definition: alg_id.cpp:13
Botan::OFB::valid_iv_length
bool valid_iv_length(size_t iv_len) const override
Definition: ofb.cpp:45
Botan::OFB::name
std::string name() const override
Definition: ofb.cpp:35
Botan::OFB::seek
void seek(uint64_t offset) override
Definition: ofb.cpp:88
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:80
Botan::OFB::clone
OFB * clone() const override
Definition: ofb.cpp:55
Botan::OFB::OFB
OFB(BlockCipher *cipher)
Definition: ofb.cpp:13
Botan::BlockCipher
Definition: block_cipher.h:21
Botan::zeroise
void zeroise(std::vector< T, Alloc > &vec)
Definition: secmem.h:160