7 #include "crypto_hashblocks_sha256.h"
8 #include "crypto_hash.h"
10 #define blocks crypto_hashblocks_sha256
12 typedef unsigned int uint32
;
14 static const char iv
[32] = {
25 int crypto_hash(unsigned char *out
,const unsigned char *in
,unsigned long long inlen
)
28 unsigned char padded
[128];
30 unsigned long long bits
= inlen
<< 3;
32 for (i
= 0;i
< 32;++i
) h
[i
] = iv
[i
];
39 for (i
= 0;i
< inlen
;++i
) padded
[i
] = in
[i
];
43 for (i
= inlen
+ 1;i
< 56;++i
) padded
[i
] = 0;
44 padded
[56] = bits
>> 56;
45 padded
[57] = bits
>> 48;
46 padded
[58] = bits
>> 40;
47 padded
[59] = bits
>> 32;
48 padded
[60] = bits
>> 24;
49 padded
[61] = bits
>> 16;
50 padded
[62] = bits
>> 8;
54 for (i
= inlen
+ 1;i
< 120;++i
) padded
[i
] = 0;
55 padded
[120] = bits
>> 56;
56 padded
[121] = bits
>> 48;
57 padded
[122] = bits
>> 40;
58 padded
[123] = bits
>> 32;
59 padded
[124] = bits
>> 24;
60 padded
[125] = bits
>> 16;
61 padded
[126] = bits
>> 8;
66 for (i
= 0;i
< 32;++i
) out
[i
] = h
[i
];