diff options
Diffstat (limited to '3rd_party/libsrp6a-sha512/t_sha.h')
| -rw-r--r-- | 3rd_party/libsrp6a-sha512/t_sha.h | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/3rd_party/libsrp6a-sha512/t_sha.h b/3rd_party/libsrp6a-sha512/t_sha.h new file mode 100644 index 0000000..2e38067 --- /dev/null +++ b/3rd_party/libsrp6a-sha512/t_sha.h | |||
| @@ -0,0 +1,147 @@ | |||
| 1 | #ifndef T_SHA_H | ||
| 2 | #define T_SHA_H | ||
| 3 | |||
| 4 | #if !defined(P) | ||
| 5 | #ifdef __STDC__ | ||
| 6 | #define P(x) x | ||
| 7 | #else | ||
| 8 | #define P(x) () | ||
| 9 | #endif | ||
| 10 | #endif | ||
| 11 | |||
| 12 | #define SHA_DIGESTSIZE 20 | ||
| 13 | |||
| 14 | #ifdef OPENSSL | ||
| 15 | #define OPENSSL_SHA 1 | ||
| 16 | #endif | ||
| 17 | |||
| 18 | #ifdef TOMCRYPT | ||
| 19 | # include <tomcrypt.h> | ||
| 20 | # ifdef SHA1 | ||
| 21 | # define TOMCRYPT_SHA 1 | ||
| 22 | # endif | ||
| 23 | #endif | ||
| 24 | |||
| 25 | #ifdef CRYPTOLIB | ||
| 26 | /* The SHA (shs) implementation in CryptoLib 1.x breaks when Update | ||
| 27 | * is called multiple times, so we still use our own code. | ||
| 28 | * Uncomment below if you think your copy of CryptoLib is fixed. */ | ||
| 29 | /*#define CRYPTOLIB_SHA 1*/ | ||
| 30 | #endif | ||
| 31 | |||
| 32 | #ifdef GCRYPT | ||
| 33 | # define GCRYPT_SHA 1 | ||
| 34 | #endif | ||
| 35 | |||
| 36 | #ifdef MBEDTLS | ||
| 37 | # define MBEDTLS_SHA 1 | ||
| 38 | #endif | ||
| 39 | |||
| 40 | #ifdef OPENSSL_SHA | ||
| 41 | #include <openssl/err.h> | ||
| 42 | #if OPENSSL_VERSION_NUMBER >= 0x30000000L | ||
| 43 | #include <openssl/evp.h> | ||
| 44 | |||
| 45 | typedef EVP_MD_CTX* SHA1_CTX; | ||
| 46 | #define SHA1Init SHA1Init_openssl | ||
| 47 | #define SHA1Update SHA1Update_openssl | ||
| 48 | #define SHA1Final SHA1Final_openssl | ||
| 49 | |||
| 50 | typedef EVP_MD_CTX* SHA512_CTX; | ||
| 51 | #define SHA512Init SHA512Init_openssl | ||
| 52 | #define SHA512Update SHA512Update_openssl | ||
| 53 | #define SHA512Final SHA512Final_openssl | ||
| 54 | |||
| 55 | void SHA1Init_openssl(SHA1_CTX *ctx); | ||
| 56 | void SHA1Update_openssl(SHA1_CTX *ctx, const void *data, unsigned int len); | ||
| 57 | void SHA1Final_openssl(unsigned char digest[20], SHA1_CTX *ctx); | ||
| 58 | |||
| 59 | void SHA512Init_openssl(SHA512_CTX *ctx); | ||
| 60 | void SHA512Update_openssl(SHA512_CTX *ctx, const void *data, unsigned int len); | ||
| 61 | void SHA512Final_openssl(unsigned char digest[64], SHA1_CTX *ctx); | ||
| 62 | #else /* for OpenSSL < 3.0 */ | ||
| 63 | #include <openssl/sha.h> | ||
| 64 | |||
| 65 | typedef SHA_CTX SHA1_CTX; | ||
| 66 | #define SHA1Init SHA1_Init | ||
| 67 | #define SHA1Update SHA1_Update | ||
| 68 | #define SHA1Final SHA1_Final | ||
| 69 | |||
| 70 | #define SHA512Init SHA512_Init | ||
| 71 | #define SHA512Update SHA512_Update | ||
| 72 | #define SHA512Final SHA512_Final | ||
| 73 | #endif /* for OpenSSL < 3.0 */ | ||
| 74 | #elif defined(TOMCRYPT_SHA) | ||
| 75 | /* mycrypt.h already included above */ | ||
| 76 | |||
| 77 | typedef hash_state SHA1_CTX; | ||
| 78 | #define SHA1Init sha1_init | ||
| 79 | #define SHA1Update sha1_process | ||
| 80 | #define SHA1Final(D,C) sha1_done(C,D) | ||
| 81 | |||
| 82 | #elif defined(GCRYPT_SHA) | ||
| 83 | #include "gcrypt.h" | ||
| 84 | |||
| 85 | typedef gcry_md_hd_t SHA1_CTX; | ||
| 86 | #define SHA1Init SHA1Init_gcry | ||
| 87 | #define SHA1Update SHA1Update_gcry | ||
| 88 | #define SHA1Final SHA1Final_gcry | ||
| 89 | typedef gcry_md_hd_t SHA512_CTX; | ||
| 90 | #define SHA512Init SHA512Init_gcry | ||
| 91 | #define SHA512Update SHA512Update_gcry | ||
| 92 | #define SHA512Final SHA512Final_gcry | ||
| 93 | |||
| 94 | void SHA1Init_gcry(SHA1_CTX * ctx); | ||
| 95 | void SHA1Update_gcry(SHA1_CTX * ctx, const void *data, unsigned int len); | ||
| 96 | void SHA1Final_gcry(unsigned char digest[20], SHA1_CTX * ctx); | ||
| 97 | |||
| 98 | void SHA512Init_gcry(SHA512_CTX * ctx); | ||
| 99 | void SHA512Update_gcry(SHA512_CTX * ctx, const void *data, unsigned int len); | ||
| 100 | void SHA512Final_gcry(unsigned char digest[64], SHA512_CTX * ctx); | ||
| 101 | |||
| 102 | #elif defined(MBEDTLS_SHA) | ||
| 103 | #include <mbedtls/md.h> | ||
| 104 | |||
| 105 | typedef mbedtls_md_context_t SHA1_CTX; | ||
| 106 | #define SHA1Init SHA1Init_mbed | ||
| 107 | #define SHA1Update SHA1Update_mbed | ||
| 108 | #define SHA1Final SHA1Final_mbed | ||
| 109 | |||
| 110 | typedef mbedtls_md_context_t SHA512_CTX; | ||
| 111 | #define SHA512Init SHA512Init_mbed | ||
| 112 | #define SHA512Update SHA512Update_mbed | ||
| 113 | #define SHA512Final SHA512Final_mbed | ||
| 114 | |||
| 115 | void SHA1Init_mbed(SHA1_CTX * ctx); | ||
| 116 | void SHA1Update_mbed(SHA1_CTX * ctx, const void *data, unsigned int len); | ||
| 117 | void SHA1Final_mbed(unsigned char digest[20], SHA1_CTX * ctx); | ||
| 118 | |||
| 119 | void SHA512Init_mbed(SHA512_CTX * ctx); | ||
| 120 | void SHA512Update_mbed(SHA512_CTX * ctx, const void *data, unsigned int len); | ||
| 121 | void SHA512Final_mbed(unsigned char digest[64], SHA512_CTX * ctx); | ||
| 122 | |||
| 123 | #elif defined(CRYPTOLIB_SHA) | ||
| 124 | #include "libcrypt.h" | ||
| 125 | |||
| 126 | typedef SHS_CTX SHA1_CTX; | ||
| 127 | #define SHA1Init shsInit | ||
| 128 | #define SHA1Update shsUpdate | ||
| 129 | #define SHA1Final shsFinalBytes | ||
| 130 | |||
| 131 | void shsFinalBytes P((unsigned char digest[20], SHS_CTX* context)); | ||
| 132 | |||
| 133 | #else | ||
| 134 | typedef unsigned int uint32; | ||
| 135 | |||
| 136 | typedef struct { | ||
| 137 | uint32 state[5]; | ||
| 138 | uint32 count[2]; | ||
| 139 | unsigned char buffer[64]; | ||
| 140 | } SHA1_CTX; | ||
| 141 | |||
| 142 | void SHA1Init P((SHA1_CTX* context)); | ||
| 143 | void SHA1Update P((SHA1_CTX* context, const unsigned char* data, unsigned int len)); | ||
| 144 | void SHA1Final P((unsigned char digest[20], SHA1_CTX* context)); | ||
| 145 | #endif /* !OPENSSL && !CRYPTOLIB */ | ||
| 146 | |||
| 147 | #endif /* T_SHA_H */ | ||
