Raven Core  3.0.0
P2P Digital Currency
Macros | Functions
sph_sha2.c File Reference
#include <stddef.h>
#include <string.h>
#include "sph_sha2.h"
#include "md_helper.c"
Include dependency graph for sph_sha2.c:

Go to the source code of this file.

Macros

#define CH(X, Y, Z)   ((((Y) ^ (Z)) & (X)) ^ (Z))
 
#define MAJ(X, Y, Z)   (((Y) & (Z)) | (((Y) | (Z)) & (X)))
 
#define ROTR   SPH_ROTR32
 
#define BSG2_0(x)   (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
 
#define BSG2_1(x)   (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
 
#define SSG2_0(x)   (ROTR(x, 7) ^ ROTR(x, 18) ^ SPH_T32((x) >> 3))
 
#define SSG2_1(x)   (ROTR(x, 17) ^ ROTR(x, 19) ^ SPH_T32((x) >> 10))
 
#define SHA2_ROUND_BODY(in, r)
 
#define SHA2_IN(x)   sph_dec32be_aligned(data + (4 * (x)))
 
#define RFUN   sha2_round
 
#define HASH   sha224
 
#define BE32   1
 
#define SHA2_IN(x)   msg[x]
 

Functions

void sph_sha224_init (void *cc)
 Initialize a SHA-224 context. More...
 
void sph_sha256_init (void *cc)
 Initialize a SHA-256 context. More...
 
void sph_sha224_close (void *cc, void *dst)
 Terminate the current SHA-224 computation and output the result into the provided buffer. More...
 
void sph_sha224_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_sha256_close (void *cc, void *dst)
 Terminate the current SHA-256 computation and output the result into the provided buffer. More...
 
void sph_sha256_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_sha224_comp (const sph_u32 msg[16], sph_u32 val[8])
 Apply the SHA-224 compression function on the provided data. More...
 

Macro Definition Documentation

◆ BE32

#define BE32   1

Definition at line 655 of file sph_sha2.c.

◆ BSG2_0

#define BSG2_0 (   x)    (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))

Definition at line 51 of file sph_sha2.c.

◆ BSG2_1

#define BSG2_1 (   x)    (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))

Definition at line 52 of file sph_sha2.c.

◆ CH

#define CH (   X,
  Y,
 
)    ((((Y) ^ (Z)) & (X)) ^ (Z))

Definition at line 46 of file sph_sha2.c.

◆ HASH

#define HASH   sha224

Definition at line 654 of file sph_sha2.c.

◆ MAJ

#define MAJ (   X,
  Y,
 
)    (((Y) & (Z)) | (((Y) | (Z)) & (X)))

Definition at line 47 of file sph_sha2.c.

◆ RFUN

#define RFUN   sha2_round

Definition at line 653 of file sph_sha2.c.

◆ ROTR

#define ROTR   SPH_ROTR32

Definition at line 49 of file sph_sha2.c.

◆ SHA2_IN [1/2]

#define SHA2_IN (   x)    sph_dec32be_aligned(data + (4 * (x)))

◆ SHA2_IN [2/2]

#define SHA2_IN (   x)    msg[x]

◆ SHA2_ROUND_BODY

#define SHA2_ROUND_BODY (   in,
 
)

Definition at line 200 of file sph_sha2.c.

◆ SSG2_0

#define SSG2_0 (   x)    (ROTR(x, 7) ^ ROTR(x, 18) ^ SPH_T32((x) >> 3))

Definition at line 53 of file sph_sha2.c.

◆ SSG2_1

#define SSG2_1 (   x)    (ROTR(x, 17) ^ ROTR(x, 19) ^ SPH_T32((x) >> 10))

Definition at line 54 of file sph_sha2.c.

Function Documentation

◆ sph_sha224_addbits_and_close()

void sph_sha224_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 SHA-224 context
ubthe extra bits
nthe number of extra bits (0 to 7)
dstthe destination buffer

Definition at line 668 of file sph_sha2.c.

◆ sph_sha224_close()

void sph_sha224_close ( void *  cc,
void *  dst 
)

Terminate the current SHA-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 SHA-224 context
dstthe destination buffer

Definition at line 660 of file sph_sha2.c.

◆ sph_sha224_comp()

void sph_sha224_comp ( const sph_u32  msg[16],
sph_u32  val[8] 
)

Apply the SHA-224 compression function on the provided data.

The msg parameter contains the 16 32-bit input blocks, as numerical values (hence after the big-endian decoding). The val parameter contains the 8 32-bit input blocks for the compression function; the output is written in place in this array.

Parameters
msgthe message block (16 values)
valthe function 256-bit input and output

Definition at line 692 of file sph_sha2.c.

◆ sph_sha224_init()

void sph_sha224_init ( void *  cc)

Initialize a SHA-224 context.

This process performs no memory allocation.

Parameters
ccthe SHA-224 context (pointer to a sph_sha224_context)

Definition at line 625 of file sph_sha2.c.

Here is the call graph for this function:

◆ sph_sha256_addbits_and_close()

void sph_sha256_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 SHA-256 context
ubthe extra bits
nthe number of extra bits (0 to 7)
dstthe destination buffer

Definition at line 684 of file sph_sha2.c.

◆ sph_sha256_close()

void sph_sha256_close ( void *  cc,
void *  dst 
)

Terminate the current SHA-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 SHA-256 context
dstthe destination buffer

Definition at line 676 of file sph_sha2.c.

◆ sph_sha256_init()

void sph_sha256_init ( void *  cc)

Initialize a SHA-256 context.

This process performs no memory allocation.

Parameters
ccthe SHA-256 context (pointer to a sph_sha256_context)

Definition at line 640 of file sph_sha2.c.

Here is the call graph for this function: