ReactOS 0.4.15-dev-5669-g09dde2c
blake2b-ref.c File Reference
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include "blake2-impl.h"
Include dependency graph for blake2b-ref.c:

Go to the source code of this file.

Macros

#define G(r, i, a, b, c, d)
 
#define ROUND(r)
 

Functions

static int blake2b_update (blake2b_state *S, const void *in, size_t inlen)
 
static void blake2b_set_lastnode (blake2b_state *S)
 
static int blake2b_is_lastblock (const blake2b_state *S)
 
static void blake2b_set_lastblock (blake2b_state *S)
 
static void blake2b_increment_counter (blake2b_state *S, const uint64_t inc)
 
static void blake2b_init0 (blake2b_state *S)
 
static void blake2b_init_param (blake2b_state *S, const blake2b_param *P)
 
static void blake2b_init (blake2b_state *S, size_t outlen)
 
static void blake2b_compress (blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKBYTES])
 
static int blake2b_final (blake2b_state *S, void *out, size_t outlen)
 
void blake2b (void *out, size_t outlen, const void *in, size_t inlen)
 

Variables

static const uint64_t blake2b_IV [8]
 
static const uint8_t blake2b_sigma [12][16]
 

Macro Definition Documentation

◆ G

#define G (   r,
  i,
  a,
  b,
  c,
  d 
)
Value:
do { \
a = a + b + m[blake2b_sigma[r][2*i+0]]; \
d = rotr64(d ^ a, 32); \
c = c + d; \
b = rotr64(b ^ c, 24); \
a = a + b + m[blake2b_sigma[r][2*i+1]]; \
d = rotr64(d ^ a, 16); \
c = c + d; \
b = rotr64(b ^ c, 63); \
} while(0)
static BLAKE2_INLINE uint64_t rotr64(const uint64_t w, const unsigned c)
Definition: blake2-impl.h:149
static const uint8_t blake2b_sigma[12][16]
Definition: blake2b-ref.c:30
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
const GLubyte * c
Definition: glext.h:8905
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
const GLfloat * m
Definition: glext.h:10848
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define d
Definition: ke_i.h:81

Definition at line 117 of file blake2b-ref.c.

◆ ROUND

#define ROUND (   r)
Value:
do { \
G(r,0,v[ 0],v[ 4],v[ 8],v[12]); \
G(r,1,v[ 1],v[ 5],v[ 9],v[13]); \
G(r,2,v[ 2],v[ 6],v[10],v[14]); \
G(r,3,v[ 3],v[ 7],v[11],v[15]); \
G(r,4,v[ 0],v[ 5],v[10],v[15]); \
G(r,5,v[ 1],v[ 6],v[11],v[12]); \
G(r,6,v[ 2],v[ 7],v[ 8],v[13]); \
G(r,7,v[ 3],v[ 4],v[ 9],v[14]); \
} while(0)
const GLdouble * v
Definition: gl.h:2040

Definition at line 129 of file blake2b-ref.c.

Function Documentation

◆ blake2b()

void blake2b ( void out,
size_t  outlen,
const void in,
size_t  inlen 
)

Definition at line 237 of file blake2b-ref.c.

238{
239 blake2b_state S[1];
240
241 blake2b_init( S, outlen );
242
243 blake2b_update( S, ( const uint8_t * )in, inlen );
244 blake2b_final( S, out, outlen );
245}
static int blake2b_final(blake2b_state *S, void *out, size_t outlen)
Definition: blake2b-ref.c:212
static void blake2b_init(blake2b_state *S, size_t outlen)
Definition: blake2b-ref.c:97
static int blake2b_update(blake2b_state *S, const void *in, size_t inlen)
Definition: blake2b-ref.c:185
GLuint in
Definition: glext.h:9616
BYTE uint8_t
Definition: msvideo1.c:66
static FILE * out
Definition: regtests2xml.c:44
Definition: movable.cpp:9

Referenced by calc_superblock_checksum(), calc_thread_main(), calc_tree_checksum(), check_sector_csum(), check_superblock_checksum(), check_tree_checksum(), get_sector_csum(), and get_tree_checksum().

◆ blake2b_compress()

static void blake2b_compress ( blake2b_state S,
const uint8_t  block[BLAKE2B_BLOCKBYTES] 
)
static

Definition at line 141 of file blake2b-ref.c.

142{
143 uint64_t m[16];
144 uint64_t v[16];
145 size_t i;
146
147 for( i = 0; i < 16; ++i ) {
148 m[i] = load64( block + i * sizeof( m[i] ) );
149 }
150
151 for( i = 0; i < 8; ++i ) {
152 v[i] = S->h[i];
153 }
154
155 v[ 8] = blake2b_IV[0];
156 v[ 9] = blake2b_IV[1];
157 v[10] = blake2b_IV[2];
158 v[11] = blake2b_IV[3];
159 v[12] = blake2b_IV[4] ^ S->t[0];
160 v[13] = blake2b_IV[5] ^ S->t[1];
161 v[14] = blake2b_IV[6] ^ S->f[0];
162 v[15] = blake2b_IV[7] ^ S->f[1];
163
164 ROUND( 0 );
165 ROUND( 1 );
166 ROUND( 2 );
167 ROUND( 3 );
168 ROUND( 4 );
169 ROUND( 5 );
170 ROUND( 6 );
171 ROUND( 7 );
172 ROUND( 8 );
173 ROUND( 9 );
174 ROUND( 10 );
175 ROUND( 11 );
176
177 for( i = 0; i < 8; ++i ) {
178 S->h[i] = S->h[i] ^ v[i] ^ v[i + 8];
179 }
180}
static BLAKE2_INLINE uint64_t load64(const void *src)
Definition: blake2-impl.h:49
static const uint64_t blake2b_IV[8]
Definition: blake2b-ref.c:22
#define ROUND(r)
Definition: blake2b-ref.c:129
UINT64 uint64_t
Definition: types.h:77
static unsigned int block
Definition: xmlmemory.c:101

Referenced by blake2b_final(), and blake2b_update().

◆ blake2b_final()

static int blake2b_final ( blake2b_state S,
void out,
size_t  outlen 
)
static

Definition at line 212 of file blake2b-ref.c.

213{
215 size_t i;
216
217 if( out == NULL || outlen < S->outlen )
218 return -1;
219
220 if( blake2b_is_lastblock( S ) )
221 return -1;
222
223 blake2b_increment_counter( S, S->buflen );
225 memset( S->buf + S->buflen, 0, BLAKE2B_BLOCKBYTES - S->buflen ); /* Padding */
226 blake2b_compress( S, S->buf );
227
228 for( i = 0; i < 8; ++i ) /* Output full hash to temp buffer */
229 store64( buffer + sizeof( S->h[i] ) * i, S->h[i] );
230
231 memcpy( out, buffer, S->outlen );
232
233 return 0;
234}
@ BLAKE2B_OUTBYTES
Definition: blake2-impl.h:163
@ BLAKE2B_BLOCKBYTES
Definition: blake2-impl.h:162
static BLAKE2_INLINE void store64(void *dst, uint64_t w)
Definition: blake2-impl.h:105
static void blake2b_set_lastblock(blake2b_state *S)
Definition: blake2b-ref.c:59
static int blake2b_is_lastblock(const blake2b_state *S)
Definition: blake2b-ref.c:54
static void blake2b_compress(blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKBYTES])
Definition: blake2b-ref.c:141
static void blake2b_increment_counter(blake2b_state *S, const uint64_t inc)
Definition: blake2b-ref.c:66
#define NULL
Definition: types.h:112
GLuint buffer
Definition: glext.h:5915
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define memset(x, y, z)
Definition: compat.h:39

Referenced by blake2b().

◆ blake2b_increment_counter()

static void blake2b_increment_counter ( blake2b_state S,
const uint64_t  inc 
)
static

Definition at line 66 of file blake2b-ref.c.

67{
68 S->t[0] += inc;
69 S->t[1] += ( S->t[0] < inc );
70}

Referenced by blake2b_final(), and blake2b_update().

◆ blake2b_init()

static void blake2b_init ( blake2b_state S,
size_t  outlen 
)
static

Definition at line 97 of file blake2b-ref.c.

98{
100
101 P->digest_length = (uint8_t)outlen;
102 P->key_length = 0;
103 P->fanout = 1;
104 P->depth = 1;
105 store32( &P->leaf_length, 0 );
106 store32( &P->node_offset, 0 );
107 store32( &P->xof_length, 0 );
108 P->node_depth = 0;
109 P->inner_length = 0;
110 memset( P->reserved, 0, sizeof( P->reserved ) );
111 memset( P->salt, 0, sizeof( P->salt ) );
112 memset( P->personal, 0, sizeof( P->personal ) );
113
115}
struct blake2b_param__ blake2b_param
Definition: blake2-impl.h:196
static BLAKE2_INLINE void store32(void *dst, uint32_t w)
Definition: blake2-impl.h:92
static void blake2b_init_param(blake2b_state *S, const blake2b_param *P)
Definition: blake2b-ref.c:81
#define P(row, col)
#define uint8_t
Definition: nsiface.idl:59

Referenced by blake2b().

◆ blake2b_init0()

static void blake2b_init0 ( blake2b_state S)
static

Definition at line 72 of file blake2b-ref.c.

73{
74 size_t i;
75 memset( S, 0, sizeof( blake2b_state ) );
76
77 for( i = 0; i < 8; ++i ) S->h[i] = blake2b_IV[i];
78}

Referenced by blake2b_init_param().

◆ blake2b_init_param()

static void blake2b_init_param ( blake2b_state S,
const blake2b_param P 
)
static

Definition at line 81 of file blake2b-ref.c.

82{
83 const uint8_t *p = ( const uint8_t * )( P );
84 size_t i;
85
87
88 /* IV XOR ParamBlock */
89 for( i = 0; i < 8; ++i )
90 S->h[i] ^= load64( p + sizeof( S->h[i] ) * i );
91
92 S->outlen = P->digest_length;
93}
static void blake2b_init0(blake2b_state *S)
Definition: blake2b-ref.c:72
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by blake2b_init().

◆ blake2b_is_lastblock()

static int blake2b_is_lastblock ( const blake2b_state S)
static

Definition at line 54 of file blake2b-ref.c.

55{
56 return S->f[0] != 0;
57}

Referenced by blake2b_final().

◆ blake2b_set_lastblock()

static void blake2b_set_lastblock ( blake2b_state S)
static

Definition at line 59 of file blake2b-ref.c.

60{
61 if( S->last_node ) blake2b_set_lastnode( S );
62
63 S->f[0] = (uint64_t)-1;
64}
static void blake2b_set_lastnode(blake2b_state *S)
Definition: blake2b-ref.c:48
#define uint64_t
Definition: nsiface.idl:62

Referenced by blake2b_final().

◆ blake2b_set_lastnode()

static void blake2b_set_lastnode ( blake2b_state S)
static

Definition at line 48 of file blake2b-ref.c.

49{
50 S->f[1] = (uint64_t)-1;
51}

Referenced by blake2b_set_lastblock().

◆ blake2b_update()

static int blake2b_update ( blake2b_state S,
const void in,
size_t  inlen 
)
static

Definition at line 185 of file blake2b-ref.c.

186{
187 const unsigned char * in = (const unsigned char *)pin;
188 if( inlen > 0 )
189 {
190 size_t left = S->buflen;
191 size_t fill = BLAKE2B_BLOCKBYTES - left;
192 if( inlen > fill )
193 {
194 S->buflen = 0;
195 memcpy( S->buf + left, in, fill ); /* Fill buffer */
197 blake2b_compress( S, S->buf ); /* Compress */
198 in += fill; inlen -= fill;
199 while(inlen > BLAKE2B_BLOCKBYTES) {
203 inlen -= BLAKE2B_BLOCKBYTES;
204 }
205 }
206 memcpy( S->buf + S->buflen, in, inlen );
207 S->buflen += inlen;
208 }
209 return 0;
210}
_STLP_MOVE_TO_STD_NAMESPACE void fill(_ForwardIter __first, _ForwardIter __last, const _Tp &__val)
Definition: _algobase.h:449
GLint left
Definition: glext.h:7726
Definition: regsvr.c:104

Referenced by blake2b().

Variable Documentation

◆ blake2b_IV

const uint64_t blake2b_IV[8]
static
Initial value:
=
{
0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL,
0x3c6ef372fe94f82bULL, 0xa54ff53a5f1d36f1ULL,
0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL,
0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL
}

Definition at line 22 of file blake2b-ref.c.

Referenced by blake2b_compress(), and blake2b_init0().

◆ blake2b_sigma

const uint8_t blake2b_sigma[12][16]
static
Initial value:
=
{
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } ,
{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 } ,
{ 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 } ,
{ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 } ,
{ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 } ,
{ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 } ,
{ 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 } ,
{ 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 } ,
{ 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 } ,
{ 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13 , 0 } ,
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } ,
{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 }
}

Definition at line 30 of file blake2b-ref.c.