Subversion Repositories RepoView

Rev

Rev 3 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3 Rev 4
Line 1... Line 1...
1
/* $Id: sha512.c 3 2024-08-20 21:05:24Z nishi $ */
1
/* $Id: sha512.c 4 2024-08-20 21:10:25Z nishi $ */
2
 
2
 
3
#include "rv_sha512.h"
3
#include "rv_sha512.h"
4
 
4
 
5
#include <openssl/sha.h>
5
#include <openssl/sha.h>
6
 
6
 
7
#include <stdlib.h>
7
#include <stdlib.h>
8
#include <string.h>
8
#include <string.h>
9
 
9
 
10
unsigned char* rv_sha512(const char* string) {
10
char* rv_sha512(const char* string) {
-
 
11
	const char hex[] = "0123456789abcdef";
11
	unsigned char* hash = malloc(SHA512_DIGEST_LENGTH);
12
	unsigned char* hash = malloc(SHA512_DIGEST_LENGTH);
12
	SHA512((const unsigned char*)string, strlen(string), hash);
13
	SHA512((const unsigned char*)string, strlen(string), hash);
-
 
14
	char* str = malloc(512 / 4 + 1);
-
 
15
	int i;
-
 
16
	for(i = 0; i < 512 / 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);
13
	return hash;
21
	return str;
14
}
22
}