summaryrefslogtreecommitdiff
path: root/chip/g/crypto_api.c
blob: 075472238dee8d5fbcaef3d9d52d91119e0fc83a (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
/*
 * Copyright 2017 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "crypto_api.h"
#include "dcrypto.h"

void app_compute_hash(const void *p_buf, size_t num_bytes, void *p_hash,
		      size_t hash_len)
{
	uint8_t sha1_digest[SHA_DIGEST_SIZE];

	/*
	 * Use the built in dcrypto engine to generate the sha1 hash of the
	 * buffer.
	 */
	DCRYPTO_SHA1_hash(p_buf, num_bytes, sha1_digest);

	memcpy(p_hash, sha1_digest, MIN(hash_len, sizeof(sha1_digest)));

	if (hash_len > sizeof(sha1_digest))
		memset((uint8_t *)p_hash + sizeof(sha1_digest), 0,
		       hash_len - sizeof(sha1_digest));
}

int app_cipher(const void *salt, void *out, const void *in, size_t size)
{
	return DCRYPTO_app_cipher(NVMEM, salt, out, in, size);
}

int crypto_enabled(void)
{
	return DCRYPTO_ladder_is_enabled();
}