File: crypto_api.c

package info (click to toggle)
signify-openbsd 13-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 528 kB
  • ctags: 489
  • sloc: ansic: 4,250; makefile: 99; sh: 11
file content (31 lines) | stat: -rw-r--r-- 670 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
/* $OpenBSD: crypto_api.c,v 1.1 2014/01/08 03:59:46 tedu Exp $ */
/*
 * Public domain. Author: Ted Unangst <tedu@openbsd.org>
 * API compatible reimplementation of functions from nacl
 */
#include <sys/types.h>

#include <string.h>
#include "sha2.h"

#include "crypto_api.h"

extern int timingsafe_bcmp(const void *b1, const void *b2, size_t n);

int
crypto_hash_sha512(unsigned char *out, const unsigned char *in,
    unsigned long long inlen)
{
	SHA2_CTX ctx;

	SHA512Init(&ctx);
	SHA512Update(&ctx, in, inlen);
	SHA512Final(out, &ctx);
	return 0;
}

int
crypto_verify_32(const unsigned char *x, const unsigned char *y)
{
	return timingsafe_bcmp(x, y, 32) ? -1 : 0;
}