5 "@(#)sha3.c 1.4 15/12/27 2015 J. Schilling";
41#if !defined(HAVE_MEMCPY) || !defined(HAVE_MEMSET)
44#if !defined(HAVE_MEMCPY) && !defined(memcpy)
45#define memcpy(s1, s2, n) movebytes(s2, s1, n)
47#if !defined(HAVE_MEMSET) && !defined(memset)
48#define memset(s, c, n) fillbytes(s, n, c)
51static void rhash_keccak_init
__PR((sha3_ctx *
ctx,
unsigned bits));
52static void keccak_theta
__PR((UInt64_t *
A));
53static void keccak_pi
__PR((UInt64_t *
A));
54static void keccak_chi
__PR((UInt64_t *
A));
55static void rhash_sha3_permutation
__PR((UInt64_t *
state));
56static void rhash_sha3_process_block
__PR((UInt64_t
hash[25],
57 const UInt64_t *
block,
67#if defined(HAVE_PRAGMA_WEAK) && defined(HAVE_LINK_WEAK)
68#pragma weak SHA3_224_Init = rhash_sha3_224_init
69#pragma weak SHA3_256_Init = rhash_sha3_256_init
70#pragma weak SHA3_384_Init = rhash_sha3_384_init
71#pragma weak SHA3_512_Init = rhash_sha3_512_init
72#pragma weak SHA3_Update = rhash_sha3_update
75void SHA3_224_Init
__PR((SHA3_CTX *
ctx));
76void SHA3_256_Init
__PR((SHA3_CTX *
ctx));
77void SHA3_384_Init
__PR((SHA3_CTX *
ctx));
78void SHA3_512_Init
__PR((SHA3_CTX *
ctx));
79void SHA3_Update
__PR((SHA3_CTX *
ctx,
80 const unsigned char *
msg,
87 rhash_sha3_224_init(
ctx);
94 rhash_sha3_256_init(
ctx);
101 rhash_sha3_384_init(
ctx);
108 rhash_sha3_512_init(
ctx);
114 const unsigned char *
msg;
122#define NumberOfRounds 24
125static UInt64_t keccak_round_constants[NumberOfRounds] = {
126 UI64(0x0000000000000001),
UI64(0x0000000000008082),
127 UI64(0x800000000000808A),
UI64(0x8000000080008000),
128 UI64(0x000000000000808B),
UI64(0x0000000080000001),
129 UI64(0x8000000080008081),
UI64(0x8000000000008009),
130 UI64(0x000000000000008A),
UI64(0x0000000000000088),
131 UI64(0x0000000080008009),
UI64(0x000000008000000A),
132 UI64(0x000000008000808B),
UI64(0x800000000000008B),
133 UI64(0x8000000000008089),
UI64(0x8000000000008003),
134 UI64(0x8000000000008002),
UI64(0x8000000000000080),
135 UI64(0x000000000000800A),
UI64(0x800000008000000A),
136 UI64(0x8000000080008081),
UI64(0x8000000000008080),
137 UI64(0x0000000080000001),
UI64(0x8000000080008008)
160rhash_sha3_224_init(
ctx)
163 rhash_keccak_init(
ctx, 224);
172rhash_sha3_256_init(
ctx)
175 rhash_keccak_init(
ctx, 256);
184rhash_sha3_384_init(
ctx)
187 rhash_keccak_init(
ctx, 384);
196rhash_sha3_512_init(
ctx)
199 rhash_keccak_init(
ctx, 512);
210 for (
x = 0;
x < 5;
x++) {
211 C[
x] =
A[
x] ^
A[
x + 5] ^
A[
x + 10] ^
A[
x + 15] ^
A[
x + 20];
219 for (
x = 0;
x < 5;
x++) {
268 for (
i = 0;
i < 25;
i += 5) {
269 UInt64_t A0 =
A[0 +
i],
A1 =
A[1 +
i];
270 A[0 +
i] ^= ~A1 &
A[2 +
i];
271 A[1 +
i] ^=
~A[2 +
i] &
A[3 +
i];
272 A[2 +
i] ^=
~A[3 +
i] &
A[4 +
i];
273 A[3 +
i] ^=
~A[4 +
i] & A0;
274 A[4 +
i] ^= ~A0 &
A1;
279rhash_sha3_permutation(
state)
331 const UInt64_t *
block;
359#ifdef FULL_SHA3_FAMILY_SUPPORT
375 rhash_sha3_permutation(
hash);
378#define SHA3_FINALIZED 0x80000000
391 const unsigned char *
msg;
397 if (
ctx->rest & SHA3_FINALIZED)
415 UInt64_t *aligned_message_block;
421 aligned_message_block = (UInt64_t *)
msg;
424 aligned_message_block =
ctx->message;
427 rhash_sha3_process_block(
ctx->hash, aligned_message_block,
448 size_t digest_length = 100 -
ctx->block_size / 2;
451 if (!(
ctx->rest & SHA3_FINALIZED))
456 ((
char *)
ctx->message)[
ctx->rest] |= 0x06;
461 ctx->rest = SHA3_FINALIZED;
484rhash_keccak_final(sha3_ctx *
ctx,
unsigned char *
result)
486 size_t digest_length = 100 -
ctx->block_size / 2;
489 if (!(
ctx->rest & SHA3_FINALIZED)) {
493 ((
char *)
ctx->message)[
ctx->rest] |= 0x01;
498 ctx->rest = SHA3_FINALIZED;
#define me64_to_le_str(to, from, length)
GLint GLint GLint GLint GLint x
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * bits
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
static DWORD block_size(DWORD block)
#define memcpy(s1, s2, n)
static unsigned(__cdecl *hash_bstr)(bstr_t s)
static UConst char sccsid[]
static unsigned int block