Botan 3.6.1
Crypto and TLS for C&
ctr.h
Go to the documentation of this file.
1/*
2* CTR-BE Mode
3* (C) 1999-2007 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#ifndef BOTAN_CTR_BE_H_
9#define BOTAN_CTR_BE_H_
10
11#include <botan/block_cipher.h>
12#include <botan/stream_cipher.h>
13
14namespace Botan {
15
16/**
17* CTR-BE (Counter mode, big-endian)
18*/
19class CTR_BE final : public StreamCipher {
20 public:
21 size_t default_iv_length() const override;
22
23 bool valid_iv_length(size_t iv_len) const override;
24
25 Key_Length_Specification key_spec() const override;
26
27 std::string name() const override;
28
29 std::unique_ptr<StreamCipher> new_object() const override;
30
31 void clear() override;
32
33 bool has_keying_material() const override;
34
35 size_t buffer_size() const override;
36
37 /**
38 * @param cipher the block cipher to use
39 */
40 explicit CTR_BE(std::unique_ptr<BlockCipher> cipher);
41
42 CTR_BE(std::unique_ptr<BlockCipher> cipher, size_t ctr_size);
43
44 void seek(uint64_t offset) override;
45
46 private:
47 void key_schedule(std::span<const uint8_t> key) override;
48 void cipher_bytes(const uint8_t in[], uint8_t out[], size_t length) override;
49 void generate_keystream(uint8_t out[], size_t length) override;
50 void set_iv_bytes(const uint8_t iv[], size_t iv_len) override;
51 void add_counter(uint64_t counter);
52
53 std::unique_ptr<BlockCipher> m_cipher;
54
55 const size_t m_block_size;
56 const size_t m_ctr_size;
57 const size_t m_ctr_blocks;
58
59 secure_vector<uint8_t> m_counter, m_pad;
60 std::vector<uint8_t> m_iv;
61 size_t m_pad_pos;
62};
63
64} // namespace Botan
65
66#endif
void clear() override
Definition ctr.cpp:37
size_t default_iv_length() const override
Definition ctr.cpp:45
bool has_keying_material() const override
Definition ctr.cpp:65
size_t buffer_size() const override
Definition ctr.cpp:53
Key_Length_Specification key_spec() const override
Definition ctr.cpp:57
bool valid_iv_length(size_t iv_len) const override
Definition ctr.cpp:49
void seek(uint64_t offset) override
Definition ctr.cpp:208
std::unique_ptr< StreamCipher > new_object() const override
Definition ctr.cpp:61
std::string name() const override
Definition ctr.cpp:76
CTR_BE(std::unique_ptr< BlockCipher > cipher)
Definition ctr.cpp:17
void cipher(const uint8_t in[], uint8_t out[], size_t len)
int(* final)(unsigned char *, CTX *)
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61