Botan 3.7.1
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/compiler.h>
11#include <botan/types.h>
12#include <botan/internal/rotate.h>
13
15
16template <size_t S>
17BOTAN_FORCE_INLINE uint32_t shl(uint32_t v) {
18 return v << S;
19}
20
21/*
22* Serpent's Linear Transform
23*/
24template <typename T>
25BOTAN_FORCE_INLINE void transform(T& B0, T& B1, T& B2, T& B3) {
26 B0 = rotl<13>(B0);
27 B2 = rotl<3>(B2);
28 B1 ^= B0 ^ B2;
29 B3 ^= B2 ^ shl<3>(B0);
30 B1 = rotl<1>(B1);
31 B3 = rotl<7>(B3);
32 B0 ^= B1 ^ B3;
33 B2 ^= B3 ^ shl<7>(B1);
34 B0 = rotl<5>(B0);
35 B2 = rotl<22>(B2);
36}
37
38/*
39* Serpent's Inverse Linear Transform
40*/
41template <typename T>
42BOTAN_FORCE_INLINE void i_transform(T& B0, T& B1, T& B2, T& B3) {
43 B2 = rotr<22>(B2);
44 B0 = rotr<5>(B0);
45 B2 ^= B3 ^ shl<7>(B1);
46 B0 ^= B1 ^ B3;
47 B3 = rotr<7>(B3);
48 B1 = rotr<1>(B1);
49 B3 ^= B2 ^ shl<3>(B0);
50 B1 ^= B0 ^ B2;
51 B2 = rotr<3>(B2);
52 B0 = rotr<13>(B0);
53}
54
56 public:
57 Key_Inserter(const uint32_t* RK) : m_RK(RK) {}
58
59 template <typename T>
60 inline void operator()(size_t R, T& B0, T& B1, T& B2, T& B3) const {
61 B0 ^= m_RK[4 * R];
62 B1 ^= m_RK[4 * R + 1];
63 B2 ^= m_RK[4 * R + 2];
64 B3 ^= m_RK[4 * R + 3];
65 }
66
67 private:
68 const uint32_t* m_RK;
69};
70
71} // namespace Botan::Serpent_F
72
73#endif
Key_Inserter(const uint32_t *RK)
Definition serpent_fn.h:57
void operator()(size_t R, T &B0, T &B1, T &B2, T &B3) const
Definition serpent_fn.h:60
int(* final)(unsigned char *, CTX *)
#define BOTAN_FORCE_INLINE
Definition compiler.h:71
FE_25519 T
Definition ge.cpp:34
BOTAN_FORCE_INLINE void transform(T &B0, T &B1, T &B2, T &B3)
Definition serpent_fn.h:25
BOTAN_FORCE_INLINE uint32_t shl(uint32_t v)
Definition serpent_fn.h:17
BOTAN_FORCE_INLINE void i_transform(T &B0, T &B1, T &B2, T &B3)
Definition serpent_fn.h:42
constexpr T rotl(T input)
Definition rotate.h:21
constexpr T rotr(T input)
Definition rotate.h:33