00001 #ifndef SHA1SUM_H
00002 #define SHA1SUM_H
00003
00004 #include <stdio.h>
00005 #include <stdlib.h>
00006 #include <string.h>
00007 #include <assert.h>
00008 #include <errno.h>
00009
00010 #undef BIG_ENDIAN_HOST
00011 typedef unsigned int u32;
00012
00013
00014
00015
00016 #if defined(__GNUC__) && defined(__i386__)
00017 static inline u32 rol( u32 x, int n)
00018 {
00019 __asm__("roll %%cl,%0"
00020 :"=r" (x)
00021 :"0" (x),"c" (n));
00022 return x;
00023 }
00024 #else
00025 #define rol(x,n) (((x) << (n)) | ((x) >> (32-(n))))
00026 #endif
00027
00028 typedef struct {
00029 u32 h0,h1,h2,h3,h4;
00030 u32 nblocks;
00031 unsigned char buf[64];
00032 int count;
00033 } SHA1_CONTEXT;
00034
00035 #define K1 0x5A827999L
00036 #define K2 0x6ED9EBA1L
00037 #define K3 0x8F1BBCDCL
00038 #define K4 0xCA62C1D6L
00039 #define F1(x,y,z) (z ^ (x & (y ^ z)))
00040 #define F2(x,y,z) (x ^ y ^ z)
00041 #define F3(x,y,z) ((x & y) | (z & (x | y)))
00042 #define F4(x,y,z) (x ^ y ^ z)
00043
00044
00045 #define M(i) (tm = x[i & 0x0f] ^ x[(i - 14) & 0x0f] \
00046 ^ x[(i - 8) & 0x0f] ^ x[( i - 3) & 0x0f] \
00047 , (x[i & 0x0f] = rol(tm, 1)))
00048
00049 #define R(a, b, c, d, e, f, k, m) do {e += rol(a, 5) \
00050 + f(b, c, d) \
00051 + k \
00052 + m; \
00053 b = rol(b, 30); \
00054 } while(0)
00055
00056
00057
00058
00059 void transform(SHA1_CONTEXT *hd, unsigned char *data);
00060
00061
00062
00063
00064 void sha1_write(SHA1_CONTEXT *hd, unsigned char *inbuf, size_t inlen);
00065
00066 void sha1_final(SHA1_CONTEXT *hd);
00067
00068 int sha1sum(char *file_name, SHA1_CONTEXT *ctx);
00069
00070 #endif