Subversion Repositories RepoView

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
33 nishi 1
/* $Id: md5.c 33 2024-08-22 02:15:44Z nishi $ */
2
 
3
#include "rv_md5.h"
4
 
5
#include <openssl/md5.h>
6
 
7
#include <stdlib.h>
8
#include <string.h>
9
 
10
char* rv_md5(const char* string) {
11
	const char hex[] = "0123456789abcdef";
12
	unsigned char* hash = malloc(MD5_DIGEST_LENGTH);
13
	MD5((const unsigned char*)string, strlen(string), hash);
14
	char* str = malloc(128 / 4 + 1);
15
	int i;
16
	for(i = 0; i < 128 / 8; i++) {
17
		str[2 * i + 0] = hex[(hash[i] >> 4) & 0xf];
18
		str[2 * i + 1] = hex[(hash[i] & 0xf)];
19
	}
20
	free(hash);
21
	return str;
22
}