]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Source/WolfSSL/cyassl/ctaocrypt/sha512.h
1434024392b560c22871c6e7bc544199a8b2d6f1
[freertos] / FreeRTOS-Plus / Source / WolfSSL / cyassl / ctaocrypt / sha512.h
1 /* sha512.h
2  *
3  * Copyright (C) 2006-2014 wolfSSL Inc.
4  *
5  * This file is part of CyaSSL.
6  *
7  * CyaSSL is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * CyaSSL is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22
23 #ifdef CYASSL_SHA512
24
25 #ifndef CTAO_CRYPT_SHA512_H
26 #define CTAO_CRYPT_SHA512_H
27
28 #include <cyassl/ctaocrypt/types.h>
29
30 #ifdef __cplusplus
31     extern "C" {
32 #endif
33
34
35 /* in bytes */
36 enum {
37     SHA512              =   4,   /* hash type unique */
38     SHA512_BLOCK_SIZE   = 128,
39     SHA512_DIGEST_SIZE  =  64,
40     SHA512_PAD_SIZE     = 112 
41 };
42
43
44 /* Sha512 digest */
45 typedef struct Sha512 {
46     word32  buffLen;   /* in bytes          */
47     word32  loLen;     /* length in bytes   */
48     word32  hiLen;     /* length in bytes   */
49     word64  digest[SHA512_DIGEST_SIZE / sizeof(word64)];
50     word64  buffer[SHA512_BLOCK_SIZE  / sizeof(word64)];
51 } Sha512;
52
53
54 CYASSL_API int InitSha512(Sha512*);
55 CYASSL_API int Sha512Update(Sha512*, const byte*, word32);
56 CYASSL_API int Sha512Final(Sha512*, byte*);
57 CYASSL_API int Sha512Hash(const byte*, word32, byte*);
58
59
60 #if defined(CYASSL_SHA384) || defined(HAVE_AESGCM)
61
62 /* in bytes */
63 enum {
64     SHA384              =   5,   /* hash type unique */
65     SHA384_BLOCK_SIZE   = 128,
66     SHA384_DIGEST_SIZE  =  48,
67     SHA384_PAD_SIZE     = 112 
68 };
69
70
71 /* Sha384 digest */
72 typedef struct Sha384 {
73     word32  buffLen;   /* in bytes          */
74     word32  loLen;     /* length in bytes   */
75     word32  hiLen;     /* length in bytes   */
76     word64  digest[SHA512_DIGEST_SIZE / sizeof(word64)]; /* for transform 512 */
77     word64  buffer[SHA384_BLOCK_SIZE  / sizeof(word64)];
78 } Sha384;
79
80
81 CYASSL_API int InitSha384(Sha384*);
82 CYASSL_API int Sha384Update(Sha384*, const byte*, word32);
83 CYASSL_API int Sha384Final(Sha384*, byte*);
84 CYASSL_API int Sha384Hash(const byte*, word32, byte*);
85
86
87 #ifdef HAVE_FIPS
88     /* fips wrapper calls, user can call direct */
89     CYASSL_API int InitSha512_fips(Sha512*);
90     CYASSL_API int Sha512Update_fips(Sha512*, const byte*, word32);
91     CYASSL_API int Sha512Final_fips(Sha512*, byte*);
92     #ifndef FIPS_NO_WRAPPERS
93         /* if not impl or fips.c impl wrapper force fips calls if fips build */
94         #define InitSha512   InitSha512_fips
95         #define Sha512Update Sha512Update_fips
96         #define Sha512Final  Sha512Final_fips
97     #endif /* FIPS_NO_WRAPPERS */
98
99     /* fips wrapper calls, user can call direct */
100     CYASSL_API int InitSha384_fips(Sha384*);
101     CYASSL_API int Sha384Update_fips(Sha384*, const byte*, word32);
102     CYASSL_API int Sha384Final_fips(Sha384*, byte*);
103     #ifndef FIPS_NO_WRAPPERS
104         /* if not impl or fips.c impl wrapper force fips calls if fips build */
105         #define InitSha384   InitSha384_fips
106         #define Sha384Update Sha384Update_fips
107         #define Sha384Final  Sha384Final_fips
108     #endif /* FIPS_NO_WRAPPERS */
109
110 #endif /* HAVE_FIPS */
111
112
113 #endif /* CYASSL_SHA384 */
114
115 #ifdef __cplusplus
116     } /* extern "C" */
117 #endif
118
119 #endif /* CTAO_CRYPT_SHA512_H */
120 #endif /* CYASSL_SHA512 */