summaryrefslogtreecommitdiff
path: root/crypto_scrypt-hash.c
blob: 1fcf49b321097f4688be0b9290e1f6f43af77ea9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdint.h>

#include "libscrypt.h"

int libscrypt_hash(char *dst, char *passphrase, uint32_t N, uint8_t r, uint8_t p)
{

	int retval;
	char salt[16];
	uint8_t	hashbuf[64];
	char outbuf[256];
	char saltbuf[256];

	libscrypt_salt_gen(salt, 16);

	retval = libscrypt_scrypt((uint8_t*)passphrase,strlen(passphrase), (uint8_t*)salt, sizeof(salt), N, r, p, hashbuf, sizeof(hashbuf));
	if(retval == -1)
		return 0;

        retval = libscrypt_b64_encode((char*)hashbuf, sizeof(hashbuf), outbuf, sizeof(outbuf));
	if(retval == -1)
		return 0;
	
        retval = libscrypt_b64_encode(salt, sizeof(salt), saltbuf, sizeof(saltbuf));
	if(retval == -1)
		return 0;

        retval = libscrypt_mcf(N, r, p, saltbuf, outbuf, dst);
	if(retval == -1)
		return 0;

	return 1;
}