1 /*
2  * Copyright (c) 2001-2019, Arm Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 
8 /*!
9  @addtogroup cc_hash_defs
10  @{
11 */
12 
13 /*!
14  @file
15  @brief This file contains definitions of the CryptoCell hash APIs.
16  */
17 
18 #ifndef CC_HASH_DEFS_H
19 #define CC_HASH_DEFS_H
20 
21 
22 #ifdef __cplusplus
23 extern "C"
24 {
25 #endif
26 
27 #include "cc_pal_types.h"
28 #include "cc_error.h"
29 #include "cc_hash_defs_proj.h"
30 
31 /************************ Defines ******************************/
32 
33 /*! The size of the hash result in words. The maximal size for SHA-512 is
34 512 bits. */
35 #define CC_HASH_RESULT_SIZE_IN_WORDS    16
36 
37 /*! The size of the MD5 digest result in bytes. */
38 #define CC_HASH_MD5_DIGEST_SIZE_IN_BYTES 16
39 
40 /*! The size of the MD5 digest result in words. */
41 #define CC_HASH_MD5_DIGEST_SIZE_IN_WORDS 4
42 
43 /*! The size of the SHA-1 digest result in bytes. */
44 #define CC_HASH_SHA1_DIGEST_SIZE_IN_BYTES 20
45 
46 /*! The size of the SHA-1 digest result in words. */
47 #define CC_HASH_SHA1_DIGEST_SIZE_IN_WORDS 5
48 
49 /*! The size of the SHA-224 digest result in words. */
50 #define CC_HASH_SHA224_DIGEST_SIZE_IN_WORDS 7
51 
52 /*! The size of the SHA-256 digest result in words. */
53 #define CC_HASH_SHA256_DIGEST_SIZE_IN_WORDS 8
54 
55 /*! The size of the SHA-384 digest result in words. */
56 #define CC_HASH_SHA384_DIGEST_SIZE_IN_WORDS 12
57 
58 /*! The size of the SHA-512 digest result in words. */
59 #define CC_HASH_SHA512_DIGEST_SIZE_IN_WORDS 16
60 
61 /*! The size of the SHA-256 digest result in bytes. */
62 #define CC_HASH_SHA224_DIGEST_SIZE_IN_BYTES 28
63 
64 /*! The size of the SHA-256 digest result in bytes. */
65 #define CC_HASH_SHA256_DIGEST_SIZE_IN_BYTES 32
66 
67 /*! The size of the SHA-384 digest result in bytes. */
68 #define CC_HASH_SHA384_DIGEST_SIZE_IN_BYTES 48
69 
70 /*! The size of the SHA-512 digest result in bytes. */
71 #define CC_HASH_SHA512_DIGEST_SIZE_IN_BYTES 64
72 
73 /*! The size of the SHA-1 hash block in words. */
74 #define CC_HASH_BLOCK_SIZE_IN_WORDS 16
75 
76 /*! The size of the SHA-1 hash block in bytes. */
77 #define CC_HASH_BLOCK_SIZE_IN_BYTES 64
78 
79 /*! The size of the SHA-2 hash block in words. */
80 #define CC_HASH_SHA512_BLOCK_SIZE_IN_WORDS  32
81 
82 /*! The size of the SHA-2 hash block in bytes. */
83 #define CC_HASH_SHA512_BLOCK_SIZE_IN_BYTES  128
84 
85 /*! The maximal data size for the update operation. */
86 #define CC_HASH_UPDATE_DATA_MAX_SIZE_IN_BYTES (1 << 29)
87 
88 
89 /************************ Enums ********************************/
90 
91 /*! The hash operation mode. */
92 typedef enum {
93     /*! SHA-1. */
94     CC_HASH_SHA1_mode          = 0,
95     /*! SHA-224. */
96     CC_HASH_SHA224_mode        = 1,
97     /*! SHA-256. */
98     CC_HASH_SHA256_mode        = 2,
99     /*! SHA-384. */
100     CC_HASH_SHA384_mode        = 3,
101     /*! SHA-512. */
102     CC_HASH_SHA512_mode        = 4,
103     /*! MD5. */
104     CC_HASH_MD5_mode           = 5,
105     /*! The number of hash modes. */
106     CC_HASH_NumOfModes,
107     /*! Reserved. */
108     CC_HASH_OperationModeLast= 0x7FFFFFFF,
109 
110 }CCHashOperationMode_t;
111 
112 /************************ Typedefs  *****************************/
113 
114 /*! The hash result buffer. */
115 typedef uint32_t CCHashResultBuf_t[CC_HASH_RESULT_SIZE_IN_WORDS];
116 
117 /************************ Structs  ******************************/
118 /*!
119  The context prototype of the user.
120  The argument type that is passed by the user to the hash APIs.
121  The context saves the state of the operation, and must be saved by the user
122  until the end of the API flow.
123 */
124 typedef struct CCHashUserContext_t {
125     /*! The internal buffer. */
126     uint32_t buff[CC_HASH_USER_CTX_SIZE_IN_WORDS];
127 }CCHashUserContext_t;
128 
129 
130 #ifdef __cplusplus
131 }
132 #endif
133 
134 /*!
135  @}
136  */
137 #endif /* #ifndef CC_HASH_DEFS_H */
138