Botan 3.9.0
Crypto and TLS for C&
serpent.h
Go to the documentation of this file.
1/*
2* Serpent
3* (C) 1999-2007 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#ifndef BOTAN_SERPENT_H_
9#define BOTAN_SERPENT_H_
10
11#include <botan/block_cipher.h>
12#include <botan/secmem.h>
13
14namespace Botan {
15
16/**
17* Serpent is the most conservative of the AES finalists
18* https://www.cl.cam.ac.uk/~rja14/serpent.html
19*/
20class Serpent final : public Block_Cipher_Fixed_Params<16, 16, 32, 8> {
21 public:
22 void encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override;
23 void decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override;
24
25 void clear() override;
26 std::string provider() const override;
27
28 std::string name() const override { return "Serpent"; }
29
30 std::unique_ptr<BlockCipher> new_object() const override { return std::make_unique<Serpent>(); }
31
32 size_t parallelism() const override { return 4; }
33
34 bool has_keying_material() const override;
35
36 private:
37#if defined(BOTAN_HAS_SERPENT_SIMD)
38 void simd_encrypt_4(const uint8_t in[16 * 4], uint8_t out[16 * 4]) const;
39 void simd_decrypt_4(const uint8_t in[16 * 4], uint8_t out[16 * 4]) const;
40#endif
41
42#if defined(BOTAN_HAS_SERPENT_AVX2)
43 void avx2_encrypt_8(const uint8_t in[16 * 8], uint8_t out[16 * 8]) const;
44 void avx2_decrypt_8(const uint8_t in[16 * 8], uint8_t out[16 * 8]) const;
45#endif
46
47#if defined(BOTAN_HAS_SERPENT_AVX512)
48 void avx512_encrypt_16(const uint8_t in[16 * 16], uint8_t out[16 * 16]) const;
49 void avx512_decrypt_16(const uint8_t in[16 * 16], uint8_t out[16 * 16]) const;
50#endif
51
52 void key_schedule(std::span<const uint8_t> key) override;
53
54 secure_vector<uint32_t> m_round_key;
55};
56
57} // namespace Botan
58
59#endif
bool has_keying_material() const override
Definition serpent.cpp:322
std::string provider() const override
Definition serpent.cpp:394
std::string name() const override
Definition serpent.h:28
void clear() override
Definition serpent.cpp:390
size_t parallelism() const override
Definition serpent.h:32
std::unique_ptr< BlockCipher > new_object() const override
Definition serpent.h:30
void encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override
Definition serpent.cpp:23
void decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override
Definition serpent.cpp:174
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:69