Botan 3.14.1
Crypto and TLS for C&
Botan::Noekeon Class Referencefinal

#include <noekeon.h>

Inheritance diagram for Botan::Noekeon:
Botan::Block_Cipher_Fixed_Params< 16, 16 > Botan::BlockCipher Botan::SymmetricAlgorithm

Public Types

enum  

Public Member Functions

size_t block_size () const final
void clear () override
BlockCipher * clone () const
BlockCipher * clone () const
void decrypt (const uint8_t in[], uint8_t out[]) const
void decrypt (std::span< const uint8_t > in, std::span< uint8_t > out) const
void decrypt (std::span< uint8_t > block) const
void decrypt (uint8_t block[]) const
void decrypt (const uint8_t in[], uint8_t out[]) const
void decrypt (std::span< const uint8_t > in, std::span< uint8_t > out) const
void decrypt (std::span< uint8_t > block) const
void decrypt (uint8_t block[]) const
void decrypt_n (const uint8_t in[], uint8_t out[], size_t blocks) const override
void decrypt_n_xex (uint8_t data[], const uint8_t mask[], size_t blocks) const
void decrypt_n_xex (uint8_t data[], const uint8_t mask[], size_t blocks) const
void encrypt (const uint8_t in[], uint8_t out[]) const
void encrypt (std::span< const uint8_t > in, std::span< uint8_t > out) const
void encrypt (std::span< uint8_t > block) const
void encrypt (uint8_t block[]) const
void encrypt (const uint8_t in[], uint8_t out[]) const
void encrypt (std::span< const uint8_t > in, std::span< uint8_t > out) const
void encrypt (std::span< uint8_t > block) const
void encrypt (uint8_t block[]) const
void encrypt_n (const uint8_t in[], uint8_t out[], size_t blocks) const override
void encrypt_n_xex (uint8_t data[], const uint8_t mask[], size_t blocks) const
void encrypt_n_xex (uint8_t data[], const uint8_t mask[], size_t blocks) const
bool has_keying_material () const override
Key_Length_Specification key_spec () const final
size_t maximum_keylength () const
size_t maximum_keylength () const
size_t minimum_keylength () const
size_t minimum_keylength () const
std::string name () const override
std::unique_ptr< BlockCipher > new_object () const override
size_t parallel_bytes () const
size_t parallel_bytes () const
size_t parallelism () const override
std::string provider () const override
void set_key (const OctetString &key)
void set_key (const uint8_t key[], size_t length)
void set_key (std::span< const uint8_t > key)
void set_key (const OctetString &key)
void set_key (const uint8_t key[], size_t length)
void set_key (std::span< const uint8_t > key)
bool valid_keylength (size_t length) const
bool valid_keylength (size_t length) const

Static Public Member Functions

static std::unique_ptr< BlockCipher > create (std::string_view algo_spec, std::string_view provider="")
static std::unique_ptr< BlockCipher > create (std::string_view algo_spec, std::string_view provider="")
static std::unique_ptr< BlockCipher > create_or_throw (std::string_view algo_spec, std::string_view provider="")
static std::unique_ptr< BlockCipher > create_or_throw (std::string_view algo_spec, std::string_view provider="")
static std::vector< std::string > providers (std::string_view algo_spec)
static std::vector< std::string > providers (std::string_view algo_spec)

Static Public Attributes

static constexpr size_t ParallelismMult
static constexpr size_t ParallelismMult = 4

Protected Member Functions

void assert_key_material_set () const
void assert_key_material_set (bool predicate) const
void assert_key_material_set () const
void assert_key_material_set (bool predicate) const

Detailed Description

Noekeon

Definition at line 19 of file noekeon.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
inherited

Definition at line 234 of file block_cipher.h.

234{ BLOCK_SIZE = BS }; /* NOLINT(*-enum-size,*-use-enum-class) */

Member Function Documentation

◆ assert_key_material_set() [1/4]

◆ assert_key_material_set() [2/4]

void Botan::SymmetricAlgorithm::assert_key_material_set ( bool predicate) const
inlineprotectedinherited

Throw Key_Not_Set unless the predicate holds

Parameters
predicateif false, a Key_Not_Set exception is thrown

Definition at line 186 of file sym_algo.h.

186 {
187 if(!predicate) {
189 }
190 }

◆ assert_key_material_set() [3/4]

◆ assert_key_material_set() [4/4]

void Botan::SymmetricAlgorithm::assert_key_material_set ( bool predicate) const
inlineprotectedinherited

Throw Key_Not_Set unless the predicate holds

Parameters
predicateif false, a Key_Not_Set exception is thrown

Definition at line 186 of file sym_algo.h.

186 {
187 if(!predicate) {
188 throw_key_not_set_error();
189 }
190 }

◆ block_size()

size_t Botan::Block_Cipher_Fixed_Params< BS, KMIN, 0, 1, BlockCipher >::block_size ( ) const
inlinefinalvirtualinherited

Return the block size of this cipher

Returns
the fixed block size BS

Implements Botan::BlockCipher.

Definition at line 240 of file block_cipher.h.

240{ return BS; }

◆ clear()

void Botan::Noekeon::clear ( )
overridevirtual

Reset the internal state. This includes not just the key, but any partial message that may have been in process.

Implements Botan::SymmetricAlgorithm.

Definition at line 245 of file noekeon.cpp.

245 {
246 zap(m_EK);
247 zap(m_DK);
248}
void zap(std::vector< T, Alloc > &vec)
Definition secmem.h:261

References Botan::zap().

◆ clone() [1/2]

BlockCipher * Botan::BlockCipher::clone ( ) const
inlineinherited

Create a new uninitialized object of the same type

Returns
new object representing the same algorithm as *this

Definition at line 210 of file block_cipher.h.

210{ return this->new_object().release(); }
virtual std::unique_ptr< BlockCipher > new_object() const=0

◆ clone() [2/2]

BlockCipher * Botan::BlockCipher::clone ( ) const
inlineinherited

Create a new uninitialized object of the same type

Returns
new object representing the same algorithm as *this

Definition at line 210 of file block_cipher.h.

210{ return this->new_object().release(); }

References new_object().

◆ create() [1/2]

std::unique_ptr< BlockCipher > Botan::BlockCipher::create ( std::string_view algo_spec,
std::string_view provider = "" )
staticinherited

Create an instance based on a name If provider is empty then best available is chosen.

Parameters
algo_specalgorithm name
providerprovider implementation to choose
Returns
a null pointer if the algo/provider combination cannot be found

Definition at line 31 of file block_cipher.cpp.

97 {
98#if defined(BOTAN_HAS_COMMONCRYPTO)
99 if(provider.empty() || provider == "commoncrypto") {
101 return bc;
102
103 if(!provider.empty())
104 return nullptr;
105 }
106#endif
107
108 // TODO: CryptoAPI
109 // TODO: /dev/crypto
110
111 // Only base providers from here on out
112 if(provider.empty() == false && provider != "base") {
113 return nullptr;
114 }
115
116#if defined(BOTAN_HAS_AES)
117 if(algo == "AES-128") {
119 }
120
121 if(algo == "AES-192") {
123 }
124
125 if(algo == "AES-256") {
127 }
128#endif
129
130#if defined(BOTAN_HAS_ARIA)
131 if(algo == "ARIA-128") {
133 }
134
135 if(algo == "ARIA-192") {
137 }
138
139 if(algo == "ARIA-256") {
141 }
142#endif
143
144#if defined(BOTAN_HAS_SERPENT)
145 if(algo == "Serpent") {
147 }
148#endif
149
150#if defined(BOTAN_HAS_SHACAL2)
151 if(algo == "SHACAL2") {
153 }
154#endif
155
156#if defined(BOTAN_HAS_TWOFISH)
157 if(algo == "Twofish") {
159 }
160#endif
161
162#if defined(BOTAN_HAS_THREEFISH_512)
163 if(algo == "Threefish-512") {
165 }
166#endif
167
168#if defined(BOTAN_HAS_BLOWFISH)
169 if(algo == "Blowfish") {
171 }
172#endif
173
174#if defined(BOTAN_HAS_CAMELLIA)
175 if(algo == "Camellia-128") {
177 }
178
179 if(algo == "Camellia-192") {
181 }
182
183 if(algo == "Camellia-256") {
185 }
186#endif
187
188#if defined(BOTAN_HAS_DES)
189 if(algo == "DES") {
190 return std::make_unique<DES>();
191 }
192
193 if(algo == "TripleDES" || algo == "3DES" || algo == "DES-EDE") {
195 }
196#endif
197
198#if defined(BOTAN_HAS_NOEKEON)
199 if(algo == "Noekeon") {
201 }
202#endif
203
204#if defined(BOTAN_HAS_CAST_128)
205 if(algo == "CAST-128" || algo == "CAST5") {
207 }
208#endif
209
210#if defined(BOTAN_HAS_IDEA)
211 if(algo == "IDEA") {
212 return std::make_unique<IDEA>();
213 }
214#endif
215
216#if defined(BOTAN_HAS_KUZNYECHIK)
217 if(algo == "Kuznyechik") {
219 }
220#endif
221
222#if defined(BOTAN_HAS_SEED)
223 if(algo == "SEED") {
224 return std::make_unique<SEED>();
225 }
226#endif
227
228#if defined(BOTAN_HAS_SM4)
229 if(algo == "SM4") {
230 return std::make_unique<SM4>();
231 }
232#endif
233
234 const AlgorithmSpec req(algo);
235
236#if defined(BOTAN_HAS_GOST_28147_89)
237 if(auto m = req.match("GOST-28147-89({params:str=R3411_94_TestParam})")) {
238 return std::make_unique<GOST_28147_89>(m->str("params"));
239 }
240#endif
241
242#if defined(BOTAN_HAS_CASCADE)
243 if(auto m = req.match("Cascade({cipher1},{cipher2})")) {
244 auto c1 = BlockCipher::create(m->str("cipher1"));
245 auto c2 = BlockCipher::create(m->str("cipher2"));
246
247 if(c1 && c2) {
249 }
250 }
251#endif
252
253#if defined(BOTAN_HAS_LION)
254 if(auto m = req.match("Lion({hash},{stream},{block_size:int=1024})")) {
255 auto hash = HashFunction::create(m->str("hash"));
256 auto stream = StreamCipher::create(m->str("stream"));
257
258 if(hash && stream) {
259 return std::make_unique<Lion>(std::move(hash), std::move(stream), m->integer("block_size"));
260 }
261 }
262#endif
263
266
267 return nullptr;
268}
#define BOTAN_UNUSED
Definition assert.h:151
static std::unique_ptr< BlockCipher > create(std::string_view algo_spec, std::string_view provider="")
static std::unique_ptr< HashFunction > create(std::string_view algo_spec, std::string_view provider="")
Definition hash.cpp:112
static std::unique_ptr< StreamCipher > create(std::string_view algo_spec, std::string_view provider="")
std::unique_ptr< BlockCipher > make_commoncrypto_block_cipher(std::string_view name)

◆ create() [2/2]

std::unique_ptr< BlockCipher > Botan::BlockCipher::create ( std::string_view algo_spec,
std::string_view provider = "" )
staticinherited

Create an instance based on a name If provider is empty then best available is chosen.

Parameters
algo_specalgorithm name
providerprovider implementation to choose
Returns
a null pointer if the algo/provider combination cannot be found

Definition at line 97 of file block_cipher.cpp.

97 {
98#if defined(BOTAN_HAS_COMMONCRYPTO)
99 if(provider.empty() || provider == "commoncrypto") {
100 if(auto bc = make_commoncrypto_block_cipher(algo))
101 return bc;
102
103 if(!provider.empty())
104 return nullptr;
105 }
106#endif
107
108 // TODO: CryptoAPI
109 // TODO: /dev/crypto
110
111 // Only base providers from here on out
112 if(provider.empty() == false && provider != "base") {
113 return nullptr;
114 }
115
116#if defined(BOTAN_HAS_AES)
117 if(algo == "AES-128") {
118 return std::make_unique<AES_128>();
119 }
120
121 if(algo == "AES-192") {
122 return std::make_unique<AES_192>();
123 }
124
125 if(algo == "AES-256") {
126 return std::make_unique<AES_256>();
127 }
128#endif
129
130#if defined(BOTAN_HAS_ARIA)
131 if(algo == "ARIA-128") {
132 return std::make_unique<ARIA_128>();
133 }
134
135 if(algo == "ARIA-192") {
136 return std::make_unique<ARIA_192>();
137 }
138
139 if(algo == "ARIA-256") {
140 return std::make_unique<ARIA_256>();
141 }
142#endif
143
144#if defined(BOTAN_HAS_SERPENT)
145 if(algo == "Serpent") {
146 return std::make_unique<Serpent>();
147 }
148#endif
149
150#if defined(BOTAN_HAS_SHACAL2)
151 if(algo == "SHACAL2") {
152 return std::make_unique<SHACAL2>();
153 }
154#endif
155
156#if defined(BOTAN_HAS_TWOFISH)
157 if(algo == "Twofish") {
158 return std::make_unique<Twofish>();
159 }
160#endif
161
162#if defined(BOTAN_HAS_THREEFISH_512)
163 if(algo == "Threefish-512") {
164 return std::make_unique<Threefish_512>();
165 }
166#endif
167
168#if defined(BOTAN_HAS_BLOWFISH)
169 if(algo == "Blowfish") {
170 return std::make_unique<Blowfish>();
171 }
172#endif
173
174#if defined(BOTAN_HAS_CAMELLIA)
175 if(algo == "Camellia-128") {
176 return std::make_unique<Camellia_128>();
177 }
178
179 if(algo == "Camellia-192") {
180 return std::make_unique<Camellia_192>();
181 }
182
183 if(algo == "Camellia-256") {
184 return std::make_unique<Camellia_256>();
185 }
186#endif
187
188#if defined(BOTAN_HAS_DES)
189 if(algo == "DES") {
190 return std::make_unique<DES>();
191 }
192
193 if(algo == "TripleDES" || algo == "3DES" || algo == "DES-EDE") {
194 return std::make_unique<TripleDES>();
195 }
196#endif
197
198#if defined(BOTAN_HAS_NOEKEON)
199 if(algo == "Noekeon") {
200 return std::make_unique<Noekeon>();
201 }
202#endif
203
204#if defined(BOTAN_HAS_CAST_128)
205 if(algo == "CAST-128" || algo == "CAST5") {
206 return std::make_unique<CAST_128>();
207 }
208#endif
209
210#if defined(BOTAN_HAS_IDEA)
211 if(algo == "IDEA") {
212 return std::make_unique<IDEA>();
213 }
214#endif
215
216#if defined(BOTAN_HAS_KUZNYECHIK)
217 if(algo == "Kuznyechik") {
218 return std::make_unique<Kuznyechik>();
219 }
220#endif
221
222#if defined(BOTAN_HAS_SEED)
223 if(algo == "SEED") {
224 return std::make_unique<SEED>();
225 }
226#endif
227
228#if defined(BOTAN_HAS_SM4)
229 if(algo == "SM4") {
230 return std::make_unique<SM4>();
231 }
232#endif
233
234 const AlgorithmSpec req(algo);
235
236#if defined(BOTAN_HAS_GOST_28147_89)
237 if(auto m = req.match("GOST-28147-89({params:str=R3411_94_TestParam})")) {
238 return std::make_unique<GOST_28147_89>(m->str("params"));
239 }
240#endif
241
242#if defined(BOTAN_HAS_CASCADE)
243 if(auto m = req.match("Cascade({cipher1},{cipher2})")) {
244 auto c1 = BlockCipher::create(m->str("cipher1"));
245 auto c2 = BlockCipher::create(m->str("cipher2"));
246
247 if(c1 && c2) {
248 return std::make_unique<Cascade_Cipher>(std::move(c1), std::move(c2));
249 }
250 }
251#endif
252
253#if defined(BOTAN_HAS_LION)
254 if(auto m = req.match("Lion({hash},{stream},{block_size:int=1024})")) {
255 auto hash = HashFunction::create(m->str("hash"));
256 auto stream = StreamCipher::create(m->str("stream"));
257
258 if(hash && stream) {
259 return std::make_unique<Lion>(std::move(hash), std::move(stream), m->integer("block_size"));
260 }
261 }
262#endif
263
264 BOTAN_UNUSED(req);
266
267 return nullptr;
268}
virtual std::string provider() const

References BOTAN_UNUSED, create(), Botan::HashFunction::create(), Botan::StreamCipher::create(), Botan::make_commoncrypto_block_cipher(), Botan::AlgorithmSpec::match(), and provider().

Referenced by botan_block_cipher_init(), Botan::AEAD_Mode::create(), create(), Botan::Cipher_Mode::create(), Botan::MessageAuthenticationCode::create(), Botan::StreamCipher::create(), and create_or_throw().

◆ create_or_throw() [1/2]

std::unique_ptr< BlockCipher > Botan::BlockCipher::create_or_throw ( std::string_view algo_spec,
std::string_view provider = "" )
staticinherited

Create an instance based on a name, or throw if the algo/provider combination cannot be found. If provider is empty then best available is chosen.

Definition at line 38 of file block_cipher.cpp.

271 {
272 if(auto bc = BlockCipher::create(algo, provider)) {
273 return bc;
274 }
275 throw Lookup_Error("Block cipher", algo, provider);
276}

◆ create_or_throw() [2/2]

std::unique_ptr< BlockCipher > Botan::BlockCipher::create_or_throw ( std::string_view algo_spec,
std::string_view provider = "" )
staticinherited

Create an instance based on a name, or throw if the algo/provider combination cannot be found. If provider is empty then best available is chosen.

Definition at line 271 of file block_cipher.cpp.

271 {
272 if(auto bc = BlockCipher::create(algo, provider)) {
273 return bc;
274 }
275 throw Lookup_Error("Block cipher", algo, provider);
276}

References create(), and provider().

Referenced by botan_nist_kw_dec(), botan_nist_kw_enc(), Botan::TLS::Connection_Cipher_State::Connection_Cipher_State(), Botan::Encrypted_PSK_Database::Encrypted_PSK_Database(), Botan::rfc3394_keyunwrap(), and Botan::rfc3394_keywrap().

◆ decrypt() [1/8]

void Botan::BlockCipher::decrypt ( const uint8_t in[],
uint8_t out[] ) const
inlineinherited

Decrypt a block.

Parameters
inThe ciphertext block to be decrypted as a byte array. Must be of length block_size().
outThe byte array designated to hold the decrypted block. Must be of length block_size().

Definition at line 96 of file block_cipher.h.

96{ decrypt_n(in, out, 1); }
virtual void decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const=0

◆ decrypt() [2/8]

void Botan::BlockCipher::decrypt ( std::span< const uint8_t > in,
std::span< uint8_t > out ) const
inlineinherited

Decrypt one or more blocks

Parameters
inthe input buffer (multiple of block_size())
outthe output buffer (same size as in)

Definition at line 144 of file block_cipher.h.

144 {
145 return decrypt_n(in.data(), out.data(), in.size() / block_size());
146 }

◆ decrypt() [3/8]

void Botan::BlockCipher::decrypt ( std::span< uint8_t > block) const
inlineinherited

Decrypt one or more blocks

Parameters
Block Ciphersthe input/output buffer (multiple of block_size())

Definition at line 126 of file block_cipher.h.

126 {
127 return decrypt_n(block.data(), block.data(), block.size() / block_size());
128 }

◆ decrypt() [4/8]

void Botan::BlockCipher::decrypt ( uint8_t block[]) const
inlineinherited

Decrypt a block.

Parameters
Block Ciphersthe ciphertext block to be decrypted Must be of length block_size(). Will hold the result when the function has finished.

Definition at line 112 of file block_cipher.h.

112{ decrypt_n(block, block, 1); }

◆ decrypt() [5/8]

void Botan::BlockCipher::decrypt ( const uint8_t in[],
uint8_t out[] ) const
inlineinherited

Decrypt a block.

Parameters
inThe ciphertext block to be decrypted as a byte array. Must be of length block_size().
outThe byte array designated to hold the decrypted block. Must be of length block_size().

Definition at line 96 of file block_cipher.h.

96{ decrypt_n(in, out, 1); }

References decrypt_n().

Referenced by Botan::nist_key_unwrap(), and Botan::nist_key_unwrap_padded().

◆ decrypt() [6/8]

void Botan::BlockCipher::decrypt ( std::span< const uint8_t > in,
std::span< uint8_t > out ) const
inlineinherited

Decrypt one or more blocks

Parameters
inthe input buffer (multiple of block_size())
outthe output buffer (same size as in)

Definition at line 144 of file block_cipher.h.

144 {
145 return decrypt_n(in.data(), out.data(), in.size() / block_size());
146 }
virtual size_t block_size() const =0

References block_size(), and decrypt_n().

◆ decrypt() [7/8]

void Botan::BlockCipher::decrypt ( std::span< uint8_t > block) const
inlineinherited

Decrypt one or more blocks

Parameters
Block Ciphersthe input/output buffer (multiple of block_size())

Definition at line 126 of file block_cipher.h.

126 {
127 return decrypt_n(block.data(), block.data(), block.size() / block_size());
128 }

References block_size(), and decrypt_n().

◆ decrypt() [8/8]

void Botan::BlockCipher::decrypt ( uint8_t block[]) const
inlineinherited

Decrypt a block.

Parameters
Block Ciphersthe ciphertext block to be decrypted Must be of length block_size(). Will hold the result when the function has finished.

Definition at line 112 of file block_cipher.h.

112{ decrypt_n(block, block, 1); }

References decrypt_n().

◆ decrypt_n()

void Botan::Noekeon::decrypt_n ( const uint8_t in[],
uint8_t out[],
size_t blocks ) const
overridevirtual

Decrypt one or more blocks

Parameters
inthe input buffer (multiple of block_size())
outthe output buffer (same size as in)
blocksthe number of blocks to process

Implements Botan::BlockCipher.

Definition at line 152 of file noekeon.cpp.

152 {
154
155#if defined(BOTAN_HAS_NOEKEON_SIMD)
157 while(blocks >= 4) {
158 simd_decrypt_4(in, out);
159 in += 4 * BLOCK_SIZE;
160 out += 4 * BLOCK_SIZE;
161 blocks -= 4;
162 }
163 }
164#endif
165
166 for(size_t i = 0; i != blocks; ++i) {
167 uint32_t A0 = load_be<uint32_t>(in, 0);
168 uint32_t A1 = load_be<uint32_t>(in, 1);
169 uint32_t A2 = load_be<uint32_t>(in, 2);
170 uint32_t A3 = load_be<uint32_t>(in, 3);
171
172 for(size_t j = 16; j != 0; --j) {
173 theta(A0, A1, A2, A3, m_DK.data());
174 A0 ^= RC[j];
175
176 A1 = rotl<1>(A1);
177 A2 = rotl<5>(A2);
178 A3 = rotl<2>(A3);
179
180 gamma(A0, A1, A2, A3);
181
182 A1 = rotr<1>(A1);
183 A2 = rotr<5>(A2);
184 A3 = rotr<2>(A3);
185 }
186
187 theta(A0, A1, A2, A3, m_DK.data());
188 A0 ^= RC[0];
189
190 store_be(out, A0, A1, A2, A3);
191
192 in += BLOCK_SIZE;
193 out += BLOCK_SIZE;
194 }
195}
static bool has(CPUID::Feature feat)
Definition cpuid.h:93
BOTAN_FORCE_INLINE constexpr T rotr(T input)
Definition rotate.h:35
BOTAN_FORCE_INLINE constexpr T rotl(T input)
Definition rotate.h:23
constexpr auto store_be(ParamTs &&... params)
Definition loadstor.h:745
constexpr auto load_be(ParamTs &&... params)
Definition loadstor.h:504

References Botan::Block_Cipher_Fixed_Params< 16, 16 >::assert_key_material_set(), Botan::Block_Cipher_Fixed_Params< 16, 16 >::BLOCK_SIZE, Botan::CPUID::has(), Botan::load_be(), Botan::rotl(), Botan::rotr(), Botan::CPUFeature::SIMD_4X32, and Botan::store_be().

◆ decrypt_n_xex() [1/2]

void Botan::BlockCipher::decrypt_n_xex ( uint8_t data[],
const uint8_t mask[],
size_t blocks ) const
inlineinherited

Decrypt blocks in XEX mode: XOR with the mask, decrypt, then XOR again

Parameters
datathe input/output buffer of blocks*block_size() bytes
maskthe mask to XOR with, same size as data
blocksthe number of blocks to process

Definition at line 189 of file block_cipher.h.

189 {
190 const size_t BS = block_size();
191 for(size_t i = 0; i != blocks * BS; ++i) {
192 data[i] ^= mask[i];
193 }
195 for(size_t i = 0; i != blocks * BS; ++i) {
196 data[i] ^= mask[i];
197 }
198 }

◆ decrypt_n_xex() [2/2]

void Botan::BlockCipher::decrypt_n_xex ( uint8_t data[],
const uint8_t mask[],
size_t blocks ) const
inlineinherited

Decrypt blocks in XEX mode: XOR with the mask, decrypt, then XOR again

Parameters
datathe input/output buffer of blocks*block_size() bytes
maskthe mask to XOR with, same size as data
blocksthe number of blocks to process

Definition at line 189 of file block_cipher.h.

189 {
190 const size_t BS = block_size();
191 for(size_t i = 0; i != blocks * BS; ++i) {
192 data[i] ^= mask[i];
193 }
194 decrypt_n(data, data, blocks);
195 for(size_t i = 0; i != blocks * BS; ++i) {
196 data[i] ^= mask[i];
197 }
198 }

References block_size(), decrypt_n(), and decrypt_n_xex().

Referenced by decrypt_n_xex().

◆ encrypt() [1/8]

void Botan::BlockCipher::encrypt ( const uint8_t in[],
uint8_t out[] ) const
inlineinherited

Encrypt a block.

Parameters
inThe plaintext block to be encrypted as a byte array. Must be of length block_size().
outThe byte array designated to hold the encrypted block. Must be of length block_size().

Definition at line 87 of file block_cipher.h.

87{ encrypt_n(in, out, 1); }
virtual void encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const=0

◆ encrypt() [2/8]

void Botan::BlockCipher::encrypt ( std::span< const uint8_t > in,
std::span< uint8_t > out ) const
inlineinherited

Encrypt one or more blocks

Parameters
inthe input buffer (multiple of block_size())
outthe output buffer (same size as in)

Definition at line 135 of file block_cipher.h.

135 {
136 return encrypt_n(in.data(), out.data(), in.size() / block_size());
137 }

◆ encrypt() [3/8]

void Botan::BlockCipher::encrypt ( std::span< uint8_t > block) const
inlineinherited

Encrypt one or more blocks

Parameters
Block Ciphersthe input/output buffer (multiple of block_size())

Definition at line 118 of file block_cipher.h.

118 {
119 return encrypt_n(block.data(), block.data(), block.size() / block_size());
120 }

◆ encrypt() [4/8]

void Botan::BlockCipher::encrypt ( uint8_t block[]) const
inlineinherited

Encrypt a block.

Parameters
Block Ciphersthe plaintext block to be encrypted Must be of length block_size(). Will hold the result when the function has finished.

Definition at line 104 of file block_cipher.h.

104{ encrypt_n(block, block, 1); }

◆ encrypt() [5/8]

void Botan::BlockCipher::encrypt ( const uint8_t in[],
uint8_t out[] ) const
inlineinherited

Encrypt a block.

Parameters
inThe plaintext block to be encrypted as a byte array. Must be of length block_size().
outThe byte array designated to hold the encrypted block. Must be of length block_size().

Definition at line 87 of file block_cipher.h.

87{ encrypt_n(in, out, 1); }

References encrypt_n().

Referenced by Botan::nist_key_wrap(), Botan::nist_key_wrap_padded(), and Botan::CFB_Mode::shift_register().

◆ encrypt() [6/8]

void Botan::BlockCipher::encrypt ( std::span< const uint8_t > in,
std::span< uint8_t > out ) const
inlineinherited

Encrypt one or more blocks

Parameters
inthe input buffer (multiple of block_size())
outthe output buffer (same size as in)

Definition at line 135 of file block_cipher.h.

135 {
136 return encrypt_n(in.data(), out.data(), in.size() / block_size());
137 }

References block_size(), and encrypt_n().

◆ encrypt() [7/8]

void Botan::BlockCipher::encrypt ( std::span< uint8_t > block) const
inlineinherited

Encrypt one or more blocks

Parameters
Block Ciphersthe input/output buffer (multiple of block_size())

Definition at line 118 of file block_cipher.h.

118 {
119 return encrypt_n(block.data(), block.data(), block.size() / block_size());
120 }

References block_size(), and encrypt_n().

◆ encrypt() [8/8]

void Botan::BlockCipher::encrypt ( uint8_t block[]) const
inlineinherited

Encrypt a block.

Parameters
Block Ciphersthe plaintext block to be encrypted Must be of length block_size(). Will hold the result when the function has finished.

Definition at line 104 of file block_cipher.h.

104{ encrypt_n(block, block, 1); }

References encrypt_n().

◆ encrypt_n()

void Botan::Noekeon::encrypt_n ( const uint8_t in[],
uint8_t out[],
size_t blocks ) const
overridevirtual

Encrypt one or more blocks

Parameters
inthe input buffer (multiple of block_size())
outthe output buffer (same size as in)
blocksthe number of blocks to process

Implements Botan::BlockCipher.

Definition at line 104 of file noekeon.cpp.

104 {
106
107#if defined(BOTAN_HAS_NOEKEON_SIMD)
109 while(blocks >= 4) {
110 simd_encrypt_4(in, out);
111 in += 4 * BLOCK_SIZE;
112 out += 4 * BLOCK_SIZE;
113 blocks -= 4;
114 }
115 }
116#endif
117
118 for(size_t i = 0; i != blocks; ++i) {
119 uint32_t A0 = load_be<uint32_t>(in, 0);
120 uint32_t A1 = load_be<uint32_t>(in, 1);
121 uint32_t A2 = load_be<uint32_t>(in, 2);
122 uint32_t A3 = load_be<uint32_t>(in, 3);
123
124 for(size_t j = 0; j != 16; ++j) {
125 A0 ^= RC[j];
126 theta(A0, A1, A2, A3, m_EK.data());
127
128 A1 = rotl<1>(A1);
129 A2 = rotl<5>(A2);
130 A3 = rotl<2>(A3);
131
132 gamma(A0, A1, A2, A3);
133
134 A1 = rotr<1>(A1);
135 A2 = rotr<5>(A2);
136 A3 = rotr<2>(A3);
137 }
138
139 A0 ^= RC[16];
140 theta(A0, A1, A2, A3, m_EK.data());
141
142 store_be(out, A0, A1, A2, A3);
143
144 in += BLOCK_SIZE;
145 out += BLOCK_SIZE;
146 }
147}

References Botan::Block_Cipher_Fixed_Params< 16, 16 >::assert_key_material_set(), Botan::Block_Cipher_Fixed_Params< 16, 16 >::BLOCK_SIZE, Botan::CPUID::has(), Botan::load_be(), Botan::rotl(), Botan::rotr(), Botan::CPUFeature::SIMD_4X32, and Botan::store_be().

◆ encrypt_n_xex() [1/2]

void Botan::BlockCipher::encrypt_n_xex ( uint8_t data[],
const uint8_t mask[],
size_t blocks ) const
inlineinherited

Encrypt blocks in XEX mode: XOR with the mask, encrypt, then XOR again

Parameters
datathe input/output buffer of blocks*block_size() bytes
maskthe mask to XOR with, same size as data
blocksthe number of blocks to process

Definition at line 171 of file block_cipher.h.

171 {
172 const size_t BS = block_size();
173 for(size_t i = 0; i != blocks * BS; ++i) {
174 data[i] ^= mask[i];
175 }
177 for(size_t i = 0; i != blocks * BS; ++i) {
178 data[i] ^= mask[i];
179 }
180 }

◆ encrypt_n_xex() [2/2]

void Botan::BlockCipher::encrypt_n_xex ( uint8_t data[],
const uint8_t mask[],
size_t blocks ) const
inlineinherited

Encrypt blocks in XEX mode: XOR with the mask, encrypt, then XOR again

Parameters
datathe input/output buffer of blocks*block_size() bytes
maskthe mask to XOR with, same size as data
blocksthe number of blocks to process

Definition at line 171 of file block_cipher.h.

171 {
172 const size_t BS = block_size();
173 for(size_t i = 0; i != blocks * BS; ++i) {
174 data[i] ^= mask[i];
175 }
176 encrypt_n(data, data, blocks);
177 for(size_t i = 0; i != blocks * BS; ++i) {
178 data[i] ^= mask[i];
179 }
180 }

References block_size(), encrypt_n(), and encrypt_n_xex().

Referenced by encrypt_n_xex().

◆ has_keying_material()

bool Botan::Noekeon::has_keying_material ( ) const
overridevirtual

Test whether a key has been set on this object

Returns
true if a key has been set on this object

Implements Botan::SymmetricAlgorithm.

Definition at line 197 of file noekeon.cpp.

197 {
198 return !m_EK.empty();
199}

◆ key_spec()

Key_Length_Specification Botan::Block_Cipher_Fixed_Params< BS, KMIN, 0, 1, BlockCipher >::key_spec ( ) const
inlinefinalvirtualinherited

Return the key lengths supported by this cipher

Returns
the fixed key length specification

Implements Botan::SymmetricAlgorithm.

Definition at line 246 of file block_cipher.h.

◆ maximum_keylength() [1/2]

size_t Botan::SymmetricAlgorithm::maximum_keylength ( ) const
inlineinherited

Return the largest acceptable key length

Returns
maximum allowed key length

Definition at line 130 of file sym_algo.h.

130{ return key_spec().maximum_keylength(); }
Key_Length_Specification key_spec() const final
size_t maximum_keylength() const
Definition sym_algo.h:58

◆ maximum_keylength() [2/2]

size_t Botan::SymmetricAlgorithm::maximum_keylength ( ) const
inlineinherited

Return the largest acceptable key length

Returns
maximum allowed key length

Definition at line 130 of file sym_algo.h.

130{ return key_spec().maximum_keylength(); }
virtual Key_Length_Specification key_spec() const =0

References key_spec().

◆ minimum_keylength() [1/2]

size_t Botan::SymmetricAlgorithm::minimum_keylength ( ) const
inlineinherited

Return the smallest acceptable key length

Returns
minimum allowed key length

Definition at line 136 of file sym_algo.h.

136{ return key_spec().minimum_keylength(); }
size_t minimum_keylength() const
Definition sym_algo.h:52

◆ minimum_keylength() [2/2]

size_t Botan::SymmetricAlgorithm::minimum_keylength ( ) const
inlineinherited

Return the smallest acceptable key length

Returns
minimum allowed key length

Definition at line 136 of file sym_algo.h.

136{ return key_spec().minimum_keylength(); }

References key_spec().

◆ name()

std::string Botan::Noekeon::name ( ) const
inlineoverridevirtual

Return the name of this algorithm

Returns
the algorithm name

Implements Botan::SymmetricAlgorithm.

Definition at line 27 of file noekeon.h.

27{ return "Noekeon"; }

◆ new_object()

std::unique_ptr< BlockCipher > Botan::Noekeon::new_object ( ) const
inlineoverridevirtual

Create a new uninitialized object of the same type

Returns
new object representing the same algorithm as *this

Implements Botan::BlockCipher.

Definition at line 29 of file noekeon.h.

29{ return std::make_unique<Noekeon>(); }

◆ parallel_bytes() [1/2]

size_t Botan::BlockCipher::parallel_bytes ( ) const
inlineinherited

Return the preferred input size for bulk processing

Returns
preferred parallelism of this cipher in bytes

Definition at line 71 of file block_cipher.h.

◆ parallel_bytes() [2/2]

size_t Botan::BlockCipher::parallel_bytes ( ) const
inlineinherited

Return the preferred input size for bulk processing

Returns
preferred parallelism of this cipher in bytes

Definition at line 71 of file block_cipher.h.

static constexpr size_t ParallelismMult

References block_size(), parallelism(), and ParallelismMult.

Referenced by Botan::CBC_Mode::ideal_granularity().

◆ parallelism()

size_t Botan::Noekeon::parallelism ( ) const
overridevirtual

Return how many blocks this cipher processes in parallel

Returns
native parallelism of this cipher in blocks

Reimplemented from Botan::BlockCipher.

Definition at line 75 of file noekeon.cpp.

75 {
76#if defined(BOTAN_HAS_NOEKEON_SIMD)
78 return 4;
79 }
80#endif
81
82 return 1;
83}

References Botan::CPUID::has(), and Botan::CPUFeature::SIMD_4X32.

◆ provider()

std::string Botan::Noekeon::provider ( ) const
overridevirtual

Return the name of the provider implementing this object

Returns
provider information about this implementation. Default is "base", might also return "sse2", "avx2", "openssl", or some other arbitrary string.

Reimplemented from Botan::BlockCipher.

Definition at line 85 of file noekeon.cpp.

85 {
86#if defined(BOTAN_HAS_NOEKEON_SIMD)
88 return *feat;
89 }
90#endif
91
92 return "base";
93}
static std::optional< std::string > check(CPUID::Feature feat)
Definition cpuid.h:66

References Botan::CPUID::check(), and Botan::CPUFeature::SIMD_4X32.

◆ providers() [1/2]

std::vector< std::string > Botan::BlockCipher::providers ( std::string_view algo_spec)
staticinherited

List the providers available for a given block cipher

Returns
list of available providers for this algorithm, empty if not available
Parameters
algo_specalgorithm name

Definition at line 45 of file block_cipher.cpp.

278 {
279 return probe_providers_of<BlockCipher>(algo, {"base", "commoncrypto"});
280}
std::vector< std::string > probe_providers_of(std::string_view algo_spec, const std::vector< std::string > &possible={"base"})

◆ providers() [2/2]

std::vector< std::string > Botan::BlockCipher::providers ( std::string_view algo_spec)
staticinherited

List the providers available for a given block cipher

Returns
list of available providers for this algorithm, empty if not available
Parameters
algo_specalgorithm name

Definition at line 278 of file block_cipher.cpp.

278 {
279 return probe_providers_of<BlockCipher>(algo, {"base", "commoncrypto"});
280}

References Botan::probe_providers_of().

◆ set_key() [1/6]

void Botan::SymmetricAlgorithm::set_key ( const OctetString & key)
inherited

Set the symmetric key of this object.

Parameters
keythe SymmetricKey to be set.

Definition at line 149 of file sym_algo.cpp.

14 {
15 set_key(std::span{key.begin(), key.length()});
16}
void set_key(const OctetString &key)
Definition sym_algo.cpp:14

◆ set_key() [2/6]

void Botan::SymmetricAlgorithm::set_key ( const uint8_t key[],
size_t length )
inlineinherited

Set the symmetric key of this object.

Parameters
keythe to be set as a byte array.
lengthin bytes of key param

Definition at line 162 of file sym_algo.h.

◆ set_key() [3/6]

void Botan::SymmetricAlgorithm::set_key ( std::span< const uint8_t > key)
inherited

Set the symmetric key of this object.

Parameters
keythe contiguous byte range to be set.

Definition at line 155 of file sym_algo.cpp.

22 {
23 if(!valid_keylength(key.size())) {
24 throw Invalid_Key_Length(name(), key.size());
25 }
27}
bool valid_keylength(size_t length) const
Definition sym_algo.h:143
virtual std::string name() const=0

◆ set_key() [4/6]

◆ set_key() [5/6]

void Botan::SymmetricAlgorithm::set_key ( const uint8_t key[],
size_t length )
inlineinherited

Set the symmetric key of this object.

Parameters
keythe to be set as a byte array.
lengthin bytes of key param

Definition at line 162 of file sym_algo.h.

162{ set_key(std::span{key, length}); }

References set_key().

Referenced by set_key().

◆ set_key() [6/6]

void Botan::SymmetricAlgorithm::set_key ( std::span< const uint8_t > key)
inherited

Set the symmetric key of this object.

Parameters
keythe contiguous byte range to be set.

Definition at line 22 of file sym_algo.cpp.

22 {
23 if(!valid_keylength(key.size())) {
24 throw Invalid_Key_Length(name(), key.size());
25 }
26 key_schedule(key);
27}

References name(), and valid_keylength().

◆ valid_keylength() [1/2]

bool Botan::SymmetricAlgorithm::valid_keylength ( size_t length) const
inlineinherited

Check whether a given key length is valid for this algorithm.

Parameters
lengththe key length to be checked.
Returns
true if the key length is valid.

Definition at line 143 of file sym_algo.h.

143{ return key_spec().valid_keylength(length); }
bool valid_keylength(size_t length) const
Definition sym_algo.h:44

◆ valid_keylength() [2/2]

bool Botan::SymmetricAlgorithm::valid_keylength ( size_t length) const
inlineinherited

Check whether a given key length is valid for this algorithm.

Parameters
lengththe key length to be checked.
Returns
true if the key length is valid.

Definition at line 143 of file sym_algo.h.

143{ return key_spec().valid_keylength(length); }

References key_spec().

Referenced by set_key().

Member Data Documentation

◆ ParallelismMult [1/2]

size_t Botan::BlockCipher::ParallelismMult
staticconstexprinherited

Multiplier on a block cipher's native parallelism

Usually notable performance gains come from further loop blocking, at least for 2 or 4x

Definition at line 53 of file block_cipher.h.

◆ ParallelismMult [2/2]

size_t Botan::BlockCipher::ParallelismMult = 4
staticconstexprinherited

Multiplier on a block cipher's native parallelism

Usually notable performance gains come from further loop blocking, at least for 2 or 4x

Definition at line 53 of file block_cipher.h.

Referenced by Botan::GCM_Mode::ideal_granularity(), Botan::GCM_SIV_Mode::ideal_granularity(), and parallel_bytes().


The documentation for this class was generated from the following files: