/* --------------------------------------------------------------------------- Copyright (c) 2002, Dr Brian Gladman, Worcester, UK. All rights reserved. LICENSE TERMS The free distribution and use of this software is allowed (with or without changes) provided that: 1. source code distributions include the above copyright notice, this list of conditions and the following disclaimer; 2. binary distributions include the above copyright notice, this list of conditions and the following disclaimer in their documentation; 3. the name of the copyright holder is not used to endorse products built using this software without specific written permission. DISCLAIMER This software is provided 'as is' with no explicit or implied warranties in respect of its properties, including, but not limited to, correctness and/or fitness for purpose. --------------------------------------------------------------------------- Issue Date: 01/08/2005 */ #ifndef _SHA2_H #define _SHA2_H #include "Common/Tcdefs.h" #include "Common/Endian.h" #define SHA_64BIT /* define the hash functions that you need */ #define SHA_2 /* for dynamic hash length */ #define SHA_224 #define SHA_256 #ifdef SHA_64BIT # define SHA_384 # define SHA_512 # define NEED_UINT_64T #endif #ifndef EXIT_SUCCESS #define EXIT_SUCCESS 0 #define EXIT_FAILURE 1 #endif #define li_64(h) 0x##h##ull #define VOID_RETURN void #define INT_RETURN int #if defined(__cplusplus) extern "C" { #endif /* Note that the following function prototypes are the same */ /* for both the bit and byte oriented implementations. But */ /* the length fields are in bytes or bits as is appropriate */ /* for the version used. Bit sequences are arrays of bytes */ /* in which bit sequence indexes increase from the most to */ /* the least significant end of each byte */ #define SHA224_DIGEST_SIZE 28 #define SHA224_BLOCK_SIZE 64 #define SHA256_DIGEST_SIZE 32 #define SHA256_BLOCK_SIZE 64 /* type to hold the SHA256 (and SHA224) context */ typedef struct { uint_32t count[2]; uint_32t hash[8]; uint_32t wbuf[16]; } sha256_ctx; typedef sha256_ctx sha224_ctx; VOID_RETURN sha256_compile(sha256_ctx ctx[1]); VOID_RETURN sha224_begin(sha224_ctx ctx[1]); #define sha224_hash sha256_hash VOID_RETURN sha224_end(unsigned char hval[], sha224_ctx ctx[1]); VOID_RETURN sha224(unsigned char hval[], const unsigned char data[], unsigned long len); VOID_RETURN sha256_begin(sha256_ctx ctx[1]); VOID_RETURN sha256_hash(const unsigned char data[], unsigned long len, sha256_ctx ctx[1]); VOID_RETURN sha256_end(unsigned char hval[], sha256_ctx ctx[1]); VOID_RETURN sha256(unsigned char hval[], const unsigned char data[], unsigned long len); #ifndef SHA_64BIT typedef struct { union { sha256_ctx ctx256[1]; } uu[1]; uint_32t sha2_len; } sha2_ctx; #define SHA2_MAX_DIGEST_SIZE SHA256_DIGEST_SIZE #else #define SHA384_DIGEST_SIZE 48 #define SHA384_BLOCK_SIZE 128 #define SHA512_DIGEST_SIZE 64 #define SHA512_BLOCK_SIZE 128 #define SHA2_MAX_DIGEST_SIZE SHA512_DIGEST_SIZE /* type to hold the SHA384 (and SHA512) context */ typedef struct { uint_64t count[2]; uint_64t hash[8]; uint_64t wbuf[16]; } sha512_ctx; typedef sha512_ctx sha384_ctx; typedef struct { union { sha256_ctx ctx256[1]; sha512_ctx ctx512[1]; } uu[1]; uint_32t sha2_len; } sha2_ctx; VOID_RETURN sha512_compile(sha512_ctx ctx[1]); VOID_RETURN sha384_begin(sha384_ctx ctx[1]); #define sha384_hash sha512_hash VOID_RETURN sha384_end(unsigned char hval[], sha384_ctx ctx[1]); VOID_RETURN sha384(unsigned char hval[], const unsigned char data[], unsigned long len); VOID_RETURN sha512_begin(sha512_ctx ctx[1]); VOID_RETURN sha512_hash(const unsigned char data[], unsigned long len, sha512_ctx ctx[1]); VOID_RETURN sha512_end(unsigned char hval[], sha512_ctx ctx[1]); VOID_RETURN sha512(unsigned char hval[], const unsigned char data[], unsigned long len); INT_RETURN sha2_begin(unsigned long size, sha2_ctx ctx[1]); VOID_RETURN sha2_hash(const unsigned char data[], unsigned long len, sha2_ctx ctx[1]); VOID_RETURN sha2_end(unsigned char hval[], sha2_ctx ctx[1]); INT_RETURN sha2(unsigned char hval[], unsigned long size, const unsigned char data[], unsigned long len); #endif #if defined(__cplusplus) } #endif #endif href='#n23'>23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426