1bf215546Sopenharmony_ci/* $OpenBSD: sha1.h,v 1.24 2012/12/05 23:19:57 deraadt Exp $ */ 2bf215546Sopenharmony_ci 3bf215546Sopenharmony_ci/* 4bf215546Sopenharmony_ci * SHA-1 in C 5bf215546Sopenharmony_ci * By Steve Reid <steve@edmweb.com> 6bf215546Sopenharmony_ci * 100% Public Domain 7bf215546Sopenharmony_ci */ 8bf215546Sopenharmony_ci 9bf215546Sopenharmony_ci#ifndef _SHA1_H 10bf215546Sopenharmony_ci#define _SHA1_H 11bf215546Sopenharmony_ci 12bf215546Sopenharmony_ci#include <stddef.h> 13bf215546Sopenharmony_ci#include <stdint.h> 14bf215546Sopenharmony_ci 15bf215546Sopenharmony_ci#define SHA1_BLOCK_LENGTH 64 16bf215546Sopenharmony_ci#define SHA1_DIGEST_LENGTH 20 17bf215546Sopenharmony_ci#define SHA1_DIGEST_STRING_LENGTH (SHA1_DIGEST_LENGTH * 2 + 1) 18bf215546Sopenharmony_ci 19bf215546Sopenharmony_ci#ifdef __cplusplus 20bf215546Sopenharmony_ciextern "C" { 21bf215546Sopenharmony_ci#endif 22bf215546Sopenharmony_ci 23bf215546Sopenharmony_citypedef struct _SHA1_CTX { 24bf215546Sopenharmony_ci uint32_t state[5]; 25bf215546Sopenharmony_ci uint64_t count; 26bf215546Sopenharmony_ci uint8_t buffer[SHA1_BLOCK_LENGTH]; 27bf215546Sopenharmony_ci} SHA1_CTX; 28bf215546Sopenharmony_ci 29bf215546Sopenharmony_civoid SHA1Init(SHA1_CTX *); 30bf215546Sopenharmony_civoid SHA1Pad(SHA1_CTX *); 31bf215546Sopenharmony_civoid SHA1Transform(uint32_t [5], const uint8_t [SHA1_BLOCK_LENGTH]); 32bf215546Sopenharmony_civoid SHA1Update(SHA1_CTX *, const uint8_t *, size_t); 33bf215546Sopenharmony_civoid SHA1Final(uint8_t [SHA1_DIGEST_LENGTH], SHA1_CTX *); 34bf215546Sopenharmony_ci 35bf215546Sopenharmony_ci#define HTONDIGEST(x) do { \ 36bf215546Sopenharmony_ci x[0] = htonl(x[0]); \ 37bf215546Sopenharmony_ci x[1] = htonl(x[1]); \ 38bf215546Sopenharmony_ci x[2] = htonl(x[2]); \ 39bf215546Sopenharmony_ci x[3] = htonl(x[3]); \ 40bf215546Sopenharmony_ci x[4] = htonl(x[4]); } while (0) 41bf215546Sopenharmony_ci 42bf215546Sopenharmony_ci#define NTOHDIGEST(x) do { \ 43bf215546Sopenharmony_ci x[0] = ntohl(x[0]); \ 44bf215546Sopenharmony_ci x[1] = ntohl(x[1]); \ 45bf215546Sopenharmony_ci x[2] = ntohl(x[2]); \ 46bf215546Sopenharmony_ci x[3] = ntohl(x[3]); \ 47bf215546Sopenharmony_ci x[4] = ntohl(x[4]); } while (0) 48bf215546Sopenharmony_ci 49bf215546Sopenharmony_ci#ifdef __cplusplus 50bf215546Sopenharmony_ci} 51bf215546Sopenharmony_ci#endif 52bf215546Sopenharmony_ci 53bf215546Sopenharmony_ci#endif /* _SHA1_H */ 54