Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
fc::sha3_impl Struct Reference

Public Member Functions

 sha3_impl ()
 
void update_step ()
 
void init ()
 
void update (const uint8_t *data, std::size_t len)
 
void finalize (char *buffer)
 

Public Attributes

union { 
 
   uint8_t   bytes [number_of_words *8] 
 
   uint64_t   words [number_of_words *5] 
 
};  
 
bool keccak = false
 
int point
 
int size
 

Static Public Attributes

static constexpr uint8_t number_of_rounds = 24
 
static constexpr uint8_t number_of_words = 25
 
static constexpr uint8_t digest_size = 32
 
static constexpr uint64_t round_constants [number_of_rounds]
 
static constexpr uint8_t rot_constants [number_of_rounds] = {1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44}
 
static constexpr uint8_t pi_lanes [number_of_rounds] = {10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1}
 

Detailed Description

Definition at line 41 of file sha3.cpp.

Constructor & Destructor Documentation

◆ sha3_impl()

fc::sha3_impl::sha3_impl ( )
inline

Definition at line 42 of file sha3.cpp.

42{ init(); }
void init()
Definition sha3.cpp:141
Here is the call graph for this function:

Member Function Documentation

◆ finalize()

void fc::sha3_impl::finalize ( char * buffer)
inline

Definition at line 160 of file sha3.cpp.

160 {
161 bytes[point] ^= keccak ? 0x01 : 0x06;
162 bytes[size-1] ^= 0x80;
163 update_step();
164 memcpy(buffer, (const char*)bytes, digest_size);
165 }
uint8_t bytes[number_of_words *8]
Definition sha3.cpp:168
bool keccak
Definition sha3.cpp:171
void update_step()
Definition sha3.cpp:57
static constexpr uint8_t digest_size
Definition sha3.cpp:46
memcpy((char *) pInfo->slotDescription, s, l)
Here is the call graph for this function:

◆ init()

void fc::sha3_impl::init ( )
inline

Definition at line 141 of file sha3.cpp.

141 {
142 memset((char *)this, 0, sizeof(*this));
143 size = 136;
144 }
memset(pInfo->slotDescription, ' ', 64)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ update()

void fc::sha3_impl::update ( const uint8_t * data,
std::size_t len )
inline

Definition at line 146 of file sha3.cpp.

146 {
147 int j = point;
148 for (std::size_t i = 0; i < len; i++)
149 {
150 bytes[j++] ^= data[i];
151 if (j >= size)
152 {
153 update_step();
154 j = 0;
155 }
156 }
157 point = j;
158 }
uint16_t j
size_t len
Here is the call graph for this function:

◆ update_step()

void fc::sha3_impl::update_step ( )
inline

Definition at line 57 of file sha3.cpp.

58 {
59 uint64_t bc[5];
60
61 if constexpr (!is_little_endian)
62 {
63 uint8_t *v;
64 // convert the buffer to little endian
65 for (std::size_t i; i < number_of_words; i++)
66 {
67 v = reinterpret_cast<uint8_t *>(words + i);
68 words[i] = ((uint64_t)v[0]) | (((uint64_t)v[1]) << 8) |
69 (((uint64_t)v[2]) << 16) | (((uint64_t)v[3]) << 24) |
70 (((uint64_t)v[4]) << 32) | (((uint64_t)v[5]) << 40) |
71 (((uint64_t)v[6]) << 48) | (((uint64_t)v[7]) << 56);
72 }
73 }
74
75 #pragma clang loop vectorize(enable) interleave(enable)
76 for (std::size_t i = 0; i < number_of_rounds; i++)
77 {
78 // theta
79 #pragma clang loop vectorize(enable) interleave(enable)
80 for (std::size_t j = 0; j < 5; j++)
81 bc[j] = words[j] ^ words[j + 5] ^ words[j + 10] ^ words[j + 15] ^ words[j + 20];
82
83 uint64_t t;
84 #pragma clang loop vectorize(enable) interleave(enable)
85 for (std::size_t j = 0; j < 5; j++)
86 {
87 t = bc[(j + 4) % 5] ^ rotl64(bc[(j + 1) % 5], 1);
88 #pragma clang loop vectorize(enable) interleave(enable)
89 for (std::size_t k = 0; k < number_of_words; k += 5)
90 words[k + j] ^= t;
91 }
92
93 // rho pi
94 t = words[1];
95 #pragma clang loop vectorize(enable) interleave(enable)
96 for (std::size_t j = 0; j < number_of_rounds; j++)
97 {
99 bc[0] = words[p];
100 words[p] = rotl64(t, rot_constants[j]);
101 t = bc[0];
102 }
103
104 // chi
105 #pragma clang loop vectorize(enable) interleave(enable)
106 for (std::size_t j = 0; j < number_of_words; j += 5)
107 {
108 #pragma clang loop vectorize(enable) interleave(enable)
109 for (std::size_t k = 0; k < 5; k++)
110 bc[k] = words[k + j];
111 #pragma clang loop vectorize(enable) interleave(enable)
112 for (std::size_t k = 0; k < 5; k++)
113 words[k + j] ^= (~bc[(k + 1) % 5]) & bc[(k + 2) % 5];
114 }
115
116 // iota
117 words[0] ^= round_constants[i];
118 }
119
120 if constexpr (!is_little_endian)
121 {
122 uint8_t *v;
123 uint64_t tmp;
124 // convert back to big endian
125 for (std::size_t i = 0; i < sizeof(words); i++)
126 {
127 v = (uint8_t *)(words + i);
128 tmp = words[i];
129 v[0] = tmp & 0xFF;
130 v[1] = (tmp >> 8) & 0xFF;
131 v[2] = (tmp >> 16) & 0xFF;
132 v[3] = (tmp >> 24) & 0xFF;
133 v[4] = (tmp >> 32) & 0xFF;
134 v[5] = (tmp >> 40) & 0xFF;
135 v[6] = (tmp >> 48) & 0xFF;
136 v[7] = (tmp >> 56) & 0xFF;
137 }
138 }
139 }
const mie::Vuint & p
Definition bn.cpp:27
bool is_little_endian()
Definition utils.cpp:89
unsigned char uint8_t
Definition stdint.h:124
unsigned __int64 uint64_t
Definition stdint.h:136
static constexpr uint8_t number_of_rounds
Definition sha3.cpp:44
static constexpr uint64_t round_constants[number_of_rounds]
Definition sha3.cpp:47
static constexpr uint8_t pi_lanes[number_of_rounds]
Definition sha3.cpp:55
uint64_t words[number_of_words *5]
Definition sha3.cpp:169
static constexpr uint8_t number_of_words
Definition sha3.cpp:45
static constexpr uint8_t rot_constants[number_of_rounds]
Definition sha3.cpp:54
Here is the caller graph for this function:

Member Data Documentation

◆ [union]

union { ... } fc::sha3_impl

◆ bytes

uint8_t fc::sha3_impl::bytes[number_of_words *8]

Definition at line 168 of file sha3.cpp.

◆ digest_size

uint8_t fc::sha3_impl::digest_size = 32
staticconstexpr

Definition at line 46 of file sha3.cpp.

◆ keccak

bool fc::sha3_impl::keccak = false

Definition at line 171 of file sha3.cpp.

◆ number_of_rounds

uint8_t fc::sha3_impl::number_of_rounds = 24
staticconstexpr

Definition at line 44 of file sha3.cpp.

◆ number_of_words

uint8_t fc::sha3_impl::number_of_words = 25
staticconstexpr

Definition at line 45 of file sha3.cpp.

◆ pi_lanes

uint8_t fc::sha3_impl::pi_lanes[number_of_rounds] = {10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1}
staticconstexpr

Definition at line 55 of file sha3.cpp.

55{10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1};

◆ point

int fc::sha3_impl::point

Definition at line 172 of file sha3.cpp.

◆ rot_constants

uint8_t fc::sha3_impl::rot_constants[number_of_rounds] = {1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44}
staticconstexpr

Definition at line 54 of file sha3.cpp.

54{1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44};

◆ round_constants

uint64_t fc::sha3_impl::round_constants[number_of_rounds]
staticconstexpr
Initial value:
= {
UINT64_C(0x0000000000000001), UINT64_C(0x0000000000008082), UINT64_C(0x800000000000808a), UINT64_C(0x8000000080008000),
UINT64_C(0x000000000000808b), UINT64_C(0x0000000080000001), UINT64_C(0x8000000080008081), UINT64_C(0x8000000000008009),
UINT64_C(0x000000000000008a), UINT64_C(0x0000000000000088), UINT64_C(0x0000000080008009), UINT64_C(0x000000008000000a),
UINT64_C(0x000000008000808b), UINT64_C(0x800000000000008b), UINT64_C(0x8000000000008089), UINT64_C(0x8000000000008003),
UINT64_C(0x8000000000008002), UINT64_C(0x8000000000000080), UINT64_C(0x000000000000800a), UINT64_C(0x800000008000000a),
UINT64_C(0x8000000080008081), UINT64_C(0x8000000000008080), UINT64_C(0x0000000080000001), UINT64_C(0x8000000080008008)}
#define UINT64_C(val)
Definition stdint.h:284

Definition at line 47 of file sha3.cpp.

47 {
48 UINT64_C(0x0000000000000001), UINT64_C(0x0000000000008082), UINT64_C(0x800000000000808a), UINT64_C(0x8000000080008000),
49 UINT64_C(0x000000000000808b), UINT64_C(0x0000000080000001), UINT64_C(0x8000000080008081), UINT64_C(0x8000000000008009),
50 UINT64_C(0x000000000000008a), UINT64_C(0x0000000000000088), UINT64_C(0x0000000080008009), UINT64_C(0x000000008000000a),
51 UINT64_C(0x000000008000808b), UINT64_C(0x800000000000008b), UINT64_C(0x8000000000008089), UINT64_C(0x8000000000008003),
52 UINT64_C(0x8000000000008002), UINT64_C(0x8000000000000080), UINT64_C(0x000000000000800a), UINT64_C(0x800000008000000a),
53 UINT64_C(0x8000000080008081), UINT64_C(0x8000000000008080), UINT64_C(0x0000000080000001), UINT64_C(0x8000000080008008)};

◆ size

int fc::sha3_impl::size

Definition at line 173 of file sha3.cpp.

◆ words

uint64_t fc::sha3_impl::words[number_of_words *5]

Definition at line 169 of file sha3.cpp.


The documentation for this struct was generated from the following file: