1 /* $NetBSD: md5hl.c,v 1.1 2007/12/09 09:21:06 agc Exp $ */
4 * Written by Jason R. Thorpe <thorpej@netbsd.org>, April 29, 1997.
12 #define MDALGORITHM iSCSI_MD5
14 /* #include "namespace.h" */
15 #include "iscsi-md5.h"
18 #define _DIAGASSERT(cond) assert(cond)
21 /* $NetBSD: md5hl.c,v 1.1 2007/12/09 09:21:06 agc Exp $ */
24 * ----------------------------------------------------------------------------
25 * "THE BEER-WARE LICENSE" (Revision 42):
26 * <phk@login.dkuug.dk> wrote this file. As long as you retain this notice you
27 * can do whatever you want with this stuff. If we meet some day, and you think
28 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
29 * ----------------------------------------------------------------------------
31 * from FreeBSD Id: mdXhl.c,v 1.8 1996/10/25 06:48:12 bde Exp
35 * Modifed April 29, 1997 by Jason R. Thorpe <thorpej@netbsd.org>
51 #define CONCAT(x,y) __CONCAT(x,y)
52 #define MDNAME(x) CONCAT(MDALGORITHM,x)
55 MDNAME(End
)(MDNAME(_CTX
) *ctx
, char *buf
)
58 unsigned char digest
[16];
59 static const char hex
[]="0123456789abcdef";
61 _DIAGASSERT(ctx
!= 0);
68 MDNAME(Final
)(digest
, ctx
);
70 for (i
= 0; i
< 16; i
++) {
71 buf
[i
+i
] = hex
[(uint32_t)digest
[i
] >> 4];
72 buf
[i
+i
+1] = hex
[digest
[i
] & 0x0f];
80 MDNAME(File
)(filename
, buf
)
84 unsigned char buffer
[BUFSIZ
];
89 _DIAGASSERT(filename
!= 0);
93 f
= open(filename
, O_RDONLY
, 0666);
97 while ((i
= read(f
, buffer
, sizeof(buffer
))) > 0)
98 MDNAME(Update
)(&ctx
, buffer
, (size_t)i
);
109 return (MDNAME(End
)(&ctx
, buf
));
113 MDNAME(Data
)(const uint8_t *data
, size_t len
, char *buf
)
117 _DIAGASSERT(data
!= 0);
120 MDNAME(Update
)(&ctx
, data
, len
);
121 return (MDNAME(End
)(&ctx
, buf
));