hirlite 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/LICENSE +28 -0
- data/Rakefile +51 -0
- data/ext/hirlite_ext/extconf.rb +33 -0
- data/ext/hirlite_ext/hirlite_ext.c +14 -0
- data/ext/hirlite_ext/hirlite_ext.h +38 -0
- data/ext/hirlite_ext/rlite.c +351 -0
- data/lib/hirlite/rlite.rb +1 -0
- data/lib/hirlite/version.rb +3 -0
- data/lib/hirlite.rb +2 -0
- data/vendor/rlite/Makefile +6 -0
- data/vendor/rlite/deps/crc64.c +191 -0
- data/vendor/rlite/deps/crc64.h +3 -0
- data/vendor/rlite/deps/endianconv.h +73 -0
- data/vendor/rlite/deps/hyperloglog.c +1547 -0
- data/vendor/rlite/deps/hyperloglog.h +14 -0
- data/vendor/rlite/deps/lzf.h +100 -0
- data/vendor/rlite/deps/lzfP.h +159 -0
- data/vendor/rlite/deps/lzf_c.c +295 -0
- data/vendor/rlite/deps/lzf_d.c +150 -0
- data/vendor/rlite/deps/sha1.c +227 -0
- data/vendor/rlite/deps/sha1.h +19 -0
- data/vendor/rlite/deps/utilfromredis.c +397 -0
- data/vendor/rlite/deps/utilfromredis.h +11 -0
- data/vendor/rlite/src/Makefile +79 -0
- data/vendor/rlite/src/constants.h +15 -0
- data/vendor/rlite/src/dump.c +191 -0
- data/vendor/rlite/src/dump.h +3 -0
- data/vendor/rlite/src/hirlite.c +3985 -0
- data/vendor/rlite/src/hirlite.h +186 -0
- data/vendor/rlite/src/page_btree.c +1556 -0
- data/vendor/rlite/src/page_btree.h +133 -0
- data/vendor/rlite/src/page_key.c +283 -0
- data/vendor/rlite/src/page_key.h +25 -0
- data/vendor/rlite/src/page_list.c +718 -0
- data/vendor/rlite/src/page_list.h +70 -0
- data/vendor/rlite/src/page_long.c +61 -0
- data/vendor/rlite/src/page_long.h +14 -0
- data/vendor/rlite/src/page_multi_string.c +538 -0
- data/vendor/rlite/src/page_multi_string.h +18 -0
- data/vendor/rlite/src/page_skiplist.c +689 -0
- data/vendor/rlite/src/page_skiplist.h +70 -0
- data/vendor/rlite/src/page_string.c +55 -0
- data/vendor/rlite/src/page_string.h +12 -0
- data/vendor/rlite/src/pqsort.c +185 -0
- data/vendor/rlite/src/pqsort.h +40 -0
- data/vendor/rlite/src/restore.c +401 -0
- data/vendor/rlite/src/restore.h +3 -0
- data/vendor/rlite/src/rlite.c +1309 -0
- data/vendor/rlite/src/rlite.h +159 -0
- data/vendor/rlite/src/sort.c +530 -0
- data/vendor/rlite/src/sort.h +18 -0
- data/vendor/rlite/src/status.h +19 -0
- data/vendor/rlite/src/type_hash.c +607 -0
- data/vendor/rlite/src/type_hash.h +29 -0
- data/vendor/rlite/src/type_list.c +477 -0
- data/vendor/rlite/src/type_list.h +23 -0
- data/vendor/rlite/src/type_set.c +796 -0
- data/vendor/rlite/src/type_set.h +34 -0
- data/vendor/rlite/src/type_string.c +613 -0
- data/vendor/rlite/src/type_string.h +34 -0
- data/vendor/rlite/src/type_zset.c +1147 -0
- data/vendor/rlite/src/type_zset.h +50 -0
- data/vendor/rlite/src/util.c +334 -0
- data/vendor/rlite/src/util.h +71 -0
- metadata +151 -0
@@ -0,0 +1,150 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2000-2007 Marc Alexander Lehmann <schmorp@schmorp.de>
|
3
|
+
*
|
4
|
+
* Redistribution and use in source and binary forms, with or without modifica-
|
5
|
+
* tion, are permitted provided that the following conditions are met:
|
6
|
+
*
|
7
|
+
* 1. Redistributions of source code must retain the above copyright notice,
|
8
|
+
* this list of conditions and the following disclaimer.
|
9
|
+
*
|
10
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
11
|
+
* notice, this list of conditions and the following disclaimer in the
|
12
|
+
* documentation and/or other materials provided with the distribution.
|
13
|
+
*
|
14
|
+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
15
|
+
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER-
|
16
|
+
* CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
17
|
+
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE-
|
18
|
+
* CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
19
|
+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
20
|
+
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
21
|
+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH-
|
22
|
+
* ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
23
|
+
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
24
|
+
*
|
25
|
+
* Alternatively, the contents of this file may be used under the terms of
|
26
|
+
* the GNU General Public License ("GPL") version 2 or any later version,
|
27
|
+
* in which case the provisions of the GPL are applicable instead of
|
28
|
+
* the above. If you wish to allow the use of your version of this file
|
29
|
+
* only under the terms of the GPL and not to allow others to use your
|
30
|
+
* version of this file under the BSD license, indicate your decision
|
31
|
+
* by deleting the provisions above and replace them with the notice
|
32
|
+
* and other provisions required by the GPL. If you do not delete the
|
33
|
+
* provisions above, a recipient may use your version of this file under
|
34
|
+
* either the BSD or the GPL.
|
35
|
+
*/
|
36
|
+
|
37
|
+
#include "lzfP.h"
|
38
|
+
|
39
|
+
#if AVOID_ERRNO
|
40
|
+
# define SET_ERRNO(n)
|
41
|
+
#else
|
42
|
+
# include <errno.h>
|
43
|
+
# define SET_ERRNO(n) errno = (n)
|
44
|
+
#endif
|
45
|
+
|
46
|
+
/*
|
47
|
+
#if (__i386 || __amd64) && __GNUC__ >= 3
|
48
|
+
# define lzf_movsb(dst, src, len) \
|
49
|
+
asm ("rep movsb" \
|
50
|
+
: "=D" (dst), "=S" (src), "=c" (len) \
|
51
|
+
: "0" (dst), "1" (src), "2" (len));
|
52
|
+
#endif
|
53
|
+
*/
|
54
|
+
|
55
|
+
unsigned int
|
56
|
+
rl_lzf_decompress (const void *const in_data, unsigned int in_len,
|
57
|
+
void *out_data, unsigned int out_len)
|
58
|
+
{
|
59
|
+
u8 const *ip = (const u8 *)in_data;
|
60
|
+
u8 *op = (u8 *)out_data;
|
61
|
+
u8 const *const in_end = ip + in_len;
|
62
|
+
u8 *const out_end = op + out_len;
|
63
|
+
|
64
|
+
do
|
65
|
+
{
|
66
|
+
unsigned int ctrl = *ip++;
|
67
|
+
|
68
|
+
if (ctrl < (1 << 5)) /* literal run */
|
69
|
+
{
|
70
|
+
ctrl++;
|
71
|
+
|
72
|
+
if (op + ctrl > out_end)
|
73
|
+
{
|
74
|
+
SET_ERRNO (E2BIG);
|
75
|
+
return 0;
|
76
|
+
}
|
77
|
+
|
78
|
+
#if CHECK_INPUT
|
79
|
+
if (ip + ctrl > in_end)
|
80
|
+
{
|
81
|
+
SET_ERRNO (EINVAL);
|
82
|
+
return 0;
|
83
|
+
}
|
84
|
+
#endif
|
85
|
+
|
86
|
+
#ifdef lzf_movsb
|
87
|
+
lzf_movsb (op, ip, ctrl);
|
88
|
+
#else
|
89
|
+
do
|
90
|
+
*op++ = *ip++;
|
91
|
+
while (--ctrl);
|
92
|
+
#endif
|
93
|
+
}
|
94
|
+
else /* back reference */
|
95
|
+
{
|
96
|
+
unsigned int len = ctrl >> 5;
|
97
|
+
|
98
|
+
u8 *ref = op - ((ctrl & 0x1f) << 8) - 1;
|
99
|
+
|
100
|
+
#if CHECK_INPUT
|
101
|
+
if (ip >= in_end)
|
102
|
+
{
|
103
|
+
SET_ERRNO (EINVAL);
|
104
|
+
return 0;
|
105
|
+
}
|
106
|
+
#endif
|
107
|
+
if (len == 7)
|
108
|
+
{
|
109
|
+
len += *ip++;
|
110
|
+
#if CHECK_INPUT
|
111
|
+
if (ip >= in_end)
|
112
|
+
{
|
113
|
+
SET_ERRNO (EINVAL);
|
114
|
+
return 0;
|
115
|
+
}
|
116
|
+
#endif
|
117
|
+
}
|
118
|
+
|
119
|
+
ref -= *ip++;
|
120
|
+
|
121
|
+
if (op + len + 2 > out_end)
|
122
|
+
{
|
123
|
+
SET_ERRNO (E2BIG);
|
124
|
+
return 0;
|
125
|
+
}
|
126
|
+
|
127
|
+
if (ref < (u8 *)out_data)
|
128
|
+
{
|
129
|
+
SET_ERRNO (EINVAL);
|
130
|
+
return 0;
|
131
|
+
}
|
132
|
+
|
133
|
+
#ifdef lzf_movsb
|
134
|
+
len += 2;
|
135
|
+
lzf_movsb (op, ref, len);
|
136
|
+
#else
|
137
|
+
*op++ = *ref++;
|
138
|
+
*op++ = *ref++;
|
139
|
+
|
140
|
+
do
|
141
|
+
*op++ = *ref++;
|
142
|
+
while (--len);
|
143
|
+
#endif
|
144
|
+
}
|
145
|
+
}
|
146
|
+
while (ip < in_end);
|
147
|
+
|
148
|
+
return op - (u8 *)out_data;
|
149
|
+
}
|
150
|
+
|
@@ -0,0 +1,227 @@
|
|
1
|
+
|
2
|
+
/* from valgrind tests */
|
3
|
+
|
4
|
+
/* ================ sha1.c ================ */
|
5
|
+
/*
|
6
|
+
SHA-1 in C
|
7
|
+
By Steve Reid <steve@edmweb.com>
|
8
|
+
100% Public Domain
|
9
|
+
|
10
|
+
Test Vectors (from FIPS PUB 180-1)
|
11
|
+
"abc"
|
12
|
+
A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
|
13
|
+
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
|
14
|
+
84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
|
15
|
+
A million repetitions of "a"
|
16
|
+
34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
|
17
|
+
*/
|
18
|
+
|
19
|
+
/* #define LITTLE_ENDIAN * This should be #define'd already, if true. */
|
20
|
+
/* #define SHA1HANDSOFF * Copies data before messing with it. */
|
21
|
+
|
22
|
+
#define SHA1HANDSOFF
|
23
|
+
|
24
|
+
#include <stdio.h>
|
25
|
+
#include <string.h>
|
26
|
+
#include <sys/types.h> /* for u_int*_t */
|
27
|
+
#if defined(__sun)
|
28
|
+
#include "solarisfixes.h"
|
29
|
+
#endif
|
30
|
+
#include "sha1.h"
|
31
|
+
|
32
|
+
#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
|
33
|
+
|
34
|
+
/* blk0() and blk() perform the initial expand. */
|
35
|
+
/* I got the idea of expanding during the round function from SSLeay */
|
36
|
+
#if BYTE_ORDER == LITTLE_ENDIAN
|
37
|
+
#define blk0(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \
|
38
|
+
|(rol(block->l[i],8)&0x00FF00FF))
|
39
|
+
#elif BYTE_ORDER == BIG_ENDIAN
|
40
|
+
#define blk0(i) block->l[i]
|
41
|
+
#else
|
42
|
+
#error "Endianness not defined!"
|
43
|
+
#endif
|
44
|
+
#define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \
|
45
|
+
^block->l[(i+2)&15]^block->l[i&15],1))
|
46
|
+
|
47
|
+
/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */
|
48
|
+
#define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30);
|
49
|
+
#define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30);
|
50
|
+
#define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30);
|
51
|
+
#define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30);
|
52
|
+
#define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30);
|
53
|
+
|
54
|
+
|
55
|
+
/* Hash a single 512-bit block. This is the core of the algorithm. */
|
56
|
+
|
57
|
+
void SHA1Transform(u_int32_t state[5], const unsigned char buffer[64])
|
58
|
+
{
|
59
|
+
u_int32_t a, b, c, d, e;
|
60
|
+
typedef union {
|
61
|
+
unsigned char c[64];
|
62
|
+
u_int32_t l[16];
|
63
|
+
} CHAR64LONG16;
|
64
|
+
#ifdef SHA1HANDSOFF
|
65
|
+
CHAR64LONG16 block[1]; /* use array to appear as a pointer */
|
66
|
+
memcpy(block, buffer, 64);
|
67
|
+
#else
|
68
|
+
/* The following had better never be used because it causes the
|
69
|
+
* pointer-to-const buffer to be cast into a pointer to non-const.
|
70
|
+
* And the result is written through. I threw a "const" in, hoping
|
71
|
+
* this will cause a diagnostic.
|
72
|
+
*/
|
73
|
+
CHAR64LONG16* block = (const CHAR64LONG16*)buffer;
|
74
|
+
#endif
|
75
|
+
/* Copy context->state[] to working vars */
|
76
|
+
a = state[0];
|
77
|
+
b = state[1];
|
78
|
+
c = state[2];
|
79
|
+
d = state[3];
|
80
|
+
e = state[4];
|
81
|
+
/* 4 rounds of 20 operations each. Loop unrolled. */
|
82
|
+
R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3);
|
83
|
+
R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7);
|
84
|
+
R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11);
|
85
|
+
R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15);
|
86
|
+
R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);
|
87
|
+
R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);
|
88
|
+
R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27);
|
89
|
+
R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31);
|
90
|
+
R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);
|
91
|
+
R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39);
|
92
|
+
R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43);
|
93
|
+
R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);
|
94
|
+
R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51);
|
95
|
+
R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55);
|
96
|
+
R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);
|
97
|
+
R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63);
|
98
|
+
R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67);
|
99
|
+
R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
|
100
|
+
R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75);
|
101
|
+
R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);
|
102
|
+
/* Add the working vars back into context.state[] */
|
103
|
+
state[0] += a;
|
104
|
+
state[1] += b;
|
105
|
+
state[2] += c;
|
106
|
+
state[3] += d;
|
107
|
+
state[4] += e;
|
108
|
+
/* Wipe variables */
|
109
|
+
a = b = c = d = e = 0;
|
110
|
+
#ifdef SHA1HANDSOFF
|
111
|
+
memset(block, '\0', sizeof(block));
|
112
|
+
#endif
|
113
|
+
}
|
114
|
+
|
115
|
+
|
116
|
+
/* SHA1Init - Initialize new context */
|
117
|
+
|
118
|
+
void SHA1Init(SHA1_CTX* context)
|
119
|
+
{
|
120
|
+
/* SHA1 initialization constants */
|
121
|
+
context->state[0] = 0x67452301;
|
122
|
+
context->state[1] = 0xEFCDAB89;
|
123
|
+
context->state[2] = 0x98BADCFE;
|
124
|
+
context->state[3] = 0x10325476;
|
125
|
+
context->state[4] = 0xC3D2E1F0;
|
126
|
+
context->count[0] = context->count[1] = 0;
|
127
|
+
}
|
128
|
+
|
129
|
+
|
130
|
+
/* Run your data through this. */
|
131
|
+
|
132
|
+
void SHA1Update(SHA1_CTX* context, const unsigned char* data, u_int32_t len)
|
133
|
+
{
|
134
|
+
u_int32_t i, j;
|
135
|
+
|
136
|
+
j = context->count[0];
|
137
|
+
if ((context->count[0] += len << 3) < j)
|
138
|
+
context->count[1]++;
|
139
|
+
context->count[1] += (len>>29);
|
140
|
+
j = (j >> 3) & 63;
|
141
|
+
if ((j + len) > 63) {
|
142
|
+
memcpy(&context->buffer[j], data, (i = 64-j));
|
143
|
+
SHA1Transform(context->state, context->buffer);
|
144
|
+
for ( ; i + 63 < len; i += 64) {
|
145
|
+
SHA1Transform(context->state, &data[i]);
|
146
|
+
}
|
147
|
+
j = 0;
|
148
|
+
}
|
149
|
+
else i = 0;
|
150
|
+
memcpy(&context->buffer[j], &data[i], len - i);
|
151
|
+
}
|
152
|
+
|
153
|
+
|
154
|
+
/* Add padding and return the message digest. */
|
155
|
+
|
156
|
+
void SHA1Final(unsigned char digest[20], SHA1_CTX* context)
|
157
|
+
{
|
158
|
+
unsigned i;
|
159
|
+
unsigned char finalcount[8];
|
160
|
+
unsigned char c;
|
161
|
+
|
162
|
+
#if 0 /* untested "improvement" by DHR */
|
163
|
+
/* Convert context->count to a sequence of bytes
|
164
|
+
* in finalcount. Second element first, but
|
165
|
+
* big-endian order within element.
|
166
|
+
* But we do it all backwards.
|
167
|
+
*/
|
168
|
+
unsigned char *fcp = &finalcount[8];
|
169
|
+
|
170
|
+
for (i = 0; i < 2; i++)
|
171
|
+
{
|
172
|
+
u_int32_t t = context->count[i];
|
173
|
+
int j;
|
174
|
+
|
175
|
+
for (j = 0; j < 4; t >>= 8, j++)
|
176
|
+
*--fcp = (unsigned char) t;
|
177
|
+
}
|
178
|
+
#else
|
179
|
+
for (i = 0; i < 8; i++) {
|
180
|
+
finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)]
|
181
|
+
>> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */
|
182
|
+
}
|
183
|
+
#endif
|
184
|
+
c = 0200;
|
185
|
+
SHA1Update(context, &c, 1);
|
186
|
+
while ((context->count[0] & 504) != 448) {
|
187
|
+
c = 0000;
|
188
|
+
SHA1Update(context, &c, 1);
|
189
|
+
}
|
190
|
+
SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */
|
191
|
+
for (i = 0; i < 20; i++) {
|
192
|
+
digest[i] = (unsigned char)
|
193
|
+
((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
|
194
|
+
}
|
195
|
+
/* Wipe variables */
|
196
|
+
memset(context, '\0', sizeof(*context));
|
197
|
+
memset(&finalcount, '\0', sizeof(finalcount));
|
198
|
+
}
|
199
|
+
/* ================ end of sha1.c ================ */
|
200
|
+
|
201
|
+
#if 0
|
202
|
+
#define BUFSIZE 4096
|
203
|
+
|
204
|
+
int
|
205
|
+
main(int argc, char **argv)
|
206
|
+
{
|
207
|
+
SHA1_CTX ctx;
|
208
|
+
unsigned char hash[20], buf[BUFSIZE];
|
209
|
+
int i;
|
210
|
+
|
211
|
+
for(i=0;i<BUFSIZE;i++)
|
212
|
+
buf[i] = i;
|
213
|
+
|
214
|
+
SHA1Init(&ctx);
|
215
|
+
for(i=0;i<1000;i++)
|
216
|
+
SHA1Update(&ctx, buf, BUFSIZE);
|
217
|
+
SHA1Final(hash, &ctx);
|
218
|
+
|
219
|
+
printf("SHA1=");
|
220
|
+
for(i=0;i<20;i++)
|
221
|
+
printf("%02x", hash[i]);
|
222
|
+
printf("\n");
|
223
|
+
return 0;
|
224
|
+
}
|
225
|
+
|
226
|
+
#endif
|
227
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
/* ================ sha1.h ================ */
|
2
|
+
/*
|
3
|
+
SHA-1 in C
|
4
|
+
By Steve Reid <steve@edmweb.com>
|
5
|
+
100% Public Domain
|
6
|
+
*/
|
7
|
+
|
8
|
+
#include <inttypes.h>
|
9
|
+
|
10
|
+
typedef struct {
|
11
|
+
uint32_t state[5];
|
12
|
+
uint32_t count[2];
|
13
|
+
unsigned char buffer[64];
|
14
|
+
} SHA1_CTX;
|
15
|
+
|
16
|
+
void SHA1Transform(uint32_t state[5], const unsigned char buffer[64]);
|
17
|
+
void SHA1Init(SHA1_CTX* context);
|
18
|
+
void SHA1Update(SHA1_CTX* context, const unsigned char* data, uint32_t len);
|
19
|
+
void SHA1Final(unsigned char digest[20], SHA1_CTX* context);
|