1/*
2 * Special version of sha512.c that uses the libc SHA512 implementation
3 * of libc.
4 */
5
6#include <string.h>
7#include <sys/sha2.h>
8
9#include "crypto/sha.h"
10
11static const uint64_t sha512_224_initial_hash_value[] = {
12	0x8c3d37c819544da2ULL,
13	0x73e1996689dcd4d6ULL,
14	0x1dfab7ae32ff9c82ULL,
15	0x679dd514582f9fcfULL,
16	0x0f6d2b697bd44da8ULL,
17	0x77e36f7304c48942ULL,
18	0x3f9d85a86a1d36c8ULL,
19	0x1112e6ad91d692a1ULL,
20};
21
22static const uint64_t sha512_256_initial_hash_value[] = {
23	0x22312194fc2bf72cULL,
24	0x9f555fa3c84c64c2ULL,
25	0x2393b86b6f53b151ULL,
26	0x963877195940eabdULL,
27	0x96283ee2a88effe3ULL,
28	0xbe5e1e2553863992ULL,
29	0x2b0199fc2c85b8aaULL,
30	0x0eb72ddc81c52ca2ULL,
31};
32
33int
34sha512_224_init(SHA512_CTX *context)
35{
36	if (context == NULL)
37		return 1;
38
39	memcpy(context->state, sha512_224_initial_hash_value,
40	    (size_t)(SHA512_DIGEST_LENGTH));
41	memset(context->buffer, 0, (size_t)(SHA512_BLOCK_LENGTH));
42	context->bitcount[0] = context->bitcount[1] =  0;
43
44	return 1;
45
46}
47
48int
49sha512_256_init(SHA512_CTX *context)
50{
51	if (context == NULL)
52		return 1;
53
54	memcpy(context->state, sha512_256_initial_hash_value,
55	    (size_t)(SHA512_DIGEST_LENGTH));
56	memset(context->buffer, 0, (size_t)(SHA512_BLOCK_LENGTH));
57	context->bitcount[0] = context->bitcount[1] =  0;
58
59	return 1;
60}
61