#ifndef __GOSTR34_11_94_H__
#define __GOSTR34_11_94_H__
#include <libecc/libec.h>
#ifndef GET_UINT32_BE
#define GET_UINT32_BE(n, b, i) \
do { \
(n) = ( ((u32) (b)[(i) ]) << 24 ) \
| ( ((u32) (b)[(i) + 1]) << 16 ) \
| ( ((u32) (b)[(i) + 2]) << 8 ) \
| ( ((u32) (b)[(i) + 3]) ); \
} while( 0 )
#endif
#ifndef GET_UINT32_LE
#define GET_UINT32_LE(n, b, i) \
do { \
(n) = ( ((u32) (b)[(i) + 3]) << 24 ) \
| ( ((u32) (b)[(i) + 2]) << 16 ) \
| ( ((u32) (b)[(i) + 1]) << 8 ) \
| ( ((u32) (b)[(i) ]) ); \
} while( 0 )
#endif
#ifndef PUT_UINT32_BE
#define PUT_UINT32_BE(n, b, i) \
do { \
(b)[(i) ] = (u8) ( (n) >> 24 ); \
(b)[(i) + 1] = (u8) ( (n) >> 16 ); \
(b)[(i) + 2] = (u8) ( (n) >> 8 ); \
(b)[(i) + 3] = (u8) ( (n) ); \
} while( 0 )
#endif
#ifndef PUT_UINT32_LE
#define PUT_UINT32_LE(n, b, i) \
do { \
(b)[(i) + 3] = (u8) ( (n) >> 24 ); \
(b)[(i) + 2] = (u8) ( (n) >> 16 ); \
(b)[(i) + 1] = (u8) ( (n) >> 8 ); \
(b)[(i) ] = (u8) ( (n) ); \
} while( 0 )
#endif
#ifndef GET_UINT64_BE
#define GET_UINT64_BE(n,b,i) \
do { \
(n) = ( ((u64) (b)[(i) ]) << 56 ) \
| ( ((u64) (b)[(i) + 1]) << 48 ) \
| ( ((u64) (b)[(i) + 2]) << 40 ) \
| ( ((u64) (b)[(i) + 3]) << 32 ) \
| ( ((u64) (b)[(i) + 4]) << 24 ) \
| ( ((u64) (b)[(i) + 5]) << 16 ) \
| ( ((u64) (b)[(i) + 6]) << 8 ) \
| ( ((u64) (b)[(i) + 7]) ); \
} while( 0 )
#endif
#ifndef GET_UINT64_LE
#define GET_UINT64_LE(n,b,i) \
do { \
(n) = ( ((u64) (b)[(i) + 7]) << 56 ) \
| ( ((u64) (b)[(i) + 6]) << 48 ) \
| ( ((u64) (b)[(i) + 5]) << 40 ) \
| ( ((u64) (b)[(i) + 4]) << 32 ) \
| ( ((u64) (b)[(i) + 3]) << 24 ) \
| ( ((u64) (b)[(i) + 2]) << 16 ) \
| ( ((u64) (b)[(i) + 1]) << 8 ) \
| ( ((u64) (b)[(i) ]) ); \
} while( 0 )
#endif
#ifndef PUT_UINT64_BE
#define PUT_UINT64_BE(n,b,i) \
do { \
(b)[(i) ] = (u8) ( (n) >> 56 ); \
(b)[(i) + 1] = (u8) ( (n) >> 48 ); \
(b)[(i) + 2] = (u8) ( (n) >> 40 ); \
(b)[(i) + 3] = (u8) ( (n) >> 32 ); \
(b)[(i) + 4] = (u8) ( (n) >> 24 ); \
(b)[(i) + 5] = (u8) ( (n) >> 16 ); \
(b)[(i) + 6] = (u8) ( (n) >> 8 ); \
(b)[(i) + 7] = (u8) ( (n) ); \
} while( 0 )
#endif
#ifndef PUT_UINT64_LE
#define PUT_UINT64_LE(n,b,i) \
do { \
(b)[(i) + 7] = (u8) ( (n) >> 56 ); \
(b)[(i) + 6] = (u8) ( (n) >> 48 ); \
(b)[(i) + 5] = (u8) ( (n) >> 40 ); \
(b)[(i) + 4] = (u8) ( (n) >> 32 ); \
(b)[(i) + 3] = (u8) ( (n) >> 24 ); \
(b)[(i) + 2] = (u8) ( (n) >> 16 ); \
(b)[(i) + 1] = (u8) ( (n) >> 8 ); \
(b)[(i) ] = (u8) ( (n) ); \
} while( 0 )
#endif
#define GOSTR34_11_94_STATE_SIZE 4
#define GOSTR34_11_94_BLOCK_SIZE 32
#define GOSTR34_11_94_DIGEST_SIZE 32
#define GOSTR34_11_94_DIGEST_SIZE_BITS 256
#define GOSTR34_11_94_HASH_MAGIC ((word_t)(0x1262734139734143ULL))
#define GOSTR34_11_94_HASH_CHECK_INITIALIZED(A, ret, err) \
MUST_HAVE((((void *)(A)) != NULL) && ((A)->magic == GOSTR34_11_94_HASH_MAGIC), ret, err)
#define ROTL_GOSTR34_11_94(x, n) ((((u32)(x)) << (n)) | (((u32)(x)) >> (32-(n))))
typedef enum {
GOST34_11_94_NORM = 0,
GOST34_11_94_RFC4357 = 1,
} gostr34_11_94_type;
typedef struct {
gostr34_11_94_type gostr34_11_94_t;
u64 gostr34_11_94_total;
u64 gostr34_11_94_state[GOSTR34_11_94_STATE_SIZE];
u8 gostr34_11_94_buffer[GOSTR34_11_94_BLOCK_SIZE];
u64 gostr34_11_94_sum[GOSTR34_11_94_STATE_SIZE];
word_t magic;
} gostr34_11_94_context;
ATTRIBUTE_WARN_UNUSED_RET int gostr34_11_94_init(gostr34_11_94_context *ctx);
ATTRIBUTE_WARN_UNUSED_RET int gostr34_11_94_set_iv(gostr34_11_94_context *ctx, const u64 iv[GOSTR34_11_94_STATE_SIZE]);
ATTRIBUTE_WARN_UNUSED_RET int gostr34_11_94_set_type(gostr34_11_94_context *ctx, gostr34_11_94_type type);
ATTRIBUTE_WARN_UNUSED_RET int gostr34_11_94_update(gostr34_11_94_context *ctx, const u8 *input, u32 ilen);
ATTRIBUTE_WARN_UNUSED_RET int gostr34_11_94_final(gostr34_11_94_context *ctx, u8 output[GOSTR34_11_94_DIGEST_SIZE]);
ATTRIBUTE_WARN_UNUSED_RET int gostr34_11_94_scattered(const u8 **inputs, const u32 *ilens,
u8 output[GOSTR34_11_94_DIGEST_SIZE], gostr34_11_94_type type);
ATTRIBUTE_WARN_UNUSED_RET int gostr34_11_94_scattered_norm(const u8 **inputs, const u32 *ilens,
u8 output[GOSTR34_11_94_DIGEST_SIZE]);
ATTRIBUTE_WARN_UNUSED_RET int gostr34_11_94_scattered_rfc4357(const u8 **inputs, const u32 *ilens,
u8 output[GOSTR34_11_94_DIGEST_SIZE]);
ATTRIBUTE_WARN_UNUSED_RET int gostr34_11_94(const u8 *input, u32 ilen, u8 output[GOSTR34_11_94_DIGEST_SIZE], gostr34_11_94_type type);
ATTRIBUTE_WARN_UNUSED_RET int gostr34_11_94_norm(const u8 *input, u32 ilen, u8 output[GOSTR34_11_94_DIGEST_SIZE]);
ATTRIBUTE_WARN_UNUSED_RET int gostr34_11_94_rfc4357(const u8 *input, u32 ilen, u8 output[GOSTR34_11_94_DIGEST_SIZE]);
#endif