cryptnox-sdk-arduino 1.0.0
Arduino library for Cryptnox Hardware Wallet
Loading...
Searching...
No Matches
keccak256.cpp File Reference

Keccak-256 (SHA3 variant) hash implementation for Ethereum. More...

#include "keccak256.h"
#include <string.h>
Include dependency graph for keccak256.cpp:

Go to the source code of this file.

Macros

#define KECCAK_ROUNDS   24

Functions

static uint64_t rol (uint64_t x, int s)
 Rotate a 64-bit integer left by s bits.
static void keccakf (uint64_t st[25])
void keccak256 (const uint8_t *in, size_t inlen, uint8_t out[32])
 Compute Keccak-256 hash of input data.

Variables

static const uint64_t keccakf_rndc [24]
static const int8_t keccakf_rotc [24]
 Keccak-f[1600] permutation on the state array.
static const int8_t keccakf_piln [24]

Detailed Description

Keccak-256 (SHA3 variant) hash implementation for Ethereum.

Implements Keccak-256 hashing suitable for Ethereum-style hashing, producing a 32-byte digest. This file contains the internal permutation function and the main keccak256 API.

Definition in file keccak256.cpp.

Macro Definition Documentation

◆ KECCAK_ROUNDS

#define KECCAK_ROUNDS   24

Definition at line 19 of file keccak256.cpp.

Referenced by keccakf().

Function Documentation

◆ keccak256()

void keccak256 ( const uint8_t * in,
size_t inlen,
uint8_t out[32] )

Compute Keccak-256 hash of input data.

Compute the Keccak-256 hash of a given input buffer.

Parameters
[in]inPointer to input buffer.
[in]inlenLength of input buffer in bytes.
[out]outPointer to a 32-byte buffer to store the hash.
Note
The output buffer must be at least 32 bytes long.
This is Ethereum's Keccak-256 (pre-SHA3 standard padding).
Examples
UsdcSigning.ino.

Definition at line 111 of file keccak256.cpp.

References keccakf().

Referenced by setup().

◆ keccakf()

void keccakf ( uint64_t st[25])
static

Definition at line 63 of file keccak256.cpp.

References KECCAK_ROUNDS, keccakf_piln, keccakf_rndc, keccakf_rotc, and rol().

Referenced by keccak256().

◆ rol()

uint64_t rol ( uint64_t x,
int s )
inlinestatic

Rotate a 64-bit integer left by s bits.

Parameters
xValue to rotate.
sNumber of bits to rotate.
Returns
Rotated value.

Definition at line 44 of file keccak256.cpp.

Referenced by keccakf().

Variable Documentation

◆ keccakf_piln

const int8_t keccakf_piln[24]
static
Initial value:
= {
10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4,
15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1
}

Definition at line 58 of file keccak256.cpp.

Referenced by keccakf().

◆ keccakf_rndc

const uint64_t keccakf_rndc[24]
static
Initial value:
= {
0x0000000000000001ULL, 0x0000000000008082ULL,
0x800000000000808aULL, 0x8000000080008000ULL,
0x000000000000808bULL, 0x0000000080000001ULL,
0x8000000080008081ULL, 0x8000000000008009ULL,
0x000000000000008aULL, 0x0000000000000088ULL,
0x0000000080008009ULL, 0x000000008000000aULL,
0x000000008000808bULL, 0x800000000000008bULL,
0x8000000000008089ULL, 0x8000000000008003ULL,
0x8000000000008002ULL, 0x8000000000000080ULL,
0x000000000000800aULL, 0x800000008000000aULL,
0x8000000080008081ULL, 0x8000000000008080ULL,
0x0000000080000001ULL, 0x8000000080008008ULL
}

Definition at line 22 of file keccak256.cpp.

Referenced by keccakf().

◆ keccakf_rotc

const int8_t keccakf_rotc[24]
static
Initial value:
= {
1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14,
27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44
}

Keccak-f[1600] permutation on the state array.

Parameters
st25-word state array (1600 bits).

This function applies the 24-round Keccak-f permutation on the input state array in-place.

Definition at line 54 of file keccak256.cpp.

Referenced by keccakf().