]> mj.ucw.cz Git - libucw.git/blob - lib/md5hex.c
hashtables: fixed combination of HASH_GIVE_ALLOC and HASH_TABLE_ALLOC
[libucw.git] / lib / md5hex.c
1 /*
2  *      UCW Library -- MD5 Binary <-> Hex Conversions
3  *
4  *      (c) 1997 Martin Mares <mj@ucw.cz>
5  *
6  *      This software may be freely distributed and used according to the terms
7  *      of the GNU Lesser General Public License.
8  */
9
10 #include "lib/lib.h"
11 #include "lib/chartype.h"
12
13 #include <stdio.h>
14
15 void
16 md5_to_hex(byte *s, byte *d)
17 {
18   int i;
19   for(i=0; i<MD5_SIZE; i++)
20     d += sprintf(d, "%02X", *s++);
21 }
22
23 void
24 hex_to_md5(byte *s, byte *d)
25 {
26   uns i, j;
27   for(i=0; i<MD5_SIZE; i++)
28     {
29       if (!Cxdigit(s[0]) || !Cxdigit(s[1]))
30         die("hex_to_md5: syntax error");
31       j = Cxvalue(*s); s++;
32       j = (j << 4) | Cxvalue(*s); s++;
33       *d++ = j;
34     }
35 }