Files
OpenCellular/chip/g/crypto_api.c
nagendra modadugu 927e01da02 g: rework DCRYPTO_app_cipher (AES-CTR) for speed
The previous implementation of DCRYPTO_app_cipher
consumed roughly 16ms to cipher a 16kB buffer
(i.e. performance that is far worse than the
hardware is capable of).

This change speeds up the implementation by about
85%, to the tune of roughly 2.2ms for a 16kB buffer.

The gains originate from various sources: loop
unrolling, data-pipelining, eliminating local
variables (to reduce register pressure), eliminating
support for unaligned input/output data, compiling
hot code with -O (rather the default -Os), and
using the hidden key-ladder, which need only be
setup once per reset.

This change also switches from AES-128 to AES-256.

BRANCH=none
BUG=chrome-os-partner:62260
TEST=make buildall succeeds;
	cipher command succeeds;
        TCG tests pass

Change-Id: I133741be6d9f1353d6ae732d0e863b4b18cc8c9e
Signed-off-by: nagendra modadugu <ngm@google.com>
Reviewed-on: https://chromium-review.googlesource.com/433359
Commit-Ready: Nagendra Modadugu <ngm@google.com>
Tested-by: Nagendra Modadugu <ngm@google.com>
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
2017-01-28 21:37:58 -08:00

32 lines
835 B
C

/*
* 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(uint8_t *p_buf, size_t num_bytes,
uint8_t *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((uint8_t *)p_buf, num_bytes, sha1_digest);
memcpy(p_hash, sha1_digest, MIN(hash_len, sizeof(sha1_digest)));
if (hash_len > sizeof(sha1_digest))
memset(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);
}