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