Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
keccak256.cpp File Reference
#include <fc/crypto/keccak256.hpp>
#include <cstring>
Include dependency graph for keccak256.cpp:

Go to the source code of this file.

Macros

#define BLOCK_SIZE   ((1600 - 256 * 2) / 8)
 
#define I64(x)
 
#define ROTL64(qword, n)
 
#define le2me_64(x)
 
#define IS_ALIGNED_64(p)
 
#define me64_to_le_str(to, from, length)
 
#define TYPE_ROUND_INFO   0
 
#define TYPE_PI_TRANSFORM   24
 
#define TYPE_RHO_TRANSFORM   48
 

Functions

uint8_t getConstant (uint8_t type, uint8_t index)
 
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)
 

Variables

const uint8_t constants []
 

Macro Definition Documentation

◆ BLOCK_SIZE

#define BLOCK_SIZE   ((1600 - 256 * 2) / 8)

Definition at line 23 of file keccak256.cpp.

◆ I64

#define I64 ( x)
Value:
x##LL

Definition at line 25 of file keccak256.cpp.

◆ IS_ALIGNED_64

#define IS_ALIGNED_64 ( p)
Value:
(0 == (7 & ((const char*)(p) - (const char*)0)))
const mie::Vuint & p
Definition bn.cpp:27

Definition at line 28 of file keccak256.cpp.

◆ le2me_64

#define le2me_64 ( x)
Value:
(x)

Definition at line 27 of file keccak256.cpp.

◆ me64_to_le_str

#define me64_to_le_str ( to,
from,
length )
Value:
memcpy((to), (from), (length))
memcpy((char *) pInfo->slotDescription, s, l)

Definition at line 29 of file keccak256.cpp.

◆ ROTL64

#define ROTL64 ( qword,
n )
Value:
((qword) << (n) ^ ((qword) >> (64 - (n))))

Definition at line 26 of file keccak256.cpp.

◆ TYPE_PI_TRANSFORM

#define TYPE_PI_TRANSFORM   24

Definition at line 49 of file keccak256.cpp.

◆ TYPE_RHO_TRANSFORM

#define TYPE_RHO_TRANSFORM   48

Definition at line 50 of file keccak256.cpp.

◆ TYPE_ROUND_INFO

#define TYPE_ROUND_INFO   0

Definition at line 48 of file keccak256.cpp.

Function Documentation

◆ getConstant()

uint8_t getConstant ( uint8_t type,
uint8_t index )
inline

Definition at line 52 of file keccak256.cpp.

52 {
53 return constants[type + index];
54 //return pgm_read_byte(&constants[type + index]);
55}
const uint8_t constants[]
Definition keccak256.cpp:35

◆ 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
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ constants

const uint8_t constants[]
Initial value:
= {
1, 26, 94, 112, 31, 33, 121, 85, 14, 12, 53, 38, 63, 79, 93, 83, 82, 72, 22, 102, 121, 88, 33, 116,
1, 6, 9, 22, 14, 20, 2, 12, 13, 19, 23, 15, 4, 24, 21, 8, 16, 5, 3, 18, 17, 11, 7, 10,
1, 62, 28, 27, 36, 44, 6, 55, 20, 3, 10, 43, 25, 39, 41, 45, 15, 21, 8, 18, 2, 61, 56, 14,
}

Definition at line 35 of file keccak256.cpp.

35 {
36
37 1, 26, 94, 112, 31, 33, 121, 85, 14, 12, 53, 38, 63, 79, 93, 83, 82, 72, 22, 102, 121, 88, 33, 116,
38//};
39
40//const uint8_t pi_transform[] PROGMEM = {
41 1, 6, 9, 22, 14, 20, 2, 12, 13, 19, 23, 15, 4, 24, 21, 8, 16, 5, 3, 18, 17, 11, 7, 10,
42//};
43
44//const uint8_t rhoTransforms[] PROGMEM = {
45 1, 62, 28, 27, 36, 44, 6, 55, 20, 3, 10, 43, 25, 39, 41, 45, 15, 21, 8, 18, 2, 61, 56, 14,
46};