1 /* $MirOS: src/gnu/usr.bin/cvs/lib/md5.c,v 1.4 2007/03/10 23:53:39 tg Exp $ */
2 
3 /*-
4  * Copyright (c) 2005, 2007
5  *	Thorsten Glaser <tg@mirbsd.de>
6  *
7  * Provided that these terms and disclaimer and all copyright notices
8  * are retained or reproduced in an accompanying document, permission
9  * is granted to deal in this work without restriction, including un-
10  * limited rights to use, publicly perform, distribute, sell, modify,
11  * merge, give away, or sublicence.
12  *
13  * This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
14  * the utmost extent permitted by applicable law, neither express nor
15  * implied; without malicious intent or gross negligence. In no event
16  * may a licensor, author or contributor be held liable for indirect,
17  * direct, other damage, loss, or other issues arising in any way out
18  * of dealing in the work, even if advised of the possibility of such
19  * damage or existence of a defect, except proven that it results out
20  * of said person's immediate fault when using the work as intended.
21  */
22 
23 #include <sys/types.h>
24 #include <stdlib.h>
25 #include "md5.h"
26 
27 __RCSID("$MirOS: src/gnu/usr.bin/cvs/lib/md5.c,v 1.4 2007/03/10 23:53:39 tg Exp $");
28 
29 char *
md5_buffer(const u_int8_t * buf,size_t buflen,char * hash)30 md5_buffer(const u_int8_t *buf, size_t buflen, char *hash)
31 {
32 	MD5_CTX ctx;
33 
34 	if (hash == NULL)
35 		if ((hash = malloc(MD5_DIGEST_LENGTH)) == NULL)
36 			return NULL;
37 
38 	MD5Init(&ctx);
39 	MD5Update(&ctx, buf, buflen);
40 	MD5Final((uint8_t *)hash, &ctx);
41 
42 	return hash;
43 }
44