Annotation of truecrypt/crypto/sha2.h, revision 1.1.1.2

1.1       root        1: /*
                      2:  ---------------------------------------------------------------------------
                      3:  Copyright (c) 2002, Dr Brian Gladman, Worcester, UK.   All rights reserved.
                      4: 
                      5:  LICENSE TERMS
                      6: 
1.1.1.2 ! root        7:  The free distribution and use of this software is allowed (with or without
        !             8:  changes) provided that:
1.1       root        9: 
1.1.1.2 ! root       10:   1. source code distributions include the above copyright notice, this
        !            11:      list of conditions and the following disclaimer;
1.1       root       12: 
1.1.1.2 ! root       13:   2. binary distributions include the above copyright notice, this list
        !            14:      of conditions and the following disclaimer in their documentation;
        !            15: 
        !            16:   3. the name of the copyright holder is not used to endorse products
        !            17:      built using this software without specific written permission.
1.1       root       18: 
                     19:  DISCLAIMER
                     20: 
                     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
                     26: */
                     27: 
                     28: #ifndef _SHA2_H
                     29: #define _SHA2_H
                     30: 
                     31: #include "Common/Tcdefs.h"
                     32: #include "Common/Endian.h"
                     33: 
                     34: #define SHA_64BIT
                     35: 
                     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
                     45: 
                     46: #ifndef EXIT_SUCCESS
                     47: #define EXIT_SUCCESS    0
                     48: #define EXIT_FAILURE    1
                     49: #endif
                     50: 
                     51: #define li_64(h) 0x##h##ull
                     52: 
                     53: #define VOID_RETURN    void
                     54: #define INT_RETURN     int
                     55: 
                     56: #if defined(__cplusplus)
                     57: extern "C"
                     58: {
                     59: #endif
                     60: 
                     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                   */
                     67: 
                     68: #define SHA224_DIGEST_SIZE  28
                     69: #define SHA224_BLOCK_SIZE   64
                     70: #define SHA256_DIGEST_SIZE  32
                     71: #define SHA256_BLOCK_SIZE   64
                     72: 
                     73: /* type to hold the SHA256 (and SHA224) context */
                     74: 
                     75: typedef struct
                     76: {   uint_32t count[2];
                     77:     uint_32t hash[8];
                     78:     uint_32t wbuf[16];
                     79: } sha256_ctx;
                     80: 
                     81: typedef sha256_ctx  sha224_ctx;
                     82: 
                     83: VOID_RETURN sha256_compile(sha256_ctx ctx[1]);
                     84: 
                     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);
                     89: 
                     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);
                     94: 
                     95: #ifndef SHA_64BIT
                     96: 
                     97: typedef struct
                     98: {   union
                     99:     { sha256_ctx  ctx256[1];
                    100:     } uu[1];
                    101:     uint_32t    sha2_len;
                    102: } sha2_ctx;
                    103: 
                    104: #define SHA2_MAX_DIGEST_SIZE    SHA256_DIGEST_SIZE
                    105: 
                    106: #else
                    107: 
                    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
                    113: 
                    114: /* type to hold the SHA384 (and SHA512) context */
                    115: 
                    116: typedef struct
                    117: {   uint_64t count[2];
                    118:     uint_64t hash[8];
                    119:     uint_64t wbuf[16];
                    120: } sha512_ctx;
                    121: 
                    122: typedef sha512_ctx  sha384_ctx;
                    123: 
                    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;
                    131: 
                    132: VOID_RETURN sha512_compile(sha512_ctx ctx[1]);
                    133: 
                    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);
                    138: 
                    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);
                    143: 
                    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);
                    148: 
                    149: #endif
                    150: 
                    151: #if defined(__cplusplus)
                    152: }
                    153: #endif
                    154: 
                    155: #endif

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.