Botan 3.5.0
Crypto and TLS for C&
serpent_fn.h
Go to the documentation of this file.
1/*
2* (C) 1999-2007,2013 Jack Lloyd
3*
4* Botan is released under the Simplified BSD License (see license.txt)
5*/
6
7#ifndef BOTAN_SERPENT_FUNCS_H_
8#define BOTAN_SERPENT_FUNCS_H_
9
10#include <botan/types.h>
11#include <botan/internal/rotate.h>
12
14
15template <size_t S>
16BOTAN_FORCE_INLINE uint32_t shl(uint32_t v) {
17 return v << S;
18}
19
20/*
21* Serpent's Linear Transform
22*/
23template <typename T>
24BOTAN_FORCE_INLINE void transform(T& B0, T& B1, T& B2, T& B3) {
25 B0 = rotl<13>(B0);
26 B2 = rotl<3>(B2);
27 B1 ^= B0 ^ B2;
28 B3 ^= B2 ^ shl<3>(B0);
29 B1 = rotl<1>(B1);
30 B3 = rotl<7>(B3);
31 B0 ^= B1 ^ B3;
32 B2 ^= B3 ^ shl<7>(B1);
33 B0 = rotl<5>(B0);
34 B2 = rotl<22>(B2);
35}
36
37/*
38* Serpent's Inverse Linear Transform
39*/
40template <typename T>
41BOTAN_FORCE_INLINE void i_transform(T& B0, T& B1, T& B2, T& B3) {
42 B2 = rotr<22>(B2);
43 B0 = rotr<5>(B0);
44 B2 ^= B3 ^ shl<7>(B1);
45 B0 ^= B1 ^ B3;
46 B3 = rotr<7>(B3);
47 B1 = rotr<1>(B1);
48 B3 ^= B2 ^ shl<3>(B0);
49 B1 ^= B0 ^ B2;
50 B2 = rotr<3>(B2);
51 B0 = rotr<13>(B0);
52}
53
55 public:
56 Key_Inserter(const uint32_t* RK) : m_RK(RK) {}
57
58 template <typename T>
59 inline void operator()(size_t R, T& B0, T& B1, T& B2, T& B3) const {
60 B0 ^= m_RK[4 * R];
61 B1 ^= m_RK[4 * R + 1];
62 B2 ^= m_RK[4 * R + 2];
63 B3 ^= m_RK[4 * R + 3];
64 }
65
66 private:
67 const uint32_t* m_RK;
68};
69
70} // namespace Botan::Serpent_F
71
72#endif
Key_Inserter(const uint32_t *RK)
Definition serpent_fn.h:56
void operator()(size_t R, T &B0, T &B1, T &B2, T &B3) const
Definition serpent_fn.h:59
int(* final)(unsigned char *, CTX *)
#define BOTAN_FORCE_INLINE
Definition compiler.h:165
FE_25519 T
Definition ge.cpp:34
BOTAN_FORCE_INLINE void transform(T &B0, T &B1, T &B2, T &B3)
Definition serpent_fn.h:24
BOTAN_FORCE_INLINE uint32_t shl(uint32_t v)
Definition serpent_fn.h:16
BOTAN_FORCE_INLINE void i_transform(T &B0, T &B1, T &B2, T &B3)
Definition serpent_fn.h:41
constexpr T rotl(T input)
Definition rotate.h:21
constexpr T rotr(T input)
Definition rotate.h:33