1 /* $MirOS: src/include/sha1.h,v 1.3 2014/03/05 14:07:26 tg Exp $ */ 2 /* $OpenBSD: sha1.h,v 1.23 2004/06/22 01:57:30 jfb Exp $ */ 3 4 /* 5 * SHA-1 in C 6 * By Steve Reid <steve@edmweb.com> 7 * 100% Public Domain 8 */ 9 10 #ifndef _SHA1_H 11 #define _SHA1_H 12 13 #define SHA1_BLOCK_LENGTH 64 14 #define SHA1_DIGEST_LENGTH 20 15 #define SHA1_DIGEST_STRING_LENGTH (SHA1_DIGEST_LENGTH * 2 + 1) 16 17 typedef struct { 18 u_int32_t state[5]; 19 u_int64_t count; 20 u_int8_t buffer[SHA1_BLOCK_LENGTH]; 21 } SHA1_CTX; 22 23 #include <sys/cdefs.h> 24 25 __BEGIN_DECLS 26 void SHA1Init(SHA1_CTX *); 27 void SHA1Pad(SHA1_CTX *); 28 void SHA1Transform(u_int32_t *, const u_int8_t *) 29 __attribute__((__bounded__(__minbytes__, 1, 20))) 30 __attribute__((__bounded__(__minbytes__, 2, SHA1_BLOCK_LENGTH))); 31 void SHA1Update(SHA1_CTX *, const u_int8_t *, size_t) 32 __attribute__((__bounded__(__string__, 2, 3))); 33 void SHA1Final(u_int8_t *, SHA1_CTX *) 34 __attribute__((__bounded__(__minbytes__, 1, SHA1_DIGEST_LENGTH))); 35 char *SHA1End(SHA1_CTX *, char *) 36 __attribute__((__bounded__(__minbytes__, 2, SHA1_DIGEST_STRING_LENGTH))); 37 char *SHA1File(const char *, char *) 38 __attribute__((__bounded__(__minbytes__, 2, SHA1_DIGEST_STRING_LENGTH))); 39 char *SHA1FileChunk(const char *, char *, off_t, off_t) 40 __attribute__((__bounded__(__minbytes__, 2, SHA1_DIGEST_STRING_LENGTH))); 41 char *SHA1Data(const u_int8_t *, size_t, char *) 42 __attribute__((__bounded__(__string__, 1, 2))) 43 __attribute__((__bounded__(__minbytes__, 3, SHA1_DIGEST_STRING_LENGTH))); 44 __END_DECLS 45 46 #define HTONDIGEST(x) do { \ 47 x[0] = htonl(x[0]); \ 48 x[1] = htonl(x[1]); \ 49 x[2] = htonl(x[2]); \ 50 x[3] = htonl(x[3]); \ 51 x[4] = htonl(x[4]); } while (0) 52 53 #define NTOHDIGEST(x) do { \ 54 x[0] = ntohl(x[0]); \ 55 x[1] = ntohl(x[1]); \ 56 x[2] = ntohl(x[2]); \ 57 x[3] = ntohl(x[3]); \ 58 x[4] = ntohl(x[4]); } while (0) 59 60 #endif /* _SHA1_H */ 61