|
|
1.1 ! root 1: /* ! 2: --------------------------------------------------------------------------- ! 3: Copyright (c) 2002, Dr Brian Gladman, Worcester, UK. All rights reserved. ! 4: ! 5: LICENSE TERMS ! 6: ! 7: The free distribution and use of this software in both source and binary ! 8: form is allowed (with or without changes) provided that: ! 9: ! 10: 1. distributions of this source code include the above copyright ! 11: notice, this list of conditions and the following disclaimer; ! 12: ! 13: 2. distributions in binary form include the above copyright ! 14: notice, this list of conditions and the following disclaimer ! 15: in the documentation and/or other associated materials; ! 16: ! 17: 3. the copyright holder's name is not used to endorse products ! 18: built using this software without specific written permission. ! 19: ! 20: ALTERNATIVELY, provided that this notice is retained in full, this product ! 21: may be distributed under the terms of the GNU General Public License (GPL), ! 22: in which case the provisions of the GPL apply INSTEAD OF those given above. ! 23: ! 24: DISCLAIMER ! 25: ! 26: This software is provided 'as is' with no explicit or implied warranties ! 27: in respect of its properties, including, but not limited to, correctness ! 28: and/or fitness for purpose. ! 29: --------------------------------------------------------------------------- ! 30: Issue Date: 01/08/2005 ! 31: */ ! 32: ! 33: #ifndef _SHA2_H ! 34: #define _SHA2_H ! 35: ! 36: #include "Common/Tcdefs.h" ! 37: #include "Common/Endian.h" ! 38: ! 39: #define SHA_64BIT ! 40: ! 41: /* define the hash functions that you need */ ! 42: #define SHA_2 /* for dynamic hash length */ ! 43: #define SHA_224 ! 44: #define SHA_256 ! 45: #ifdef SHA_64BIT ! 46: # define SHA_384 ! 47: # define SHA_512 ! 48: # define NEED_UINT_64T ! 49: #endif ! 50: ! 51: #ifndef EXIT_SUCCESS ! 52: #define EXIT_SUCCESS 0 ! 53: #define EXIT_FAILURE 1 ! 54: #endif ! 55: ! 56: #define li_64(h) 0x##h##ull ! 57: ! 58: #define VOID_RETURN void ! 59: #define INT_RETURN int ! 60: ! 61: #if defined(__cplusplus) ! 62: extern "C" ! 63: { ! 64: #endif ! 65: ! 66: /* Note that the following function prototypes are the same */ ! 67: /* for both the bit and byte oriented implementations. But */ ! 68: /* the length fields are in bytes or bits as is appropriate */ ! 69: /* for the version used. Bit sequences are arrays of bytes */ ! 70: /* in which bit sequence indexes increase from the most to */ ! 71: /* the least significant end of each byte */ ! 72: ! 73: #define SHA224_DIGEST_SIZE 28 ! 74: #define SHA224_BLOCK_SIZE 64 ! 75: #define SHA256_DIGEST_SIZE 32 ! 76: #define SHA256_BLOCK_SIZE 64 ! 77: ! 78: /* type to hold the SHA256 (and SHA224) context */ ! 79: ! 80: typedef struct ! 81: { uint_32t count[2]; ! 82: uint_32t hash[8]; ! 83: uint_32t wbuf[16]; ! 84: } sha256_ctx; ! 85: ! 86: typedef sha256_ctx sha224_ctx; ! 87: ! 88: VOID_RETURN sha256_compile(sha256_ctx ctx[1]); ! 89: ! 90: VOID_RETURN sha224_begin(sha224_ctx ctx[1]); ! 91: #define sha224_hash sha256_hash ! 92: VOID_RETURN sha224_end(unsigned char hval[], sha224_ctx ctx[1]); ! 93: VOID_RETURN sha224(unsigned char hval[], const unsigned char data[], unsigned long len); ! 94: ! 95: VOID_RETURN sha256_begin(sha256_ctx ctx[1]); ! 96: VOID_RETURN sha256_hash(const unsigned char data[], unsigned long len, sha256_ctx ctx[1]); ! 97: VOID_RETURN sha256_end(unsigned char hval[], sha256_ctx ctx[1]); ! 98: VOID_RETURN sha256(unsigned char hval[], const unsigned char data[], unsigned long len); ! 99: ! 100: #ifndef SHA_64BIT ! 101: ! 102: typedef struct ! 103: { union ! 104: { sha256_ctx ctx256[1]; ! 105: } uu[1]; ! 106: uint_32t sha2_len; ! 107: } sha2_ctx; ! 108: ! 109: #define SHA2_MAX_DIGEST_SIZE SHA256_DIGEST_SIZE ! 110: ! 111: #else ! 112: ! 113: #define SHA384_DIGEST_SIZE 48 ! 114: #define SHA384_BLOCK_SIZE 128 ! 115: #define SHA512_DIGEST_SIZE 64 ! 116: #define SHA512_BLOCK_SIZE 128 ! 117: #define SHA2_MAX_DIGEST_SIZE SHA512_DIGEST_SIZE ! 118: ! 119: /* type to hold the SHA384 (and SHA512) context */ ! 120: ! 121: typedef struct ! 122: { uint_64t count[2]; ! 123: uint_64t hash[8]; ! 124: uint_64t wbuf[16]; ! 125: } sha512_ctx; ! 126: ! 127: typedef sha512_ctx sha384_ctx; ! 128: ! 129: typedef struct ! 130: { union ! 131: { sha256_ctx ctx256[1]; ! 132: sha512_ctx ctx512[1]; ! 133: } uu[1]; ! 134: uint_32t sha2_len; ! 135: } sha2_ctx; ! 136: ! 137: VOID_RETURN sha512_compile(sha512_ctx ctx[1]); ! 138: ! 139: VOID_RETURN sha384_begin(sha384_ctx ctx[1]); ! 140: #define sha384_hash sha512_hash ! 141: VOID_RETURN sha384_end(unsigned char hval[], sha384_ctx ctx[1]); ! 142: VOID_RETURN sha384(unsigned char hval[], const unsigned char data[], unsigned long len); ! 143: ! 144: VOID_RETURN sha512_begin(sha512_ctx ctx[1]); ! 145: VOID_RETURN sha512_hash(const unsigned char data[], unsigned long len, sha512_ctx ctx[1]); ! 146: VOID_RETURN sha512_end(unsigned char hval[], sha512_ctx ctx[1]); ! 147: VOID_RETURN sha512(unsigned char hval[], const unsigned char data[], unsigned long len); ! 148: ! 149: INT_RETURN sha2_begin(unsigned long size, sha2_ctx ctx[1]); ! 150: VOID_RETURN sha2_hash(const unsigned char data[], unsigned long len, sha2_ctx ctx[1]); ! 151: VOID_RETURN sha2_end(unsigned char hval[], sha2_ctx ctx[1]); ! 152: INT_RETURN sha2(unsigned char hval[], unsigned long size, const unsigned char data[], unsigned long len); ! 153: ! 154: #endif ! 155: ! 156: #if defined(__cplusplus) ! 157: } ! 158: #endif ! 159: ! 160: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.