2
** Copyright 2008 Double Precision, Inc.
3
** See COPYING for distribution information.
9
static const char rcsid[]="$Id: sha512_hash.c,v 1.1 2008/12/25 14:39:11 mrsam Exp $";
11
static const char base64tab[]=
12
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
14
const char *sha512_hash(const char *passw)
16
SHA512_DIGEST sha512buf;
17
static char hash_buffer[1+(sizeof(sha512buf)+2)/3*4];
22
sha512_digest(passw, strlen(passw), sha512buf);
26
for (i=0; i<sizeof(sha512buf); i += 3)
29
b= i+1 < sizeof(sha512buf) ? sha512buf[i+1]:0;
30
c= i+2 < sizeof(sha512buf) ? sha512buf[i+2]:0;
32
d=base64tab[ a >> 2 ];
33
e=base64tab[ ((a & 3 ) << 4) | (b >> 4)];
34
f=base64tab[ ((b & 15) << 2) | (c >> 6)];
35
g=base64tab[ c & 63 ];
36
if (i + 1 >= sizeof(sha512buf)) f='=';
37
if (i + 2 >= sizeof(sha512buf)) g='=';