Add phnxdeco with debian patch set (version 0.33-3).
[delutions.git] / tc / crypto / Sha2.h
blob6d0aeb0f17c880d014b75d29419f335b0b8b06f5
1 /*
2 ---------------------------------------------------------------------------
3 Copyright (c) 2002, Dr Brian Gladman, Worcester, UK. All rights reserved.
5 LICENSE TERMS
7 The free distribution and use of this software is allowed (with or without
8 changes) provided that:
10 1. source code distributions include the above copyright notice, this
11 list of conditions and the following disclaimer;
13 2. binary distributions include the above copyright notice, this list
14 of conditions and the following disclaimer in their documentation;
16 3. the name of the copyright holder is not used to endorse products
17 built using this software without specific written permission.
19 DISCLAIMER
21 This software is provided 'as is' with no explicit or implied warranties
22 in respect of its properties, including, but not limited to, correctness
23 and/or fitness for purpose.
24 ---------------------------------------------------------------------------
25 Issue Date: 01/08/2005
28 #ifndef _SHA2_H
29 #define _SHA2_H
31 #include "Common/Tcdefs.h"
32 #include "Common/Endian.h"
34 #define SHA_64BIT
36 /* define the hash functions that you need */
37 #define SHA_2 /* for dynamic hash length */
38 #define SHA_224
39 #define SHA_256
40 #ifdef SHA_64BIT
41 # define SHA_384
42 # define SHA_512
43 # define NEED_UINT_64T
44 #endif
46 #ifndef EXIT_SUCCESS
47 #define EXIT_SUCCESS 0
48 #define EXIT_FAILURE 1
49 #endif
51 #define li_64(h) 0x##h##ull
53 #define VOID_RETURN void
54 #define INT_RETURN int
56 #if defined(__cplusplus)
57 extern "C"
59 #endif
61 /* Note that the following function prototypes are the same */
62 /* for both the bit and byte oriented implementations. But */
63 /* the length fields are in bytes or bits as is appropriate */
64 /* for the version used. Bit sequences are arrays of bytes */
65 /* in which bit sequence indexes increase from the most to */
66 /* the least significant end of each byte */
68 #define SHA224_DIGEST_SIZE 28
69 #define SHA224_BLOCK_SIZE 64
70 #define SHA256_DIGEST_SIZE 32
71 #define SHA256_BLOCK_SIZE 64
73 /* type to hold the SHA256 (and SHA224) context */
75 typedef struct
76 { uint_32t count[2];
77 uint_32t hash[8];
78 uint_32t wbuf[16];
79 } sha256_ctx;
81 typedef sha256_ctx sha224_ctx;
83 VOID_RETURN sha256_compile(sha256_ctx ctx[1]);
85 VOID_RETURN sha224_begin(sha224_ctx ctx[1]);
86 #define sha224_hash sha256_hash
87 VOID_RETURN sha224_end(unsigned char hval[], sha224_ctx ctx[1]);
88 VOID_RETURN sha224(unsigned char hval[], const unsigned char data[], unsigned long len);
90 VOID_RETURN sha256_begin(sha256_ctx ctx[1]);
91 VOID_RETURN sha256_hash(const unsigned char data[], unsigned long len, sha256_ctx ctx[1]);
92 VOID_RETURN sha256_end(unsigned char hval[], sha256_ctx ctx[1]);
93 VOID_RETURN sha256(unsigned char hval[], const unsigned char data[], unsigned long len);
95 #ifndef SHA_64BIT
97 typedef struct
98 { union
99 { sha256_ctx ctx256[1];
100 } uu[1];
101 uint_32t sha2_len;
102 } sha2_ctx;
104 #define SHA2_MAX_DIGEST_SIZE SHA256_DIGEST_SIZE
106 #else
108 #define SHA384_DIGEST_SIZE 48
109 #define SHA384_BLOCK_SIZE 128
110 #define SHA512_DIGEST_SIZE 64
111 #define SHA512_BLOCK_SIZE 128
112 #define SHA2_MAX_DIGEST_SIZE SHA512_DIGEST_SIZE
114 /* type to hold the SHA384 (and SHA512) context */
116 typedef struct
117 { uint_64t count[2];
118 uint_64t hash[8];
119 uint_64t wbuf[16];
120 } sha512_ctx;
122 typedef sha512_ctx sha384_ctx;
124 typedef struct
125 { union
126 { sha256_ctx ctx256[1];
127 sha512_ctx ctx512[1];
128 } uu[1];
129 uint_32t sha2_len;
130 } sha2_ctx;
132 VOID_RETURN sha512_compile(sha512_ctx ctx[1]);
134 VOID_RETURN sha384_begin(sha384_ctx ctx[1]);
135 #define sha384_hash sha512_hash
136 VOID_RETURN sha384_end(unsigned char hval[], sha384_ctx ctx[1]);
137 VOID_RETURN sha384(unsigned char hval[], const unsigned char data[], unsigned long len);
139 VOID_RETURN sha512_begin(sha512_ctx ctx[1]);
140 VOID_RETURN sha512_hash(const unsigned char data[], unsigned long len, sha512_ctx ctx[1]);
141 VOID_RETURN sha512_end(unsigned char hval[], sha512_ctx ctx[1]);
142 VOID_RETURN sha512(unsigned char hval[], const unsigned char data[], unsigned long len);
144 INT_RETURN sha2_begin(unsigned long size, sha2_ctx ctx[1]);
145 VOID_RETURN sha2_hash(const unsigned char data[], unsigned long len, sha2_ctx ctx[1]);
146 VOID_RETURN sha2_end(unsigned char hval[], sha2_ctx ctx[1]);
147 INT_RETURN sha2(unsigned char hval[], unsigned long size, const unsigned char data[], unsigned long len);
149 #endif
151 #if defined(__cplusplus)
153 #endif
155 #endif