cryptnox-pos 1.0.0
Standalone USDC payment terminal firmware (ESP32 + Cryptnox smart card)
Loading...
Searching...
No Matches
keccak256.cpp File Reference

Original (pre-NIST) Keccak-256 implementation, 0x01 padding. More...

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

Go to the source code of this file.

Macros

#define KECCAK_ROUNDS   24U
#define KECCAK_RATE   136U /* 1088 / 8 bytes — rate for 256-bit output */
#define KECCAK_STATE_LANE   25U /* 5×5 uint64_t lanes */

Functions

static uint64_t rot64 (uint64_t x, uint8_t n)
 Rotate a 64-bit lane left by n bits.
static void keccak_f1600 (uint64_t st[KECCAK_STATE_LANE])
 Apply the full 24-round Keccak-f[1600] permutation in place.
void keccak256 (const uint8_t *input, size_t length, uint8_t digest[32])
 Compute the Keccak-256 digest of a buffer.

Variables

static const uint64_t kRC [KECCAK_ROUNDS]
static const uint8_t kRHO [KECCAK_STATE_LANE]

Detailed Description

Original (pre-NIST) Keccak-256 implementation, 0x01 padding.

Definition in file keccak256.cpp.

Macro Definition Documentation

◆ KECCAK_RATE

#define KECCAK_RATE   136U /* 1088 / 8 bytes — rate for 256-bit output */

Definition at line 25 of file keccak256.cpp.

Referenced by keccak256().

◆ KECCAK_ROUNDS

#define KECCAK_ROUNDS   24U

Definition at line 24 of file keccak256.cpp.

Referenced by keccak_f1600().

◆ KECCAK_STATE_LANE

#define KECCAK_STATE_LANE   25U /* 5×5 uint64_t lanes */

Definition at line 26 of file keccak256.cpp.

Referenced by keccak256(), and keccak_f1600().

Function Documentation

◆ keccak256()

void keccak256 ( const uint8_t * input,
size_t length,
uint8_t digest[32] )

Compute the Keccak-256 digest of a buffer.

Ethereum uses the original Keccak-256 (0x01 padding), NOT the NIST-finalised SHA3-256 (0x06 padding).

Parameters
[in]inputInput bytes (may be NULL only if length is 0).
[in]lengthNumber of input bytes.
[out]digest32-byte output digest.

Definition at line 120 of file keccak256.cpp.

References keccak_f1600(), KECCAK_RATE, and KECCAK_STATE_LANE.

Referenced by admin_derive(), card_read_payouts(), eth_addr_format(), eth_addr_parse(), and sign_and_broadcast().

◆ keccak_f1600()

void keccak_f1600 ( uint64_t st[KECCAK_STATE_LANE])
static

Apply the full 24-round Keccak-f[1600] permutation in place.

Parameters
[in,out]st5x5 lane state, modified in place.

Definition at line 73 of file keccak256.cpp.

References KECCAK_ROUNDS, KECCAK_STATE_LANE, kRC, kRHO, and rot64().

Referenced by keccak256().

◆ rot64()

uint64_t rot64 ( uint64_t x,
uint8_t n )
static

Rotate a 64-bit lane left by n bits.

Parameters
[in]xLane value.
[in]nRotation amount, 0-63.
Returns
Rotated value.

Definition at line 63 of file keccak256.cpp.

Referenced by keccak_f1600().

Variable Documentation

◆ kRC

const uint64_t kRC[KECCAK_ROUNDS]
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 28 of file keccak256.cpp.

Referenced by keccak_f1600().

◆ kRHO

const uint8_t kRHO[KECCAK_STATE_LANE]
static
Initial value:
= {
0, 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 44 of file keccak256.cpp.

Referenced by keccak_f1600().