]> mj.ucw.cz Git - libucw.git/blob - lib/md5hex.c
143168db92fdff7022c999b6caa418edb02658b0
[libucw.git] / lib / md5hex.c
1 /*
2  *      Sherlock Library -- MD5 Binary <-> Hex Conversions
3  *
4  *      (c) 1997 Martin Mares, <mj@atrey.karlin.mff.cuni.cz>
5  */
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <fcntl.h>
10 #include <unistd.h>
11
12 #include "lib.h"
13 #include "string.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 }