diff options
author | Julius Werner <jwerner@chromium.org> | 2014-12-16 19:24:54 -0800 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2015-01-06 23:43:30 +0000 |
commit | f10e9099286202f83ce4c1dc5ef1e85fcb5ccde7 (patch) | |
tree | 7346b671a9f427c6e7dd0b7a8cdb10b41e1db9e6 /firmware/lib21 | |
parent | f47eccf65b05ebab7f3f24c14a09aceb442e08fc (diff) | |
download | vboot-f10e9099286202f83ce4c1dc5ef1e85fcb5ccde7.tar.gz |
vboot2: Introduce vb2ex_hwcrypto APIstabilize-storm-6683.Bstabilize-6670.Bstabilize-6662.B
This patch extends the vboot2 API by three callback functions that the
platform firmware may implement to offer hardware crypto engine support.
For now we only support this for hash algorithms, and we will only allow
it for firmware body hashes (not the keyblock or preamble which are too
small to matter execution-time-wise anyway). The API is similar to the
vb2api_*_hash() functions used to start body hashing in the first place,
but we still take this round trip through vboot to allow it to do
key/signature management and retain full control of the verification
process. We also add a new preamble flag to explicitly disable this
feature, so that we can later return to a solely software-based
verification path through a firmware update in case a hardware crypto
engine turns out to be insecure.
CQ-DEPEND=CL:236435
BRANCH=None
BUG=chrome-os-partner:32987
TEST='make runtests VBOOT2=1'. Manually booted on Pinky with and without
HW crypto support and with the preamble flag set to confirm expected
behavior. lib21/ parts untested except for compiling and new unit tests.
Change-Id: I17c7d02f392089875a5942a5aafcf6a657354863
Signed-off-by: Julius Werner <jwerner@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/236453
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'firmware/lib21')
-rw-r--r-- | firmware/lib21/api.c | 24 | ||||
-rw-r--r-- | firmware/lib21/include/vb2_struct.h | 6 |
2 files changed, 28 insertions, 2 deletions
diff --git a/firmware/lib21/api.c b/firmware/lib21/api.c index beed98bc..7c1aa014 100644 --- a/firmware/lib21/api.c +++ b/firmware/lib21/api.c @@ -47,7 +47,7 @@ int vb2api_init_hash2(struct vb2_context *ctx, struct vb2_digest_context *dc; struct vb2_workbuf wb; uint32_t hash_offset; - int i; + int i, rv; vb2_workbuf_from_ctx(ctx, &wb); @@ -93,6 +93,23 @@ int vb2api_init_hash2(struct vb2_context *ctx, if (size) *size = sig->data_size; + if (!(pre->flags & VB2_FIRMWARE_PREAMBLE_DISALLOW_HWCRYPTO)) { + rv = vb2ex_hwcrypto_digest_init(sig->hash_alg, sig->data_size); + if (!rv) { + VB2_DEBUG("Using HW crypto engine for hash_alg %d\n", + sig->hash_alg); + dc->hash_alg = sig->hash_alg; + dc->using_hwcrypto = 1; + return VB2_SUCCESS; + } + if (rv != VB2_ERROR_EX_HWCRYPTO_UNSUPPORTED) + return rv; + VB2_DEBUG("HW crypto for hash_alg %d not supported, using SW\n", + sig->hash_alg); + } else { + VB2_DEBUG("HW crypto forbidden by preamble, using SW\n"); + } + return vb2_digest_init(dc, sig->hash_alg); } @@ -131,7 +148,10 @@ int vb2api_check_hash(struct vb2_context *ctx) return VB2_ERROR_API_CHECK_HASH_WORKBUF_DIGEST; /* Finalize the digest */ - rv = vb2_digest_finalize(dc, digest, digest_size); + if (dc->using_hwcrypto) + rv = vb2ex_hwcrypto_digest_finalize(digest, digest_size); + else + rv = vb2_digest_finalize(dc, digest, digest_size); if (rv) return rv; diff --git a/firmware/lib21/include/vb2_struct.h b/firmware/lib21/include/vb2_struct.h index d9921d94..62e1a080 100644 --- a/firmware/lib21/include/vb2_struct.h +++ b/firmware/lib21/include/vb2_struct.h @@ -291,6 +291,12 @@ struct vb2_keyblock { #define VB2_FW_PREAMBLE_VERSION_MAJOR 3 #define VB2_FW_PREAMBLE_VERSION_MINOR 0 +/* Flags for vb2_fw_preamble.flags */ +/* Reserved; do not use */ +#define VB2_FIRMWARE_PREAMBLE_RESERVED0 0x00000001 +/* Do not allow use of any hardware crypto accelerators. */ +#define VB2_FIRMWARE_PREAMBLE_DISALLOW_HWCRYPTO 0x00000002 + /* * Firmware preamble * |