diff options
author | Daisuke Nojiri <dnojiri@chromium.org> | 2016-05-06 12:32:38 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-06-22 20:01:58 -0700 |
commit | 7931177cc35f5dcd2505e1efa448511ba8a0b3b1 (patch) | |
tree | 1fbfb4397bfecffca574c79ef6f095640b3e0080 /tests/bdb_sprw_test.c | |
parent | 05cd8ce75f97a76c4ef155734d191cd275bac231 (diff) | |
download | vboot-7931177cc35f5dcd2505e1efa448511ba8a0b3b1.tar.gz |
bdb: Add vba_update_buc
vba_update_buc writes a BUC (boot unlock code) to NVM-RW. It will be called
by AP-RW to update a BUC.
BUG=chrome-os-partner:51907
BRANCH=tot
TEST=make runtests
Change-Id: Ic91f34b60b11ebce948bce01993ddb44519a59b8
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/346233
Diffstat (limited to 'tests/bdb_sprw_test.c')
-rw-r--r-- | tests/bdb_sprw_test.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/bdb_sprw_test.c b/tests/bdb_sprw_test.c index 06739ae5..75deba63 100644 --- a/tests/bdb_sprw_test.c +++ b/tests/bdb_sprw_test.c @@ -8,6 +8,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <openssl/aes.h> #include "2sha.h" #include "2hmac.h" @@ -34,6 +35,13 @@ struct bdb_ro_secrets secrets = { .nvm_rw = {0x00, }, }; +struct bdb_rw_secrets rw_secrets = { + .buc = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff}, +}; + static int vbe_write_nvm_failure = 0; static struct bdb_header *create_bdb(const char *key_dir, @@ -554,6 +562,48 @@ static void test_update_kernel_version(void) verify_kernel_version(0, 0, 1, 0, BDB_SUCCESS); } +int vbe_aes256_encrypt(const uint8_t *msg, uint32_t len, const uint8_t *key, + uint8_t *out) +{ + int i; + + for (i = 0; i < len; i++) + out[i] = msg[i] ^ key[i % 256/8]; + + return BDB_SUCCESS; +} + +int vbe_aes256_decrypt(const uint8_t *msg, uint32_t len, const uint8_t *key, + uint8_t *out) +{ + int i; + + for (i = 0; i < len; i++) + out[i] = msg[i] ^ key[i % 256/8]; + + return BDB_SUCCESS; +} + +static void test_update_buc(void) +{ + uint8_t new_buc[BUC_ENC_DIGEST_SIZE]; + uint8_t enc_buc[BUC_ENC_DIGEST_SIZE]; + struct nvmrw *nvm = (struct nvmrw *)nvmrw1; + struct vba_context ctx = { + .bdb = NULL, + .ro_secrets = &secrets, + .rw_secrets = &rw_secrets, + }; + + install_nvm(NVM_TYPE_RW_PRIMARY, 0, 1, 0); + install_nvm(NVM_TYPE_RW_SECONDARY, 1, 0, 0); + + TEST_SUCC(vba_update_buc(&ctx, new_buc), NULL); + vbe_aes256_encrypt(new_buc, sizeof(new_buc), ctx.rw_secrets->buc, + enc_buc); + TEST_SUCC(memcmp(nvm->buc_enc_digest, enc_buc, sizeof(new_buc)), NULL); +} + int main(int argc, char *argv[]) { if (argc != 2) { @@ -566,6 +616,7 @@ int main(int argc, char *argv[]) test_nvm_read(); test_nvm_write(); test_update_kernel_version(); + test_update_buc(); return gTestSuccess ? 0 : 255; } |