1 /* 2 * Copyright 2014-2022 The GmSSL Project. All Rights Reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the License); you may 5 * not use this file except in compliance with the License. 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 */ 9 10 11 #ifndef GMSSL_SHA1_H 12 #define GMSSL_SHA1_H 13 14 #include <string.h> 15 #include <stdint.h> 16 17 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 21 22 #define SHA1_IS_BIG_ENDIAN 1 23 24 #define SHA1_DIGEST_SIZE 20 25 #define SHA1_BLOCK_SIZE 64 26 #define SHA1_STATE_WORDS (SHA1_DIGEST_SIZE/sizeof(uint32_t)) 27 28 29 typedef struct { 30 uint32_t state[SHA1_STATE_WORDS]; 31 uint64_t nblocks; 32 uint8_t block[SHA1_BLOCK_SIZE]; 33 size_t num; 34 } SHA1_CTX; 35 36 void sha1_init(SHA1_CTX *ctx); 37 void sha1_update(SHA1_CTX *ctx, const uint8_t *data, size_t datalen); 38 void sha1_finish(SHA1_CTX *ctx, uint8_t dgst[SHA1_DIGEST_SIZE]); 39 void sha1_digest(const uint8_t *data, size_t datalen, uint8_t dgst[SHA1_DIGEST_SIZE]); 40 41 42 #ifdef __cplusplus 43 } 44 #endif 45 #endif 46