~ubuntu-branches/debian/wheezy/courier/wheezy

« back to all changes in this revision

Viewing changes to sha1/sha512_hash.c

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Hornburg (Racke)
  • Date: 2009-03-08 16:42:08 UTC
  • mfrom: (1.2.1 upstream) (4.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20090308164208-nlve2wtx9bbrulmd
Tags: 0.61.2-1
* New upstream release.
* Lintian:
  - fix chown in courier-webadmin postinst
  - removed courier-base preinst
  - added debhelper token to courier-mta.preinst
  - removed *.conffiles

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
** Copyright 2008 Double Precision, Inc.
 
3
** See COPYING for distribution information.
 
4
*/
 
5
 
 
6
#include        "sha1.h"
 
7
#include        <string.h>
 
8
 
 
9
static const char rcsid[]="$Id: sha512_hash.c,v 1.1 2008/12/25 14:39:11 mrsam Exp $";
 
10
 
 
11
static const char base64tab[]=
 
12
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 
13
 
 
14
const char *sha512_hash(const char *passw)
 
15
{
 
16
SHA512_DIGEST sha512buf;
 
17
static char hash_buffer[1+(sizeof(sha512buf)+2)/3*4];
 
18
int     a=0,b=0,c=0;
 
19
int     i, j;
 
20
int     d, e, f, g;
 
21
 
 
22
        sha512_digest(passw, strlen(passw), sha512buf);
 
23
 
 
24
        j=0;
 
25
 
 
26
        for (i=0; i<sizeof(sha512buf); i += 3)
 
27
        {
 
28
                a=sha512buf[i];
 
29
                b= i+1 < sizeof(sha512buf) ? sha512buf[i+1]:0;
 
30
                c= i+2 < sizeof(sha512buf) ? sha512buf[i+2]:0;
 
31
 
 
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='=';
 
38
                hash_buffer[j++]=d;
 
39
                hash_buffer[j++]=e;
 
40
                hash_buffer[j++]=f;
 
41
                hash_buffer[j++]=g;
 
42
        }
 
43
 
 
44
        hash_buffer[j]=0;
 
45
        return (hash_buffer);
 
46
}