| 1 | /* Sha256.h -- SHA-256 Hash\r |
| 2 | 2021-01-01 : Igor Pavlov : Public domain */\r |
| 3 | \r |
| 4 | #ifndef __7Z_SHA256_H\r |
| 5 | #define __7Z_SHA256_H\r |
| 6 | \r |
| 7 | #include "7zTypes.h"\r |
| 8 | \r |
| 9 | EXTERN_C_BEGIN\r |
| 10 | \r |
| 11 | #define SHA256_NUM_BLOCK_WORDS 16\r |
| 12 | #define SHA256_NUM_DIGEST_WORDS 8\r |
| 13 | \r |
| 14 | #define SHA256_BLOCK_SIZE (SHA256_NUM_BLOCK_WORDS * 4)\r |
| 15 | #define SHA256_DIGEST_SIZE (SHA256_NUM_DIGEST_WORDS * 4)\r |
| 16 | \r |
| 17 | typedef void (MY_FAST_CALL *SHA256_FUNC_UPDATE_BLOCKS)(UInt32 state[8], const Byte *data, size_t numBlocks);\r |
| 18 | \r |
| 19 | /*\r |
| 20 | if (the system supports different SHA256 code implementations)\r |
| 21 | {\r |
| 22 | (CSha256::func_UpdateBlocks) will be used\r |
| 23 | (CSha256::func_UpdateBlocks) can be set by\r |
| 24 | Sha256_Init() - to default (fastest)\r |
| 25 | Sha256_SetFunction() - to any algo\r |
| 26 | }\r |
| 27 | else\r |
| 28 | {\r |
| 29 | (CSha256::func_UpdateBlocks) is ignored.\r |
| 30 | }\r |
| 31 | */\r |
| 32 | \r |
| 33 | typedef struct\r |
| 34 | {\r |
| 35 | SHA256_FUNC_UPDATE_BLOCKS func_UpdateBlocks;\r |
| 36 | UInt64 count;\r |
| 37 | UInt64 __pad_2[2];\r |
| 38 | UInt32 state[SHA256_NUM_DIGEST_WORDS];\r |
| 39 | \r |
| 40 | Byte buffer[SHA256_BLOCK_SIZE];\r |
| 41 | } CSha256;\r |
| 42 | \r |
| 43 | \r |
| 44 | #define SHA256_ALGO_DEFAULT 0\r |
| 45 | #define SHA256_ALGO_SW 1\r |
| 46 | #define SHA256_ALGO_HW 2\r |
| 47 | \r |
| 48 | /*\r |
| 49 | Sha256_SetFunction()\r |
| 50 | return:\r |
| 51 | 0 - (algo) value is not supported, and func_UpdateBlocks was not changed\r |
| 52 | 1 - func_UpdateBlocks was set according (algo) value.\r |
| 53 | */\r |
| 54 | \r |
| 55 | BoolInt Sha256_SetFunction(CSha256 *p, unsigned algo);\r |
| 56 | \r |
| 57 | void Sha256_InitState(CSha256 *p);\r |
| 58 | void Sha256_Init(CSha256 *p);\r |
| 59 | void Sha256_Update(CSha256 *p, const Byte *data, size_t size);\r |
| 60 | void Sha256_Final(CSha256 *p, Byte *digest);\r |
| 61 | \r |
| 62 | \r |
| 63 | \r |
| 64 | \r |
| 65 | // void MY_FAST_CALL Sha256_UpdateBlocks(UInt32 state[8], const Byte *data, size_t numBlocks);\r |
| 66 | \r |
| 67 | /*\r |
| 68 | call Sha256Prepare() once at program start.\r |
| 69 | It prepares all supported implementations, and detects the fastest implementation.\r |
| 70 | */\r |
| 71 | \r |
| 72 | void Sha256Prepare(void);\r |
| 73 | \r |
| 74 | EXTERN_C_END\r |
| 75 | \r |
| 76 | #endif\r |