3
* (C) 2013,2014 Jack Lloyd
4
* (C) 2016 Daniel Neus, Rohde & Schwarz Cybersecurity
6
* Botan is released under the Simplified BSD License (see license.txt)
9
#ifndef BOTAN_AEAD_OCB_H_
10
#define BOTAN_AEAD_OCB_H_
12
#include <botan/aead.h>
20
* OCB Mode (base class for OCB_Encryption and OCB_Decryption). Note
21
* that OCB is patented, but is freely licensed in some circumstances.
23
* @see "The OCB Authenticated-Encryption Algorithm" RFC 7253
24
* https://tools.ietf.org/html/rfc7253
25
* @see "OCB For Block Ciphers Without 128-Bit Blocks"
26
* (draft-krovetz-ocb-wide-d3) for the extension of OCB to
27
* block ciphers with larger block sizes.
28
* @see Free Licenses http://www.cs.ucdavis.edu/~rogaway/ocb/license.htm
29
* @see OCB home page http://www.cs.ucdavis.edu/~rogaway/ocb
31
class BOTAN_PUBLIC_API(2,0) OCB_Mode : public AEAD_Mode
34
void set_associated_data(const uint8_t ad[], size_t ad_len) override;
36
std::string name() const override;
38
size_t update_granularity() const override;
40
Key_Length_Specification key_spec() const override;
42
bool valid_nonce_length(size_t) const override;
44
size_t tag_size() const override { return m_tag_size; }
46
void clear() override;
48
void reset() override;
53
* @param cipher the block cipher to use
54
* @param tag_size is how big the auth tag will be
56
OCB_Mode(BlockCipher* cipher, size_t tag_size);
58
size_t block_size() const { return m_block_size; }
59
size_t par_blocks() const { return m_par_blocks; }
60
size_t par_bytes() const { return m_checksum.size(); }
62
// fixme make these private
63
std::unique_ptr<BlockCipher> m_cipher;
64
std::unique_ptr<L_computer> m_L;
66
size_t m_block_index = 0;
68
secure_vector<uint8_t> m_checksum;
69
secure_vector<uint8_t> m_ad_hash;
71
void start_msg(const uint8_t nonce[], size_t nonce_len) override;
73
void key_schedule(const uint8_t key[], size_t length) override;
75
secure_vector<uint8_t> update_nonce(const uint8_t nonce[], size_t nonce_len);
77
const size_t m_tag_size;
78
const size_t m_block_size;
79
const size_t m_par_blocks;
80
secure_vector<uint8_t> m_last_nonce;
81
secure_vector<uint8_t> m_stretch;
84
class BOTAN_PUBLIC_API(2,0) OCB_Encryption final : public OCB_Mode
88
* @param cipher the block cipher to use
89
* @param tag_size is how big the auth tag will be
91
OCB_Encryption(BlockCipher* cipher, size_t tag_size = 16) :
92
OCB_Mode(cipher, tag_size) {}
94
size_t output_length(size_t input_length) const override
95
{ return input_length + tag_size(); }
97
size_t minimum_final_size() const override { return 0; }
99
size_t process(uint8_t buf[], size_t size) override;
101
void finish(secure_vector<uint8_t>& final_block, size_t offset = 0) override;
103
void encrypt(uint8_t input[], size_t blocks);
106
class BOTAN_PUBLIC_API(2,0) OCB_Decryption final : public OCB_Mode
110
* @param cipher the block cipher to use
111
* @param tag_size is how big the auth tag will be
113
OCB_Decryption(BlockCipher* cipher, size_t tag_size = 16) :
114
OCB_Mode(cipher, tag_size) {}
116
size_t output_length(size_t input_length) const override
118
BOTAN_ASSERT(input_length >= tag_size(), "Sufficient input");
119
return input_length - tag_size();
122
size_t minimum_final_size() const override { return tag_size(); }
124
size_t process(uint8_t buf[], size_t size) override;
126
void finish(secure_vector<uint8_t>& final_block, size_t offset = 0) override;
128
void decrypt(uint8_t input[], size_t blocks);