Olive.Hash/Blake2/blake2.inc

154 lines
5.8 KiB
PHP

{
BLAKE2 reference source code package - reference C implementations
Copyright 2012, Samuel Neves <sneves@dei.uc.pt>. You may use this under the
terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at
your option. The terms of these licenses can be found at:
- CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
- OpenSSL license : https://www.openssl.org/source/license.html
- Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
More information about the BLAKE2 hash function can be found at
https://blake2.net.
}
{$ifndef BLAKE2_H}
{$define BLAKE2_H}
{$endif}
{$packrecords c}
const
BLAKE2S_BLOCKBYTES = 64;
BLAKE2S_OUTBYTES = 32;
BLAKE2S_KEYBYTES = 32;
BLAKE2S_SALTBYTES = 8;
BLAKE2S_PERSONALBYTES = 8;
BLAKE2B_BLOCKBYTES = 128;
BLAKE2B_OUTBYTES = 64;
BLAKE2B_KEYBYTES = 64;
BLAKE2B_SALTBYTES = 16;
BLAKE2B_PERSONALBYTES = 16;
type
blake2s_state = record
h : array [0..7] of cuint32;
t, f : array [0..1] of cuint32;
buf : array [0..BLAKE2S_BLOCKBYTES-1] of cuint8;
buflen, outlen : csize_t;
last_node : cuint8;
end;
blake2b_state = record
h : array [0..7] of cuint64;
t, f : array [0..1] of cuint64;
buf : array [0..BLAKE2B_BLOCKBYTES-1] of cuint8;
buflen, outlen : csize_t;
last_node : cuint8;
end;
blake2sp_state = record
S : array [0..7,0..0] of blake2s_state;
R : array [0..1] of blake2s_state;
buf : array [0..(8 * BLAKE2S_BLOCKBYTES)-1] of cuint8;
buflen, outlen : csize_t;
end;
blake2bp_state = record
S : array [0..3,0..0] of blake2b_state;
R : array [0..1] of blake2b_state;
buf : array [0..(4 * BLAKE2B_BLOCKBYTES)-1] of cuint8;
buflen, outlen : csize_t;
end;
blake2s_param = packed record
digest_length, // 1
key_length, // 2
fanout, // 3
depth : cuint8; // 4
leaf_length, // 8
node_offset : cuint32; // 12
xof_length : cuint16; // 14
node_depth, // 15
inner_length : cuint8; // 16
salt : array [0..BLAKE2S_SALTBYTES-1] of cuint8; // 24
personal : array [0..BLAKE2S_PERSONALBYTES-1] of cuint8; // 32
end;
blake2b_param = packed record
digest_length, // 1
key_length, // 2
fanout, // 3
depth : cuint8; // 4
leaf_length, // 8
node_offset, // 12
xof_length : cuint32; // 14
node_depth, // 15
inner_length : cuint8; // 16
reserved : array[0..13] of cuint8; // 32
salt : array [0..BLAKE2B_SALTBYTES-1] of cuint8; // 48
personal : array [0..BLAKE2B_PERSONALBYTES-1] of cuint8; // 64
end;
blake2xs_state = record
S : array[0..0] of blake2s_state;
P : array[0..0] of blake2s_param;
end;
blake2xb_state = record
S : array[0..0] of blake2b_state;
P : array[0..0] of blake2b_param;
end;
{ Padded structs result in a compile-time error }
{ enum
BLAKE2_DUMMY_1 = 1/(sizeof(blake2s_param) == BLAKE2S_OUTBYTES),
BLAKE2_DUMMY_2 = 1/(sizeof(blake2b_param) == BLAKE2B_OUTBYTES)
}
{ /* Streaming API */
int blake2s_init( blake2s_state *S, size_t outlen );
int blake2s_init_key( blake2s_state *S, size_t outlen, const void *key, size_t keylen );
int blake2s_init_param( blake2s_state *S, const blake2s_param *P );
int blake2s_update( blake2s_state *S, const void *in, size_t inlen );
int blake2s_final( blake2s_state *S, void *out, size_t outlen );
int blake2b_init( blake2b_state *S, size_t outlen );
int blake2b_init_key( blake2b_state *S, size_t outlen, const void *key, size_t keylen );
int blake2b_init_param( blake2b_state *S, const blake2b_param *P );
int blake2b_update( blake2b_state *S, const void *in, size_t inlen );
int blake2b_final( blake2b_state *S, void *out, size_t outlen );
int blake2sp_init( blake2sp_state *S, size_t outlen );
int blake2sp_init_key( blake2sp_state *S, size_t outlen, const void *key, size_t keylen );
int blake2sp_update( blake2sp_state *S, const void *in, size_t inlen );
int blake2sp_final( blake2sp_state *S, void *out, size_t outlen );
int blake2bp_init( blake2bp_state *S, size_t outlen );
int blake2bp_init_key( blake2bp_state *S, size_t outlen, const void *key, size_t keylen );
int blake2bp_update( blake2bp_state *S, const void *in, size_t inlen );
int blake2bp_final( blake2bp_state *S, void *out, size_t outlen );
/* Variable output length API */
int blake2xs_init( blake2xs_state *S, const size_t outlen );
int blake2xs_init_key( blake2xs_state *S, const size_t outlen, const void *key, size_t keylen );
int blake2xs_update( blake2xs_state *S, const void *in, size_t inlen );
int blake2xs_final(blake2xs_state *S, void *out, size_t outlen);
int blake2xb_init( blake2xb_state *S, const size_t outlen );
int blake2xb_init_key( blake2xb_state *S, const size_t outlen, const void *key, size_t keylen );
int blake2xb_update( blake2xb_state *S, const void *in, size_t inlen );
int blake2xb_final(blake2xb_state *S, void *out, size_t outlen);
/* Simple API */
int blake2s( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen );
int blake2b( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen );
int blake2sp( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen );
int blake2bp( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen );
int blake2xs( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen );
int blake2xb( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen );
/* This is simply an alias for blake2b */
int blake2( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen );
}