Welcome to little lamb

Code » test-hashes » next » tree

[next] / include / sha3-nettle-impl.h

#ifndef SHA3_H
#define SHA3_H

#include <stdint.h>
#include <stddef.h> /* For size_t */

#define SHA3_ROUNDS 24

/* The sha3 state is a 5x5 matrix of 64-bit words. In the notation of
   Keccak description, S[x,y] is element x + 5*y, so if x is
   interpreted as the row index and y the column index, it is stored
   in column-major order. */
#define SHA3_STATE_LENGTH 25

/* The "width" is 1600 bits or 200 octets */
struct sha3_state {
	uint64_t a[SHA3_STATE_LENGTH];
};

void sha3_permute (struct sha3_state *state);

unsigned _sha3_update (struct sha3_state *state, unsigned block_size, uint8_t *block,
		unsigned pos, size_t length, const uint8_t *data);
void _sha3_pad (struct sha3_state *state, unsigned block_size, uint8_t *block, unsigned pos);


typedef struct {
	struct sha3_state state;
	unsigned index;
	uint8_t block[200];
	int mdlen, blksize;
} sha3_ctx_t;

// OpenSSL - like interfece
int sha3_init(sha3_ctx_t *c, int mdlen);    // mdlen = hash output in bytes
int sha3_update(sha3_ctx_t *c, const void *data, size_t len);
int sha3_final(void *md, sha3_ctx_t *c);    // digest goes to md

// compute a sha3 hash (md) of given byte length from "in"
void *sha3(const void *in, size_t inlen, void *md, int mdlen);

#endif /* SHA3_H */