1 /* $NetBSD: mdXhl.c,v 1.8 2009/03/06 18:15:24 apb Exp $ */
4 * ----------------------------------------------------------------------------
5 * "THE BEER-WARE LICENSE" (Revision 42):
6 * <phk@login.dkuug.dk> wrote this file. As long as you retain this notice you
7 * can do whatever you want with this stuff. If we meet some day, and you think
8 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
9 * ----------------------------------------------------------------------------
11 * from FreeBSD Id: mdXhl.c,v 1.8 1996/10/25 06:48:12 bde Exp
15 * Modified April 29, 1997 by Jason R. Thorpe <thorpej@NetBSD.org>
18 #if HAVE_NBTOOL_CONFIG_H
19 #include "nbtool_config.h"
22 #define CONCAT(x,y) __CONCAT(x,y)
23 #define MDNAME(x) CONCAT(MDALGORITHM,x)
25 #if !defined(_KERNEL) && defined(__weak_alias) && !defined(HAVE_NBTOOL_CONFIG_H)
26 #define WA(a,b) __weak_alias(a,b)
27 WA(MDNAME(End
),CONCAT(_
,MDNAME(End
)))
28 WA(MDNAME(File
),CONCAT(_
,MDNAME(File
)))
29 WA(MDNAME(Data
),CONCAT(_
,MDNAME(Data
)))
33 #include "namespace.h"
35 #include <sys/types.h>
53 unsigned char digest
[16];
54 static const char hex
[]="0123456789abcdef";
56 _DIAGASSERT(ctx
!= 0);
63 MDNAME(Final
)(digest
, ctx
);
65 for (i
= 0; i
< 16; i
++) {
66 buf
[i
+i
] = hex
[(u_int32_t
)digest
[i
] >> 4];
67 buf
[i
+i
+1] = hex
[digest
[i
] & 0x0f];
75 MDNAME(File
)(filename
, buf
)
79 unsigned char buffer
[BUFSIZ
];
83 _DIAGASSERT(filename
!= 0);
87 f
= open(filename
, O_RDONLY
, 0666);
91 while ((i
= read(f
, buffer
, sizeof(buffer
))) > 0)
92 MDNAME(Update
)(&ctx
, buffer
, (unsigned int)i
);
101 return (MDNAME(End
)(&ctx
, buf
));
105 MDNAME(Data
)(data
, len
, buf
)
106 const unsigned char *data
;
112 _DIAGASSERT(data
!= 0);
115 MDNAME(Update
)(&ctx
, data
, len
);
116 return (MDNAME(End
)(&ctx
, buf
));