diff options
| author | Sam Varshavchik | 2013-08-19 16:39:41 -0400 | 
|---|---|---|
| committer | Sam Varshavchik | 2013-08-25 14:43:51 -0400 | 
| commit | 9c45d9ad13fdf439d44d7443ae75da15ea0223ed (patch) | |
| tree | 7a81a04cb51efb078ee350859a64be2ebc6b8813 /sha1/sha256_hash.c | |
| parent | a9520698b770168d1f33d6301463bb70a19655ec (diff) | |
| download | courier-libs-9c45d9ad13fdf439d44d7443ae75da15ea0223ed.tar.bz2 | |
Initial checkin
Imported from subversion report, converted to git. Updated all paths in
scripts and makefiles, reflecting the new directory hierarchy.
Diffstat (limited to 'sha1/sha256_hash.c')
| -rw-r--r-- | sha1/sha256_hash.c | 45 | 
1 files changed, 45 insertions, 0 deletions
| diff --git a/sha1/sha256_hash.c b/sha1/sha256_hash.c new file mode 100644 index 0000000..a6f7bc1 --- /dev/null +++ b/sha1/sha256_hash.c @@ -0,0 +1,45 @@ +/* +** Copyright 2005 Double Precision, Inc. +** See COPYING for distribution information. +*/ + +#include	"sha1.h" +#include	<string.h> + + +static const char base64tab[]= +"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + +const char *sha256_hash(const char *passw) +{ +SHA256_DIGEST sha256buf; +static char hash_buffer[1+(sizeof(sha256buf)+2)/3*4]; +int	a=0,b=0,c=0; +int	i, j; +int	d, e, f, g; + +	sha256_digest(passw, strlen(passw), sha256buf); + +	j=0; + +	for (i=0; i<sizeof(sha256buf); i += 3) +	{ +		a=sha256buf[i]; +		b= i+1 < sizeof(sha256buf) ? sha256buf[i+1]:0; +		c= i+2 < sizeof(sha256buf) ? sha256buf[i+2]:0; + +		d=base64tab[ a >> 2 ]; +		e=base64tab[ ((a & 3 ) << 4) | (b >> 4)]; +		f=base64tab[ ((b & 15) << 2) | (c >> 6)]; +		g=base64tab[ c & 63 ]; +		if (i + 1 >= sizeof(sha256buf))	f='='; +		if (i + 2 >= sizeof(sha256buf)) g='='; +		hash_buffer[j++]=d; +		hash_buffer[j++]=e; +		hash_buffer[j++]=f; +		hash_buffer[j++]=g; +	} + +	hash_buffer[j]=0; +	return (hash_buffer); +} | 
