• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*############################################################################
2 # Copyright 2017 Intel Corporation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 ############################################################################*/
16 /// Interface to a SHA-512 implementation.
17 /*! \file */
18 
19 #ifndef EPID_MEMBER_TINY_MATH_SHA512_H_
20 #define EPID_MEMBER_TINY_MATH_SHA512_H_
21 
22 #include <stddef.h>
23 #include <stdint.h>
24 
25 /// block size
26 #define SHA512_BLOCK_SIZE (128)
27 /// digest size
28 #define SHA512_DIGEST_SIZE (64)
29 /// number of words in SHA state
30 #define SHA512_DIGEST_WORDS (8)
31 
32 /// The SHA state
33 /// \cond
34 typedef struct sha512_state {
35   uint64_t iv[SHA512_DIGEST_WORDS];
36   uint64_t bits_hashed_low;
37   uint64_t bits_hashed_high;
38   unsigned char leftover[SHA512_BLOCK_SIZE];
39   unsigned int leftover_offset;
40 } sha512_state;
41 /// \endcond
42 
43 /// Initializes the hash state
44 /*!
45 
46   \param[in,out] s
47   The hash state to initialize.
48  */
49 void tinysha512_init(sha512_state* s);
50 
51 /// Hashes data into state using SHA-512
52 /*!
53 
54   \warning
55   The state buffer 'leftover' is left in memory after processing. If
56   your application intends to have sensitive data in this buffer,
57   remember to erase it after the data has been processed
58 
59   \param[in,out] s
60   The hash state. Must be non-null or behavior is undefined.
61 
62   \param[in] data
63   The data to hash into s.
64 
65   \param[in] data_length
66   The size of data in bytes.
67  */
68 void tinysha512_update(sha512_state* s, void const* data, size_t data_length);
69 
70 /// Computes the SHA-512 hash in the digest buffer
71 /*!
72 
73   \note Assumes SHA512_DIGEST_SIZE bytes are available to accept the
74   digest.
75 
76   \warning
77   The state buffer 'leftover' is left in memory after processing. If
78   your application intends to have sensitive data in this buffer,
79   remember to erase it after the data has been processed
80 
81   \param[out] digest
82   The computed digest. Must be non-null or behavior is undefined.
83 
84   \param[in] s
85   The hash state. Must be non-null or behavior is undefined.
86  */
87 void tinysha512_final(unsigned char* digest, sha512_state* s);
88 
89 #endif  // EPID_MEMBER_TINY_MATH_SHA512_H_
90