Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

echo.c File Reference
#include <stddef.h>
#include <string.h>
#include <limits.h>
#include "sph_echo.h"
#include "aes_helper.c"
+ Include dependency graph for echo.c:

Go to the source code of this file.

Macros

#define T32   SPH_T32
 
#define C32   SPH_C32
 
#define AES_BIG_ENDIAN   0
 
#define DECL_STATE_SMALL   sph_u32 W[16][4];
 
#define DECL_STATE_BIG   sph_u32 W[16][4];
 
#define INPUT_BLOCK_SMALL(sc)
 
#define INPUT_BLOCK_BIG(sc)
 
#define AES_2ROUNDS(X)
 
#define BIG_SUB_WORDS
 
#define SHIFT_ROW1(a, b, c, d)
 
#define SHIFT_ROW2(a, b, c, d)
 
#define SHIFT_ROW3(a, b, c, d)   SHIFT_ROW1(d, c, b, a)
 
#define BIG_SHIFT_ROWS
 
#define MIX_COLUMN1(ia, ib, ic, id, n)
 
#define MIX_COLUMN(a, b, c, d)
 
#define BIG_MIX_COLUMNS
 
#define BIG_ROUND
 
#define FINAL_SMALL
 
#define FINAL_BIG
 
#define COMPRESS_SMALL(sc)
 
#define COMPRESS_BIG(sc)
 
#define INCR_COUNTER(sc, val)
 

Functions

static void echo_small_init (sph_echo_small_context *sc, unsigned out_len)
 
static void echo_big_init (sph_echo_big_context *sc, unsigned out_len)
 
static void echo_small_compress (sph_echo_small_context *sc)
 
static void echo_big_compress (sph_echo_big_context *sc)
 
static void echo_small_core (sph_echo_small_context *sc, const unsigned char *data, size_t len)
 
static void echo_big_core (sph_echo_big_context *sc, const unsigned char *data, size_t len)
 
static void echo_small_close (sph_echo_small_context *sc, unsigned ub, unsigned n, void *dst, unsigned out_size_w32)
 
static void echo_big_close (sph_echo_big_context *sc, unsigned ub, unsigned n, void *dst, unsigned out_size_w32)
 
void sph_echo224_init (void *cc)
 Initialize an ECHO-224 context. More...
 
void sph_echo224 (void *cc, const void *data, size_t len)
 Process some data bytes. More...
 
void sph_echo224_close (void *cc, void *dst)
 Terminate the current ECHO-224 computation and output the result into the provided buffer. More...
 
void sph_echo224_addbits_and_close (void *cc, unsigned ub, unsigned n, void *dst)
 Add a few additional bits (0 to 7) to the current computation, then terminate it and output the result in the provided buffer, which must be wide enough to accomodate the result (28 bytes). More...
 
void sph_echo256_init (void *cc)
 Initialize an ECHO-256 context. More...
 
void sph_echo256 (void *cc, const void *data, size_t len)
 Process some data bytes. More...
 
void sph_echo256_close (void *cc, void *dst)
 Terminate the current ECHO-256 computation and output the result into the provided buffer. More...
 
void sph_echo256_addbits_and_close (void *cc, unsigned ub, unsigned n, void *dst)
 Add a few additional bits (0 to 7) to the current computation, then terminate it and output the result in the provided buffer, which must be wide enough to accomodate the result (32 bytes). More...
 
void sph_echo384_init (void *cc)
 Initialize an ECHO-384 context. More...
 
void sph_echo384 (void *cc, const void *data, size_t len)
 Process some data bytes. More...
 
void sph_echo384_close (void *cc, void *dst)
 Terminate the current ECHO-384 computation and output the result into the provided buffer. More...
 
void sph_echo384_addbits_and_close (void *cc, unsigned ub, unsigned n, void *dst)
 Add a few additional bits (0 to 7) to the current computation, then terminate it and output the result in the provided buffer, which must be wide enough to accomodate the result (48 bytes). More...
 
void sph_echo512_init (void *cc)
 Initialize an ECHO-512 context. More...
 
void sph_echo512 (void *cc, const void *data, size_t len)
 Process some data bytes. More...
 
void sph_echo512_close (void *cc, void *dst)
 Terminate the current ECHO-512 computation and output the result into the provided buffer. More...
 
void sph_echo512_addbits_and_close (void *cc, unsigned ub, unsigned n, void *dst)
 Add a few additional bits (0 to 7) to the current computation, then terminate it and output the result in the provided buffer, which must be wide enough to accomodate the result (64 bytes). More...
 

Macro Definition Documentation

◆ AES_2ROUNDS

#define AES_2ROUNDS (   X)
Value:
do { \
sph_u32 Y0, Y1, Y2, Y3; \
AES_ROUND_LE(X[0], X[1], X[2], X[3], \
K0, K1, K2, K3, Y0, Y1, Y2, Y3); \
AES_ROUND_NOKEY_LE(Y0, Y1, Y2, Y3, X[0], X[1], X[2], X[3]); \
if ((K0 = T32(K0 + 1)) == 0) { \
if ((K1 = T32(K1 + 1)) == 0) \
if ((K2 = T32(K2 + 1)) == 0) \
K3 = T32(K3 + 1); \
} \
} while (0)
#define T32
Definition: echo.c:67
#define X(name)
Definition: net.cpp:756

Definition at line 419 of file echo.c.

◆ AES_BIG_ENDIAN

#define AES_BIG_ENDIAN   0

Definition at line 73 of file echo.c.

◆ BIG_MIX_COLUMNS

#define BIG_MIX_COLUMNS
Value:
do { \
MIX_COLUMN(0, 1, 2, 3); \
MIX_COLUMN(4, 5, 6, 7); \
MIX_COLUMN(8, 9, 10, 11); \
MIX_COLUMN(12, 13, 14, 15); \
} while (0)

Definition at line 573 of file echo.c.

◆ BIG_ROUND

#define BIG_ROUND
Value:
do { \
BIG_SUB_WORDS; \
BIG_SHIFT_ROWS; \
BIG_MIX_COLUMNS; \
} while (0)

Definition at line 580 of file echo.c.

◆ BIG_SHIFT_ROWS

#define BIG_SHIFT_ROWS
Value:
do { \
SHIFT_ROW1(1, 5, 9, 13); \
SHIFT_ROW2(2, 6, 10, 14); \
SHIFT_ROW3(3, 7, 11, 15); \
} while (0)

Definition at line 506 of file echo.c.

◆ BIG_SUB_WORDS

#define BIG_SUB_WORDS
Value:
do { \
AES_2ROUNDS(W[ 0]); \
AES_2ROUNDS(W[ 1]); \
AES_2ROUNDS(W[ 2]); \
AES_2ROUNDS(W[ 3]); \
AES_2ROUNDS(W[ 4]); \
AES_2ROUNDS(W[ 5]); \
AES_2ROUNDS(W[ 6]); \
AES_2ROUNDS(W[ 7]); \
AES_2ROUNDS(W[ 8]); \
AES_2ROUNDS(W[ 9]); \
AES_2ROUNDS(W[10]); \
AES_2ROUNDS(W[11]); \
AES_2ROUNDS(W[12]); \
AES_2ROUNDS(W[13]); \
AES_2ROUNDS(W[14]); \
AES_2ROUNDS(W[15]); \
} while (0)

Definition at line 431 of file echo.c.

◆ C32

#define C32   SPH_C32

Definition at line 68 of file echo.c.

◆ COMPRESS_BIG

#define COMPRESS_BIG (   sc)
Value:
do { \
sph_u32 K0 = sc->C0; \
sph_u32 K1 = sc->C1; \
sph_u32 K2 = sc->C2; \
sph_u32 K3 = sc->C3; \
unsigned u; \
INPUT_BLOCK_BIG(sc); \
for (u = 0; u < 10; u ++) { \
BIG_ROUND; \
} \
FINAL_BIG; \
} while (0)

Definition at line 622 of file echo.c.

Referenced by echo_big_compress().

◆ COMPRESS_SMALL

#define COMPRESS_SMALL (   sc)
Value:
do { \
sph_u32 K0 = sc->C0; \
sph_u32 K1 = sc->C1; \
sph_u32 K2 = sc->C2; \
sph_u32 K3 = sc->C3; \
unsigned u; \
INPUT_BLOCK_SMALL(sc); \
for (u = 0; u < 8; u ++) { \
BIG_ROUND; \
} \
FINAL_SMALL; \
} while (0)

Definition at line 609 of file echo.c.

Referenced by echo_small_compress().

◆ DECL_STATE_BIG

#define DECL_STATE_BIG   sph_u32 W[16][4];

Definition at line 350 of file echo.c.

Referenced by echo_big_compress().

◆ DECL_STATE_SMALL

#define DECL_STATE_SMALL   sph_u32 W[16][4];

Definition at line 347 of file echo.c.

Referenced by echo_small_compress().

◆ FINAL_BIG

#define FINAL_BIG
Value:
do { \
unsigned u; \
sph_u32 *VV = &sc->u.Vs[0][0]; \
sph_u32 *WW = &W[0][0]; \
for (u = 0; u < 32; u ++) { \
VV[u] ^= sph_dec32le_aligned(sc->buf + (u * 4)) \
^ WW[u] ^ WW[u + 32]; \
} \
} while (0)
static SPH_INLINE sph_u32 sph_dec32le_aligned(const void *src)
Decode a 32-bit value from the provided buffer (little endian convention).
Definition: sph_types.h:1615

Definition at line 599 of file echo.c.

◆ FINAL_SMALL

#define FINAL_SMALL
Value:
do { \
unsigned u; \
sph_u32 *VV = &sc->u.Vs[0][0]; \
sph_u32 *WW = &W[0][0]; \
for (u = 0; u < 16; u ++) { \
VV[u] ^= sph_dec32le_aligned(sc->buf + (u * 4)) \
^ sph_dec32le_aligned(sc->buf + (u * 4) + 64) \
^ sph_dec32le_aligned(sc->buf + (u * 4) + 128) \
^ WW[u] ^ WW[u + 16] \
^ WW[u + 32] ^ WW[u + 48]; \
} \
} while (0)
static SPH_INLINE sph_u32 sph_dec32le_aligned(const void *src)
Decode a 32-bit value from the provided buffer (little endian convention).
Definition: sph_types.h:1615

Definition at line 586 of file echo.c.

◆ INCR_COUNTER

#define INCR_COUNTER (   sc,
  val 
)
Value:
do { \
sc->C0 = T32(sc->C0 + (sph_u32)(val)); \
if (sc->C0 < (sph_u32)(val)) { \
if ((sc->C1 = T32(sc->C1 + 1)) == 0) \
if ((sc->C2 = T32(sc->C2 + 1)) == 0) \
sc->C3 = T32(sc->C3 + 1); \
} \
} while (0)
#define T32
Definition: echo.c:67
unsigned long sph_u32
Definition: sph_types.h:870

Definition at line 637 of file echo.c.

Referenced by echo_big_close(), echo_big_core(), echo_small_close(), and echo_small_core().

◆ INPUT_BLOCK_BIG

#define INPUT_BLOCK_BIG (   sc)
Value:
do { \
unsigned u; \
memcpy(W, sc->u.Vs, 32 * sizeof(sph_u32)); \
for (u = 0; u < 8; u ++) { \
W[u + 8][0] = sph_dec32le_aligned( \
sc->buf + 16 * u); \
W[u + 8][1] = sph_dec32le_aligned( \
sc->buf + 16 * u + 4); \
W[u + 8][2] = sph_dec32le_aligned( \
sc->buf + 16 * u + 8); \
W[u + 8][3] = sph_dec32le_aligned( \
sc->buf + 16 * u + 12); \
} \
} while (0)
static SPH_INLINE sph_u32 sph_dec32le_aligned(const void *src)
Decode a 32-bit value from the provided buffer (little endian convention).
Definition: sph_types.h:1615
unsigned long sph_u32
Definition: sph_types.h:870

Definition at line 368 of file echo.c.

◆ INPUT_BLOCK_SMALL

#define INPUT_BLOCK_SMALL (   sc)
Value:
do { \
unsigned u; \
memcpy(W, sc->u.Vs, 16 * sizeof(sph_u32)); \
for (u = 0; u < 12; u ++) { \
W[u + 4][0] = sph_dec32le_aligned( \
sc->buf + 16 * u); \
W[u + 4][1] = sph_dec32le_aligned( \
sc->buf + 16 * u + 4); \
W[u + 4][2] = sph_dec32le_aligned( \
sc->buf + 16 * u + 8); \
W[u + 4][3] = sph_dec32le_aligned( \
sc->buf + 16 * u + 12); \
} \
} while (0)
static SPH_INLINE sph_u32 sph_dec32le_aligned(const void *src)
Decode a 32-bit value from the provided buffer (little endian convention).
Definition: sph_types.h:1615
unsigned long sph_u32
Definition: sph_types.h:870

Definition at line 353 of file echo.c.

◆ MIX_COLUMN

#define MIX_COLUMN (   a,
  b,
  c,
 
)
Value:
do { \
MIX_COLUMN1(a, b, c, d, 0); \
MIX_COLUMN1(a, b, c, d, 1); \
MIX_COLUMN1(a, b, c, d, 2); \
MIX_COLUMN1(a, b, c, d, 3); \
} while (0)

Definition at line 564 of file echo.c.

◆ MIX_COLUMN1

#define MIX_COLUMN1 (   ia,
  ib,
  ic,
  id,
 
)
Value:
do { \
sph_u32 a = W[ia][n]; \
sph_u32 b = W[ib][n]; \
sph_u32 c = W[ic][n]; \
sph_u32 d = W[id][n]; \
sph_u32 ab = a ^ b; \
sph_u32 bc = b ^ c; \
sph_u32 cd = c ^ d; \
sph_u32 abx = ((ab & C32(0x80808080)) >> 7) * 27U \
^ ((ab & C32(0x7F7F7F7F)) << 1); \
sph_u32 bcx = ((bc & C32(0x80808080)) >> 7) * 27U \
^ ((bc & C32(0x7F7F7F7F)) << 1); \
sph_u32 cdx = ((cd & C32(0x80808080)) >> 7) * 27U \
^ ((cd & C32(0x7F7F7F7F)) << 1); \
W[ia][n] = abx ^ bc ^ d; \
W[ib][n] = bcx ^ a ^ cd; \
W[ic][n] = cdx ^ ab ^ d; \
W[id][n] = abx ^ bcx ^ cdx ^ ab ^ c; \
} while (0)
#define C32
Definition: echo.c:68

Definition at line 544 of file echo.c.

◆ SHIFT_ROW1

#define SHIFT_ROW1 (   a,
  b,
  c,
 
)
Value:
do { \
sph_u32 tmp; \
tmp = W[a][0]; \
W[a][0] = W[b][0]; \
W[b][0] = W[c][0]; \
W[c][0] = W[d][0]; \
W[d][0] = tmp; \
tmp = W[a][1]; \
W[a][1] = W[b][1]; \
W[b][1] = W[c][1]; \
W[c][1] = W[d][1]; \
W[d][1] = tmp; \
tmp = W[a][2]; \
W[a][2] = W[b][2]; \
W[b][2] = W[c][2]; \
W[c][2] = W[d][2]; \
W[d][2] = tmp; \
tmp = W[a][3]; \
W[a][3] = W[b][3]; \
W[b][3] = W[c][3]; \
W[c][3] = W[d][3]; \
W[d][3] = tmp; \
} while (0)

Definition at line 452 of file echo.c.

◆ SHIFT_ROW2

#define SHIFT_ROW2 (   a,
  b,
  c,
 
)
Value:
do { \
sph_u32 tmp; \
tmp = W[a][0]; \
W[a][0] = W[c][0]; \
W[c][0] = tmp; \
tmp = W[b][0]; \
W[b][0] = W[d][0]; \
W[d][0] = tmp; \
tmp = W[a][1]; \
W[a][1] = W[c][1]; \
W[c][1] = tmp; \
tmp = W[b][1]; \
W[b][1] = W[d][1]; \
W[d][1] = tmp; \
tmp = W[a][2]; \
W[a][2] = W[c][2]; \
W[c][2] = tmp; \
tmp = W[b][2]; \
W[b][2] = W[d][2]; \
W[d][2] = tmp; \
tmp = W[a][3]; \
W[a][3] = W[c][3]; \
W[c][3] = tmp; \
tmp = W[b][3]; \
W[b][3] = W[d][3]; \
W[d][3] = tmp; \
} while (0)

Definition at line 476 of file echo.c.

◆ SHIFT_ROW3

#define SHIFT_ROW3 (   a,
  b,
  c,
 
)    SHIFT_ROW1(d, c, b, a)

Definition at line 504 of file echo.c.

◆ T32

#define T32   SPH_T32

Definition at line 67 of file echo.c.

Function Documentation

◆ echo_big_close()

◆ echo_big_compress()

static void echo_big_compress ( sph_echo_big_context sc)
static

Definition at line 723 of file echo.c.

References COMPRESS_BIG, and DECL_STATE_BIG.

Referenced by echo_big_close(), and echo_big_core().

◆ echo_big_core()

static void echo_big_core ( sph_echo_big_context sc,
const unsigned char *  data,
size_t  len 
)
static

◆ echo_big_init()

◆ echo_small_close()

◆ echo_small_compress()

static void echo_small_compress ( sph_echo_small_context sc)
static

Definition at line 715 of file echo.c.

References COMPRESS_SMALL, and DECL_STATE_SMALL.

Referenced by echo_small_close(), and echo_small_core().

◆ echo_small_core()

static void echo_small_core ( sph_echo_small_context sc,
const unsigned char *  data,
size_t  len 
)
static

◆ echo_small_init()

◆ sph_echo224()

void sph_echo224 ( void *  cc,
const void *  data,
size_t  len 
)

Process some data bytes.

It is acceptable that len is zero (in which case this function does nothing).

Parameters
ccthe ECHO-224 context
datathe input data
lenthe input data length (in bytes)

Definition at line 927 of file echo.c.

References echo_small_core().

◆ sph_echo224_addbits_and_close()

void sph_echo224_addbits_and_close ( void *  cc,
unsigned  ub,
unsigned  n,
void *  dst 
)

Add a few additional bits (0 to 7) to the current computation, then terminate it and output the result in the provided buffer, which must be wide enough to accomodate the result (28 bytes).

If bit number i in ub has value 2^i, then the extra bits are those numbered 7 downto 8-n (this is the big-endian convention at the byte level). The context is automatically reinitialized.

Parameters
ccthe ECHO-224 context
ubthe extra bits
nthe number of extra bits (0 to 7)
dstthe destination buffer

Definition at line 941 of file echo.c.

References echo_small_close().

◆ sph_echo224_close()

void sph_echo224_close ( void *  cc,
void *  dst 
)

Terminate the current ECHO-224 computation and output the result into the provided buffer.

The destination buffer must be wide enough to accomodate the result (28 bytes). The context is automatically reinitialized.

Parameters
ccthe ECHO-224 context
dstthe destination buffer

Definition at line 934 of file echo.c.

References echo_small_close().

◆ sph_echo224_init()

void sph_echo224_init ( void *  cc)

Initialize an ECHO-224 context.

This process performs no memory allocation.

Parameters
ccthe ECHO-224 context (pointer to a sph_echo224_context)

Definition at line 920 of file echo.c.

References echo_small_init().

◆ sph_echo256()

void sph_echo256 ( void *  cc,
const void *  data,
size_t  len 
)

Process some data bytes.

It is acceptable that len is zero (in which case this function does nothing).

Parameters
ccthe ECHO-256 context
datathe input data
lenthe input data length (in bytes)

Definition at line 955 of file echo.c.

References echo_small_core().

◆ sph_echo256_addbits_and_close()

void sph_echo256_addbits_and_close ( void *  cc,
unsigned  ub,
unsigned  n,
void *  dst 
)

Add a few additional bits (0 to 7) to the current computation, then terminate it and output the result in the provided buffer, which must be wide enough to accomodate the result (32 bytes).

If bit number i in ub has value 2^i, then the extra bits are those numbered 7 downto 8-n (this is the big-endian convention at the byte level). The context is automatically reinitialized.

Parameters
ccthe ECHO-256 context
ubthe extra bits
nthe number of extra bits (0 to 7)
dstthe destination buffer

Definition at line 969 of file echo.c.

References echo_small_close().

◆ sph_echo256_close()

void sph_echo256_close ( void *  cc,
void *  dst 
)

Terminate the current ECHO-256 computation and output the result into the provided buffer.

The destination buffer must be wide enough to accomodate the result (32 bytes). The context is automatically reinitialized.

Parameters
ccthe ECHO-256 context
dstthe destination buffer

Definition at line 962 of file echo.c.

References echo_small_close().

◆ sph_echo256_init()

void sph_echo256_init ( void *  cc)

Initialize an ECHO-256 context.

This process performs no memory allocation.

Parameters
ccthe ECHO-256 context (pointer to a sph_echo256_context)

Definition at line 948 of file echo.c.

References echo_small_init().

◆ sph_echo384()

void sph_echo384 ( void *  cc,
const void *  data,
size_t  len 
)

Process some data bytes.

It is acceptable that len is zero (in which case this function does nothing).

Parameters
ccthe ECHO-384 context
datathe input data
lenthe input data length (in bytes)

Definition at line 983 of file echo.c.

References echo_big_core().

◆ sph_echo384_addbits_and_close()

void sph_echo384_addbits_and_close ( void *  cc,
unsigned  ub,
unsigned  n,
void *  dst 
)

Add a few additional bits (0 to 7) to the current computation, then terminate it and output the result in the provided buffer, which must be wide enough to accomodate the result (48 bytes).

If bit number i in ub has value 2^i, then the extra bits are those numbered 7 downto 8-n (this is the big-endian convention at the byte level). The context is automatically reinitialized.

Parameters
ccthe ECHO-384 context
ubthe extra bits
nthe number of extra bits (0 to 7)
dstthe destination buffer

Definition at line 997 of file echo.c.

References echo_big_close().

◆ sph_echo384_close()

void sph_echo384_close ( void *  cc,
void *  dst 
)

Terminate the current ECHO-384 computation and output the result into the provided buffer.

The destination buffer must be wide enough to accomodate the result (48 bytes). The context is automatically reinitialized.

Parameters
ccthe ECHO-384 context
dstthe destination buffer

Definition at line 990 of file echo.c.

References echo_big_close().

◆ sph_echo384_init()

void sph_echo384_init ( void *  cc)

Initialize an ECHO-384 context.

This process performs no memory allocation.

Parameters
ccthe ECHO-384 context (pointer to a sph_echo384_context)

Definition at line 976 of file echo.c.

References echo_big_init().

◆ sph_echo512()

void sph_echo512 ( void *  cc,
const void *  data,
size_t  len 
)

Process some data bytes.

It is acceptable that len is zero (in which case this function does nothing).

Parameters
ccthe ECHO-512 context
datathe input data
lenthe input data length (in bytes)

Definition at line 1011 of file echo.c.

References echo_big_core().

Referenced by HashX11().

◆ sph_echo512_addbits_and_close()

void sph_echo512_addbits_and_close ( void *  cc,
unsigned  ub,
unsigned  n,
void *  dst 
)

Add a few additional bits (0 to 7) to the current computation, then terminate it and output the result in the provided buffer, which must be wide enough to accomodate the result (64 bytes).

If bit number i in ub has value 2^i, then the extra bits are those numbered 7 downto 8-n (this is the big-endian convention at the byte level). The context is automatically reinitialized.

Parameters
ccthe ECHO-512 context
ubthe extra bits
nthe number of extra bits (0 to 7)
dstthe destination buffer

Definition at line 1025 of file echo.c.

References echo_big_close().

◆ sph_echo512_close()

void sph_echo512_close ( void *  cc,
void *  dst 
)

Terminate the current ECHO-512 computation and output the result into the provided buffer.

The destination buffer must be wide enough to accomodate the result (64 bytes). The context is automatically reinitialized.

Parameters
ccthe ECHO-512 context
dstthe destination buffer

Definition at line 1018 of file echo.c.

References echo_big_close().

Referenced by HashX11().

◆ sph_echo512_init()

void sph_echo512_init ( void *  cc)

Initialize an ECHO-512 context.

This process performs no memory allocation.

Parameters
ccthe ECHO-512 context (pointer to a sph_echo512_context)

Definition at line 1004 of file echo.c.

References echo_big_init().

Referenced by HashX11().

Released under the MIT license