Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
keccak256.hpp File Reference
#include <cstdint>
Include dependency graph for keccak256.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  SHA3_CTX
 

Macros

#define __KECCAK256_HPP_
 
#define sha3_max_permutation_size   25
 
#define sha3_max_rate_in_qwords   24
 

Typedefs

typedef struct SHA3_CTX SHA3_CTX
 

Functions

void keccak_init (SHA3_CTX *ctx)
 
void keccak_update (SHA3_CTX *ctx, const unsigned char *msg, uint16_t size)
 
void keccak_final (SHA3_CTX *ctx, unsigned char *result)
 

Macro Definition Documentation

◆ __KECCAK256_HPP_

#define __KECCAK256_HPP_

Definition at line 25 of file keccak256.hpp.

◆ sha3_max_permutation_size

#define sha3_max_permutation_size   25

Definition at line 27 of file keccak256.hpp.

◆ sha3_max_rate_in_qwords

#define sha3_max_rate_in_qwords   24

Definition at line 28 of file keccak256.hpp.

Typedef Documentation

◆ SHA3_CTX

typedef struct SHA3_CTX SHA3_CTX

Function Documentation

◆ keccak_final()

void keccak_final ( SHA3_CTX * ctx,
unsigned char * result )

Store calculated hash into the given array.

Parameters
ctxthe algorithm context containing current hashing state
resultcalculated hash in binary form

Definition at line 220 of file keccak256.cpp.

221{
223
224// if (!(ctx->rest & SHA3_FINALIZED)) {
225 /* clear the rest of the data queue */
226 memset((char*)ctx->message + ctx->rest, 0, BLOCK_SIZE - ctx->rest);
227 ((char*)ctx->message)[ctx->rest] |= 0x01;
228 ((char*)ctx->message)[BLOCK_SIZE - 1] |= 0x80;
229
230 /* process final block */
231 sha3_process_block(ctx->hash, ctx->message);
232// ctx->rest = SHA3_FINALIZED; /* mark context as finalized */
233// }
234
235 if (result) {
236 me64_to_le_str(result, ctx->hash, digest_length);
237 }
238}
#define me64_to_le_str(to, from, length)
Definition keccak256.cpp:29
#define BLOCK_SIZE
Definition keccak256.cpp:23
unsigned short uint16_t
Definition stdint.h:125
uint16_t rest
Definition keccak256.hpp:37
uint64_t message[sha3_max_rate_in_qwords]
Definition keccak256.hpp:35
uint64_t hash[sha3_max_permutation_size]
Definition keccak256.hpp:33
CK_ULONG digest_length
memset(pInfo->slotDescription, ' ', 64)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ keccak_init()

void keccak_init ( SHA3_CTX * ctx)

Definition at line 75 of file keccak256.cpp.

75 {
76 /* NB: The Keccak capacity parameter = bits * 2 */
77
78 std::memset(ctx, 0, sizeof(SHA3_CTX));
79}
Here is the caller graph for this function:

◆ keccak_update()

void keccak_update ( SHA3_CTX * ctx,
const unsigned char * msg,
uint16_t size )

Calculate message hash. Can be called repeatedly with chunks of the message to be hashed.

Parameters
ctxthe algorithm context containing current hashing state
msgmessage chunk
sizelength of the message chunk

Definition at line 175 of file keccak256.cpp.

176{
177 uint16_t idx = (uint16_t)ctx->rest;
178
179 //if (ctx->rest & SHA3_FINALIZED) return; /* too late for additional input */
180 ctx->rest = (unsigned)((ctx->rest + size) % BLOCK_SIZE);
181
182 /* fill partial block */
183 if (idx) {
184 uint16_t left = BLOCK_SIZE - idx;
185 memcpy((char*)ctx->message + idx, msg, (size < left ? size : left));
186 if (size < left) return;
187
188 /* process partial block */
189 sha3_process_block(ctx->hash, ctx->message);
190 msg += left;
191 size -= left;
192 }
193
194 while (size >= BLOCK_SIZE) {
195 uint64_t* aligned_message_block;
196 if (IS_ALIGNED_64(msg)) {
197 // the most common case is processing of an already aligned message without copying it
198 aligned_message_block = (uint64_t*)(void*)msg;
199 } else {
200 memcpy(ctx->message, msg, BLOCK_SIZE);
201 aligned_message_block = ctx->message;
202 }
203
204 sha3_process_block(ctx->hash, aligned_message_block);
205 msg += BLOCK_SIZE;
206 size -= BLOCK_SIZE;
207 }
208
209 if (size) {
210 memcpy(ctx->message, msg, size); /* save leftovers */
211 }
212}
#define IS_ALIGNED_64(p)
Definition keccak256.cpp:28
unsigned __int64 uint64_t
Definition stdint.h:136
memcpy((char *) pInfo->slotDescription, s, l)
Here is the call graph for this function:
Here is the caller graph for this function: