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