1 /**
2  * Author......: See docs/credits.txt
3  * License.....: MIT
4  */
5 
6 #ifndef _INC_HASH_SHA384_H
7 #define _INC_HASH_SHA384_H
8 
9 #define SHIFT_RIGHT_64(x,n) ((x) >> (n))
10 
11 #define SHA384_S0_S(x) (hc_rotr64_S ((x), 28) ^ hc_rotr64_S ((x), 34) ^ hc_rotr64_S ((x), 39))
12 #define SHA384_S1_S(x) (hc_rotr64_S ((x), 14) ^ hc_rotr64_S ((x), 18) ^ hc_rotr64_S ((x), 41))
13 #define SHA384_S2_S(x) (hc_rotr64_S ((x),  1) ^ hc_rotr64_S ((x),  8) ^ SHIFT_RIGHT_64 ((x), 7))
14 #define SHA384_S3_S(x) (hc_rotr64_S ((x), 19) ^ hc_rotr64_S ((x), 61) ^ SHIFT_RIGHT_64 ((x), 6))
15 
16 #define SHA384_S0(x) (hc_rotr64 ((x), 28) ^ hc_rotr64 ((x), 34) ^ hc_rotr64 ((x), 39))
17 #define SHA384_S1(x) (hc_rotr64 ((x), 14) ^ hc_rotr64 ((x), 18) ^ hc_rotr64 ((x), 41))
18 #define SHA384_S2(x) (hc_rotr64 ((x),  1) ^ hc_rotr64 ((x),  8) ^ SHIFT_RIGHT_64 ((x), 7))
19 #define SHA384_S3(x) (hc_rotr64 ((x), 19) ^ hc_rotr64 ((x), 61) ^ SHIFT_RIGHT_64 ((x), 6))
20 
21 #define SHA384_F0(x,y,z) ((z) ^ ((x) & ((y) ^ (z))))
22 #define SHA384_F1(x,y,z) (((x) & (y)) | ((z) & ((x) ^ (y))))
23 
24 #ifdef USE_BITSELECT
25 #define SHA384_F0o(x,y,z) (bitselect ((z), (y), (x)))
26 #define SHA384_F1o(x,y,z) (bitselect ((x), (y), ((x) ^ (z))))
27 #else
28 #define SHA384_F0o(x,y,z) (SHA384_F0 ((x), (y), (z)))
29 #define SHA384_F1o(x,y,z) (SHA384_F1 ((x), (y), (z)))
30 #endif
31 
32 #define SHA384_STEP_S(F0,F1,a,b,c,d,e,f,g,h,x,K)  \
33 {                                                 \
34   h += K;                                         \
35   h += x;                                         \
36   h += SHA384_S1_S (e);                           \
37   h += F0 (e, f, g);                              \
38   d += h;                                         \
39   h += SHA384_S0_S (a);                           \
40   h += F1 (a, b, c);                              \
41 }
42 
43 #define SHA384_EXPAND_S(x,y,z,w) (SHA384_S3_S (x) + y + SHA384_S2_S (z) + w)
44 
45 #define SHA384_STEP(F0,F1,a,b,c,d,e,f,g,h,x,K)  \
46 {                                               \
47   h += K;                                       \
48   h += x;                                       \
49   h += SHA384_S1 (e);                           \
50   h += F0 (e, f, g);                            \
51   d += h;                                       \
52   h += SHA384_S0 (a);                           \
53   h += F1 (a, b, c);                            \
54 }
55 
56 #define SHA384_EXPAND(x,y,z,w) (SHA384_S3 (x) + y + SHA384_S2 (z) + w)
57 
58 typedef struct sha384_ctx
59 {
60   u64 h[8];
61 
62   u32 w0[4];
63   u32 w1[4];
64   u32 w2[4];
65   u32 w3[4];
66   u32 w4[4];
67   u32 w5[4];
68   u32 w6[4];
69   u32 w7[4];
70 
71   int len;
72 
73 } sha384_ctx_t;
74 
75 typedef struct sha384_hmac_ctx
76 {
77   sha384_ctx_t ipad;
78   sha384_ctx_t opad;
79 
80 } sha384_hmac_ctx_t;
81 
82 typedef struct sha384_ctx_vector
83 {
84   u64x h[8];
85 
86   u32x w0[4];
87   u32x w1[4];
88   u32x w2[4];
89   u32x w3[4];
90   u32x w4[4];
91   u32x w5[4];
92   u32x w6[4];
93   u32x w7[4];
94 
95   int  len;
96 
97 } sha384_ctx_vector_t;
98 
99 typedef struct sha384_hmac_ctx_vector
100 {
101   sha384_ctx_vector_t ipad;
102   sha384_ctx_vector_t opad;
103 
104 } sha384_hmac_ctx_vector_t;
105 
106 DECLSPEC void sha384_transform (const u32 *w0, const u32 *w1, const u32 *w2, const u32 *w3, const u32 *w4, const u32 *w5, const u32 *w6, const u32 *w7, u64 *digest);
107 DECLSPEC void sha384_init (sha384_ctx_t *ctx);
108 DECLSPEC void sha384_update_128 (sha384_ctx_t *ctx, u32 *w0, u32 *w1, u32 *w2, u32 *w3, u32 *w4, u32 *w5, u32 *w6, u32 *w7, const int len);
109 DECLSPEC void sha384_update (sha384_ctx_t *ctx, const u32 *w, const int len);
110 DECLSPEC void sha384_update_swap (sha384_ctx_t *ctx, const u32 *w, const int len);
111 DECLSPEC void sha384_update_utf16le (sha384_ctx_t *ctx, const u32 *w, const int len);
112 DECLSPEC void sha384_update_utf16le_swap (sha384_ctx_t *ctx, const u32 *w, const int len);
113 DECLSPEC void sha384_update_global (sha384_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len);
114 DECLSPEC void sha384_update_global_swap (sha384_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len);
115 DECLSPEC void sha384_update_global_utf16le (sha384_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len);
116 DECLSPEC void sha384_update_global_utf16le_swap (sha384_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len);
117 DECLSPEC void sha384_final (sha384_ctx_t *ctx);
118 DECLSPEC void sha384_hmac_init_128 (sha384_hmac_ctx_t *ctx, const u32 *w0, const u32 *w1, const u32 *w2, const u32 *w3, const u32 *w4, const u32 *w5, const u32 *w6, const u32 *w7);
119 DECLSPEC void sha384_hmac_init (sha384_hmac_ctx_t *ctx, const u32 *w, const int len);
120 DECLSPEC void sha384_hmac_init_swap (sha384_hmac_ctx_t *ctx, const u32 *w, const int len);
121 DECLSPEC void sha384_hmac_init_global (sha384_hmac_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len);
122 DECLSPEC void sha384_hmac_init_global_swap (sha384_hmac_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len);
123 DECLSPEC void sha384_hmac_update_128 (sha384_hmac_ctx_t *ctx, u32 *w0, u32 *w1, u32 *w2, u32 *w3, u32 *w4, u32 *w5, u32 *w6, u32 *w7, const int len);
124 DECLSPEC void sha384_hmac_update (sha384_hmac_ctx_t *ctx, const u32 *w, const int len);
125 DECLSPEC void sha384_hmac_update_swap (sha384_hmac_ctx_t *ctx, const u32 *w, const int len);
126 DECLSPEC void sha384_hmac_update_utf16le (sha384_hmac_ctx_t *ctx, const u32 *w, const int len);
127 DECLSPEC void sha384_hmac_update_utf16le_swap (sha384_hmac_ctx_t *ctx, const u32 *w, const int len);
128 DECLSPEC void sha384_hmac_update_global (sha384_hmac_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len);
129 DECLSPEC void sha384_hmac_update_global_swap (sha384_hmac_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len);
130 DECLSPEC void sha384_hmac_update_global_utf16le (sha384_hmac_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len);
131 DECLSPEC void sha384_hmac_update_global_utf16le_swap (sha384_hmac_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len);
132 DECLSPEC void sha384_hmac_final (sha384_hmac_ctx_t *ctx);
133 DECLSPEC void sha384_transform_vector (const u32x *w0, const u32x *w1, const u32x *w2, const u32x *w3, const u32x *w4, const u32x *w5, const u32x *w6, const u32x *w7, u64x *digest);
134 DECLSPEC void sha384_init_vector (sha384_ctx_vector_t *ctx);
135 DECLSPEC void sha384_init_vector_from_scalar (sha384_ctx_vector_t *ctx, sha384_ctx_t *ctx0);
136 DECLSPEC void sha384_update_vector_128 (sha384_ctx_vector_t *ctx, u32x *w0, u32x *w1, u32x *w2, u32x *w3, u32x *w4, u32x *w5, u32x *w6, u32x *w7, const int len);
137 DECLSPEC void sha384_update_vector (sha384_ctx_vector_t *ctx, const u32x *w, const int len);
138 DECLSPEC void sha384_update_vector_swap (sha384_ctx_vector_t *ctx, const u32x *w, const int len);
139 DECLSPEC void sha384_update_vector_utf16le (sha384_ctx_vector_t *ctx, const u32x *w, const int len);
140 DECLSPEC void sha384_update_vector_utf16le_swap (sha384_ctx_vector_t *ctx, const u32x *w, const int len);
141 DECLSPEC void sha384_update_vector_utf16beN (sha384_ctx_vector_t *ctx, const u32x *w, const int len);
142 DECLSPEC void sha384_final_vector (sha384_ctx_vector_t *ctx);
143 DECLSPEC void sha384_hmac_init_vector_128 (sha384_hmac_ctx_vector_t *ctx, const u32x *w0, const u32x *w1, const u32x *w2, const u32x *w3, const u32x *w4, const u32x *w5, const u32x *w6, const u32x *w7);
144 DECLSPEC void sha384_hmac_init_vector (sha384_hmac_ctx_vector_t *ctx, const u32x *w, const int len);
145 DECLSPEC void sha384_hmac_update_vector_128 (sha384_hmac_ctx_vector_t *ctx, u32x *w0, u32x *w1, u32x *w2, u32x *w3, u32x *w4, u32x *w5, u32x *w6, u32x *w7, const int len);
146 DECLSPEC void sha384_hmac_update_vector (sha384_hmac_ctx_vector_t *ctx, const u32x *w, const int len);
147 DECLSPEC void sha384_hmac_final_vector (sha384_hmac_ctx_vector_t *ctx);
148 
149 #endif // _INC_HASH_SHA384_H
150