File: sample-libscrypt-kdf.c

package info (click to toggle)
scrypt 1.3.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,368 kB
  • sloc: ansic: 5,763; sh: 5,504; makefile: 257
file content (35 lines) | stat: -rw-r--r-- 758 bytes parent folder | download
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
#include <stdint.h>
#include <stdio.h>
#include <string.h>

#include "scrypt-kdf.h"

/* Parameters controlling memory usage and CPU time. */
#define N 16384
#define r 8
#define p 1

/* How much data should scrypt return? */
#define OUTPUT_BUFLEN 8

int
main(void)
{
	const char * passwd = "hunter2";
	const char * salt = "DANGER -- this should be a random salt -- DANGER";
	uint8_t output[OUTPUT_BUFLEN];
	int exitcode;

	/* Perform hashing. */
	exitcode = scrypt_kdf((const uint8_t *)passwd, strlen(passwd),
	    (const uint8_t*)salt, strlen(salt), N, r, p,
	    output, OUTPUT_BUFLEN);

	/* Notify user of success / failure. */
	if (exitcode == 0)
		printf("scrypt(): success\n");
	else
		printf("scrypt(): failure %d\n", exitcode);

	return (exitcode);
}