2 ---------------------------------------------------------------------------
3 Copyright (c) 2002, Dr Brian Gladman, Worcester, UK. All rights reserved.
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.
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
31 #include "Common/Tcdefs.h"
32 #include "Common/Endian.h"
36 /* define the hash functions that you need */
37 #define SHA_2 /* for dynamic hash length */
43 # define NEED_UINT_64T
47 #define EXIT_SUCCESS 0
48 #define EXIT_FAILURE 1
51 #define li_64(h) 0x##h##ull
53 #define VOID_RETURN void
54 #define INT_RETURN int
56 #if defined(__cplusplus)
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 */
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
);
99 { sha256_ctx ctx256
[1];
104 #define SHA2_MAX_DIGEST_SIZE SHA256_DIGEST_SIZE
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 */
122 typedef sha512_ctx sha384_ctx
;
126 { sha256_ctx ctx256
[1];
127 sha512_ctx ctx512
[1];
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
);
151 #if defined(__cplusplus)