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