00001 /* 00002 --------------------------------------------------------------------------- 00003 Copyright (c) 2002, Dr Brian Gladman, Worcester, UK. All rights reserved. 00004 00005 LICENSE TERMS 00006 00007 The free distribution and use of this software in both source and binary 00008 form is allowed (with or without changes) provided that: 00009 00010 1. distributions of this source code include the above copyright 00011 notice, this list of conditions and the following disclaimer; 00012 00013 2. distributions in binary form include the above copyright 00014 notice, this list of conditions and the following disclaimer 00015 in the documentation and/or other associated materials; 00016 00017 3. the copyright holder's name is not used to endorse products 00018 built using this software without specific written permission. 00019 00020 ALTERNATIVELY, provided that this notice is retained in full, this product 00021 may be distributed under the terms of the GNU General Public License (GPL), 00022 in which case the provisions of the GPL apply INSTEAD OF those given above. 00023 00024 DISCLAIMER 00025 00026 This software is provided 'as is' with no explicit or implied warranties 00027 in respect of its properties, including, but not limited to, correctness 00028 and/or fitness for purpose. 00029 --------------------------------------------------------------------------- 00030 Issue Date: 26/08/2003 00031 */ 00032 00033 #ifndef _SHA1_H 00034 #define _SHA1_H 00035 00036 #include <limits.h> 00037 00038 #define SHA1_BLOCK_SIZE 64 00039 #define SHA1_DIGEST_SIZE 20 00040 00041 #if defined(__cplusplus) 00042 extern "C" 00043 { 00044 #endif 00045 00046 /* define an unsigned 32-bit type */ 00047 00048 #if defined(_MSC_VER) 00049 typedef unsigned long sha1_32t; 00050 #elif defined(ULONG_MAX) && ULONG_MAX == 0xfffffffful 00051 typedef unsigned long sha1_32t; 00052 #elif defined(UINT_MAX) && UINT_MAX == 0xffffffff 00053 typedef unsigned int sha1_32t; 00054 #else 00055 # error Please define sha1_32t as an unsigned 32 bit type in sha1.h 00056 #endif 00057 00058 /* type to hold the SHA256 context */ 00059 00060 typedef struct 00061 { sha1_32t count[2]; 00062 sha1_32t hash[5]; 00063 sha1_32t wbuf[16]; 00064 } sha1_ctx; 00065 00066 /* Note that these prototypes are the same for both bit and */ 00067 /* byte oriented implementations. However the length fields */ 00068 /* are in bytes or bits as appropriate for the version used */ 00069 /* and bit sequences are input as arrays of bytes in which */ 00070 /* bit sequences run from the most to the least significant */ 00071 /* end of each byte */ 00072 00073 void sha1_compile(sha1_ctx ctx[1]); 00074 00075 void sha1_begin(sha1_ctx ctx[1]); 00076 void sha1_hash(const unsigned char data[], unsigned long len, sha1_ctx ctx[1]); 00077 void sha1_end(unsigned char hval[], sha1_ctx ctx[1]); 00078 void sha1(unsigned char hval[], const unsigned char data[], unsigned long len); 00079 00080 #if defined(__cplusplus) 00081 } 00082 #endif 00083 00084 #endif