summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorNamyoon Woo <namyoon@chromium.org>2020-03-02 09:13:49 -0800
committerCommit Bot <commit-bot@chromium.org>2020-03-03 15:43:15 +0000
commit91b40f83bf2d990b88fbbbebc6f4155a97c9328f (patch)
treeeabad7a9f5cdb07c45ea7a18230c60a0f893af1c /test
parent8bd1645dd4c3777db7070702711c3445b365ebb4 (diff)
downloadchrome-ec-91b40f83bf2d990b88fbbbebc6f4155a97c9328f.tar.gz
remove board/cr50 and chip/g
This patch removes cr50 related files from platform/ec. BUG=b:149350081 BRANCH=none TEST=$ make buildall -j $ cros_workon --host list chromeos-base/chromeos-cr50-dev chromeos-base/chromeos-ec chromeos-base/chromeos-ec-headers chromeos-base/ec-devutils chromeos-base/ec-utils chromeos-base/ec-utils-test dev-util/hdctools $ sudo emerge chromeos-cr50-dev -j $ sudo emerge chromeos-ec -j $ sudo emerge chromeos-ec-headers -j $ sudo emerge ec-devutils -j $ sudo emerge ec-utils -j $ sudo emerge ec-utils-test -j $ sudo emerge hdctools -j $ cros_workon-octopus list chromeos-base/chromeos-ec chromeos-base/chromeos-ec-headers chromeos-base/ec-devutils chromeos-base/ec-utils chromeos-base/ec-utils-test dev-util/hdctools $ sudo emerge-octopus chromeos-ec -j $ sudo emerge-octopus chromeos-ec-headers -j $ sudo emerge-octopus ec-devutils -j $ sudo emerge-octopus ec-utils -j $ sudo emerge-octopus ec-utils-test -j $ sudo emerge-octopus hdctools -j Signed-off-by: Namyoon Woo <namyoon@chromium.org> Change-Id: Ifa3a037fff17177204ce1a9b88474490fb9be3ed Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2083659 Reviewed-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-by: Denis Brockus <dbrockus@chromium.org>
Diffstat (limited to 'test')
-rw-r--r--test/build.mk2
-rw-r--r--test/rma_auth.c214
-rw-r--r--test/tpm_test/Makefile85
-rw-r--r--test/tpm_test/README.md49
-rw-r--r--test/tpm_test/bn_test.c412
-rw-r--r--test/tpm_test/crypto_test.py243
-rw-r--r--test/tpm_test/crypto_test.xml899
-rw-r--r--test/tpm_test/drbg_test.py108
-rw-r--r--test/tpm_test/ecc_test.py165
-rw-r--r--test/tpm_test/ecies_test.py233
-rw-r--r--test/tpm_test/ftdi_spi_tpm.c495
-rw-r--r--test/tpm_test/ftdi_spi_tpm.h25
-rw-r--r--test/tpm_test/ftdi_spi_tpm.i50
-rw-r--r--test/tpm_test/genvectors.py77
-rw-r--r--test/tpm_test/hash_test.py160
-rw-r--r--test/tpm_test/hkdf_test.py112
-rw-r--r--test/tpm_test/mpsse.c728
-rw-r--r--test/tpm_test/mpsse.h45
-rwxr-xr-xtest/tpm_test/nist_entropy.sh21
-rw-r--r--test/tpm_test/rsa1024.pem15
-rw-r--r--test/tpm_test/rsa2048.pem27
-rw-r--r--test/tpm_test/rsa4096.pem51
-rw-r--r--test/tpm_test/rsa768.pem12
-rw-r--r--test/tpm_test/rsa_test.py818
-rw-r--r--test/tpm_test/subcmd.py19
-rw-r--r--test/tpm_test/support.c218
-rw-r--r--test/tpm_test/support.h87
-rw-r--r--test/tpm_test/testlib/common.c17
-rw-r--r--test/tpm_test/testlib/common.h18
-rw-r--r--test/tpm_test/testlib/trng.h6
-rw-r--r--test/tpm_test/testlib/util.h6
-rwxr-xr-xtest/tpm_test/tpmtest.py179
-rw-r--r--test/tpm_test/trng_test.py50
-rw-r--r--test/tpm_test/upgrade_test.py68
-rw-r--r--test/tpm_test/utils.py38
35 files changed, 0 insertions, 5752 deletions
diff --git a/test/build.mk b/test/build.mk
index 4235274312..2658cca4af 100644
--- a/test/build.mk
+++ b/test/build.mk
@@ -62,7 +62,6 @@ test-list-host += pinweaver
test-list-host += power_button
test-list-host += printf
test-list-host += queue
-test-list-host += rma_auth
test-list-host += rsa
test-list-host += rsa3
test-list-host += rtc
@@ -147,7 +146,6 @@ power_button-y=power_button.o
powerdemo-y=powerdemo.o
printf-y=printf.o
queue-y=queue.o
-rma_auth-y=rma_auth.o
rsa-y=rsa.o
rsa3-y=rsa.o
rtc-y=rtc.o
diff --git a/test/rma_auth.c b/test/rma_auth.c
deleted file mode 100644
index c03ba70acd..0000000000
--- a/test/rma_auth.c
+++ /dev/null
@@ -1,214 +0,0 @@
-/* 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.
- *
- * Test RMA auth challenge/response
- */
-
-#include <endian.h>
-#include <stdio.h>
-#include "common.h"
-#include "chip/g/board_id.h"
-#include "curve25519.h"
-#include "base32.h"
-#include "sha256.h"
-#include "rma_auth.h"
-#include "test_util.h"
-#include "timer.h"
-#include "util.h"
-
-/* Dummy implementations for testing */
-static uint8_t dummy_board_id[4] = {'Z', 'Z', 'C', 'R'};
-static uint8_t dummy_device_id[8] = {'T', 'H', 'X', 1, 1, 3, 8, 0xfe};
-static int server_protocol_version = RMA_CHALLENGE_VERSION;
-static uint8_t server_private_key[32] = RMA_TEST_SERVER_PRIVATE_KEY;
-static int server_key_id = RMA_TEST_SERVER_KEY_ID;
-
-void rand_bytes(void *buffer, size_t len)
-{
- FILE *f = fopen("/dev/urandom", "rb");
-
- assert(f);
- fread(buffer, 1, len, f);
- fclose(f);
-}
-
-int read_board_id(struct board_id *id)
-{
- memcpy(&id->type, dummy_board_id, sizeof(id->type));
- id->type_inv = ~id->type;
- id->flags = 0xFF00;
- return EC_SUCCESS;
-}
-
-int system_get_chip_unique_id(uint8_t **id)
-{
- *id = dummy_device_id;
- return sizeof(dummy_device_id);
-}
-
-/**
- * Simulate the server side of a RMA challenge-response.
- *
- * @param out_auth_code Buffer for generated authorization code
- * (must be >= CR50_AUTH_CODE_CHARS + 1 chars)
- * @param challenge Challenge from device
- * @return 0 if success, non-zero if error.
- */
-int rma_server_side(char *out_auth_code, const char *challenge)
-{
- int version, key_id;
- uint32_t device_id[2];
- uint8_t secret[32];
- uint8_t hmac[32];
- struct rma_challenge c;
- uint8_t *cptr = (uint8_t *)&c;
-
- /* Convert the challenge back into binary */
- if (base32_decode(cptr, 8 * sizeof(c), challenge, 9) != 8 * sizeof(c)) {
- printf("Error decoding challenge\n");
- return -1;
- }
-
- version = RMA_CHALLENGE_GET_VERSION(c.version_key_id);
- if (version != server_protocol_version) {
- printf("Unsupported challenge version %d\n", version);
- return -1;
- }
-
- key_id = RMA_CHALLENGE_GET_KEY_ID(c.version_key_id);
-
- printf("\nChallenge: %s\n", challenge);
- printf(" Version: %d\n", version);
- printf(" Server KeyID: %d\n", key_id);
- printf(" BoardID: %c%c%c%c\n",
- isprint(c.board_id[0]) ? c.board_id[0] : '?',
- isprint(c.board_id[1]) ? c.board_id[1] : '?',
- isprint(c.board_id[2]) ? c.board_id[2] : '?',
- isprint(c.board_id[3]) ? c.board_id[3] : '?');
-
- memcpy(device_id, c.device_id, sizeof(device_id));
- printf(" DeviceID: 0x%08x 0x%08x\n", device_id[0], device_id[1]);
-
- if (key_id != server_key_id) {
- printf("Unsupported KeyID %d\n", key_id);
- return -1;
- }
-
- /*
- * Make sure the current user is authorized to reset this board.
- *
- * Since this is just a test, here we'll just make sure the BoardID
- * and DeviceID match what we expected.
- */
- if (memcmp(c.board_id, dummy_board_id, sizeof(c.board_id))) {
- printf("BoardID mismatch\n");
- return -1;
- }
- if (memcmp(c.device_id, dummy_device_id, sizeof(c.device_id))) {
- printf("DeviceID mismatch\n");
- return -1;
- }
-
- /* Calculate the shared secret */
- X25519(secret, server_private_key, c.device_pub_key);
-
- /*
- * Auth code is a truncated HMAC of the ephemeral public key, BoardID,
- * and DeviceID.
- */
- hmac_SHA256(hmac, secret, sizeof(secret), cptr + 1, sizeof(c) - 1);
- if (base32_encode(out_auth_code, RMA_AUTHCODE_BUF_SIZE,
- hmac, RMA_AUTHCODE_CHARS * 5, 0)) {
- printf("Error encoding auth code\n");
- return -1;
- }
- printf("Authcode: %s\n", out_auth_code);
-
- return 0;
-};
-
-#define FORCE_TIME(t) { ts.val = (t); force_time(ts); }
-
-/*
- * rma_try_authcode expects a buffer that is at least RMA_AUTHCODE_CHARS long,
- * so copy the input string to a buffer before calling the function.
- */
-static int rma_try_authcode_pad(const char *code)
-{
- char authcode[RMA_AUTHCODE_BUF_SIZE];
-
- memset(authcode, 0, sizeof(authcode));
- strncpy(authcode, code, sizeof(authcode));
-
- return rma_try_authcode(authcode);
-}
-
-static int test_rma_auth(void)
-{
- const char *challenge;
- char authcode[RMA_AUTHCODE_BUF_SIZE];
- timestamp_t ts;
-
- /* Test rate limiting */
- FORCE_TIME(9 * SECOND);
- TEST_ASSERT(rma_create_challenge() == EC_ERROR_TIMEOUT);
- TEST_ASSERT(rma_try_authcode_pad("Bad") == EC_ERROR_ACCESS_DENIED);
- TEST_ASSERT(strlen(rma_get_challenge()) == 0);
-
- FORCE_TIME(10 * SECOND);
- TEST_ASSERT(rma_create_challenge() == 0);
- TEST_ASSERT(strlen(rma_get_challenge()) == RMA_CHALLENGE_CHARS);
-
- /* Test using up tries */
- TEST_ASSERT(rma_try_authcode_pad("Bad") == EC_ERROR_INVAL);
- TEST_ASSERT(strlen(rma_get_challenge()) == RMA_CHALLENGE_CHARS);
- TEST_ASSERT(rma_try_authcode_pad("BadCodeZ") == EC_ERROR_INVAL);
- TEST_ASSERT(strlen(rma_get_challenge()) == RMA_CHALLENGE_CHARS);
- TEST_ASSERT(rma_try_authcode_pad("BadLongCode") == EC_ERROR_INVAL);
- /* Out of tries now */
- TEST_ASSERT(strlen(rma_get_challenge()) == 0);
- TEST_ASSERT(rma_try_authcode_pad("Bad") == EC_ERROR_ACCESS_DENIED);
-
- FORCE_TIME(19 * SECOND);
- TEST_ASSERT(rma_create_challenge() == EC_ERROR_TIMEOUT);
- TEST_ASSERT(strlen(rma_get_challenge()) == 0);
-
- FORCE_TIME(21 * SECOND);
- TEST_ASSERT(rma_create_challenge() == 0);
- challenge = rma_get_challenge();
- TEST_ASSERT(strlen(challenge) == RMA_CHALLENGE_CHARS);
- TEST_ASSERT(rma_server_side(authcode, challenge) == 0);
- TEST_ASSERT(rma_try_authcode(authcode) == EC_SUCCESS);
-
- /*
- * Make sure the server-side checks for fields work. That is, test
- * our ability to test those fields...
- */
- server_protocol_version++;
- TEST_ASSERT(rma_server_side(authcode, challenge) == -1);
- server_protocol_version--;
-
- server_key_id++;
- TEST_ASSERT(rma_server_side(authcode, challenge) == -1);
- server_key_id--;
-
- dummy_board_id[0]++;
- TEST_ASSERT(rma_server_side(authcode, challenge) == -1);
- dummy_board_id[0]--;
-
- dummy_device_id[0]++;
- TEST_ASSERT(rma_server_side(authcode, challenge) == -1);
- dummy_device_id[0]--;
-
- return EC_SUCCESS;
-}
-
-void run_test(void)
-{
- test_reset();
-
- RUN_TEST(test_rma_auth);
-
- test_print_result();
-}
diff --git a/test/tpm_test/Makefile b/test/tpm_test/Makefile
deleted file mode 100644
index 8942f0db1d..0000000000
--- a/test/tpm_test/Makefile
+++ /dev/null
@@ -1,85 +0,0 @@
-# Copyright 2015 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.
-
-# V unset for normal output, V=1 for verbose output, V=0 for silent build
-# (warnings/errors only). Use echo thus: $(call echo,"stuff to echo")
-ifeq ($(V),0)
-Q := @
-echo = echo -n;
-else
-echo = echo $(1);
-ifeq ($(V),)
-Q := @
-else
-Q :=
-endif
-endif
-
-obj = ../../build/tpm_test
-src = .
-SWIG = /usr/bin/swig
-
-vpath %c $(src) ../../chip/g/dcrypto $(src)/testlib
-
-CFLAGS = -fPIC
-CFLAGS += -I /usr/include/python2.7
-CFLAGS += -I../../../../third_party/cryptoc/include
-CFLAGS += -I../../board/cr50
-CFLAGS += -I../../chip/g
-CFLAGS += -I../../chip/g/dcrypto
-CFLAGS += -I../../fuzz
-CFLAGS += -I../../include
-CFLAGS += -I..
-CFLAGS += -I../..
-CFLAGS += -I.
-CFLAGS += -Itestlib
-CFLAGS += -DLIBFTDI1=1
-CFLAGS += -c
-CFLAGS += -DCR50_NO_BN_ASM
-CFLAGS += -I../../fuzz
-TARGET = ftdi_spi_tpm
-
-.PRECIOUS: $(obj)/ftdi_spi_tpm_wrap.c
-
-all: $(obj)/_$(TARGET).so $(obj)/bn_test
-
-BN_OBJS = $(obj)/bn_test.o $(obj)/common.o $(obj)/bn.o
-
-OBJS = $(obj)/$(TARGET).o $(obj)/$(TARGET)_wrap.o $(obj)/mpsse.o \
- $(obj)/support.o
-
-DEPS := $(OBJS:.o=.o.d) $(BN_OBJS:.o=.o.d)
-
-$(OBJS) $(BN_OBJS): | $(obj)
-
-$(obj)/%.o: $(obj)/%.c
- $(call echo," CC $(notdir $@)")
- $(Q)gcc $(CFLAGS) -o $@ $<
-
-# See "Commonly used compiler options" for more documentation
-$(obj)/%.o: %.c
- $(call echo," CC $(notdir $@)")
- $(Q)gcc $(CFLAGS) -Wall -Werror -MMD -MF $@.d -MT $@ -o $@ $<
-
-$(obj)/_$(TARGET).so: $(OBJS) $(obj)/$(TARGET).py
- $(call echo," LD $(notdir $@)")
- $(Q)rm -f $@
- $(Q)gcc -shared $(OBJS) -lftdi1 -o $@
-
-$(obj)/%_wrap.c: $(src)/%.i
- $(call echo," SWIG $(notdir $@)")
- $(Q)swig -python -outdir $(obj) -o $@ $<
-
-clean:
- @rm -rf $(obj)/
-
-$(obj):
- $(call echo," MKDIR $(obj)")
- $(Q)mkdir -p $(obj)
-
-$(obj)/bn_test: $(BN_OBJS)
- $(call echo," LD $(notdir $@)")
- $(Q)$(CC) -o $@ $^ -lcrypto
-
--include $(DEPS)
diff --git a/test/tpm_test/README.md b/test/tpm_test/README.md
deleted file mode 100644
index 80aaa0a76f..0000000000
--- a/test/tpm_test/README.md
+++ /dev/null
@@ -1,49 +0,0 @@
-# TPM / Crypto unit tests
-tpmtest.py runs set of tests to check correctness of cryptographic functions
-implementation. These tests require a special firmware image built with
-CRYPTO_TEST=1 flag to enable direct exposure of low-level cryptographic
-functions via TPM extensions and vendor commands. TPM functionality itself
-is disabled due to not enough enough flash/memory to fit both.
-As such, these tests are expected to run over H1 Red board.
-
-Firmware image is expected to be built with:
-
-make BOARD=cr50 CRYPTO_TEST=1 -j
-
-Cryptographic tests are invoked when tpmtest.py is executed with no command-line
-parameters:
-
- ./tpmtest.py
-
-Option *-d* can be used for debugging. It adds output of actual data
-sent/received from H1, which is handy when adding new functionality:
-
- ./tpmtest.py -d
-
-# TRNG tests
-Another functionality is statistical assessment of entropy from True Random
-Number Generator (TRNG). These tests are prerequisite for FIPS 140-2/3
-certification and governed by NIST SP 800-90B.
-tpmtest.py implements a mode to download raw data from TRNG:
-
- ./tpmtest.py -t
-
-Script nist_entropy.sh automated this testing by
-1. Downloading latest NIST Entropy Assessment tool from
- [https://github.com/usnistgov/SP800-90B_EntropyAssessment] and building it.
-2. Gathering 1000000 of 8-bit samples from H1 TRNG and
- storing it in /tmp/trng_output using tpmtest.py -t
-3. Running NIST tool in non-IID (independent and identically distributed) mode
- to estimate entropy. This specific mode is choosed as there is no formal
- proof that TRNG data is independent and identically distributed.
- It follows manual in
- [https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90B.pdf]
-
-The successful result is being awarded entropy estimate for TRNG, which is
-expected to be more than 7 (8 is theoretical max).
-If test fails, no entropy assessment is awarded.
-
-This script is expected to run in platform/ec/test/tpm_test directory
-(where ./tpmtest.py is located)
-
-
diff --git a/test/tpm_test/bn_test.c b/test/tpm_test/bn_test.c
deleted file mode 100644
index db06ee93d4..0000000000
--- a/test/tpm_test/bn_test.c
+++ /dev/null
@@ -1,412 +0,0 @@
-/* Copyright 2016 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 "dcrypto.h"
-
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/param.h>
-
-#include <openssl/bn.h>
-
-/**
- * Compatibility layer for OpenSSL 1.0.x.
- * BN_bn2lebinpad and BN_lebin2bn were added in OpenSSL 1.1, to provide
- * import/export functionality as BIGNUM struct became opaque.
- */
-#if OPENSSL_VERSION_NUMBER < 0x10100000L
-#define BN_RAND_TOP_ANY -1
-#define BN_RAND_TOP_ONE 0
-#define BN_RAND_TOP_TWO 1
-#define BN_RAND_BOTTOM_ODD 1
-#define BN_RAND_BOTTOM_ANY 0
-
-/* export BIGNUM as little-endian padded to tolen bytes binary */
-static int BN_bn2lebinpad(const BIGNUM *a, unsigned char *to, int tolen)
-{
- int i;
- BN_ULONG l;
-
- bn_check_top(a);
- i = BN_num_bytes(a);
- if (tolen < i)
- return -1;
- /* Add trailing zeroes if necessary */
- if (tolen > i)
- memset(to + i, 0, tolen - i);
- to += i;
- while (i--) {
- l = a->d[i / BN_BYTES];
- to--;
- *to = (unsigned char)(l >> (8 * (i % BN_BYTES))) & 0xff;
- }
- return tolen;
-}
-
-/* import BIGNUM from little-endian binary of specified length */
-static BIGNUM *BN_lebin2bn(const unsigned char *s, int len, BIGNUM *ret)
-{
- unsigned int i, m;
- unsigned int n;
- BN_ULONG l;
- BIGNUM *bn = NULL;
-
- if (ret == NULL)
- ret = bn = BN_new();
- if (ret == NULL)
- return (NULL);
- bn_check_top(ret);
- s += len;
- /* Skip trailing zeroes. */
- for (; len > 0 && s[-1] == 0; s--, len--)
- continue;
- n = len;
- if (n == 0) {
- ret->top = 0;
- return ret;
- }
- i = ((n - 1) / BN_BYTES) + 1;
- m = ((n - 1) % (BN_BYTES));
- if (bn_wexpand(ret, (int)i) == NULL) {
- BN_free(bn);
- return NULL;
- }
- ret->top = i;
- ret->neg = 0;
- l = 0;
- while (n--) {
- s--;
- l = (l << 8L) | *s;
- if (m-- == 0) {
- ret->d[--i] = l;
- l = 0;
- m = BN_BYTES - 1;
- }
- }
- /*
- * need to call this due to clear byte at top if avoiding
- * having the top bit set (-ve number)
- */
- bn_correct_top(ret);
- return ret;
-}
-#endif
-
-#define MAX_BN_TEST_SIZE 2048
-
-static char to_hexchar(unsigned char c)
-{
- return (c < 10) ? c + '0' : c - 10 + 'A';
-}
-
-static void hex_print(FILE *fp, unsigned char *d, int size)
-{
- char buf[MAX_BN_TEST_SIZE / 4 + 1];
- int i = 0;
-
- assert((size * 2) + 1 <= sizeof(buf));
- while (i < size) {
- buf[i * 2] = to_hexchar((d[size - i - 1] >> 4) & 0xF);
- buf[i * 2 + 1] = to_hexchar(d[size - i - 1] & 0xF);
- i++;
- };
- buf[size * 2] = 0;
- fprintf(fp, buf);
-}
-
-static void dcrypto_print(FILE *fp, struct LITE_BIGNUM *d, int size)
-{
- hex_print(fp, (unsigned char *)d->d, size);
-}
-
-static int bn_dcrypto_cmpeq(const BIGNUM *b, struct LITE_BIGNUM *d)
-{
- unsigned char buf[MAX_BN_TEST_SIZE / 8];
- int size = BN_num_bytes(b);
-
- assert(size <= sizeof(buf));
- BN_bn2lebinpad(b, buf, size);
- return memcmp(d->d, buf, size);
-}
-
-/* Convert OpenSSL BIGNUM to Dcrypto, assumes caller provides buffer */
-static void bn_to_dcrypto(const BIGNUM *b, struct LITE_BIGNUM *d, uint32_t *buf,
- size_t bufsize)
-{
- int bn_size = BN_num_bytes(b);
-
- assert(bn_size <= bufsize);
- memset(buf, 0, bufsize);
- /**
- * OpenSSL 1.0 was only working for little-endian architectures (x86)
- * and had direct access to BIGNUM structure, so DCRYPTO_bn_wrap which
- * just sets a pointer to user provided buffer as source for
- * LITE_BIGNUM could be applied to data in BIGNUM as is.
- * In OpenSSL 1.1 BIGNUM became opaque, so we need to export binary
- * to get data in little-endian format which used by DCRYPTO_*.
- */
- BN_bn2lebinpad(b, (unsigned char *)buf, bn_size);
- DCRYPTO_bn_wrap(d, buf, bufsize);
-}
-
-static int test_bn_modinv_helper(const BIGNUM *E, BN_CTX *ctx, int mod_top,
- int mod_bottom)
-{
- int i, result = 0;
- BIGNUM *MOD, *r;
-
- BN_CTX_start(ctx);
- MOD = BN_CTX_get(ctx);
- r = BN_CTX_get(ctx);
-
- for (i = 0; i < 1000; i++) {
- uint32_t m_buf[MAX_BN_TEST_SIZE / LITE_BN_BITS2];
- uint32_t d_buf[MAX_BN_TEST_SIZE / LITE_BN_BITS2];
- uint32_t e_buf[MAX_BN_TEST_SIZE / LITE_BN_BITS2];
- int has_inverse;
- int test_inverse;
-
- struct LITE_BIGNUM m;
- struct LITE_BIGNUM e;
- struct LITE_BIGNUM d;
-
- /* Top bit set, bottom bit clear. */
- BN_rand(MOD, MAX_BN_TEST_SIZE, mod_top, mod_bottom);
-
- if (BN_mod_inverse(r, E, MOD, ctx))
- has_inverse = 1;
- else
- has_inverse = 0;
- bn_to_dcrypto(MOD, &m, m_buf, sizeof(m_buf));
- bn_to_dcrypto(E, &e, e_buf, sizeof(e_buf));
-
- bn_init(&d, d_buf, sizeof(d_buf));
-
- test_inverse = bn_modinv_vartime(&d, &e, &m);
-
- if (test_inverse != has_inverse) {
- fprintf(stderr,
- "ossl inverse: %d, dcrypto inverse: %d\n",
- has_inverse, test_inverse);
- fprintf(stderr, "d : ");
- BN_print_fp(stderr, r);
- fprintf(stderr, "\n");
-
- fprintf(stderr, "e : ");
- BN_print_fp(stderr, E);
- fprintf(stderr, "\n");
-
- fprintf(stderr, "M : ");
- BN_print_fp(stderr, MOD);
- fprintf(stderr, "\n");
- result = 1;
- goto fail;
- }
-
- if (has_inverse) {
- if (bn_dcrypto_cmpeq(r, &d) != 0) {
- fprintf(stderr,
- "dcrypto bn_modinv_vartime fail\n");
- fprintf(stderr, "d : ");
- BN_print_fp(stderr, r);
- fprintf(stderr, "\n dd: ");
- dcrypto_print(stderr, &d, BN_num_bytes(r));
- fprintf(stderr, "\n");
-
- fprintf(stderr, "e : ");
- BN_print_fp(stderr, E);
- fprintf(stderr, "\n");
-
- fprintf(stderr, "M : ");
- BN_print_fp(stderr, MOD);
- fprintf(stderr, "\n");
-
- result = 1;
- goto fail;
- }
- }
- }
-fail:
- BN_CTX_end(ctx);
- return result;
-}
-
-static int test_bn_modinv(void)
-{
- BN_CTX *ctx;
- BIGNUM *E;
- int result = 1;
-
- ctx = BN_CTX_new();
- BN_CTX_start(ctx);
-
- E = BN_CTX_get(ctx);
-
- BN_rand(E, 1024, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ODD);
- /* Top bit set, bottom bit clear. */
- if (test_bn_modinv_helper(E, ctx, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY))
- goto fail;
-
- if (test_bn_modinv_helper(E, ctx, BN_RAND_TOP_TWO, BN_RAND_BOTTOM_ANY))
- goto fail;
-
- BN_rand(E, 32, BN_RAND_TOP_TWO, BN_RAND_BOTTOM_ODD);
- if (test_bn_modinv_helper(E, ctx, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY))
- goto fail;
-
- BN_rand(E, 17, BN_RAND_TOP_ANY, BN_RAND_BOTTOM_ODD);
- if (test_bn_modinv_helper(E, ctx, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY))
- goto fail;
-
- BN_set_word(E, 3);
- if (test_bn_modinv_helper(E, ctx, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY))
- goto fail;
-
- BN_set_word(E, 65537);
- if (test_bn_modinv_helper(E, ctx, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY))
- goto fail;
-
- result = 0;
-fail:
- BN_CTX_end(ctx);
- BN_CTX_free(ctx);
- return result;
-}
-
-/* Build a BIGNUM with following template:
- * 11111111111111110000001111111111111000000000000123455667
- * size - size in bits
- * front_ones mid_ones_pos,mid_ones, rand_low
- * front_ones - number of 1 bits in highest position
- * mid_ones_pos - starting position of middle ones
- * mid_ones - number of 1 bits in the middle
- * rand_low - number of random low bits
- */
-static BIGNUM *bn_gen(BIGNUM *out, int size, int front_ones, int mid_ones_pos,
- int mid_ones, int rand_low)
-{
- unsigned char n[MAX_BN_TEST_SIZE / 8] = {};
-
- assert(size <= sizeof(n) * 8);
- assert(front_ones < size);
- assert(mid_ones_pos < (size - front_ones - 1));
- assert(mid_ones < (size - mid_ones_pos - 1));
- assert(rand_low < (size - mid_ones_pos - mid_ones - 1));
- /* generate little-endian representation */
- while (front_ones) {
- n[(size - front_ones) / 8] |= 1 << ((size - front_ones) & 7);
- front_ones--;
- }
- while (mid_ones) {
- n[(mid_ones_pos - mid_ones) / 8] |=
- 1 << ((mid_ones_pos - mid_ones) & 7);
- mid_ones--;
- }
- while (rand_low) {
- n[(rand_low - 1) / 8] |= (rand() & 1) << ((rand_low - 1) & 7);
- rand_low--;
- }
-
- return BN_lebin2bn(n, size / 8, out);
-}
-
-static int test_bn_div(void)
-{
- const int NSIZE = MAX_BN_TEST_SIZE;
- const int PSIZE = MAX_BN_TEST_SIZE / 2;
- BIGNUM *N, *P, *Q, *R;
- BN_CTX *ctx;
- int result = 0, total = 0, prev = 1;
- int nf, nmps, nms, pf, pmps, pms;
- struct LITE_BIGNUM p;
- struct LITE_BIGNUM q;
- struct LITE_BIGNUM n;
- struct LITE_BIGNUM r;
-
- uint32_t p_buff[MAX_BN_TEST_SIZE / LITE_BN_BITS2];
- uint32_t q_buff[MAX_BN_TEST_SIZE / LITE_BN_BITS2];
- uint32_t n_buff[MAX_BN_TEST_SIZE / LITE_BN_BITS2];
- uint32_t r_buff[MAX_BN_TEST_SIZE / LITE_BN_BITS2];
-
- ctx = BN_CTX_new();
- BN_CTX_start(ctx);
- N = BN_CTX_get(ctx);
- P = BN_CTX_get(ctx);
- Q = BN_CTX_get(ctx);
- R = BN_CTX_get(ctx);
-
- for (nf = 1; nf <= NSIZE / 8; nf++)
- for (nmps = NSIZE / 16; nmps < (NSIZE / 16) + 2; nmps++)
- for (nms = NSIZE / 32; nms < (NSIZE / 32) + 2; nms++) {
- N = bn_gen(N, NSIZE, nf, nmps, nms, (nmps - nms) / 2);
- for (pf = 1; pf <= PSIZE / 4; pf++)
- for (pmps = PSIZE / 16; pmps < (PSIZE / 16) + 2; pmps++)
- for (pms = PSIZE / 32; pms < (PSIZE / 32) + 2; pms++) {
- P = bn_gen(P, PSIZE, pf, pmps, pms, (pmps - pms) / 2);
- total++;
- bn_to_dcrypto(N, &n, n_buff, sizeof(n_buff));
- bn_to_dcrypto(P, &p, p_buff, sizeof(p_buff));
- DCRYPTO_bn_wrap(&q, q_buff, sizeof(q_buff));
- DCRYPTO_bn_wrap(&r, r_buff, sizeof(r_buff));
-
- BN_div(Q, R, N, P, ctx);
- DCRYPTO_bn_div(&q, &r, &n, &p);
-
- if ((bn_dcrypto_cmpeq(Q, &q) != 0) ||
- (bn_dcrypto_cmpeq(R, &r) != 0)) {
- result++;
- if (result > prev) {
- /* print only 1 sample in 100000 */
- prev = result + 100000;
- fprintf(stderr, "N : ");
- BN_print_fp(stderr, N);
- fprintf(stderr, "\n");
- fprintf(stderr, "P : ");
- BN_print_fp(stderr, P);
- fprintf(stderr, "\n");
-
- fprintf(stderr, "Q : ");
- BN_print_fp(stderr, Q);
- fprintf(stderr, "\nQd: ");
- dcrypto_print(stderr, &q,
- BN_num_bytes(Q));
- fprintf(stderr, "\n");
-
- fprintf(stderr, "R : ");
- BN_print_fp(stderr, R);
- fprintf(stderr, "\nRd: ");
- dcrypto_print(stderr, &r,
- BN_num_bytes(R));
- fprintf(stderr, "\n");
- }
- }
- }
- }
- if (result)
- fprintf(stderr, "DCRYPTO_bn_div: total=%d, failures=%d\n",
- total, result);
- BN_CTX_end(ctx);
- BN_CTX_free(ctx);
-
- return result;
-}
-
-void *always_memset(void *s, int c, size_t n)
-{
- memset(s, c, n);
- return s;
-}
-
-void watchdog_reload(void)
-{
-}
-
-int main(void)
-{
- assert(test_bn_modinv() == 0);
- assert(test_bn_div() == 0);
- fprintf(stderr, "PASS\n");
- return 0;
-}
diff --git a/test/tpm_test/crypto_test.py b/test/tpm_test/crypto_test.py
deleted file mode 100644
index 36253952c5..0000000000
--- a/test/tpm_test/crypto_test.py
+++ /dev/null
@@ -1,243 +0,0 @@
-#!/usr/bin/env python2
-# Copyright 2015 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.
-
-"""Module for testing cryptography functions using extended commands."""
-
-from __future__ import print_function
-
-import binascii
-import struct
-import xml.etree.ElementTree as ET
-
-import subcmd
-import utils
-
-# Basic crypto operations
-DECRYPT = 0
-ENCRYPT = 1
-
-def get_attribute(tdesc, attr_name, required=True):
- """Retrieve an attribute value from an XML node.
-
- Args:
- tdesc: an Element of the ElementTree, a test descriptor containing
- necessary information to run a single encryption/description
- session.
- attr_name: a string, the name of the attribute to retrieve.
- required: a Boolean, if True - the attribute must be present in the
- descriptor, otherwise it is considered optional
- Returns:
- The attribute value as a string (ascii or binary)
- Raises:
- subcmd.TpmTestError: on various format errors, or in case a required
- attribute is not found, the error message describes the problem.
-
- """
- # Fields stored in hex format by default.
- default_hex = ('aad', 'cipher_text', 'iv', 'key', 'tag')
-
- data = tdesc.find(attr_name)
- if data is None:
- if required:
- raise subcmd.TpmTestError('node "%s" does not have attribute "%s"' %
- (tdesc.get('name'), attr_name))
- return ''
-
- # Attribute is present, does it have to be decoded from hex?
- cell_format = data.get('format')
- if not cell_format:
- if attr_name in default_hex:
- cell_format = 'hex'
- else:
- cell_format = 'ascii'
- elif cell_format not in ('hex', 'ascii'):
- raise subcmd.TpmTestError('%s:%s, unrecognizable format "%s"' %
- (tdesc.get('name'), attr_name, cell_format))
-
- text = ' '.join(x.strip() for x in data.text.splitlines() if x)
- if cell_format == 'ascii':
- return text
-
- # Drop spaces from hex representation.
- text = text.replace(' ', '')
-
- # Convert hex-text to little-endian binary (in 4-byte word chunks)
- value = ''
- for x in range(len(text)/8):
- try:
- value += struct.pack('<I', int('0x%s' % text[8*x:8*(x+1)], 16))
- except ValueError:
- raise subcmd.TpmTestError('%s:%s %swrong hex value' %
- (tdesc.get('name'), attr_name, utils.hex_dump(text)))
-
- # Unpack remaining hex text, without introducing a zero pad.
- for x in range(-1, -(len(text) % 8), -1):
- value += chr(int(text[2*x:len(text) + (2*x)+2], 16))
-
- return value
-
-
-class CryptoD(object):
- """A helper object to contain an encryption scheme description.
-
- Attributes:
- subcmd: a 16 bit max integer, the extension subcommand to be used with
- this encryption scheme.
- sumbodes: an optional dictionary, the keys are strings, names of the
- encryption scheme submodes, the values are integers to be included in
- the appropriate subcommand fields to communicat the submode to the
- device.
- """
-
- def __init__(self, subcommand, submodes=None):
- self.subcmd = subcommand
- if not submodes:
- submodes = {}
- self.submodes = submodes
-
-SUPPORTED_MODES = {
- 'AES': CryptoD(subcmd.AES, {
- 'ECB': 0,
- 'CTR': 1,
- 'CBC': 2,
- 'GCM': 3,
- 'OFB': 4,
- 'CFB': 5
- }),
-}
-
-def crypto_run(node_name, op_type, key, iv, aad, in_text, out_text, tpm):
- """Perform a basic operation(encrypt or decrypt).
-
- This function creates an extended command with the requested parameters,
- sends it to the device, and then compares the response to the expected
- value.
-
- Args:
- node_name: a string, the name of the XML node this data comes from. The
- format of the name is "<enc type>:<submode> ....", where <enc type> is
- the major encryption mode (say AED or DES) and submode - a variant of
- the major scheme, if exists.
-
- op_type: an int, encodes the operation to perform (encrypt/decrypt), passed
- directly to the device as a field in the extended command
- key: a binary string
- iv: a binary string, might be empty
- aad: additional authenticated data
- in_text: a binary string, the input of the encrypt/decrypt operation
- out_text: a binary string, might be empty, the expected output of the
- operation. Note that it could be shorter than actual output (padded to
- integer number of blocks), in which case only its length of bytes is
- compared debug_mode: a Boolean, if True - enables tracing on the console
- tpm: a TPM object to send extended commands to an initialized TPM
-
- Returns:
- The actual binary string, result of the operation, if the
- comparison with the expected value was successful.
-
- Raises:
- subcmd.TpmTestError: in case there were problems parsing the node name, or
- verifying the operation results.
-
- """
- mode_name, submode_name = node_name.split(':')
- submode_name = submode_name[:3].upper()
-
- mode = SUPPORTED_MODES.get(mode_name.upper())
- if not mode:
- raise subcmd.TpmTestError('unrecognizable mode in node "%s"' % node_name)
-
- submode = mode.submodes.get(submode_name, 0)
- cmd = '%c' % op_type # Encrypt or decrypt
- cmd += '%c' % submode # A particular type of a generic algorithm.
- cmd += '%c' % len(key)
- cmd += key
- cmd += '%c' % len(iv)
- if iv:
- cmd += iv
- cmd += '%c' % len(aad)
- if aad:
- cmd += aad
- cmd += struct.pack('>H', len(in_text))
- cmd += in_text
- if tpm.debug_enabled():
- print('%d:%d cmd size' % (op_type, mode.subcmd),
- len(cmd), utils.hex_dump(cmd))
- wrapped_response = tpm.command(tpm.wrap_ext_command(mode.subcmd, cmd))
- real_out_text = tpm.unwrap_ext_response(mode.subcmd, wrapped_response)
- if out_text:
- if len(real_out_text) > len(out_text):
- real_out_text = real_out_text[:len(out_text)] # Ignore padding
- if real_out_text != out_text:
- if tpm.debug_enabled():
- print('Out text mismatch in node %s:\n' % node_name)
- else:
- raise subcmd.TpmTestError(
- 'Out text mismatch in node %s, operation %s:\n'
- 'In text:%sExpected out text:%sReal out text:%s' % (
- node_name, 'ENCRYPT' if op_type == ENCRYPT else 'DECRYPT',
- utils.hex_dump(in_text),
- utils.hex_dump(out_text),
- utils.hex_dump(real_out_text)))
- return real_out_text
-
-
-def crypto_test(tdesc, tpm):
- """Perform a single test described in the xml file.
-
- The xml node contains all pertinent information about the test inputs and
- outputs.
-
- Args:
- tdesc: an Element of the ElementTree, a test descriptor containing
- necessary information to run a single encryption/description
- session.
- tpm: a TPM object to send extended commands to an initialized TPM
- Raises:
- subcmd.TpmTestError: on various execution errors, the details are included
- in the error message.
-
- """
- node_name = tdesc.get('name')
- key = get_attribute(tdesc, 'key')
- if len(key) not in (16, 24, 32):
- raise subcmd.TpmTestError('wrong key size "%s:%s"' % (
- node_name,
- ''.join('%2.2x' % ord(x) for x in key)))
- iv = get_attribute(tdesc, 'iv', required=False)
- if iv and not node_name.startswith('AES:GCM') and len(iv) != 16:
- raise subcmd.TpmTestError('wrong iv size "%s:%s"' % (
- node_name,
- ''.join('%2.2x' % ord(x) for x in iv)))
- clear_text = get_attribute(tdesc, 'clear_text', required=False)
- if clear_text:
- clear_text_len = get_attribute(tdesc, 'clear_text_len', required=False)
- if clear_text_len:
- clear_text = clear_text[:int(clear_text_len)]
- else:
- clear_text_len = None
- if tpm.debug_enabled():
- print('clear text size', len(clear_text))
- cipher_text = get_attribute(tdesc, 'cipher_text', required=False)
- if clear_text_len:
- cipher_text = cipher_text[:int(clear_text_len)]
- tag = get_attribute(tdesc, 'tag', required=False)
- aad = get_attribute(tdesc, 'aad', required=False)
- if aad:
- aad_len = get_attribute(tdesc, 'aad_len', required=False)
- if aad_len:
- aad = aad[:int(aad_len)]
- real_cipher_text = crypto_run(node_name, ENCRYPT, key, iv,
- aad or '', clear_text, cipher_text + tag, tpm)
- crypto_run(node_name, DECRYPT, key, iv, aad or '',
- real_cipher_text[:len(real_cipher_text) - len(tag)],
- clear_text + tag, tpm)
- print(utils.cursor_back() + 'SUCCESS: %s' % node_name)
-
-def crypto_tests(tpm, xml_file):
- tree = ET.parse(xml_file)
- root = tree.getroot()
- for child in root:
- crypto_test(child, tpm)
diff --git a/test/tpm_test/crypto_test.xml b/test/tpm_test/crypto_test.xml
deleted file mode 100644
index 152f55c97f..0000000000
--- a/test/tpm_test/crypto_test.xml
+++ /dev/null
@@ -1,899 +0,0 @@
-<?xml version="1.0"?>
-<!--
-Copyright 2015 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.
-
-This file describes test vectors for various encryption schemes.
-
-Each description is encapsulated in a 'crypto_test' element. This element must
-have the name property set. The name starts witht the encryption scheme's name
-(say AES or DES), delimited by a colon, and followed by a three character
-encryption submode, if necessary (say ECB for AES).
-
-The rest of the attributes are self explanatory. The default format for the
-clear_text element is ASCII, for the rest - hex. This default could be
-overridded using the 'format' property.
-
-The ascii strings are stripped of leading and trailing whitespace and then
-joined using space as a separator. Whitespace in hes strings is ignored.
-
-Hex values are interpreted as a set of 4 byte entities in network byte order.
-Many of the crypto_test elements were borrowed from NIST test vectors.
--->
-<crypto_tests>
- <crypto_test name="AES:ECB common">
- <clear_text>
- this is the text which will be encrypted if everything is going fine.
- </clear_text>
- <key>0123456789abcdef0123456789abcdef0123456789abcdef</key>
- <cipher_text>
- <!--
- Cipher text matches the case of the clear text padded with zeros to
- the nearest block size.
- -->
- f90fe23d ce62d9ee 57178af0 d08604c6
- 7244ec3d 871879d8 6d81313f 10bb4c66
- 9fe08dda ccb36763 bde8b464 c9a9b012
- 9ff06d09 fbaee2a4 901cfe0d f0fee26c
- 34b58f68 a9e27607 7bdd8e72 8b2b528b
- </cipher_text>
- </crypto_test>
-
- <crypto_test name="AES:ECB128 1">
- <clear_text format="hex">
- 33221100 77665544 bbaa9988 ffeeddcc
- </clear_text>
- <key>03020100 07060504 0b0a0908 0f0e0d0c</key>
- <cipher_text>
- d8e0c469 30047b6a 80b7cdd8 5ac5b470
- </cipher_text>
- </crypto_test>
- <crypto_test name="AES:ECB192 1">
- <clear_text format="hex">
- 00000000 00000000 00000000 00000000
- </clear_text>
- <key>
- 6e0fd215 9f647ebc b1765bd9 badae607
- 948a7c96 297f7984
- </key>
- <cipher_text>
- 42184e8e 3d1a594e 76086f5b 94856ff1
- </cipher_text>
- </crypto_test>
- <crypto_test name="AES:ECB256 1">
- <clear_text format="hex">
- 00000000 00000000 00000000 00000000
- </clear_text>
- <key>
- 00000080 00000000 00000000 00000000
- 00000000 00000000 00000000 00000000
- </key>
- <cipher_text>
- cb6d5ae3 a001b219 8afabc1e 59572ba2
- </cipher_text>
- </crypto_test>
- <crypto_test name="AES:ECB256 2">
- <clear_text format="hex">
- 45249ff6 179b4fdf 7b412bad 10376ce6
- </clear_text>
- <key>
- 10eb3d60 be71ca15 f0ae732b 81777d85
- 072c351f d708613b a310982d f4df1409
- </key>
- <cipher_text>
- 7a4b3023 fff3f939 8f8d7d06 c7ec249e
- </cipher_text>
- </crypto_test>
- <crypto_test name="AES:CTR128I 1">
- <clear_text format="hex">
- e2bec16b 969f402e 117e3de9 2a179373
- </clear_text>
- <key>
- 16157e2b a6d2ae28 8815f7ab 3c4fcf09
- </key>
- <cipher_text>
- 91614d87 26e320b6 6468ef1b ceb60d99
- </cipher_text>
- <iv>f3f2f1f0 f7f6f5f4 fbfaf9f8 fffefdfc</iv>
- </crypto_test>
-
- <crypto_test name="AES:CTR128I 2">
- <clear_text format="hex">
- 8081582f 93b9e22f b62411a3 1cc78eac
- 43e9160a e450aeee c03fd20f 2c857832
- </clear_text>
- <key>
- 8c6b27c1 b3f18092 f782418c 0f52779d
- </key>
- <cipher_text>
- 0d61fe65 927bb9db 9f9c8cc4 6287a402
- f530a9cf c892dec2 86cb6ae3 2b54fc89
- </cipher_text>
- <iv>
- 00000000 00000000 00000000 FFFFFFFF
- </iv>
- </crypto_test>
-
- <crypto_test name="AES:CTR128I 3">
- <clear_text format="hex">
- d66dc833 7ca1d802 572c5244 a24ae3ab
- ef87947a f917ccf8 568e4d8d 5a4c46d0
- </clear_text>
- <key>
- 82bee9e5 57d2cc8c fa8796d4 338eff1d
- </key>
- <cipher_text>
- 4ab3cfa4 2866ae63 ea4bbc19 a041774d
- 3c16e4a3 5b5589f2 ff6e2e94 6ead92ba
- </cipher_text>
- <iv>
- 00000000 00000000 FFFFFFFF FFFFFFFF
- </iv>
- </crypto_test>
-
- <crypto_test name="AES:CTR128I 4">
- <clear_text format="hex">
- 50ee7879 ff5eeb9b 8b9bbf8d 75d13193
- a61b24a3 5b3cd159 1fa0290c 67693d8c
- </clear_text>
- <key>
- ad9af8e4 dfca7c06 d61adf4c a5d845a3
- </key>
- <cipher_text>
- 123b06d0 fdfcc772 a8a96688 29f40ff2
- 0fcfa412 01fc81ec 15bde846 1ef15d21
- </cipher_text>
- <iv>
- 00000000 FFFFFFFF FFFFFFFF FFFFFFFF
- </iv>
- </crypto_test>
-
- <crypto_test name="AES:CTR128I 5">
- <clear_text format="hex">
- 3b0c5276 f93ae7c6 7791b673 c2af23a1
- c907cb9b 44681b6a dce78a4c f688dcb1
- </clear_text>
- <key>
- f8e5cff3 c5032a29 f1ec8fb9 d01cb31a
- </key>
- <cipher_text>
- 9a74141f 8f8db10e 81e6f51e 84f571a6
- 72e1d939 4b1ad600 7fd5d973 4497a688
- </cipher_text>
- <iv>
- FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF
- </iv>
- </crypto_test>
-
- <crypto_test name="AES:CTR256I 1">
- <clear_text format="hex">
- 13c31e60 a5895777 04f5a7b7 28d2f3bb
- </clear_text>
- <key>
- 10eb3d60 be71ca15 f0ae732b 81777d85
- 072c351f d708613b a310982d f4df1409
- </key>
- <cipher_text>
- e2bec16b 969f402e 117e3de9 2a179373
- </cipher_text>
- <iv>f3f2f1f0 f7f6f5f4 fbfaf9f8 fffefdfc</iv>
- </crypto_test>
-
- <crypto_test name="AES:CBC128 1">
- <clear_text format="hex">
- a636839ed2b0ad1abf458f93adb6d5eb
- </clear_text>
- <key>
- 1f5b102067bf5ed28c24733abceb8b17
- </key>
- <cipher_text>
- d955527cf393f7a6a2cdec0f1692104c
- </cipher_text>
- <iv>
- f67c127e03e4f4de49f690f3b953b6db
- </iv>
- </crypto_test>
-
- <crypto_test name="AES:CBC128 2">
- <clear_text format="hex">
- da092d3ab24b2a6b585ea1cc7cd2f9f000d06d5c5169d20d02d883eda07224f5
- </clear_text>
- <key>
- 8587d0474afdd5fb265928fea02bce8b
- </key>
- <cipher_text>
- 2f039d2e6324fde3778a77f011b975d6e0ac68ad12edee19308536028e7d6e0e
- </cipher_text>
- <iv>
- fd450534ab529f92567ab5c05f221ce2
- </iv>
- </crypto_test>
-
- <crypto_test name="AES:CBC192 1">
- <clear_text format="hex">
- 9b4d5e71fed8bf8650ac1f4165a24dbf
- </clear_text>
- <key>
- 1ccc3bc8256027789502909f6633488906d18472dc5668de
- </key>
- <cipher_text>
- cb0d808aecbf13aadbf9445ef31b211b
- </cipher_text>
- <iv>
- b0aa195cfdb8128cd37006f7be857d2a
- </iv>
- </crypto_test>
-
- <crypto_test name="AES:CBC192 2">
- <clear_text format="hex">
- 796a503d47ce4f508c781b05cabdf090b10bbd35eb8f266d6aefdf9c2557d1dd
- </clear_text>
- <key>
- f24f6e0e8de446d81be04e8535cba109af54814946a58281
- </key>
- <cipher_text>
- 2da16ace5b1928f892816c4564a2156110eb6427068a8b84b91d3f7e2e8ba509
- </cipher_text>
- <iv>
- 72cc0e1acd9c45d80ed3aa24748a2d8b
- </iv>
- </crypto_test>
-
- <crypto_test name="AES:CBC256 1">
- <clear_text format="hex">
- aac63e7086300c38038512e8897c22d2
- </clear_text>
- <key>
- a0af53a1b0d721ab33888afab77c4629332dd3a6c8e6025da3a5227289dec227
- </key>
- <cipher_text>
- 4b8dd68ed2ddac5a738c0ed8e881574d
- </cipher_text>
- <iv>
- 187a3ea27c383d45b864036adaa27a26
- </iv>
- </crypto_test>
-
- <crypto_test name="AES:CBC256 2">
- <clear_text format="hex">
- 02c6dc282c745fe663457d93d3dc6b8259ab14bf7c56ef1ec1ac59c9a650804d
- </clear_text>
- <key>
- 5c01c80bc7206471558c157b5f0c053d9d77a0f3ea81059a1384dc9963e7fa67
- </key>
- <cipher_text>
- de4838d472a8bf060378659f073a640d4978a9602e110eb02f70dade4d49e82b
- </cipher_text>
- <iv>
- 2dbb1d53de16d52185af3828884a61b3
- </iv>
- </crypto_test>
-
- <crypto_test name="AES:CFB128 1">
- <clear_text format="hex">
- c27e8ebe08
- </clear_text>
- <key>
- 21df77a9938963824ad4fb63699b9e10
- </key>
- <cipher_text>
- 93541291b3
- </cipher_text>
- <iv>
- 5b906ff8038ecdf186461cde68ceb87d
- </iv>
- </crypto_test>
-
- <crypto_test name="AES:CFB128 2">
- <clear_text format="hex">
- 1ba5fec5c8ca5f28a79ee5f531d708c2
- </clear_text>
- <key>
- db5331b06fae350196419746be3c8a99
- </key>
- <cipher_text>
- a44756b5f721ee427f2a46e53ff4d1f5
- </cipher_text>
- <iv>
- f43f8a8fe7db8f22f3627d7d594ead2f
- </iv>
- </crypto_test>
-
- <crypto_test name="AES:CFB128 3">
- <clear_text format="hex">
- 8395cf5fa9dc4693d0489ed99ed3d79e4117441110
- </clear_text>
- <key>
- c51e8b5aaac64563fdd3edf3756f4bae
- </key>
- <cipher_text>
- 229f61813f1d51524a11c17075a7999745055b3011
- </cipher_text>
- <iv>
- d4e2873e252d374f3ab8bee783e33056
- </iv>
- </crypto_test>
-
- <crypto_test name="AES:CFB128 4">
- <clear_text format="hex">
- a35814e166659c2fd82894bdccde6f6371025b213bde35920423a7223a09eca3
- </clear_text>
- <key>
- 549ab2663df248cd6a971ea07bc4d7b1
- </key>
- <cipher_text>
- 40cf3a37ca6db39340f1004a57dda9ed3d0629cc93e4facf143c62e02246d0e4
- </cipher_text>
- <iv>
- 8a69c1cf5f9611c00b54478e8a27558b
- </iv>
- </crypto_test>
-
- <crypto_test name="AES:CFB192 1">
- <clear_text format="hex">
- 86c4803c42
- </clear_text>
- <key>
- 746831e7e595aa3fddcbedc1ae26f94bfce4ee40f3e1e980
- </key>
- <cipher_text>
- 1856d5a500
- </cipher_text>
- <iv>
- 01039108067aaa1d4a5047e15f52a9a3
- </iv>
- </crypto_test>
-
- <crypto_test name="AES:CFB192 2">
- <clear_text format="hex">
- 369a7f259cec0ee6cff199b5098dc0ac
- </clear_text>
- <key>
- 6a924856035968f0a1f99e098573085530af14165eb41c01
- </key>
- <cipher_text>
- 49d28326ac3ecabe84b8658ed267beb7
- </cipher_text>
- <iv>
- 944506624e812e1abd7eb0ab7fa08b05
- </iv>
- </crypto_test>
-
- <crypto_test name="AES:CFB192 3">
- <clear_text format="hex">
- 7677dda1638143702f960d314c8b42e9ba012528d9
- </clear_text>
- <key>
- a5f67cbae2b8fdd4ade986274787e74b0c943c4bb3f8ebec
- </key>
- <cipher_text>
- 4729f94311972a541de3a0c6a3808e582059db884f
- </cipher_text>
- <iv>
- 511d4661e60516891d167322417d565b
- </iv>
- </crypto_test>
-
- <crypto_test name="AES:CFB192 4">
- <clear_text format="hex">
- 2ddc71dd68cd0b01a350180216d1d4de32b620e83c77a96decc5c45b571338ab
- </clear_text>
- <key>
- f929b89472bdffa025a3a060e068734cd018e6a28071e48b
- </key>
- <cipher_text>
- 21e716bd4ebc84627786d1380df8499502dc1c028361442ffbe912fd7052d197
- </cipher_text>
- <iv>
- 23975ea307cc5204f29c235b61687ec1
- </iv>
- </crypto_test>
-
- <crypto_test name="AES:CFB256 1">
- <clear_text format="hex">
- d1657ed2b3
- </clear_text>
- <key>
- cc0e6b12df0610b91f6d33ee1f712d87ffc798c157cd11e2f52c9a50bf093371
- </key>
- <cipher_text>
- 3319824a4f
- </cipher_text>
- <iv>
- b123401360708c4aa6f11f5f04e191e1
- </iv>
- </crypto_test>
-
- <crypto_test name="AES:CFB256 2">
- <clear_text format="hex">
- 7933ff6df6c98722419edcd3011a0b6b
- </clear_text>
- <key>
- f42a206acd1c7064017cc869eed6a2807ac57e5f25edc220832e1c13daf113e1
- </key>
- <cipher_text>
- ba6b4bd81d0e6926ed83ae684c2dd829
- </cipher_text>
- <iv>
- 79d679c00af714f943a1f649217d34b4
- </iv>
- </crypto_test>
-
- <crypto_test name="AES:CFB256 3">
- <clear_text format="hex">
- 913091426fa791d9f7b822e5a5e360ca7d575943ea
- </clear_text>
- <key>
- 3c65a7d551d48c9ee6e37cb3f8d1f31cee6c1369e2068843905249346bbca0fa
- </key>
- <cipher_text>
- fff98201e5fa0b08d818da9a614775c4b1e9d399a8
- </cipher_text>
- <iv>
- 70998e67f207486e575b640cfd8ae59f
- </iv>
- </crypto_test>
-
- <crypto_test name="AES:CFB256 4">
- <clear_text format="hex">
- 59ee972cefa6d30c2c3c0c6c73c189066ced4cc0d59afd0728087223d3724943
- </clear_text>
- <key>
- 2826c55b27fdf41c6890a03d4113bb57ae0abb75c5b460e276edc148d3f96dc7
- </key>
- <cipher_text>
- e17c9f488be47bcc54ea366704b9a0941e6e681d8f8445bec6c358038b5169b2
- </cipher_text>
- <iv>
- c3f2173953f34012e82a3f1a6adf9b48
- </iv>
- </crypto_test>
-
- <crypto_test name="AES:OFB128 1">
- <clear_text format="hex">
- c69758215b
- </clear_text>
- <key>
- 30499479a11899b1b6c5293528809bd3
- </key>
- <cipher_text>
- 32fab4a0ac
- </cipher_text>
- <iv>
- 36d1827861331652397de67d24b9f6fa
- </iv>
- </crypto_test>
-
- <crypto_test name="AES:OFB128 2">
- <clear_text format="hex">
- 41efde8ba6e71b9b034234cb7a99b47c
- </clear_text>
- <key>
- 5b966ff25d38416a701a27f686a915cf
- </key>
- <cipher_text>
- b752d8e79190e4b8491268f1456a9511
- </cipher_text>
- <iv>
- 38acff7be2fdffc9314dfe410b24b3a2
- </iv>
- </crypto_test>
-
- <crypto_test name="AES:OFB128 3">
- <clear_text format="hex">
- 49c74e50fb982a979eaf39ac2a558be1a9e5488e4b
- </clear_text>
- <key>
- 49385d8eb6ea0e63cb32c9383d5c3cb6
- </key>
- <cipher_text>
- 6b4f54782fae0cc337b9f806d459df35191fad0b80
- </cipher_text>
- <iv>
- b417edffedd3fc706b5b0fea19ba409b
- </iv>
- </crypto_test>
-
- <crypto_test name="AES:OFB128 4">
- <clear_text format="hex">
- 557c59c190a96492e7e3ce9a7c06a8e33931b1ed02002cb8727c4cc93ee7fcc0
- </clear_text>
- <key>
- f458f61d05a9fff961c38cc2edbf02dc
- </key>
- <cipher_text>
- 778ed8ee5ecb0d41bafea9fbfa8ab5f1f4ab34eb176e9aabab0bc86f33370233
- </cipher_text>
- <iv>
- 90dfffe4e188f48eced3b2c39490530f
- </iv>
- </crypto_test>
-
- <crypto_test name="AES:OFB192 1">
- <clear_text format="hex">
- bb45f365fd
- </clear_text>
- <key>
- 37fa0d1f182f35cb59a11df8737a0c9d0b56801372d2f7ec
- </key>
- <cipher_text>
- 3e84a0d15c
- </cipher_text>
- <iv>
- b3343ff1fdef4f95944b088e218e1b72
- </iv>
- </crypto_test>
-
- <crypto_test name="AES:OFB192 2">
- <clear_text format="hex">
- 44bd7e4e005bc3c01f3f053c7e0589d7
- </clear_text>
- <key>
- 529b351bbe630dbf2d8f0c70331d57848cb773a7b70fe6cb
- </key>
- <cipher_text>
- ac3dc2b0692da4604ac51a7136111bba
- </cipher_text>
- <iv>
- 9fa0ccfcd6368e9fa3ff25137c1a8112
- </iv>
- </crypto_test>
-
- <crypto_test name="AES:OFB192 3">
- <clear_text format="hex">
- 0ff5e3ec8a978b623d72cdaf0ef94154b184161d74
- </clear_text>
- <key>
- 165a62acbf5ec4a01405b4a2f90fa50575327ceb8f70eb78
- </key>
- <cipher_text>
- 2e70ae41889b5d3074221fd830fc1c4774a3c53233
- </cipher_text>
- <iv>
- aa4a6b2c9682c261651836c9205efabe
- </iv>
- </crypto_test>
-
- <crypto_test name="AES:OFB192 4">
- <clear_text format="hex">
- 4d67b3b279c79349f4ca2cea233a2c982739ee38f40ffd1a2c65c0a15b23b0a0
- </clear_text>
- <key>
- fe9a1fb428ac71ad58a5d701701db9cb385c3f366e0dc4cd
- </key>
- <cipher_text>
- c082c1156c2aaab98094c4a097f1e2d1c986062ce89e86c79420512ad313121d
- </cipher_text>
- <iv>
- db72feeeda791cfcb96b6ee6b724f986
- </iv>
- </crypto_test>
-
- <crypto_test name="AES:OFB256 1">
- <clear_text format="hex">
- 732b346426
- </clear_text>
- <key>
- 2d6f926b2954d80e58e00145a74583dcce46efc6167d7d00b7c01ab73ffa83da
- </key>
- <cipher_text>
- 9626f27f3d
- </cipher_text>
- <iv>
- d987a6c6956a951218959da30e2a2169
- </iv>
- </crypto_test>
-
- <crypto_test name="AES:OFB256 2">
- <clear_text format="hex">
- 71fd48054f6db38d33c7314c62b362c2
- </clear_text>
- <key>
- b8eee3cd1a391b59d2894dd47faa4a8266c814e95a460184b2361efd8b386a7a
- </key>
- <cipher_text>
- d221511b5691c96a03c8b0729f8fc944
- </cipher_text>
- <iv>
- e9404d883cb1fbfe4a1ed33193f9bbcf
- </iv>
- </crypto_test>
-
- <crypto_test name="AES:OFB256 3">
- <clear_text format="hex">
- 4990a1bf14a3c56b62c32c670dbdb0d1bc2ce052d8
- </clear_text>
- <key>
- 8b04f99cf4a659490673fce9e81938895210ff98eb74235c22d5fdcc70f61d96
- </key>
- <cipher_text>
- 1246ec884679c1ddad53052a2daeb05f952e54a2d2
- </cipher_text>
- <iv>
- e401e83a2cf2ece54d4b15ed2805d71d
- </iv>
- </crypto_test>
-
- <crypto_test name="AES:OFB256 4">
- <clear_text format="hex">
- f9e4439e4eb67cce27f46417d74bcbb4d38040ac87e9ccbcfa2ad9f6ca612686
- </clear_text>
- <key>
- 5f6bc2dd955f56882c890b619769114796969b7162e1bbcb1260d25f78aae0bb
- </key>
- <cipher_text>
- af05d2d2be7aeea3208e56741144f41369c98691c6e60f3ad2160bcc238d9099
- </cipher_text>
- <iv>
- b11bf6f21675a8799172a8f52ee927a1
- </iv>
- </crypto_test>
-
- <crypto_test name="AES:GCM128 1">
- <key>
- 53c372160082fa7a468a6b4c26d0f0f6
- </key>
- <iv>
- 05
- </iv>
- <tag>
- 21d72a8e745f45f9313db5d88e7ef241
- </tag>
- </crypto_test>
-
- <crypto_test name="AES:GCM128 2">
- <key>
- 74b5dd7fd041c2533aedfb3e1c374ec4
- </key>
- <iv>
- 3f3a28eee37555c78748fd3e
- </iv>
- <tag>
- f91d6db396e5d5b97f8b3ef8b31c9752
- </tag>
- <clear_text format="hex">
- b442ded5256c646129bd875ca2b9d362
- </clear_text>
- <cipher_text>
- a5a4cd2c1eb95c410f2a5c13fdb2c978
- </cipher_text>
- </crypto_test>
-
- <crypto_test name="AES:GCM128 3">
- <key>
- 5571dcfeb2002d197598dd3cbaebb90d
- </key>
- <iv>
- f5746ba756171a5cb13883a0
- </iv>
- <tag>
- 55c43dd28798d4ceeae817c78429ecbe
- </tag>
- <aad>
- c406d22a557e6e173688a02afa16688859e777fa
- </aad>
- <clear_text format="hex">
- 5b433168f1da578848b113c5b5130d8290c42ca7989aa7bdd820f5a6d1393c76
- </clear_text>
- <cipher_text>
- 0538821592a189da6f1dfc3b564d78878b12d1badedbff4da52fbbef685ec362
- </cipher_text>
- </crypto_test>
-
- <crypto_test name="AES:GCM128 4">
- <key>
- 7063be77e2c4718979cbd140eb7fd7e8
- </key>
- <iv>
- 190fe0e001bad7fef397a736
- </iv>
- <tag>
- 8dcc9f2093ed753666719c8e46d99d70
- </tag>
- <aad>
- 1dec437a785a0a9c3365b1a0ab3c21a6
- </aad>
- </crypto_test>
-
- <crypto_test name="AES:GCM128 5">
- <key>
- 79e8e399576e683ec585821d2b5ef764
- </key>
- <iv>
- b80addc2a86ada68230d9cad
- </iv>
- <tag>
- 10ba4f3f341faf0eaaadbab0855d99e9
- </tag>
- <aad>
- 2de468b6a84c444ed9fd3cb2d5ed9f5a21a58a17b0904814f53c73936c5222cf47ee17599a8041658c7a86c6fc099339
- </aad>
- </crypto_test>
-
- <crypto_test name="AES:GCM128 6">
- <key>
- 8824a2d45c1dddf8d6a7196c4c9617ca
- </key>
- <iv>
- 7f83d5f3041aac22d5d1e025
- </iv>
- <tag>
- f9ac3ef273f8cdd186c526779c6e8248
- </tag>
- <aad>
- 24d4c5f1c6963fb88cb28cad470ed2a05a3b025e
- </aad>
- <clear_text format="hex">
- 6a01437b97648916e67b45fb2241a5d2
- </clear_text>
- <cipher_text>
- ee67bdc2ac5ce9f56eb0e327a8d03130
- </cipher_text>
- </crypto_test>
-
- <crypto_test name="AES:GCM128 7">
- <key>
- 635c7cbd562b54b771be0ea088156a33
- </key>
- <iv>
- 231f72878e3c9cbabc1a57a5
- </iv>
- <tag>
- 2267b59c2e250b0d46ff7bb9f80fb0e4
- </tag>
- <aad>
- 7580eca60e37d3a0188959b7483eb9f36251474499b89749a9a67fa84e849f93b7a88a003b4c9f0e28d3191ae743f56bcbfe7b12a517ada1ccfc53ecacecfa266953c7c47daa8e4963ef6a702709004dbae4119b5e3e996c0000d99e
- </aad>
- <aad_len>
- 90
- </aad_len>
- <clear_text format="hex">
- bbdd15de6121201ef69aa7e8f3c65aa5
- </clear_text>
- <cipher_text>
- c028eb4162d7e4fe612397de80bc63c8
- </cipher_text>,
- </crypto_test>
-
- <crypto_test name="AES:GCM128 8">
- <key>
- 23deefdff02b12c689b50a37734b800e
- </key>
- <iv>
- 02a8d6920f679099e279de16
- </iv>
- <tag>
- 9982a39d07c5cd680dc3d1941545cd41
- </tag>
- <aad>
- 786db1a2c1e61d250e35ce9142f25e5c
- </aad>
- <clear_text format="hex">
- 8c0a266478e97d2821756ce9000000d0
- </clear_text>
- <clear_text_len>
- 13
- </clear_text_len>
- <cipher_text>
- 94de78bf177c848ab4d44936000000d0
- </cipher_text>
- </crypto_test>
-
- <crypto_test name="AES:GCM128 9">
- <key>
- dbb8d3cbce11fbfce60657341a8873cd
- </key>
- <iv>
- 68bb62dc5d9aecd041679d75
- </iv>
- <tag>
- b2215a420c5890ea03349188b54b912b
- </tag>
- <aad>
- 61b64409f39462fe08bb2ac959b2c17e4edc32b068285f0c636ebe1c478f17c25af32643c280cad3e785348ec852b2e5
- </aad>
- <aad_len>
- 48
- </aad_len>
- <clear_text format="hex">
- f53bf8855bd5df982adebfc800000064
- </clear_text>
- <clear_text_len>
- 13
- </clear_text_len>
- <cipher_text>
- 3b6b6f20ecdf32b040839fd3000000b1
- </cipher_text>
- </crypto_test>
-
- <crypto_test name="AES:GCM128 10">
- <key>
- 1007719909c0ab5969bdf2e438b39d86
- </key>
- <iv>
- 5ea9a9079c1e82a35132c613
- </iv>
- <tag>
- 11d970781a81547ff1706934410c09de
- </tag>
- <clear_text format="hex">
- 50c34bf56f4fed1fa85efb6d0bdf060182e636d85cb72562e8f622028359b359
- </clear_text>
- <cipher_text>
- 59c156056cf34ef8452b60b10920b1261b6175c7c04db6ff9792cad9016a2ccd
- </cipher_text>
- </crypto_test>
-
- <crypto_test name="AES:GCM128 11">
- <key>
- a17cbf8fdd25d52f58621ee9c251fe73
- </key>
- <iv>
- 51ea0b20a190977b5eafadcf
- </iv>
- <tag>
- 7407867cb93283f8bd6bcea727a77202
- </tag>
- <aad>
- 7fc014a4ec0be6e29e40cc9c6f9c899ebb8005e661c807262385f0f71bda9ce61d713a9c09359c1dc9e471176d99b9502e4fd00a10b3d1002a545358ff9fe0960fc82efc2887f88caef094f5a6984fb18b4e23882703f7fb000064b3
- </aad>
- <aad_len>
- 90
- </aad_len>
- <clear_text format="hex">
- 27e6d33963494b7c42160d840aaefae697dae25b554e1cf602ce57bbc4d40319
- </clear_text>
- <cipher_text>
- f78e67fe95ac696f6d3b55db7aa0d5ad51e1c89da39f6afe1662cda16878b836
- </cipher_text>
- </crypto_test>
-
- <crypto_test name="AES:GCM128 12">
- <key>
- bb5315b6b9954885d01c75298403f8c5
- </key>
- <iv>
- 99f963885de564ae5774bd0b
- </iv>
- <tag>
- 4a5f9b5dc6c16898d86fbd9c4013f051
- </tag>
- <aad>
- f2b514d9e58cb0d1b39ca53e45725810
- </aad>
- <clear_text format="hex">
- 32111b9beac4d01712cf4379adc6693c36973c2e75c9518c55d1454186eee1ddffcac840975c7af1136ad237f34bee7e006d0969
- </clear_text>
- <clear_text_len>
- 51
- </clear_text_len>
- <cipher_text>
- 63b4faac80258a2b3df11251bc82e085bd49dc89a84f169242d2daa2f2b2a1c3df2f6f695f0279f5a96e143f7de4a37d00654bc3
- </cipher_text>
- </crypto_test>
-
- <crypto_test name="AES:GCM128 13">
- <key>
- 2862503caa50f4680c99280936ebe115
- </key>
- <iv>
- 90521d81e7578d76c7b67bd8
- </iv>
- <tag>
- fc5e9bbdcd0880a47d4f3a974438722c
- </tag>
- <aad>
- e0c7e2da2bfdd3a319ca4ec0a07851b184cfb503c2280c890ff215a67f42db8a128c69707887efb2fb93110c7416cdb8
- </aad>
- <clear_text format="hex">
- f8a8d0ed19e93328bfe20f744acfde9edc726cc8ef0c4989aa83697b85fc99af7dc85c6c7c8af96327f31b86a86dea1f00ab156a
- </clear_text>
- <clear_text_len>
- 51
- </clear_text_len>
- <cipher_text>
- b02514a54b3b8d6005ecd446f0da1dca8920dd2bec5405ae841c2afbdc823dc6abb9dd71490b1f1b7cd22adee773512b00a60a00
- </cipher_text>
- </crypto_test>
-</crypto_tests>
diff --git a/test/tpm_test/drbg_test.py b/test/tpm_test/drbg_test.py
deleted file mode 100644
index 097a222923..0000000000
--- a/test/tpm_test/drbg_test.py
+++ /dev/null
@@ -1,108 +0,0 @@
-#!/usr/bin/env python2
-# Copyright 2019 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.
-
-"""Module for testing hash functions using extended commands."""
-
-from __future__ import print_function
-
-from binascii import a2b_hex as a2b
-from struct import pack
-
-import subcmd
-import utils
-
-
-# A standard empty response to DRBG extended commands.
-EMPTY_DRBG_RESPONSE = ''.join('%c' % x for x in (0x80, 0x01,
- 0x00, 0x00, 0x00, 0x0c,
- 0x00, 0x00, 0x00, 0x00,
- 0x00, subcmd.DRBG_TEST))
-
-DRBG_INIT = 0
-DRBG_RESEED = 1
-DRBG_GENERATE = 2
-
-test_inputs = (
- (DRBG_INIT,
- ('C40894D0C37712140924115BF8A3110C7258532365BB598F81B127A5E4CB8EB0',
- 'FBB1EDAF92D0C2699F5C0A7418D308B09AC679FFBB0D8918C8E62D35091DD2B9',
- '2B18535D739F7E75AF4FF0C0C713DD4C9B0A6803D2E0DB2BDE3C4F3650ABF750')),
- (DRBG_RESEED,
- ('4D58A621857706450338CCA8A1AF5CD2BD9305F3475CF1A8752518DD8E8267B6',
- '0153A0A1D7487E2EE9915E2CAA8488F97239C67595F418D9503D0B11CC07044E', '')),
- (DRBG_GENERATE,
- ('39AE66C2939D1D73EF21AE22988B04CC7E8EA2D790C75E1FC6ACC7FEEEF90F98',
- '')),
- (DRBG_GENERATE,
- ('B8031829E07B09EEEADEBA149D0AC9F08B110197CD8BBDDC32744BCD66FCF3C4',
- 'A1307377F6B472661BC3C6D44C035FB20A13CCB04D6601B2425FC4DDA3B6D7DF')),
- (DRBG_INIT,
- ('3A2D261884010CCB4C2C4D7B323CCB7BD4515089BEB749C565A7492710922164',
- '9E4D22471A4546F516099DD4D737967562D1BB77D774B67B7FE4ED893AE336CF',
- '5837CAA74345CC2D316555EF820E9F3B0FD454D8C5B7BDE68E4A176D52EE7D1C')),
- (DRBG_GENERATE,
- ('4D87985505D779F1AD98455E04199FE8F2FE8E550E6FEB1D26177A2C5B744B9F',
- '')),
- (DRBG_GENERATE,
- ('85D011A3B36AC6B25A792F213A1C22C80BFD1C5B47BCA04CD0D9834BB466447B',
- 'B03863C42C9396B4936D83A551871A424C5A8EDBDC9D1E0E8E89710D58B5CA1E')),
-
-)
-
-_DRBG_INIT_FORMAT = '{op:c}{p0l:s}{p0}{p1l:s}{p1}{p2l:s}{p2}'
-def _drbg_init_cmd(op, entropy, nonce, perso):
- return _DRBG_INIT_FORMAT.format(op=op,
- p0l=pack('>H', len(entropy)), p0=entropy,
- p1l=pack('>H', len(nonce)), p1=nonce,
- p2l=pack('>H', len(perso)), p2=perso)
-
-_DRBG_GEN_FORMAT = '{op:c}{p0l:s}{p0}{p1l:s}'
-
-def _drbg_gen_cmd(inp, out):
- outlen = len(out)
- if outlen == 0:
- outlen = 32 # if we don't care about output value, still need to have it
- return _DRBG_GEN_FORMAT.format(op=DRBG_GENERATE,
- p0l=pack('>H', len(inp)), p0=inp,
- p1l=pack('>H', outlen))
-
-
-def drbg_test(tpm):
- """Runs DRBG test case.
-
- Args:
- tpm: a tpm object used to communicate with the device
-
- Raises:
- subcmd.TpmTestError: on unexpected target responses
- """
-
- for test in test_inputs:
- drbg_op, drbg_params = test
- if drbg_op == DRBG_INIT:
- entropy, nonce, perso = drbg_params
- cmd = _drbg_init_cmd(drbg_op, a2b(entropy), a2b(nonce), a2b(perso))
- response = tpm.command(tpm.wrap_ext_command(subcmd.DRBG_TEST, cmd))
- if response != EMPTY_DRBG_RESPONSE:
- raise subcmd.TpmTestError("Unexpected response to DRBG_INIT: %s" %
- (utils.hex_dump(wrapped_response)))
- elif drbg_op == DRBG_RESEED:
- entropy, inp1, inp2 = drbg_params
- cmd = _drbg_init_cmd(drbg_op, a2b(entropy), a2b(inp1), a2b(inp2))
- response = tpm.command(tpm.wrap_ext_command(subcmd.DRBG_TEST, cmd))
- if response != EMPTY_DRBG_RESPONSE:
- raise subcmd.TpmTestError("Unexpected response to DRBG_RESEED: %s" %
- (utils.hex_dump(wrapped_response)))
- elif drbg_op == DRBG_GENERATE:
- inp, expected = drbg_params
- cmd = _drbg_gen_cmd(a2b(inp), a2b(expected))
- response = tpm.command(tpm.wrap_ext_command(subcmd.DRBG_TEST, cmd))
- if expected != '':
- result = response[12:]
- if a2b(expected) != result:
- raise subcmd.TpmTestError('error:\nexpected %s\nreceived %s' %
- (utils.hex_dump(a2b(expected)),
- utils.hex_dump(result)))
- print('%sSUCCESS: %s' % (utils.cursor_back(), 'DRBG test'))
diff --git a/test/tpm_test/ecc_test.py b/test/tpm_test/ecc_test.py
deleted file mode 100644
index 155a497b98..0000000000
--- a/test/tpm_test/ecc_test.py
+++ /dev/null
@@ -1,165 +0,0 @@
-#!/usr/bin/env python2
-# Copyright 2016 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.
-
-"""Module for testing ecc functions using extended commands."""
-import binascii
-import hashlib
-import os
-import struct
-
-import subcmd
-import utils
-
-_ECC_OPCODES = {
- 'SIGN': 0x00,
- 'VERIFY': 0x01,
- 'KEYGEN': 0x02,
- 'KEYDERIVE': 0x03,
-}
-
-_ECC_CURVES = {
- 'NIST-P256': 0x03,
-}
-
-# TPM2 signature codes.
-_SIGN_MODE = {
- 'NONE': 0x00,
- 'ECDSA': 0x18,
- # TODO(ngm): add support for SCHNORR.
- # 'SCHNORR': 0x1c
-}
-
-# TPM2 ALG codes.
-_HASH = {
- 'NONE': 0x00,
- 'SHA1': 0x04,
- 'SHA256': 0x0B
-}
-
-_HASH_FUNC = {
- 'NIST-P256': hashlib.sha256
-}
-
-# Command format.
-#
-# 0x00 OP
-# 0x00 CURVE_ID
-# 0x00 SIGN_MODE
-# 0x00 HASHING
-# 0x00 MSB IN LEN
-# 0x00 LSB IN LEN
-# .... IN
-# 0x00 MSB DIGEST LEN
-# 0x00 LSB DIGEST LEN
-# .... DIGEST
-#
-_ECC_CMD_FORMAT = '{o:c}{c:c}{s:c}{h:c}{ml:s}{msg}{dl:s}{dig}'
-
-
-def _sign_cmd(curve_id, hash_func, sign_mode, msg):
- op = _ECC_OPCODES['SIGN']
- digest = hash_func(msg).digest()
- digest_len = len(digest)
- return _ECC_CMD_FORMAT.format(o=op, c=curve_id, s=sign_mode, h=_HASH['NONE'],
- ml=struct.pack('>H', 0), msg='',
- dl=struct.pack('>H', digest_len), dig=digest)
-
-
-def _verify_cmd(curve_id, hash_func, sign_mode, msg, sig):
- op = _ECC_OPCODES['VERIFY']
- sig_len = len(sig)
- digest = hash_func(msg).digest()
- digest_len = len(digest)
- return _ECC_CMD_FORMAT.format(o=op, c=curve_id, s=sign_mode, h=_HASH['NONE'],
- ml=struct.pack('>H', sig_len), msg=sig,
- dl=struct.pack('>H', digest_len), dig=digest)
-
-
-def _keygen_cmd(curve_id):
- op = _ECC_OPCODES['KEYGEN']
- return _ECC_CMD_FORMAT.format(o=op, c=curve_id, s=_SIGN_MODE['NONE'],
- h=_HASH['NONE'], ml=struct.pack('>H', 0), msg='',
- dl=struct.pack('>H', 0), dig='')
-
-
-def _keyderive_cmd(curve_id, seed):
- op = _ECC_OPCODES['KEYDERIVE']
- seed_len = len(seed)
- return _ECC_CMD_FORMAT.format(o=op, c=curve_id, s=_SIGN_MODE['NONE'],
- h=_HASH['NONE'], ml=struct.pack('>H', seed_len),
- msg=seed, dl=struct.pack('>H', 0), dig='')
-
-
-_SIGN_INPUTS = (
- ('NIST-P256', 'ECDSA'),
-)
-
-
-_KEYGEN_INPUTS = (
- ('NIST-P256',),
-)
-
-
-_KEYDERIVE_INPUTS = (
- # Curve-id, random seed size.
- ('NIST-P256', 32),
-)
-
-
-def _sign_test(tpm):
- msg = 'Hello CR50'
-
- for data in _SIGN_INPUTS:
- curve_id, sign_mode = data
- test_name = 'ECC-SIGN:%s:%s' % data
- cmd = _sign_cmd(_ECC_CURVES[curve_id], _HASH_FUNC[curve_id],
- _SIGN_MODE[sign_mode], msg)
- wrapped_response = tpm.command(tpm.wrap_ext_command(subcmd.ECC, cmd))
- signature = tpm.unwrap_ext_response(subcmd.ECC, wrapped_response)
-
- cmd = _verify_cmd(_ECC_CURVES[curve_id], _HASH_FUNC[curve_id],
- _SIGN_MODE[sign_mode], msg, signature)
- wrapped_response = tpm.command(tpm.wrap_ext_command(subcmd.ECC, cmd))
- verified = tpm.unwrap_ext_response(subcmd.ECC, wrapped_response)
- expected = '\x01'
- if verified != expected:
- raise subcmd.TpmTestError('%s error:%s:%s' % (
- test_name, utils.hex_dump(verified), utils.hex_dump(expected)))
- print('%sSUCCESS: %s' % (utils.cursor_back(), test_name))
-
-
-def _keygen_test(tpm):
- for data in _KEYGEN_INPUTS:
- curve_id, = data
- test_name = 'ECC-KEYGEN:%s' % data
- cmd = _keygen_cmd(_ECC_CURVES[curve_id])
- wrapped_response = tpm.command(tpm.wrap_ext_command(subcmd.ECC, cmd))
- valid = tpm.unwrap_ext_response(subcmd.ECC, wrapped_response)
- expected = '\x01'
- if valid != expected:
- raise subcmd.TpmTestError('%s error:%s:%s' % (
- test_name, utils.hex_dump(valid), utils.hex_dump(expected)))
- print('%sSUCCESS: %s' % (utils.cursor_back(), test_name))
-
-
-def _keyderive_test(tpm):
- for data in _KEYDERIVE_INPUTS:
- curve_id, seed_bytes = data
- seed = os.urandom(seed_bytes)
- test_name = 'ECC-KEYDERIVE:%s' % data[0]
- cmd = _keyderive_cmd(_ECC_CURVES[curve_id], seed)
- wrapped_response = tpm.command(tpm.wrap_ext_command(subcmd.ECC, cmd))
- valid = tpm.unwrap_ext_response(subcmd.ECC, wrapped_response)
- expected = '\x01'
- if valid != expected:
- raise subcmd.TpmTestError('%s error:%s:%s' % (
- test_name, utils.hex_dump(valid), utils.hex_dump(expected)))
- print('%sSUCCESS: %s' % (utils.cursor_back(), test_name))
-
-
-def ecc_test(tpm):
- _sign_test(tpm)
- _keygen_test(tpm)
- _keyderive_test(tpm)
diff --git a/test/tpm_test/ecies_test.py b/test/tpm_test/ecies_test.py
deleted file mode 100644
index 96620c14b5..0000000000
--- a/test/tpm_test/ecies_test.py
+++ /dev/null
@@ -1,233 +0,0 @@
-#!/usr/bin/env python2
-# Copyright 2016 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.
-
-"""Module for testing ECIES using extended commands."""
-from binascii import b2a_hex as b2a
-from binascii import a2b_hex as a2b
-from struct import pack
-
-import subcmd
-import utils
-
-_ECIES_OPCODES = {
- 'ENCRYPT': 0x00,
- 'DECRYPT': 0x01,
-}
-
-#
-# Command format.
-#
-# WIDTH FIELD
-# 1 OP
-# 1 MSB IN LEN
-# 1 LSB IN LEN
-# IN_LEN IN
-# 1 MSB AUTH_DATA LEN
-# 1 LSB AUTH_DATA LEN
-# 16 IV
-# 1 MSB PUB_X LEN
-# 1 LSB PUB_X LEN
-# PUB_X_LEN PUB_X
-# 1 MSB PUB_Y LEN
-# 1 LSB PUB_Y LEN
-# PUB_Y_LEN PUB_Y
-# 1 MSB SALT LEN
-# 1 LSB SALT LEN
-# SALT_LEN SALT
-# 1 MSB INFO LEN
-# 1 LSB INFO LEN
-# INFO_LEN INFO
-#
-_ECIES_CMD_FORMAT = '{o:c}{inl:s}{input}{al:s}{iv}{xl:s}{x}{yl:s}{y}{sl:s}{s}{il:s}{i}'
-
-
-_DEFAULT_SALT = 'Salt!'
-_DEFAULT_INFO = 'Info!'
-_STATIC_IV = ''.join([chr(x) for x in range(16)])
-
-_ECIES_INPUTS = (
- (
- '',
- 'Test message!!',
- _STATIC_IV,
- a2b('6fdaf5e2e11dd61c116222c748d99b45f69031c9d4d3d5787a9a0fdd3b9c471a'),
- a2b('98e76f53febd6bedc8fa19ce1543cb3f8f5cbc72c74602f1bfdee88c19d3d9d0'),
- a2b('8750c295cd33be5846868e2869bf2c8cfeefbc4a574874c7388bf40f74e8e0e6'),
- _DEFAULT_SALT,
- _DEFAULT_INFO,
- 'SIMPLE'
- ),
- (
- '',
- 'Multi block test message!!!!',
- _STATIC_IV,
- a2b('6fdaf5e2e11dd61c116222c748d99b45f69031c9d4d3d5787a9a0fdd3b9c471a'),
- a2b('98e76f53febd6bedc8fa19ce1543cb3f8f5cbc72c74602f1bfdee88c19d3d9d0'),
- a2b('8750c295cd33be5846868e2869bf2c8cfeefbc4a574874c7388bf40f74e8e0e6'),
- _DEFAULT_SALT,
- _DEFAULT_INFO,
- 'MULTI-BLOCK'
- ),
- (
- 'Auth data',
- 'Test message!!!!',
- _STATIC_IV,
- a2b('6fdaf5e2e11dd61c116222c748d99b45f69031c9d4d3d5787a9a0fdd3b9c471a'),
- a2b('98e76f53febd6bedc8fa19ce1543cb3f8f5cbc72c74602f1bfdee88c19d3d9d0'),
- a2b('8750c295cd33be5846868e2869bf2c8cfeefbc4a574874c7388bf40f74e8e0e6'),
- _DEFAULT_SALT,
- _DEFAULT_INFO,
- 'AUTH-DATA'
- ),
- (
- 'Auth data' * 10,
- 'Test message!!!!',
- _STATIC_IV,
- a2b('6fdaf5e2e11dd61c116222c748d99b45f69031c9d4d3d5787a9a0fdd3b9c471a'),
- a2b('98e76f53febd6bedc8fa19ce1543cb3f8f5cbc72c74602f1bfdee88c19d3d9d0'),
- a2b('8750c295cd33be5846868e2869bf2c8cfeefbc4a574874c7388bf40f74e8e0e6'),
- _DEFAULT_SALT,
- _DEFAULT_INFO,
- 'LARGE-AUTH-DATA'
- ),
- (
- 'Auth data',
- 'Test message!!!!' * 5,
- _STATIC_IV,
- a2b('6fdaf5e2e11dd61c116222c748d99b45f69031c9d4d3d5787a9a0fdd3b9c471a'),
- a2b('98e76f53febd6bedc8fa19ce1543cb3f8f5cbc72c74602f1bfdee88c19d3d9d0'),
- a2b('8750c295cd33be5846868e2869bf2c8cfeefbc4a574874c7388bf40f74e8e0e6'),
- _DEFAULT_SALT,
- _DEFAULT_INFO,
- 'LARGE-PLAINTEXT-DATA'
- ),
- (
- '',
- 'Test message!!',
- _STATIC_IV,
- a2b('6fdaf5e2e11dd61c116222c748d99b45f69031c9d4d3d5787a9a0fdd3b9c471a'),
- a2b('98e76f53febd6bedc8fa19ce1543cb3f8f5cbc72c74602f1bfdee88c19d3d9d0'),
- a2b('8750c295cd33be5846868e2869bf2c8cfeefbc4a574874c7388bf40f74e8e0e6'),
- '',
- '',
- 'NO-SALT-INFO'
- ),
- (
- 'Auth data',
- '',
- _STATIC_IV,
- a2b('6fdaf5e2e11dd61c116222c748d99b45f69031c9d4d3d5787a9a0fdd3b9c471a'),
- a2b('98e76f53febd6bedc8fa19ce1543cb3f8f5cbc72c74602f1bfdee88c19d3d9d0'),
- a2b('8750c295cd33be5846868e2869bf2c8cfeefbc4a574874c7388bf40f74e8e0e6'),
- _DEFAULT_SALT,
- _DEFAULT_INFO,
- 'AUTH-NULL-PLAINTEXT'
- ),
- (
- '',
- '',
- _STATIC_IV,
- a2b('6fdaf5e2e11dd61c116222c748d99b45f69031c9d4d3d5787a9a0fdd3b9c471a'),
- a2b('98e76f53febd6bedc8fa19ce1543cb3f8f5cbc72c74602f1bfdee88c19d3d9d0'),
- a2b('8750c295cd33be5846868e2869bf2c8cfeefbc4a574874c7388bf40f74e8e0e6'),
- _DEFAULT_SALT,
- _DEFAULT_INFO,
- 'NULL-PLAINTEXT'
- ),
-)
-
-_ECIES_COMPAT_INPUTS = (
- (
- a2b('d61262f22e8c70414777cbc060d1e387'),
- 'The quick brown fox jumps over the lazy dog.',
- a2b('d61262f22e8c70414777cbc060d1e387'),
- a2b('040c23b1abb7f7e3d2da6ffd70ce9e6f5bf90467c0e1f2e708483d2e61220f0a'
- '0257110d695bec78ac1e15333219d7ba3f8f2f155b76acd56d99680031d83853'
- '99d61262f22e8c70414777cbc060d1e387a4e9ac4624b79e326c19396b44842b'
- 'd995123343efe844821ff97ed08e38db59141ed8185359f76121d5fce7c4491d'
- '902551bdd9bbd28e0ae27d1d4c9a6c1a9bb7b8aa36d1b1f6cce0425739'),
- a2b('67e0df0b8e5131766340c895553c13053332fdee1fbd2d9cdde22a331a49aaa1'),
- _DEFAULT_SALT,
- _DEFAULT_INFO,
- 'COMPAT-TEST1'
- ),
- (
- a2b('b3a89ed5a7fb6685a67db54c62e663e7'),
- 'Test message!!',
- a2b('b3a89ed5a7fb6685a67db54c62e663e7'),
- a2b('04b9d46d1f333baf6896ce7b64d344092671795438b1dc35a21b0d13b004f28a1c'
- 'edd4f1f7ff63106772270050cb62152b07e9c02bbee79db7a3fb4155c464e0d5b3'
- 'a89ed5a7fb6685a67db54c62e663e70fed2b44ce0f705e9a84a09978b82f6c603e'
- 'b6e6923d592f22193fb7ba0e1765ecd4861ec46c138d85b7206dbd41'),
- a2b('6fdaf5e2e11dd61c116222c748d99b45f69031c9d4d3d5787a9a0fdd3b9c471a'),
- _DEFAULT_SALT,
- _DEFAULT_INFO,
- 'COMPAT-TEST2'
- )
-)
-
-
-def _encrypt_cmd(auth, input, iv, pubx, puby, salt, info):
- op = _ECIES_OPCODES['ENCRYPT']
- return _ECIES_CMD_FORMAT.format(o=op, inl=pack('>H', len(auth+input)), input=auth+input,
- al=pack('>H', len(auth)), iv=iv,
- xl=pack('>H', len(pubx)), x=pubx,
- yl=pack('>H', len(puby)), y=puby,
- sl=pack('>H', len(salt)), s=salt,
- il=pack('>H', len(info)), i=info)
-
-
-def _decrypt_cmd(auth, input, iv, d, salt, info):
- op = _ECIES_OPCODES['DECRYPT']
- return _ECIES_CMD_FORMAT.format(o=op, inl=pack('>H', len(input)), input=input,
- al=pack('>H', len(auth)), iv=iv,
- xl=pack('>H', len(d)), x=d,
- yl=pack('>H', 0), y='',
- sl=pack('>H', len(salt)), s=salt,
- il=pack('>H', len(info)), i=info)
-
-
-def _ecies_test(tpm):
- for data in _ECIES_INPUTS:
- auth, input, iv, d, pubx, puby, salt, info = data[:-1]
- test_name = 'ECIES-TEST:%s' % data[-1]
- cmd = _encrypt_cmd(auth, input, iv, pubx, puby, salt, info)
- wrapped_response = tpm.command(tpm.wrap_ext_command(subcmd.ECIES, cmd))
- encrypted = tpm.unwrap_ext_response(subcmd.ECIES, wrapped_response)
- # check length of encrypted.
- if not encrypted:
- raise subcmd.TpmTestError('%s error:%s' % (
- test_name, 'null encrypted'))
-
- cmd = _decrypt_cmd(auth, encrypted, iv, d, salt, info)
- wrapped_response = tpm.command(tpm.wrap_ext_command(subcmd.ECIES, cmd))
- decrypted = tpm.unwrap_ext_response(subcmd.ECIES, wrapped_response)
-
- expected = auth + input
- if decrypted != expected:
- raise subcmd.TpmTestError('%s error:%s:%s' % (
- test_name, utils.hex_dump(decrypted), utils.hex_dump(expected)))
- print('%sSUCCESS: %s' % (utils.cursor_back(), test_name))
-
-
-def _compat_test(tpm):
- for data in _ECIES_COMPAT_INPUTS:
- auth, plaintext, iv, ciphertext, d, salt, info = data[:-1]
- test_name = 'ECIES-TEST:%s' % data[-1]
-
- cmd = _decrypt_cmd(auth, ciphertext, iv, d, salt, info)
- wrapped_response = tpm.command(tpm.wrap_ext_command(subcmd.ECIES, cmd))
- decrypted = tpm.unwrap_ext_response(subcmd.ECIES, wrapped_response)
-
- expected = auth + plaintext
- if decrypted != expected:
- raise subcmd.TpmTestError('%s error:%s:%s' % (
- test_name, utils.hex_dump(decrypted), utils.hex_dump(expected)))
- print('%sSUCCESS: %s' % (utils.cursor_back(), test_name))
-
-
-def ecies_test(tpm):
- _ecies_test(tpm)
- _compat_test(tpm)
diff --git a/test/tpm_test/ftdi_spi_tpm.c b/test/tpm_test/ftdi_spi_tpm.c
deleted file mode 100644
index 4fc281aa24..0000000000
--- a/test/tpm_test/ftdi_spi_tpm.c
+++ /dev/null
@@ -1,495 +0,0 @@
-/* Copyright 2015 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 <endian.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
-
-#include "ftdi_spi_tpm.h"
-
-static struct mpsse_context *mpsse_;
-static unsigned locality_; /* Set at initialization. */
-static int ftdi_trace_enabled;
-
-/* Assorted TPM2 registers for interface type FIFO. */
-#define TPM_LOCALITY_0_SPI_BASE 0x00d40000
-
-#define TPM_ACCESS_REG (TPM_LOCALITY_0_SPI_BASE + 0)
-#define TPM_STS_REG (TPM_LOCALITY_0_SPI_BASE + 0x18)
-#define TPM_DATA_FIFO_REG (TPM_LOCALITY_0_SPI_BASE + 0x24)
-#define TPM_DID_VID_REG (TPM_LOCALITY_0_SPI_BASE + 0xf00)
-#define TPM_RID_REG (TPM_LOCALITY_0_SPI_BASE + 0xf04)
-#define TPM_FW_VER (TPM_LOCALITY_0_SPI_BASE + 0xf90)
-
-static struct swig_string_data empty_string_data = (struct swig_string_data){
- .size = 0, .data = NULL
-};
-
-/* Locality management bits (in TPM_ACCESS_REG). */
-enum TpmAccessBits {
- tpmRegValidSts = (1 << 7),
- activeLocality = (1 << 5),
- requestUse = (1 << 1),
- tpmEstablishment = (1 << 0),
-};
-
-enum TpmStsBits {
- tpmFamilyShift = 26,
- tpmFamilyMask = ((1 << 2) - 1), /* 2 bits wide. */
- tpmFamilyTPM2 = 1,
- resetEstablishmentBit = (1 << 25),
- commandCancel = (1 << 24),
- burstCountShift = 8,
- burstCountMask = ((1 << 16) - 1), /* 16 bits wide. */
- stsValid = (1 << 7),
- commandReady = (1 << 6),
- tpmGo = (1 << 5),
- dataAvail = (1 << 4),
- Expect = (1 << 3),
- selfTestDone = (1 << 2),
- responseRetry = (1 << 1),
-};
-
-enum {
- false = 0,
- true = 1
-};
-
-/*
- * SPI frame header for TPM transactions is 4 bytes in size, it is described
- * in section "6.4.6 Spi Bit Protocol" of the TCG issued "TPM Profile (PTP)
- * Specification Revision 00.43.
- */
-struct SpiFrameHeader {
- unsigned char body[4];
-};
-
-void FtdiStop(void)
-{
- if (mpsse_)
- Close(mpsse_);
-
- mpsse_ = NULL;
-}
-
-/*
- * If the TPM is asleep we may need to poke it once to wake it up. Just assert
- * the CS briefly without sending any data, then wait a bit to be sure it's
- * awake.
- */
-static void FtdiSpiPoke(void)
-{
- Start(mpsse_);
- usleep(1000);
- Stop(mpsse_);
- usleep(60000);
-}
-
-static void StartTransaction(int read_write, size_t bytes, unsigned addr)
-{
- struct SpiFrameHeader header;
- int i;
- uint8_t flow_c;
- char *transfer_data;
-
- /*
- * give it 10 ms. TODO(vbendeb): remove this once cr50 SPS TPM driver
- * performance is fixed.
- */
- usleep(10000);
-
- /*
- * The first byte of the frame header encodes the transaction type
- * (read or write) and size (set to length - 1).
- */
- header.body[0] = (read_write ? 0x80 : 0) | 0x40 | (bytes - 1);
-
- /* The rest of the frame header is the internal address in the TPM. */
- for (i = 0; i < 3; i++)
- header.body[i + 1] = (addr >> (8 * (2 - i))) & 0xff;
-
- Start(mpsse_);
-
- transfer_data =
- Transfer(mpsse_, (char *)header.body, sizeof(header.body));
-
- /*
- * The TCG TPM over SPI specification itroduces the notion of SPI flow
- * control (Section "6.4.5 Flow Control" of the TCG issued "TPM
- * Profile (PTP) Specification Revision 00.43).
- *
- * The slave (TPM device) expects each transaction to start with a 4
- * byte header trasmitted by master. If the slave needs to stall the
- * transaction, it sets the MOSI bit to 0 during the last clock of the
- * 4 byte header. In this case the master is supposed to start polling
- * the line, byte at time, until the last bit in the received byte
- * (transferred during the last clock of the byte) is set to 1.
- */
- flow_c = transfer_data[3];
- free(transfer_data);
- while (!(flow_c & 1)) {
- transfer_data = Read(mpsse_, 1);
- flow_c = transfer_data[0];
- free(transfer_data);
- }
-}
-
-static void trace_dump(const char *prefix, unsigned reg, size_t bytes,
- const uint8_t *buffer)
-{
- if (!ftdi_trace_enabled)
- return;
- printf("%s %2.2x:", prefix, reg);
- if (bytes == 4) {
- printf(" %8.8x\n", *(const uint32_t *)buffer);
- } else {
- int i;
-
- for (i = 0; i < bytes; i++)
- printf(" %2.2x", buffer[i]);
- printf("\n");
- }
-}
-
-static int FtdiWriteReg(unsigned reg_number, size_t bytes, void *buffer)
-{
- if (!mpsse_)
- return false;
-
- trace_dump("W", reg_number, bytes, buffer);
- StartTransaction(false, bytes, reg_number + locality_ * 0x10000);
- Write(mpsse_, buffer, bytes);
- Stop(mpsse_);
- return true;
-}
-
-static int FtdiReadReg(unsigned reg_number, size_t bytes, void *buffer)
-{
- void *data;
-
- if (!mpsse_)
- return false;
-
- StartTransaction(true, bytes, reg_number + locality_ * 0x10000);
- data = Read(mpsse_, bytes);
- if (data)
- memcpy(buffer, data, bytes);
- free(data);
- Stop(mpsse_);
- trace_dump("R", reg_number, bytes, buffer);
- return true;
-}
-
-static int ReadTpmSts(uint32_t *status)
-{
- return FtdiReadReg(TPM_STS_REG, sizeof(*status), status);
-}
-
-static int WriteTpmSts(uint32_t status)
-{
- return FtdiWriteReg(TPM_STS_REG, sizeof(status), &status);
-}
-
-static uint32_t GetBurstCount(void)
-{
- uint32_t status;
-
- ReadTpmSts(&status);
- return (status >> burstCountShift) & burstCountMask;
-}
-
-static void GetVersion(void)
-{
- int chunk_count = 0;
- uint32_t chunk = 0;
- char vstr[sizeof(chunk) + 1]; /* room for 4 chars + zero */
-
- /*
- * Does not really matter what's written, this just makes sure
- * the version is reported from the beginning.
- */
- FtdiWriteReg(TPM_FW_VER, sizeof(chunk), &chunk);
-
- /* Print it out in 4 byte chunks. */
- vstr[sizeof(vstr) - 1] = 0;
- do {
- FtdiReadReg(TPM_FW_VER, sizeof(chunk), vstr);
- printf("%s", vstr);
-
- /*
- * While string is not over, and no more than 200
- * characters.
- * This is likely result in one extra printk()
- * invocation with an empty string, not a big deal.
- */
- } while (vstr[0] && (chunk_count++ < (400 / sizeof(chunk))));
-
- printf("\n");
-}
-
-int FtdiSpiInit(uint32_t freq, int enable_debug)
-{
- uint32_t did_vid, status;
- uint8_t cmd;
- uint16_t vid;
-
- if (mpsse_)
- return true;
-
- ftdi_trace_enabled = enable_debug;
-
- /* round frequency down to the closest 100KHz */
- freq = (freq / (100 * 1000)) * 100 * 1000;
-
- printf("Starting MPSSE at %d kHz\n", freq / 1000);
- mpsse_ = MPSSE(freq, MSB, NULL);
- if (!mpsse_)
- return false;
-
- /* Just in case, make sure bootsrap is not triggered. */
- PinLow(mpsse_, GPIOL0);
-
- FtdiSpiPoke();
-
- FtdiReadReg(TPM_DID_VID_REG, sizeof(did_vid), &did_vid);
-
- vid = did_vid & 0xffff;
- if ((vid != 0x15d1) && (vid != 0x1ae0)) {
- fprintf(stderr, "unknown did_vid: %#x\n", did_vid);
- return false;
- }
-
- /* Try claiming locality zero. */
- FtdiReadReg(TPM_ACCESS_REG, sizeof(cmd), &cmd);
- if ((cmd & (activeLocality & tpmRegValidSts)) ==
- (activeLocality & tpmRegValidSts)) {
- /*
- * Locality active - maybe reset line is not connected?
- * Release the locality and try again
- */
- cmd = activeLocality;
- FtdiWriteReg(TPM_ACCESS_REG, sizeof(cmd), &cmd);
- FtdiReadReg(TPM_ACCESS_REG, sizeof(cmd), &cmd);
- }
-
- /* tpmEstablishment can be either set or not. */
- if ((cmd & ~tpmEstablishment) != tpmRegValidSts) {
- fprintf(stderr, "invalid reset status: %#x\n", cmd);
- return false;
- }
- cmd = requestUse;
- FtdiWriteReg(TPM_ACCESS_REG, sizeof(cmd), &cmd);
- FtdiReadReg(TPM_ACCESS_REG, sizeof(cmd), &cmd);
- if ((cmd & ~tpmEstablishment) != (tpmRegValidSts | activeLocality)) {
- fprintf(stderr, "failed to claim locality, status: %#x\n", cmd);
- return false;
- }
-
- ReadTpmSts(&status);
- if (((status >> tpmFamilyShift) & tpmFamilyMask) != tpmFamilyTPM2) {
- fprintf(stderr, "unexpected TPM family value, status: %#x\n",
- status);
- return false;
- }
- FtdiReadReg(TPM_RID_REG, sizeof(cmd), &cmd);
- printf("Connected to device vid:did:rid of %4.4x:%4.4x:%2.2x\n",
- did_vid & 0xffff, did_vid >> 16, cmd);
-
- GetVersion();
-
- return true;
-}
-
-/* This is in seconds (prime generation may take several minutes). */
-#define MAX_STATUS_TIMEOUT 900
-static int WaitForStatus(uint32_t statusMask, uint32_t statusExpected)
-{
- uint32_t status;
- time_t target_time;
- static unsigned max_timeout;
-
- target_time = time(NULL) + MAX_STATUS_TIMEOUT;
- do {
- usleep(10000);
- if (time(NULL) >= target_time) {
- fprintf(stderr, "failed to get expected status %x\n",
- statusExpected);
- return false;
- }
- ReadTpmSts(&status);
- } while ((status & statusMask) != statusExpected);
-
- /* Calculate time spent waiting */
- target_time = MAX_STATUS_TIMEOUT - target_time + time(NULL);
- if (max_timeout < (unsigned)target_time) {
- max_timeout = target_time;
- printf("New max timeout: %d s\n", max_timeout);
- }
-
- return true;
-}
-
-static void SpinSpinner(void)
-{
- static const char *spinner = "\\|/-";
- static int index;
-
- if (index > strlen(spinner))
- index = 0;
-
- fprintf(stdout, "%c[1D%c", 0x1b, spinner[index++]);
- fflush(stdout);
-}
-
-#define MAX_RESPONSE_SIZE 4096
-#define HEADER_SIZE 6
-
-/* tpm_command points at a buffer 4096 bytes in size */
-struct swig_string_data FtdiSendCommandAndWait(char *tpm_command,
- int command_size)
-{
- uint32_t status;
- uint32_t expected_status_bits;
- size_t handled_so_far;
- uint32_t payload_size;
- char message[100];
- int offset = 0;
- uint8_t *response;
-
- if (!mpsse_) {
- fprintf(stderr, "attempt to use an uninitialized FTDI TPM!\n");
- return empty_string_data;
- }
-
- response = malloc(MAX_RESPONSE_SIZE);
- if (!response) {
- fprintf(stderr, "attempt to use an uninitialized FTDI TPM!\n");
- return empty_string_data;
- }
-
- handled_so_far = 0;
-
- WriteTpmSts(commandReady);
-
- memcpy(&payload_size, tpm_command + 2, sizeof(payload_size));
- payload_size = be32toh(payload_size);
- offset +=
- snprintf(message, sizeof(message), "Message size %d", payload_size);
-
- /*
- * No need to wait for the sts.Expect bit to be set, at least with the
- * 15d1:001b and 1ae0:0028 devices. Let's just write the command into
- * FIFO, make sure not to exceed the burst count.
- */
- do {
- uint32_t transaction_size;
- uint32_t burst_count = GetBurstCount();
-
- if (burst_count > 64)
- burst_count = 64;
-
- transaction_size = command_size - handled_so_far;
- if (transaction_size > burst_count)
- transaction_size = burst_count;
-
- if (transaction_size) {
- FtdiWriteReg(TPM_DATA_FIFO_REG, transaction_size,
- tpm_command + handled_so_far);
- handled_so_far += transaction_size;
- }
- } while (handled_so_far != command_size);
-
- /* And tell the device it can start processing it. */
- WriteTpmSts(tpmGo);
-
- expected_status_bits = stsValid | dataAvail;
- if (!WaitForStatus(expected_status_bits, expected_status_bits)) {
- size_t i;
-
- printf("Failed processing. %s:", message);
- for (i = 0; i < command_size; i++) {
- if (!(i % 16))
- printf("\n");
- printf(" %2.2x", (uint8_t)tpm_command[i]);
- }
- printf("\n");
- return empty_string_data;
- }
-
- /*
- * The tpm_command is ready, let's read it.
- *
- * First we read the FIFO payload header, to see how much data to
- * expect. The header size is fixed to six bytes, the total payload
- * size is stored in network order in the last four bytes of the
- * header.
- */
- FtdiReadReg(TPM_DATA_FIFO_REG, HEADER_SIZE, response);
- handled_so_far = HEADER_SIZE;
-
- /* Figure out the total payload size. */
- memcpy(&payload_size, response + 2, sizeof(payload_size));
- payload_size = be32toh(payload_size);
-
- if (ftdi_trace_enabled)
- printf("%s response size %d\n\n", message, payload_size);
- else
- SpinSpinner();
-
- if (payload_size > MAX_RESPONSE_SIZE)
- return empty_string_data;
- /*
- * Let's read all but the last byte in the FIFO to make sure the
- * status register is showing correct flow control bits: 'more data'
- * until the last byte and then 'no more data' once the last byte is
- * read.
- */
- payload_size = payload_size - 1;
- do {
- uint32_t transaction_size;
- uint32_t burst_count = GetBurstCount();
-
- if (burst_count > 64)
- burst_count = 64;
-
- transaction_size = payload_size - handled_so_far;
- if (transaction_size > burst_count)
- transaction_size = burst_count;
-
- if (transaction_size) {
- FtdiReadReg(TPM_DATA_FIFO_REG, transaction_size,
- response + handled_so_far);
- handled_so_far += transaction_size;
- }
- } while (handled_so_far != payload_size);
-
- /* Verify that there is still data to come. */
- ReadTpmSts(&status);
- if ((status & expected_status_bits) != expected_status_bits) {
- fprintf(stderr, "unexpected status %#x\n", status);
- return empty_string_data;
- }
-
- FtdiReadReg(TPM_DATA_FIFO_REG, 1, response + handled_so_far);
-
- /* Verify that 'data available' is not asseretd any more. */
- ReadTpmSts(&status);
- if ((status & expected_status_bits) != stsValid) {
- fprintf(stderr, "unexpected status %#x\n", status);
- return empty_string_data;
- }
-
- /* Move the TPM back to idle state. */
- WriteTpmSts(commandReady);
-
- handled_so_far++;
-
- return (struct swig_string_data) {
- .size = handled_so_far, .data = response};
-}
diff --git a/test/tpm_test/ftdi_spi_tpm.h b/test/tpm_test/ftdi_spi_tpm.h
deleted file mode 100644
index 5393d4cd86..0000000000
--- a/test/tpm_test/ftdi_spi_tpm.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/* Copyright 2015 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.
- */
-
-#ifndef __EC_TEST_TPM_TEST_FTDI_SPI_TPM_H
-#define __EC_TEST_TPM_TEST_FTDI_SPI_TPM_H
-
-#include "mpsse.h"
-
-/*
- * This structure allows to convert string representation between C and
- * Python.
- */
-struct swig_string_data {
- int size;
- uint8_t *data;
-};
-
-int FtdiSpiInit(uint32_t freq, int enable_debug);
-void FtdiStop(void);
-struct swig_string_data FtdiSendCommandAndWait(char *tpm_command,
- int command_size);
-
-#endif /* ! __EC_TEST_TPM_TEST_FTDI_SPI_TPM_H */
diff --git a/test/tpm_test/ftdi_spi_tpm.i b/test/tpm_test/ftdi_spi_tpm.i
deleted file mode 100644
index c9cc2fc535..0000000000
--- a/test/tpm_test/ftdi_spi_tpm.i
+++ /dev/null
@@ -1,50 +0,0 @@
-/* Copyright 2015 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.
- */
-
-%module ftdi_spi_tpm
-typedef unsigned uint32_t;
-typedef unsigned char uint8_t;
-
-%{
-typedef struct swig_string_data
-{
- int size;
- char *data;
-} swig_string_data;
-
-extern int FtdiSpiInit(uint32_t freq, int enable_debug);
-extern void FtdiStop(void);
-extern swig_string_data FtdiSendCommandAndWait(char *tpm_command,
- int command_size);
-%}
-
-%typemap(in) (char *tpm_command, int command_size)
-{
- if(!PyString_Check($input))
- {
- PyErr_SetString(PyExc_ValueError, "String value required");
- return NULL;
- }
-
- $1 = PyString_AsString($input);
- $2 = PyString_Size($input);
-}
-
-%typemap(out) swig_string_data
-{
- $result = PyString_FromStringAndSize($1.data, $1.size);
- free($1.data);
-}
-
-typedef struct swig_string_data
-{
- int size;
- char *data;
-} swig_string_data;
-
-extern int FtdiSpiInit(uint32_t freq, int enable_debug);
-extern void FtdiStop(void);
-extern swig_string_data FtdiSendCommandAndWait(char *tpm_command,
- int command_size);
diff --git a/test/tpm_test/genvectors.py b/test/tpm_test/genvectors.py
deleted file mode 100644
index 593a6aab71..0000000000
--- a/test/tpm_test/genvectors.py
+++ /dev/null
@@ -1,77 +0,0 @@
-#!/usr/bin/env python2
-# Copyright 2016 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.
-
-"""Module for generating AES test vectors."""
-
-from binascii import b2a_hex as b2a
-from Crypto.Cipher import AES
-from itertools import izip_longest
-import os
-
-modes = {
- AES.MODE_CBC: 'CBC',
- AES.MODE_CFB: 'CFB',
- AES.MODE_OFB: 'OFB',
-}
-
-template = \
-'''
- <crypto_test name="AES:{mode}{key_bits} {test_num}">
- <clear_text format="hex">
- {pt}
- </clear_text>
- <key>
- {key}
- </key>
- <cipher_text>
- {ct}
- </cipher_text>
- <iv>
- {iv}
- </iv>
- </crypto_test>
-'''
-
-def h2be(v):
- # Convert input big-endian byte-string to 4-byte segmented
- # little-endian words. Pad-bytes (if necessary) are the empty string.
- word = [iter(v)] * 4
- return ''.join([
- ''.join(b[::-1]) for b in izip_longest(*word, fillvalue='')
- ])
-
-
-for mode in [AES.MODE_CBC, AES.MODE_CFB, AES.MODE_OFB]:
- for key_bytes in [16, 24, 32]:
- test_num = 0
- for pt_len in [5, 16, 21, 32]:
- # CBC mode requires block sized inputs.
- if mode == AES.MODE_CBC and pt_len % 16:
- continue
- test_num += 1
-
- actual_pt_len = pt_len
- if pt_len % 16:
- pt_len = 16 * ((pt_len / 16) + 1)
-
- key = os.urandom(key_bytes)
- iv = os.urandom(16)
- pt = os.urandom(pt_len)
-
- obj = AES.new(key, mode=mode, IV=iv, segment_size=128)
- ct = obj.encrypt(pt)
- obj = AES.new(key, mode=mode, IV=iv, segment_size=128)
-
- assert obj.decrypt(ct)[:pt_len] == pt
-
- print template.format(mode=modes[mode],
- key_bits=str(key_bytes * 8),
- test_num=str(test_num),
- pt=b2a(h2be(pt[:actual_pt_len])),
- key=b2a(h2be(key)),
- ct=b2a(h2be(ct[:actual_pt_len])),
- iv=b2a(h2be(iv))),
-
-
diff --git a/test/tpm_test/hash_test.py b/test/tpm_test/hash_test.py
deleted file mode 100644
index 9f10894d2e..0000000000
--- a/test/tpm_test/hash_test.py
+++ /dev/null
@@ -1,160 +0,0 @@
-#!/usr/bin/env python2
-# Copyright 2015 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.
-
-"""Module for testing hash functions using extended commands."""
-
-from __future__ import print_function
-
-import hashlib
-import hmac
-import struct
-
-import subcmd
-import utils
-
-# Hash command modes
-CMD_HASH_START = 0
-CMD_HASH_CONT = 1
-CMD_HASH_FINISH = 2
-CMD_HASH = 3
-CMD_HMAC_SW = 4
-CMD_HMAC_HW = 5
-
-
-# Hash algorithm
-ALG_SHA1 = 0
-ALG_SHA256 = 1
-ALG_SHA384 = 2
-ALG_SHA512 = 3
-
-# A standard empty response to HASH extended commands.
-EMPTY_RESPONSE = ''.join('%c' % x for x in (0x80, 0x01, 0x00, 0x00, 0x00, 0x0c,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x01))
-test_inputs = (
- # Hash cmd alg handle hmac_key text
- (CMD_HMAC_SW, ALG_SHA256, 0, 'hmac_key1', 'some text, this time for sw hmac'),
- (CMD_HMAC_SW, ALG_SHA1, 0, 'hmac_key2', 'some text, this time for sw hmac'),
- (CMD_HMAC_SW, ALG_SHA384, 0, 'hmac_key3', 'some text, this time for sw hmac'),
- (CMD_HMAC_SW, ALG_SHA512, 0, 'hmac_key4', 'some text, this time for sw hmac'),
- (CMD_HMAC_HW, ALG_SHA256, 0, 'hmac_key5', 'some text, this time for hw hmac'),
- (CMD_HMAC_SW, ALG_SHA256, 0, 'very long hmac_key 456456789012345', ' text'),
- (CMD_HMAC_HW, ALG_SHA256, 0, 'very long hmac_key 123456789012345', ' text'),
- (CMD_HMAC_SW, ALG_SHA384, 0, 'very long hmac_key 456456789012345', ' text'),
- (CMD_HMAC_SW, ALG_SHA512, 0, 'very long hmac_key 456456789012345', ' text'),
- (CMD_HASH, ALG_SHA1, 0, '', ''),
- (CMD_HASH, ALG_SHA256, 0, '', ''),
- (CMD_HASH, ALG_SHA1, 0, '', 'anything really will work here'),
- (CMD_HASH, ALG_SHA256, 0, '', 'some more text, this time for sha256'),
- (CMD_HASH_START, ALG_SHA256, 1, '', 'some more text, this time for sha256'),
- (CMD_HASH_CONT, ALG_SHA256, 1, '', 'some more text, this time for sha256'),
- (CMD_HASH_START, ALG_SHA256, 2, '', 'this could be anything here'),
- (CMD_HASH, ALG_SHA1, 3, '', 'interleave a SHA1 single shot'),
- (CMD_HASH, ALG_SHA256, 3, '', 'interleave a SHA256 single shot'),
- (CMD_HASH_START, ALG_SHA1, 3, '', 'let\'s interleave a sha1 calculation'),
- (CMD_HASH_CONT, ALG_SHA256, 2, '', 'fill up a second context with data'),
- (CMD_HASH_CONT, ALG_SHA256, 1, '', 'let\'s feed some more into context 1'),
- (CMD_HASH_FINISH, ALG_SHA256, 1, '', 'some more text, this time for sha256'),
- (CMD_HASH_CONT, ALG_SHA1, 3, '', 'with two active sha256 calculations'),
- (CMD_HASH_FINISH, ALG_SHA1, 3, '', 'this should be enough'),
- (CMD_HASH_FINISH, ALG_SHA256, 2, '', 'it does not really matter what'),
- (CMD_HASH, ALG_SHA384, 0, '', 'some more text, this time for sha384'),
- (CMD_HASH, ALG_SHA512, 0, '', 'some more text, this time for sha512'),
- (CMD_HASH_START, ALG_SHA256, 0, '', 'some more text, this time for sha256'),
- (CMD_HASH_START, ALG_SHA384, 1, '', 'some more text, this time for sha384'),
- (CMD_HASH_CONT, ALG_SHA384, 1, '', 'some more text, this time for sha384'),
- (CMD_HASH_CONT, ALG_SHA256, 0, '', 'some more text, this time for sha256'),
- (CMD_HASH_START, ALG_SHA512, 2, '', 'some more text, this time for sha512'),
- (CMD_HASH_CONT, ALG_SHA512, 2, '', 'some more text, this time for sha512'),
- (CMD_HASH_FINISH, ALG_SHA512, 2, '', 'this should be enough'),
- (CMD_HASH_FINISH, ALG_SHA256, 0, '', 'this should be enough'),
- (CMD_HASH_FINISH, ALG_SHA384, 1, '', 'this should be enough'),
-)
-
-def hash_test(tpm):
- """Exercise multiple hash threads simultaneously.
-
- Command structure, shared out of band with the test running on the target:
-
- field | size | note
- ===================================================================
- hash_cmd | 1 | 0 - start, 1 - cont., 2 - finish, 3 - single
- | | 4 - SW HMAC single shot (TPM code)
- | | 5 - HW HMAC SHA256 single shot (dcrypto code)
- hash_alg | 1 | 0 - sha1, 1 - sha256, 2 - sha384, 3 - sha512
- handle | 1 | session handle, ignored in 'single' mode
- text_len | 2 | size of the text to process, big endian
- text | text_len | text to hash
- for HMAC single shot only:
- key_len | 2 | size of the key for HMAC, big endian
- key | key_len | key for HMAC single shot
- Args:
- tpm: a tpm object used to communicate with the device
-
- Raises:
- subcmd.TpmTestError: on unexpected target responses
- """
-
- contexts = {}
-
- alg_map = {
- ALG_SHA1: ('sha1', hashlib.sha1),
- ALG_SHA256: ('sha256', hashlib.sha256),
- ALG_SHA384: ('sha384', hashlib.sha384),
- ALG_SHA512: ('sha512', hashlib.sha512),
- }
-
- cmd_map = {
- CMD_HASH_START: 'hash start',
- CMD_HASH_CONT: 'hash cont',
- CMD_HASH_FINISH: 'hash finish',
- CMD_HASH: 'hash',
- CMD_HMAC_SW: 'hmac sw',
- CMD_HMAC_HW: 'hmac hw'
- }
-
- for test in test_inputs:
- hash_cmd, hash_alg, handle, hmac_key, text = test
- mode_name = cmd_map[hash_cmd]
- alg_name, hash_func = alg_map[hash_alg]
-
- test_name = '%s:%s:%d' % (mode_name, alg_name, handle)
-
- cmd = '%c' % hash_cmd
- cmd += '%c' % hash_alg
- cmd += '%c' % handle # Ignored for single shots
-
- cmd += struct.pack('>H', len(text))
- cmd += text
- # for HMAC add key
- if hash_cmd in (CMD_HMAC_SW, CMD_HMAC_HW):
- cmd += struct.pack('>H', len(hmac_key))
- cmd += hmac_key
- wrapped_response = tpm.command(tpm.wrap_ext_command(subcmd.HASH, cmd))
- if hash_cmd in (CMD_HASH_START, CMD_HASH_CONT):
- if hash_cmd == CMD_HASH_START:
- contexts[handle] = hash_func()
- h = contexts[handle]
- h.update(text)
- if wrapped_response != EMPTY_RESPONSE:
- raise subcmd.TpmTestError("Unexpected response to '%s': %s" %
- (test_name, utils.hex_dump(wrapped_response)))
- continue
- if hash_cmd == CMD_HASH_FINISH:
- h = contexts[handle]
- elif hash_cmd == CMD_HASH:
- h = hash_func()
- elif hash_cmd in (CMD_HMAC_SW, CMD_HMAC_HW):
- h = hmac.new(bytes(hmac_key), digestmod=hash_func)
- else:
- raise subcmd.TpmTestError('Unknown command %d' % hash_cmd)
- h.update(text)
- digest = h.digest()
- result = wrapped_response[12:]
- if result != h.digest():
- raise subcmd.TpmTestError('%s error:%s%s' % (test_name,
- utils.hex_dump(digest),
- utils.hex_dump(result)))
-
- print('%sSUCCESS: %s' % (utils.cursor_back(), test_name))
diff --git a/test/tpm_test/hkdf_test.py b/test/tpm_test/hkdf_test.py
deleted file mode 100644
index 3330d50105..0000000000
--- a/test/tpm_test/hkdf_test.py
+++ /dev/null
@@ -1,112 +0,0 @@
-#!/usr/bin/env python2
-# Copyright 2016 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.
-
-"""Module for testing HKDF using extended commands."""
-
-from binascii import a2b_hex as a2b
-from struct import pack
-
-import subcmd
-import utils
-
-
-_HKDF_OPCODES = {
- 'TEST_RFC': 0x00,
-}
-
-
-# Command format.
-#
-# WIDTH FIELD
-# 1 OP
-# 1 MSB SALT LEN
-# 1 LSB SALT LEN
-# SALT_LEN SALT
-# 1 MSB IKM LEN
-# 1 LSB IKM LEN
-# IKM_LEN IKM
-# 1 MSB INFO LEN
-# 1 LSB INFO LEN
-# INFO_LEN INFO
-# 1 MSB OKM LEN
-# 1 LSB OKM LEN
-#
-_HKDF_CMD_FORMAT = '{op:c}{sl:s}{salt}{ikml:s}{ikm}{infol:s}{info}{okml:s}'
-
-
-def _rfc_test_cmd(salt, ikm, info, okml):
- op = _HKDF_OPCODES['TEST_RFC']
- return _HKDF_CMD_FORMAT.format(op=op,
- sl=pack('>H', len(salt)), salt=salt,
- ikml=pack('>H', len(ikm)), ikm=ikm,
- infol=pack('>H', len(info)), info=info,
- okml=pack('>H', okml))
-
-
-#
-# Test vectors for HKDF-SHA256 from RFC 5869.
-#
-_RFC_TEST_INPUTS = (
- (
- '0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b',
- '000102030405060708090a0b0c',
- 'f0f1f2f3f4f5f6f7f8f9',
- ('3cb25f25faacd57a90434f64d0362f2a'
- '2d2d0a90cf1a5a4c5db02d56ecc4c5bf'
- '34007208d5b887185865'),
- 'BASIC',
- ),
- (
- ('000102030405060708090a0b0c0d0e0f'
- '101112131415161718191a1b1c1d1e1f'
- '202122232425262728292a2b2c2d2e2f'
- '303132333435363738393a3b3c3d3e3f'
- '404142434445464748494a4b4c4d4e4f'),
- ('606162636465666768696a6b6c6d6e6f'
- '707172737475767778797a7b7c7d7e7f'
- '808182838485868788898a8b8c8d8e8f'
- '909192939495969798999a9b9c9d9e9f'
- 'a0a1a2a3a4a5a6a7a8a9aaabacadaeaf'),
- ('b0b1b2b3b4b5b6b7b8b9babbbcbdbebf'
- 'c0c1c2c3c4c5c6c7c8c9cacbcccdcecf'
- 'd0d1d2d3d4d5d6d7d8d9dadbdcdddedf'
- 'e0e1e2e3e4e5e6e7e8e9eaebecedeeef'
- 'f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff'),
- ('b11e398dc80327a1c8e7f78c596a4934'
- '4f012eda2d4efad8a050cc4c19afa97c'
- '59045a99cac7827271cb41c65e590e09'
- 'da3275600c2f09b8367793a9aca3db71'
- 'cc30c58179ec3e87c14c01d5c1f3434f'
- '1d87'),
- 'LONG INPUTS',
- ),
- (
- '0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b',
- '',
- '',
- ('8da4e775a563c18f715f802a063c5a31'
- 'b8a11f5c5ee1879ec3454e5f3c738d2d'
- '9d201395faa4b61a96c8'),
- 'ZERO SALT/INFO',
- )
-)
-
-
-def _rfc_tests(tpm):
- for data in _RFC_TEST_INPUTS:
- IKM, salt, info, OKM = map(a2b, data[:-1])
- test_name = 'HKDF:SHA256:%s' % data[-1]
- cmd = _rfc_test_cmd(salt, IKM, info, len(OKM))
- wrapped_response = tpm.command(tpm.wrap_ext_command(subcmd.HKDF, cmd))
- result = tpm.unwrap_ext_response(subcmd.HKDF, wrapped_response)
-
- if result != OKM:
- raise subcmd.TpmTestError('%s error:%s%s' % (
- test_name, utils.hex_dump(result), utils.hex_dump(OKM)))
- print('%sSUCCESS: %s' % (utils.cursor_back(), test_name))
-
-
-def hkdf_test(tpm):
- _rfc_tests(tpm)
diff --git a/test/tpm_test/mpsse.c b/test/tpm_test/mpsse.c
deleted file mode 100644
index e57a9cf761..0000000000
--- a/test/tpm_test/mpsse.c
+++ /dev/null
@@ -1,728 +0,0 @@
-/* Copyright 2015 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.
- *
- * Based on Craig Heffner's version of Dec 27 2011, published on
- * https://github.com/devttys0/libmpsse
- */
-
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#if LIBFTDI1 == 1
-#include <libftdi1/ftdi.h>
-#else
-#include <ftdi.h>
-#endif
-
-#include "mpsse.h"
-#include "support.h"
-
-/* FTDI interfaces */
-enum interface {
- IFACE_ANY = INTERFACE_ANY,
- IFACE_A = INTERFACE_A,
- IFACE_B = INTERFACE_B,
- IFACE_C = INTERFACE_C,
- IFACE_D = INTERFACE_D
-};
-
-enum mpsse_commands {
- INVALID_COMMAND = 0xAB,
- ENABLE_ADAPTIVE_CLOCK = 0x96,
- DISABLE_ADAPTIVE_CLOCK = 0x97,
- ENABLE_3_PHASE_CLOCK = 0x8C,
- DISABLE_3_PHASE_CLOCK = 0x8D,
- TCK_X5 = 0x8A,
- TCK_D5 = 0x8B,
- CLOCK_N_CYCLES = 0x8E,
- CLOCK_N8_CYCLES = 0x8F,
- PULSE_CLOCK_IO_HIGH = 0x94,
- PULSE_CLOCK_IO_LOW = 0x95,
- CLOCK_N8_CYCLES_IO_HIGH = 0x9C,
- CLOCK_N8_CYCLES_IO_LOW = 0x9D,
- TRISTATE_IO = 0x9E,
-};
-
-/* Common clock rates */
-enum clock_rates {
- ONE_HUNDRED_KHZ = 100000,
- FOUR_HUNDRED_KHZ = 400000,
- ONE_MHZ = 1000000,
- TWO_MHZ = 2000000,
- FIVE_MHZ = 5000000,
- SIX_MHZ = 6000000,
- TEN_MHZ = 10000000,
- TWELVE_MHZ = 12000000,
- FIFTEEN_MHZ = 15000000,
- THIRTY_MHZ = 30000000,
- SIXTY_MHZ = 60000000
-};
-
-#define NULL_CONTEXT_ERROR_MSG "NULL MPSSE context pointer!"
-#define SPI_TRANSFER_SIZE 512
-#define SPI_RW_SIZE (63 * 1024)
-#define SETUP_DELAY 25000
-#define LATENCY_MS 2
-#define USB_TIMEOUT 120000
-#define CHUNK_SIZE 65535
-#define MAX_SETUP_COMMANDS 10
-
-/* SK and CS are high, GPIO1 is reset on the FPGA hookup, all others low */
-#define DEFAULT_PORT (SK | CS | GPIO1)
-/* SK/DO/CS and GPIOs are outputs, DI is an input */
-#define DEFAULT_TRIS (SK | DO | CS | GPIO0 | GPIO1 | GPIO2 | GPIO3)
-
-static struct vid_pid {
- int vid;
- int pid;
- char *description;
- int use_B;
-} supported_devices[] = {
- {
- 0x0403, 0x6010, "FT2232 Future Technology Devices International, Ltd",
- 1},
- {
- 0x0403, 0x6011, "FT4232 Future Technology Devices International, Ltd"},
- {
- 0x0403, 0x6014,
- "FT232H Future Technology Devices International, Ltd"},
- /* These devices are based on FT2232 chips, but have not been tested. */
- {
- 0x0403, 0x8878, "Bus Blaster v2 (channel A)"}, {
- 0x0403, 0x8879, "Bus Blaster v2 (channel B)"}, {
- 0x0403, 0xBDC8, "Turtelizer JTAG/RS232 Adapter A"}, {
- 0x0403, 0xCFF8, "Amontec JTAGkey"}, {
- 0x0403, 0x8A98, "TIAO Multi Protocol Adapter"}, {
- 0x15BA, 0x0003, "Olimex Ltd. OpenOCD JTAG"}, {
- 0x15BA, 0x0004, "Olimex Ltd. OpenOCD JTAG TINY"}, {
- 0x18d1, 0x0304, "Google UltraDebug", 1}, {
- 0, 0, NULL}
-};
-
-/*
- * Enables or disables flushing of the FTDI chip's RX buffers after each read
- * operation. Flushing is disable by default.
- *
- * @mpsse - MPSSE context pointer.
- * @tf - Set to 1 to enable flushing, or 0 to disable flushing.
- *
- * Returns void.
- */
-static void FlushAfterRead(struct mpsse_context *mpsse, int tf)
-{
- mpsse->flush_after_read = tf;
-}
-
-/*
- * Enable / disable internal loopback.
- *
- * @mpsse - MPSSE context pointer.
- * @enable - Zero to disable loopback, 1 to enable loopback.
- *
- * Returns MPSSE_OK on success.
- * Returns MPSSE_FAIL on failure.
- */
-static int SetLoopback(struct mpsse_context *mpsse, int enable)
-{
- unsigned char buf[1] = { 0 };
- int retval = MPSSE_FAIL;
-
- if (is_valid_context(mpsse)) {
- if (enable)
- buf[0] = LOOPBACK_START;
- else
- buf[0] = LOOPBACK_END;
-
- retval = raw_write(mpsse, buf, 1);
- }
-
- return retval;
-}
-
-/*
- * Sets the appropriate divisor for the desired clock frequency.
- *
- * @mpsse - MPSSE context pointer.
- * @freq - Desired clock frequency in hertz.
- *
- * Returns MPSSE_OK on success.
- * Returns MPSSE_FAIL on failure.
- */
-static int SetClock(struct mpsse_context *mpsse, uint32_t freq)
-{
- int retval = MPSSE_FAIL;
- uint32_t system_clock = 0;
- uint16_t divisor = 0;
- unsigned char buf[CMD_SIZE] = { 0 };
-
- /*
- * Do not call is_valid_context() here, as the FTDI chip may not be
- * completely configured when SetClock is called
- */
- if (!mpsse)
- return retval;
-
- if (freq > SIX_MHZ) {
- buf[0] = TCK_X5;
- system_clock = SIXTY_MHZ;
- } else {
- buf[0] = TCK_D5;
- system_clock = TWELVE_MHZ;
- }
-
- if (raw_write(mpsse, buf, 1) == MPSSE_OK) {
- if (freq <= 0)
- divisor = 0xFFFF;
- else
- divisor = freq2div(system_clock, freq);
-
- buf[0] = TCK_DIVISOR;
- buf[1] = (divisor & 0xFF);
- buf[2] = ((divisor >> 8) & 0xFF);
-
- if (raw_write(mpsse, buf, 3) == MPSSE_OK) {
- mpsse->clock = div2freq(system_clock, divisor);
- retval = MPSSE_OK;
- }
- }
-
- return retval;
-}
-
-/*
- * Sets the appropriate transmit and receive commands based on the requested
- * mode and byte order.
- *
- * @mpsse - MPSSE context pointer.
- * @endianness - MPSSE_MSB or MPSSE_LSB.
- *
- * Returns MPSSE_OK on success.
- * Returns MPSSE_FAIL on failure.
- */
-static int SetMode(struct mpsse_context *mpsse, int endianness)
-{
- int retval = MPSSE_OK, i = 0, setup_commands_size = 0;
- unsigned char buf[CMD_SIZE] = { 0 };
- unsigned char setup_commands[CMD_SIZE * MAX_SETUP_COMMANDS] = { 0 };
-
- /*
- * Do not call is_valid_context() here, as the FTDI chip may not be
- * completely configured when SetMode is called
- */
- if (!mpsse)
- return MPSSE_FAIL;
-
- /* Read and write commands need to include endianness */
- mpsse->tx = MPSSE_DO_WRITE | endianness;
- mpsse->rx = MPSSE_DO_READ | endianness;
- mpsse->txrx = MPSSE_DO_WRITE | MPSSE_DO_READ | endianness;
-
- /*
- * Clock, data out, chip select pins are outputs; all others are
- * inputs.
- */
- mpsse->tris = DEFAULT_TRIS;
-
- /* Clock and chip select pins idle high; all others are low */
- mpsse->pidle = mpsse->pstart = mpsse->pstop = DEFAULT_PORT;
-
- /* During reads and writes the chip select pin is brought low */
- mpsse->pstart &= ~CS;
-
- /* Disable FTDI internal loopback */
- SetLoopback(mpsse, 0);
-
- /* Ensure adaptive clock is disabled */
- setup_commands[setup_commands_size++] = DISABLE_ADAPTIVE_CLOCK;
-
- switch (mpsse->mode) {
- case SPI0:
- /* SPI mode 0 clock idles low */
- mpsse->pidle &= ~SK;
- mpsse->pstart &= ~SK;
- mpsse->pstop &= ~SK;
-
- /*
- * SPI mode 0 propogates data on the falling edge and read
- * data on the rising edge of the clock
- */
- mpsse->tx |= MPSSE_WRITE_NEG;
- mpsse->rx &= ~MPSSE_READ_NEG;
- mpsse->txrx |= MPSSE_WRITE_NEG;
- mpsse->txrx &= ~MPSSE_READ_NEG;
- break;
- default:
- fprintf(stderr, "%s:%d attempt to set an unsupported mode %d\n",
- __func__, __LINE__, mpsse->mode);
- retval = MPSSE_FAIL;
- }
-
- /* Send any setup commands to the chip */
- if ((retval == MPSSE_OK) && (setup_commands_size > 0))
- retval = raw_write(mpsse, setup_commands, setup_commands_size);
-
- if (retval == MPSSE_OK) {
- /* Set the idle pin states */
- set_bits_low(mpsse, mpsse->pidle);
-
- /* All GPIO pins are outputs, set low */
- mpsse->trish = 0xFF;
- mpsse->gpioh = 0x00;
-
- buf[i++] = SET_BITS_HIGH;
- buf[i++] = mpsse->gpioh;
- buf[i++] = mpsse->trish;
-
- retval = raw_write(mpsse, buf, i);
- }
-
- return retval;
-}
-
-/*
- * Open device by VID/PID/index
- *
- * @vid - Device vendor ID.
- * @pid - Device product ID.
- * @freq - Clock frequency to use for the specified mode.
- * @endianness - Specifies how data is clocked in/out (MSB, LSB).
- * @interface - FTDI interface to use (IFACE_A - IFACE_D).
- * @description - Device product description (set to NULL if not needed).
- * @serial - Device serial number (set to NULL if not needed).
- * @index - Device index (set to 0 if not needed).
- *
- * Returns a pointer to an MPSSE context structure.
- * On success, mpsse->open will be set to 1.
- * On failure, mpsse->open will be set to 0.
- */
-static struct mpsse_context *OpenIndex(int vid,
- int pid,
- int freq,
- int endianness,
- int interface,
- const char *description,
- const char *serial, int index)
-{
- int status = 0;
- struct mpsse_context *mpsse = NULL;
- enum modes mode = SPI0; /* Let's use this mode at all times. */
-
- mpsse = malloc(sizeof(struct mpsse_context));
- if (!mpsse)
- return NULL;
-
- memset(mpsse, 0, sizeof(struct mpsse_context));
-
- /* Legacy; flushing is no longer needed, so disable it by default. */
- FlushAfterRead(mpsse, 0);
-
- /* ftdilib initialization */
- if (ftdi_init(&mpsse->ftdi)) {
- fprintf(stderr, "%s:%d failed to initialize FTDI\n",
- __func__, __LINE__);
- free(mpsse);
- return NULL;
- }
-
- mpsse->ftdi_initialized = 1;
-
- /* Set the FTDI interface */
- ftdi_set_interface(&mpsse->ftdi, interface);
-
- /* Try opening the specified device */
- if (ftdi_usb_open_desc_index
- (&mpsse->ftdi, vid, pid, description, serial, index)) {
- Close(mpsse);
- return NULL;
- }
-
- mpsse->mode = mode;
- mpsse->vid = vid;
- mpsse->pid = pid;
- mpsse->status = STOPPED;
- mpsse->endianness = endianness;
- mpsse->xsize = SPI_RW_SIZE;
-
- status |= ftdi_usb_reset(&mpsse->ftdi);
- status |= ftdi_set_latency_timer(&mpsse->ftdi, LATENCY_MS);
- status |= ftdi_write_data_set_chunksize(&mpsse->ftdi, CHUNK_SIZE);
- status |= ftdi_read_data_set_chunksize(&mpsse->ftdi, CHUNK_SIZE);
- status |= ftdi_set_bitmode(&mpsse->ftdi, 0, BITMODE_RESET);
-
- if (status) {
- fprintf(stderr,
- "%s:%d failed setting basic config for %4.4x:%4.4x\n",
- __func__, __LINE__, vid, pid);
- Close(mpsse);
- return NULL;
- }
- /* Set the read and write timeout periods */
- set_timeouts(mpsse, USB_TIMEOUT);
-
- ftdi_set_bitmode(&mpsse->ftdi, 0, BITMODE_MPSSE);
-
- if ((SetClock(mpsse, freq) != MPSSE_OK)
- || (SetMode(mpsse, endianness) != MPSSE_OK)) {
- fprintf(stderr,
- "%s:%d failed setting clock/mode for %4.4x:%4.4x\n",
- __func__, __LINE__, vid, pid);
- Close(mpsse);
- return NULL;
- }
-
- mpsse->open = 1;
-
- /* Give the chip a few mS to initialize */
- usleep(SETUP_DELAY);
-
- /*
- * Not all FTDI chips support all the commands that SetMode may have
- * sent. This clears out any errors from unsupported commands that
- * might have been sent during set up.
- */
- ftdi_usb_purge_buffers(&mpsse->ftdi);
-
- return mpsse;
-}
-
-/*
- * Opens and initializes the first FTDI device found.
- *
- * @freq - Clock frequency to use for the specified mode.
- * @endianness - Specifies how data is clocked in/out (MSB, LSB).
- * @serial - Serial number of the USB device (NULL if not needed).
- *
- * Returns a pointer to an MPSSE context structure.
- * On success, mpsse->open will be set to 1.
- * On failure, mpsse->open will be set to 0.
- */
-struct mpsse_context *MPSSE(int freq, int endianness, const char *serial)
-{
- int i = 0;
- struct mpsse_context *mpsse = NULL;
-
- for (i = 0; supported_devices[i].vid != 0; i++) {
- mpsse = OpenIndex(supported_devices[i].vid,
- supported_devices[i].pid, freq, endianness,
- supported_devices[i].use_B ?
- IFACE_B : IFACE_A,
- NULL, serial, 0);
- if (!mpsse)
- continue;
-
- if (mpsse->open) {
- mpsse->description = supported_devices[i].description;
- break;
- }
- /*
- * If there is another device still left to try, free
- * the context pointer and try again
- */
- if (supported_devices[i + 1].vid != 0) {
- Close(mpsse);
- mpsse = NULL;
- }
- }
-
- return mpsse;
-}
-
-/*
- * Closes the device, deinitializes libftdi, and frees the MPSSE context
- * pointer.
- *
- * @mpsse - MPSSE context pointer.
- *
- * Returns void.
- */
-
-void Close(struct mpsse_context *mpsse)
-{
- if (!mpsse)
- return;
-
- if (mpsse->open) {
- ftdi_usb_close(&mpsse->ftdi);
- ftdi_set_bitmode(&mpsse->ftdi, 0, BITMODE_RESET);
- }
-
- if (mpsse->ftdi_initialized)
- ftdi_deinit(&mpsse->ftdi);
-
- free(mpsse);
-}
-
-/*
- * Retrieves the last error string from libftdi.
- *
- * @mpsse - MPSSE context pointer.
- *
- * Returns a pointer to the last error string.
- */
-const char *ErrorString(struct mpsse_context *mpsse)
-{
- if (mpsse)
- return ftdi_get_error_string(&mpsse->ftdi);
-
- return NULL_CONTEXT_ERROR_MSG;
-}
-
-/*
- * Send data start condition.
- *
- * @mpsse - MPSSE context pointer.
- *
- * Returns MPSSE_OK on success.
- * Returns MPSSE_FAIL on failure.
- */
-int Start(struct mpsse_context *mpsse)
-{
- int status;
-
- if (!is_valid_context(mpsse)) {
- mpsse->status = STOPPED;
- return MPSSE_FAIL;
- }
-
- /* Set the start condition */
- status = set_bits_low(mpsse, mpsse->pstart);
-
- if (status == MPSSE_OK)
- mpsse->status = STARTED;
-
- return status;
-}
-
-/*
- * Send data out via the selected serial protocol.
- *
- * @mpsse - MPSSE context pointer.
- * @data - Buffer of data to send.
- * @size - Size of data.
- *
- * Returns MPSSE_OK on success.
- * Returns MPSSE_FAIL on failure.
- */
-int Write(struct mpsse_context *mpsse, char *data, int size)
-{
- int n = 0;
-
- if (!is_valid_context(mpsse))
- return MPSSE_FAIL;
-
- if (!mpsse->mode)
- return MPSSE_FAIL;
-
- while (n < size) {
- unsigned char *buf;
- int retval, buf_size, txsize;
-
- txsize = size - n;
- if (txsize > mpsse->xsize)
- txsize = mpsse->xsize;
-
- buf = build_block_buffer(mpsse, mpsse->tx,
- (unsigned char *)(data + n),
- txsize, &buf_size);
- if (!buf)
- return MPSSE_FAIL;
-
- retval = raw_write(mpsse, buf, buf_size);
- n += txsize;
- free(buf);
-
- if (retval != MPSSE_OK)
- return retval;
-
- }
-
- return MPSSE_OK;
-}
-
-/* Performs a read. For internal use only; see Read() and ReadBits(). */
-static char *InternalRead(struct mpsse_context *mpsse, int size)
-{
- unsigned char *buf;
- int n = 0;
-
- if (!is_valid_context(mpsse))
- return NULL;
-
- if (!mpsse->mode)
- return NULL;
- buf = malloc(size);
-
- if (!buf)
- return NULL;
-
- while (n < size) {
- int rxsize, data_size, retval;
- unsigned char *data;
- unsigned char sbuf[SPI_RW_SIZE] = { 0 };
-
- rxsize = size - n;
- if (rxsize > mpsse->xsize)
- rxsize = mpsse->xsize;
-
- data = build_block_buffer(mpsse, mpsse->rx,
- sbuf, rxsize, &data_size);
- if (!data) {
- free(buf);
- return NULL;
- }
-
- retval = raw_write(mpsse, data, data_size);
- free(data);
-
- if (retval != MPSSE_OK) {
- free(buf);
- return NULL;
- }
- n += raw_read(mpsse, buf + n, rxsize);
- }
-
- return (char *)buf;
-}
-
-/*
- * Reads data over the selected serial protocol.
- *
- * @mpsse - MPSSE context pointer.
- * @size - Number of bytes to read.
- *
- * Returns a pointer to the read data on success.
- * Returns NULL on failure.
- */
-char *Read(struct mpsse_context *mpsse, int size)
-{
- char *buf = NULL;
-
- buf = InternalRead(mpsse, size);
- return buf;
-}
-
-/*
- * Reads and writes data over the selected serial protocol (SPI only).
- *
- * @mpsse - MPSSE context pointer.
- * @data - Buffer containing bytes to write.
- * @size - Number of bytes to transfer.
- *
- * Returns a pointer to the read data on success.
- * Returns NULL on failure.
- */
-char *Transfer(struct mpsse_context *mpsse, char *data, int size)
-{
- unsigned char *txdata = NULL, *buf = NULL;
- int n = 0, data_size = 0, rxsize = 0, retval = MPSSE_OK;
-
- if (!is_valid_context(mpsse))
- return NULL;
-
- buf = malloc(size);
- if (!buf)
- return NULL;
-
- while (n < size) {
- /*
- * When sending and receiving, FTDI chips don't seem to like
- * large data blocks. Limit the size of each block to
- * SPI_TRANSFER_SIZE
- */
- rxsize = size - n;
- if (rxsize > SPI_TRANSFER_SIZE)
- rxsize = SPI_TRANSFER_SIZE;
-
- txdata = build_block_buffer(mpsse, mpsse->txrx,
- (unsigned char *)(data + n),
- rxsize, &data_size);
- if (!txdata) {
- retval = MPSSE_FAIL;
- break;
- }
- retval = raw_write(mpsse, txdata, data_size);
- free(txdata);
-
- if (retval != MPSSE_OK)
- break;
-
- n += raw_read(mpsse, (buf + n), rxsize);
- }
-
- if (retval != MPSSE_OK)
- return NULL;
-
- return (char *)buf;
-}
-
-/*
- * Send data stop condition.
- *
- * @mpsse - MPSSE context pointer.
- *
- * Returns MPSSE_OK on success.
- * Returns MPSSE_FAIL on failure.
- */
-int Stop(struct mpsse_context *mpsse)
-{
- int retval = MPSSE_OK;
-
- if (is_valid_context(mpsse)) {
- /* Send the stop condition */
- retval |= set_bits_low(mpsse, mpsse->pstop);
-
- if (retval == MPSSE_OK) {
- /* Restore the pins to their idle states */
- retval |= set_bits_low(mpsse, mpsse->pidle);
- }
-
- mpsse->status = STOPPED;
- } else {
- retval = MPSSE_FAIL;
- mpsse->status = STOPPED;
- }
-
- return retval;
-}
-
-/*
- * Sets the specified pin high.
- *
- * @mpsse - MPSSE context pointer.
- * @pin - Pin number to set high.
- *
- * Returns MPSSE_OK on success.
- * Returns MPSSE_FAIL on failure.
- */
-int PinHigh(struct mpsse_context *mpsse, int pin)
-{
- int retval = MPSSE_FAIL;
-
- if (is_valid_context(mpsse))
- retval = gpio_write(mpsse, pin, HIGH);
-
- return retval;
-}
-
-/*
- * Sets the specified pin low.
- *
- * @mpsse - MPSSE context pointer.
- * @pin - Pin number to set low.
- *
- * Returns MPSSE_OK on success.
- * Returns MPSSE_FAIL on failure.
- */
-int PinLow(struct mpsse_context *mpsse, int pin)
-{
- int retval = MPSSE_FAIL;
-
- if (is_valid_context(mpsse))
- retval = gpio_write(mpsse, pin, LOW);
-
- return retval;
-}
diff --git a/test/tpm_test/mpsse.h b/test/tpm_test/mpsse.h
deleted file mode 100644
index 2925dfe27a..0000000000
--- a/test/tpm_test/mpsse.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/* Copyright 2015 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.
- *
- * Based on Craig Heffner's version of Dec 27 2011, published on
- * https://github.com/devttys0/libmpsse
- */
-
-#ifndef __EC_TEST_TPM_TEST_MPSSE_H
-#define __EC_TEST_TPM_TEST_MPSSE_H
-
-#define MPSSE_OK 0
-#define MPSSE_FAIL -1
-
-#define MSB 0x00
-#define LSB 0x08
-
-enum gpio_pins {
- GPIOL0 = 0,
- GPIOL1 = 1,
- GPIOL2 = 2,
- GPIOL3 = 3,
- GPIOH0 = 4,
- GPIOH1 = 5,
- GPIOH2 = 6,
- GPIOH3 = 7,
- GPIOH4 = 8,
- GPIOH5 = 9,
- GPIOH6 = 10,
- GPIOH7 = 11
-};
-
-struct mpsse_context;
-
-int Write(struct mpsse_context *mpsse, char *data, int size);
-int Stop(struct mpsse_context *mpsse);
-char *Transfer(struct mpsse_context *mpsse, char *data, int size);
-char *Read(struct mpsse_context *mpsse, int size);
-struct mpsse_context *MPSSE(int freq, int endianness, const char *serial);
-void Close(struct mpsse_context *mpsse);
-int PinHigh(struct mpsse_context *mpsse, int pin);
-int PinLow(struct mpsse_context *mpsse, int pin);
-int Start(struct mpsse_context *mpsse);
-
-#endif /* ! __EC_TEST_TPM_TEST_MPSSE_H */
diff --git a/test/tpm_test/nist_entropy.sh b/test/tpm_test/nist_entropy.sh
deleted file mode 100755
index f69c5652cd..0000000000
--- a/test/tpm_test/nist_entropy.sh
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/bin/bash
-# Copyright 2019 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.
-
-# NIST toolset needs sudo emerge dev-libs/libdivsufsort
-rm -rf /tmp/ea
-git clone --depth 1 https://github.com/usnistgov/SP800-90B_EntropyAssessment.git /tmp/ea/
-make -C /tmp/ea/cpp/ non_iid
-make -C /tmp/ea/cpp/ restart
-TRNG_OUT=/tmp/trng_output
-rm -f $TRNG_OUT
-./tpmtest.py -t
-if [ ! -f "$TRNG_OUT" ]; then
- echo "$TRNG_OUT does not exist"
- exit 1
-fi
-/tmp/ea/cpp/ea_non_iid -a $TRNG_OUT | tee ea_non_iid.log
-entropy=`grep min ea_non_iid.log | awk '{ print $5 }'`
-echo "Minimal entropy" $entropy
-/tmp/ea/cpp/ea_restart $TRNG_OUT $entropy | tee -a ea_non_iid.log
diff --git a/test/tpm_test/rsa1024.pem b/test/tpm_test/rsa1024.pem
deleted file mode 100644
index 3a349130f0..0000000000
--- a/test/tpm_test/rsa1024.pem
+++ /dev/null
@@ -1,15 +0,0 @@
------BEGIN RSA PRIVATE KEY-----
-MIICXAIBAAKBgQDfTq9zRZSYNDB+Jq1Ag/kXIbBOGw1qRM5OPi5yTJffiYo5ECWu
-IEzyOyCypRDdsmtiTqafkkrZhpfMcCA7ajJjyn9Z+1e2qZnp0C4PHNR9i6C9D9LV
-Ox8RtGqUz08KK0Tn+mskkbSCH/Z1tpHFoPYv1f8Qc5s09nqII6lCPKgkkQIDAQAB
-AoGBAJpthfQHqG1hmi+De8jj+3y9tXkuSCa3kpyVb/VndpgGO+qeehBjEhNqRICG
-mpVWb+C6V4x+1Ph9lbixyfiMxm7le6CvoE5OhNeXuVrdMuUr5YCzsr9W/wHc5qZs
-SoEdj+pL7SQI9GevDfL9Nz8xJfruNbDbZhH/SeHl/xvMww4JAkEA+V55ZUNwQINQ
-Crths4d7JI8qA1u1S5SUZ6qY1hRAkDykDW1YMcVC8S0VDufN5j7K2JQ3qkzW8yEu
-pP4deUTXswJBAOU+zUuXxZY5cJc6EKnDNQrWK/USjbLACxxfoAuGg6eQ6fgWkp/O
-E0wU6J5MJO//WCIG+c/9Gbcj+eOz43qbsKsCQFYw7Uyu7pGd0YCkG7Tt0wZj5WWb
-wSIKjPD36jO0dExmaV2quZ0aTXUG3Ax22pgGhB4vvL3EKVeH1JN6sb1EqjkCQC8X
-yqanxABLRnTaicfGASR7wMX0jMVWrDGk90TG2k7W9yluwaowdEhh1zOFouTmiJ1c
-3365mMnFizUapDVwvEcCQGqkxcod+m/s4Zq2a9DAyfN3FD2AtJ7QasveLXvR16Od
-MRa0hOWA8d3hh+eHU8DsJ+csEuKeDui3tV4kY0UTF0Y=
------END RSA PRIVATE KEY-----
diff --git a/test/tpm_test/rsa2048.pem b/test/tpm_test/rsa2048.pem
deleted file mode 100644
index 8031296fbd..0000000000
--- a/test/tpm_test/rsa2048.pem
+++ /dev/null
@@ -1,27 +0,0 @@
------BEGIN RSA PRIVATE KEY-----
-MIIEowIBAAKCAQEAnNdhLkOOFb7Nc5+39YZL45WQXIUZTB0uLO9uH+11Mg8KwXKf
-DHhQopmCU5C+ZCNJdXsM6y1ol9avsaoq3l6b4wYN8qzZ1x9Qbsld67TwwJgjBDBG
-ENzUa1fHMMMG3a9RbkBB+BDeSRhSsxjKSVCoOs22lHvb8S0FzlcLvjhIu8mxdja4
-qMziB1zIe8/P8Pqjxdc6XrL0v+rC7VEWopKcNqaGDiSlZhXnlyJQBP/JTbC8JwVe
-LPfv3F1YoTtgg7eMt9A2bVUuBSNjdEqXN6d4QO8+Zv26brNySiGCHzOtYgzyGtJq
-tafyUWkfOKVXmsWIZ+MRplNPsekHQd7o35OpmQIDAQABAoIBAE6dAh/fSouJvI8U
-4m8VZlpncBl/uUNWaPuq8ybbrd9ufLSj0Ca+86Pcj9908IleyoYxLDOA6ikZOa0y
-nxQglcBAG6OkkffqwTUWh5YKdpYCa6LA043GMk6vi67cQkfBhW5elPJS+ifnIiSU
-62e+HuSCkd5xCrgjGgLnzIIG0iYVVJdSzfU/bca5cDC+xYimsGUWnEyE4npu6ce9
-z0Un/BnGIx0riKJnH8LW06B5+7/qOKjfT7ybju4Et3wA15UaA4J66EG4sa9/8TCJ
-Vm0HEVV53WgPgghczCRHVGiG8fA/UhCt5BYzFgIhYuMvXesiW2S0KSJ0JCmpTGaE
-McqZlfUCgYEAyIBv9i/7SYt3OeI9PR9N+btUBg1xv1SxHqIgft3PIRbpwLqUAtKk
-Lng8+2Sg5+knZCkZdMV3u+FttIMdQ1qAcuw8MsMgLM73uvbGDPRW/d8hVfPiViWm
-s5aknLj9nOyH+toupPYPFOaBIoTnwB3RP+2wutjk6dQYM64pUXl50Q8CgYEAyEEq
-QvFqgawGq9C3wLvGE939Xjx3/sEudvCUwF0kizAN+CrHJngbgVpClq33DqQbLI84
-BgWNmG43ZbQsgOI41XnS6mLyMqx7iJDDTp5T5X7vE7Hj1UHRqRUEPGF0XhoAXIqL
-F9V4rV7gzzVjCpUecL6X8tN4BoqImyfIsrE9itcCgYA0NHzydPvQ4mdgwu9/Aq+i
-3ou6J7X+Q2b6uuwLHGXaD8U9UVdIhOAK2XPHYSQkPijrg2gFZ4UNfly6K4lrCB15
-zti9vuCZyinmnGpk5RnhcD+VybKdC6CkEg06YVBnk460Wira+NZkcsAc5M4Sz7C0
-HIdvnxm7aGYEzswjUqXNMQKBgEA49e7GMdwoaXNM2sGK9vmEJi/EwM8I8XffrDUN
-Kh0hajl+rqPdvSR86AIfBK7DXpupytPTkBeksUuCvwsOgh+klEnrNbWer3eaxag/
-CrT9QntUf7bzBuRtAxDCSGmteRQ0smsQYUVoujx56KuKK1sJJP4RZ9rhLvJjjfAQ
-+6W9AoGBAL0hOd3kCVY8kxDQry9M30lPZcftJga2IxTErBex60rA9ifmHLm4iFXt
-/e52/1OZVE4Cf7QFEFeSLiBA+U8I0FdV4VMyrfTpjKNVBIDB7JmskdhQbIPXOZzY
-fC2yxCmVsD6PjMDDlT//ck5AQVrktdDpwBj3OX7JSc31KOMBb8FU
------END RSA PRIVATE KEY-----
diff --git a/test/tpm_test/rsa4096.pem b/test/tpm_test/rsa4096.pem
deleted file mode 100644
index c1f82a2d38..0000000000
--- a/test/tpm_test/rsa4096.pem
+++ /dev/null
@@ -1,51 +0,0 @@
------BEGIN RSA PRIVATE KEY-----
-MIIJJwIBAAKCAgEAtNKrnPpCmjdwKuQth2d/FbYxBgbVWumOqdRta5K5Yzd9nPDK
-CkQZ8HGnTOCQnL5pSpxVGLNCQ9lsZf3RzyAMkjQnRkhYCxPN8WdwAn7nTKnY/UgX
-gPYBDmGwvu+HK3EOZYHBUM64ZdLX+nbEtxPZ7drWn54QslD0/fT57NgzVu/0ItPC
-uknVqQuwGKPZJs0ndmpyGzGsPULo2SbTkLs5ZLvqiQt6tIg56unKGYxC+2kiyo69
-bHO3iKChGaj6lFUgb4C612kSH3SC7K/uKK/N2q0bW1TkK+8MTdGr1wPEpJmgvH6d
-PC80O9Xdau2mGZODvuLUb5L/Vaf3Z+vjRtPnbcAplSu/3bSTu0UB/FMhzp+LkIAJ
-uhpuCIcVtHSj3LvbRfI4IIXDnkpFHnUYBUKGrUfmqu2Imp83o7jHmTXiqI6dLrzy
-ZEjDY08c0EXDQaG+5cKkXUXwA4PJgExo8NHa8VGB1f7E6IrWMpU42Dva94xcawH0
-bhK1tjbj0apJRGrz5nsZffg1yy24YlTPLWazf+A3ZRmC1ogkwjF+H27aSyivXivo
-NLLcx9GVDJTnCaDtqpEvkW/wAN8NRu/SWXtlzqLtiuIe0OGTcn8YeRg188rbAV8J
-SCFF/olE7Qd5aDLY1ougxtz5VolbzjUF6cFKHiQLyHMYGWvt+T6SkvILdSUCAwEA
-AQKCAgBWbFY/edE5WgPPTC2CiPHRk7mMktmIURaxjukZQBBBHnV3/BHkpDXtmLSI
-ZtBXSh6S3XNCkfK68QEBIjYUE9JOUoTu74a9DKMinPiJCNRN7OPb8ofhSDKrB//s
-0hi9p5Rk6YZWs+aoLAS0He3ZPrCrISvxMB/0ygK+GkcVbyPiil8aAjIQzVdEK2Tn
-8e/Ivsb8rtWIr84NnZwipY76nrFItxPamlT0UiO0ZjcEzOf6t348Z8qbOhdfQr6c
-wAm7uY/+Gv2yFPLne81TiKaAZb4ypQftN/6yDNfJncvOwWtL7G1Jig5mhH0nmAjy
-oVEA6mNOaaV1CkHlU5lI3xJKeN8j5DWPVu8+12gCjQgasBwo9aEMgNZgu+GYJEt5
-YnNZNz0aYcwajRGrOnrGQBMdlj97ZGgJQableFqWxjxx2TnUuhr6jj62fyMB5FBh
-zVeFesLIvoobRXxYC7vpe1oyfy+hJjTrmDlhQiBLpX4zoAJG3qgqtuQPWrM3dkjT
-yESNSMoLIL2WA2XclWWlH/nQDYGB3HzJtJeg+M6+EDRxTL+pgTgsWxDIkizSiI1c
-Ums7slNfSrNlPPt8hCqyI+Hm+CjgSSXM8//mZjgWI0Req3Pj6aiYeCMJbSyNTJK1
-J4S4MNcLmG0c4rxd1SH9b3S9cIesKLibkl9X23pF8jW7xXxDZQKCAQEA596OJByw
-BAqoj/Vor3SOdnpTmXLpqNAT4YsmA4futyySPGuVaP4dypGrZhu6OTrnuQaUxcad
-3bbnpZeM6UQKoEbN7egCruWSx6h9wi3qzdXjm1OiLnTsPzKGm5U3nvp1CIZCUoay
-ceNWWeDcNTmZupnjKkG8RUpdqAy5pytji81L2y8eT38EbHLPVN5QpaJ9NS1TzuFF
-qZeOD3CbkxfNp1fy39dVq5Zx3n8Eg3vi6LvHWTYY6i4eG5HP5adb/CnT2MO7T//P
-qRb0ERIBmR+R+BTkBXQFUc65mTuV4XCxmvA4Nz8ydk5+4Gh6s5PZwiazeDH87Eup
-awv2b/pZsxr8twKCAQEAx6Qj7vE5MRSFA193+OnLgp4pikCosEzv+xcXmaYeuVmi
-H3RSexwM9QwtPy2cd9vIAsnG+o1aUTkU7I+MO4ZFLHp7DNVuXDS3hHPjYYx5GC87
-7NsTP3+fXNCJDsb5lO812BkTEijNcokazim9vyJxNL/2GDmYNPL1KcN0KTMhskdi
-3vBscyQ+lYMcqL6fi25mNL1F+JKIA7dT7yoEnvx9xqJPmvlktogILmfoowfdpi5k
-h6FVq40XyLpBQ/M2GiDmL4PNSLSAFnVhab8mh2ULGrMSGy/a6BEHz7qa18mjGseO
-NXL4FlVyfdsv3CWlitQqoiKUnwHnHeuNr28W6vh5AwKCAQAr4be+59r7+NRr4kL8
-qa9ohsAZk2DbPP32OnJoSqqH6hyG6MlvBGC4/JaWjXrR5+8A2lj/kRZBZqMyeJsH
-boQgTyYb90PCu9nqhV2/iRcd+3PG6q4P4rrvPu2wti2/naDWiyo0Gh/dY+vsuJyU
-SiFo6kTOs4AhEPDmo/nixFhjlefcRG+VFfHNYHESm7xhjH3ruXdZ+NJJRVByZZpb
-3S5jlEZ3zHX/Mkq8lAdTpveLmjYhERboAvBZwV+6E9FZyMS6ClkBy+UOGDT6ohDB
-XPMwIywASDPVhq0jbd5wuvYx33KUKhavwy1J5RwLrliQ4OgoQDWgtrUKeEocaSHe
-vqXDAoIBAEYG4UPTAUih9fY06pQ5DdWHPPLtsz4D/rmIZBLVHjnNovx9hOEB+dmK
-p+RdT2ELiqDPvifspR2QdDJ2N645btInNDpQMyHMrAKd08hHycId71spjRrc3T1l
-OG4ihTEkpzJhuTrJbScbyHdAVPpSTns+Skg9C5KnFi/MC1bYRJ2QRLIGi0PoFrvC
-/a6DDtuNofQl4AFNBMCo8ZwWlQBfeI7QKDQn/pe4J4Z/lC57d9futfyNLsu59fnG
-u1XmXbfUimloRf2Wssct7Tl2f0FGxBpdbaBzrMlyD9dhkSbX54phLRS6eyL6Xeqf
-k64Y1nRX74xnrNIJjNQF5/D9eoB5H5kCggEADkSUsvqv/hpMMNRIyXsIKIko4EW3
-L0ceh7Unl1vvekku7aLMrHqzu6tu6QoUXc9jMxhS9et41a7NqeLH4MFEqENoxQ6G
-tJTCuklNgKWiooQIN/Wm0t82a3M3kvcqIbCCG5EGDL/7Uh48DQGpSOGehEn6TYnG
-W42bU/Beq38LQzN4eQPhsiqmOwNJ4dYc4NqpOIkXi6UTCe9hDcpX2p7hG55zkpOA
-2rxpIOeOVSRHHOE8RsfIr8FzO/823P1mOQe5xMSCf1GSj6I+bopT0chL9JsiHLZa
-1VPn744OJjXt14LAt4byOVvgdSoQAgxWEC0LhmHYNXt8/YRMJiZ01bc1dA==
------END RSA PRIVATE KEY-----
diff --git a/test/tpm_test/rsa768.pem b/test/tpm_test/rsa768.pem
deleted file mode 100644
index 5be0fdf5f7..0000000000
--- a/test/tpm_test/rsa768.pem
+++ /dev/null
@@ -1,12 +0,0 @@
------BEGIN RSA PRIVATE KEY-----
-MIIBywIBAAJhALDb7UbZMvB81CAj0jVahhfbJHI2MzvCZIukSW50/vrSggzEEjpI
-Z+EVzJTfRBtOwBi6RhtRLOIPwDJ37V+L5aMA5jwtpxCJU6grM3Q49zYA/d1bvXvB
-fOF1kCt4LTmFaQIDAQABAmEArq25UCWMG1yfQtM+dnXfRUarW6bOuXJJTmbIJDGn
-+WHbEvLBMhF7kCOwuUU/Bl2i1zUP3fwD342Ra4P5We5nHhognov49uKy9SlxTCJU
-z36XvHAk3W1S/hfZ1kF7dkABAjEA1glkyPNcAsfGR05/Q50xRnozhaCkFuoie81k
-m1Dspy9+z+tpKTSOt7Wzun+bAX1pAjEA04iSLdXGKfTwLmHwYK2pRhGpDGkUMQk2
-i3AbEZsmOTQ0/fGaiVFjCsZgC7oYjsgBAjA8oMSPt3+kufoMUMvz1x8SG6NkgrB4
-XTIPZ4rMBAxE/0sokkJjjaOvniSe+25o6aECMQCG3oedM7SSIbpVSFqTuYW4yB/J
-auHV1fLx+ns3wX0gcdnro3SNYtfMEelA8NkhiAECMGVIqAN9qpGW5qAyikDrmzod
-7+wMrWHefpWKsih4+MIvAo7WOOoM+1UasRwVGhMxFQ==
------END RSA PRIVATE KEY-----
diff --git a/test/tpm_test/rsa_test.py b/test/tpm_test/rsa_test.py
deleted file mode 100644
index e411df57b0..0000000000
--- a/test/tpm_test/rsa_test.py
+++ /dev/null
@@ -1,818 +0,0 @@
-#!/usr/bin/env python2
-# Copyright 2015 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.
-
-"""Module for testing rsa functions using extended commands."""
-
-import binascii
-import Crypto
-import Crypto.Hash.SHA
-import Crypto.Hash.SHA256
-import Crypto.Hash.SHA384
-import Crypto.Hash.SHA512
-from Crypto.PublicKey import RSA
-import Crypto.Signature.PKCS1_PSS
-import Crypto.Signature.PKCS1_v1_5
-import hashlib
-import os
-import rsa
-import struct
-
-import subcmd
-import utils
-
-_MODULE_DIR = os.path.dirname(os.path.abspath(__file__))
-
-_RSA_OPCODES = {
- 'ENCRYPT': 0x00,
- 'DECRYPT': 0x01,
- 'SIGN': 0x02,
- 'VERIFY': 0x03,
- 'KEYGEN': 0x04,
- 'KEYTEST': 0x05,
- 'PRIMEGEN': 0x06,
- 'X509_VERIFY': 0x07
-}
-
-
-# TPM2 ALG codes.
-_RSA_PADDING = {
- 'NONE': 0x00,
- 'PKCS1-SSA': 0x14,
- 'PKCS1-ES': 0x15,
- 'PKCS1-PSS': 0x16,
- 'OAEP': 0x17,
- 'NULL': 0x10,
-}
-
-
-# TPM2 ALG codes.
-_HASH = {
- 'NONE': 0x00,
- 'SHA1': 0x04,
- 'SHA256': 0x0B,
- 'SHA384': 0x0C,
- 'SHA512': 0x0D,
-}
-
-_SIGNER = {
- 'PKCS1-SSA': Crypto.Signature.PKCS1_v1_5,
- 'PKCS1-PSS': Crypto.Signature.PKCS1_PSS,
-}
-
-_HASHER = {
- 'SHA1': Crypto.Hash.SHA,
- 'SHA256': Crypto.Hash.SHA256,
- 'SHA384': Crypto.Hash.SHA384,
- 'SHA512': Crypto.Hash.SHA512,
-}
-
-_KEYS = {
- 768: RSA.importKey(open(os.path.join(_MODULE_DIR, 'rsa768.pem')).read()),
- 1024: RSA.importKey(open(os.path.join(_MODULE_DIR, 'rsa1024.pem')).read()),
- 2048: RSA.importKey(open(os.path.join(_MODULE_DIR, 'rsa2048.pem')).read()),
- 4096: RSA.importKey(open(os.path.join(_MODULE_DIR, 'rsa4096.pem')).read()),
-}
-
-# Command format.
-#
-# 0x00 OP
-# 0x00 PADDING
-# 0x00 HASHING
-# 0x00 MSB KEY LEN
-# 0x00 LSB KEY LEN
-# 0x00 MSB IN LEN
-# 0x00 LSB IN LEN
-# .... IN
-# 0x00 MSB DIGEST LEN
-# 0x00 LSB DIGEST LEN
-# .... DIGEST
-#
-_RSA_CMD_FORMAT = '{o:c}{p:c}{h:c}{kl:s}{ml:s}{msg}{dl:s}{dig}'
-
-
-def _decrypt_cmd(padding, hashing, key_len, msg):
- op = _RSA_OPCODES['DECRYPT']
- msg_len = len(msg)
- return _RSA_CMD_FORMAT.format(o=op, p=padding, h=hashing,
- kl=struct.pack('>H', key_len),
- ml=struct.pack('>H', msg_len), msg=msg,
- dl='', dig='')
-
-
-def _encrypt_cmd(padding, hashing, key_len, msg):
- op = _RSA_OPCODES['ENCRYPT']
- msg_len = len(msg)
- return _RSA_CMD_FORMAT.format(o=op, p=padding, h=hashing,
- kl=struct.pack('>H', key_len),
- ml=struct.pack('>H', msg_len), msg=msg,
- dl='', dig='')
-
-
-def _sign_cmd(padding, hashing, key_len, digest):
- op = _RSA_OPCODES['SIGN']
- digest_len = len(digest)
- return _RSA_CMD_FORMAT.format(o=op, p=padding, h=hashing,
- kl=struct.pack('>H', key_len),
- ml=struct.pack('>H', digest_len), msg=digest,
- dl='', dig='')
-
-
-def _verify_cmd(padding, hashing, key_len, sig, digest):
- op = _RSA_OPCODES['VERIFY']
- sig_len = len(sig)
- digest_len = len(digest)
- return _RSA_CMD_FORMAT.format(o=op, p=padding, h=hashing,
- kl=struct.pack('>H', key_len),
- ml=struct.pack('>H', sig_len), msg=sig,
- dl=struct.pack('>H', digest_len), dig=digest)
-
-
-def _keytest_cmd(key_len):
- op = _RSA_OPCODES['KEYTEST']
- return _RSA_CMD_FORMAT.format(o=op, p=0, h=_HASH['NONE'],
- kl=struct.pack('>H', key_len),
- ml=struct.pack('>H', 0), msg='',
- dl='', dig='')
-
-
-def _keygen_cmd(key_len, e, label):
- op = _RSA_OPCODES['KEYGEN']
- padding = _RSA_PADDING['NONE']
- hashing = _HASH['NONE']
- return _RSA_CMD_FORMAT.format(o=op, p=padding, h=hashing,
- kl=struct.pack('>H', key_len),
- ml=struct.pack('>H', len(label)), msg=label,
- dl=struct.pack('>H', 0), dig='')
-
-
-def _primegen_cmd(seed):
- op = _RSA_OPCODES['PRIMEGEN']
- padding = _RSA_PADDING['NONE']
- hashing = _HASH['NONE']
- return _RSA_CMD_FORMAT.format(o=op, p=padding, h=hashing,
- kl=struct.pack('>H', len(seed) * 8 * 2),
- ml=struct.pack('>H', len(seed)), msg=seed,
- dl=struct.pack('>H', 0), dig='')
-
-def _x509_verify_cmd(key_len):
- op = _RSA_OPCODES['X509_VERIFY']
- padding = _RSA_PADDING['NONE']
- hashing = _HASH['NONE']
- return _RSA_CMD_FORMAT.format(o=op, p=padding, h=hashing,
- kl=struct.pack('>H', key_len),
- ml=struct.pack('>H', 0), msg='',
- dl=struct.pack('>H', 0), dig='')
-
-
-_PRIMES = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53,
- 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131,
- 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199,
- 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281,
- 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373,
- 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457,
- 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557,
- 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641,
- 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733,
- 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827,
- 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929,
- 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019,
- 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091,
- 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171,
- 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249,
- 1259, 1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319,
- 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, 1427, 1429,
- 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489,
- 1493, 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571,
- 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637,
- 1657, 1663, 1667, 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733,
- 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, 1823,
- 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, 1901, 1907,
- 1913, 1931, 1933, 1949, 1951, 1973, 1979, 1987, 1993, 1997, 1999,
- 2003, 2011, 2017, 2027, 2029, 2039, 2053, 2063, 2069, 2081, 2083,
- 2087, 2089, 2099, 2111, 2113, 2129, 2131, 2137, 2141, 2143, 2153,
- 2161, 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243, 2251, 2267,
- 2269, 2273, 2281, 2287, 2293, 2297, 2309, 2311, 2333, 2339, 2341,
- 2347, 2351, 2357, 2371, 2377, 2381, 2383, 2389, 2393, 2399, 2411,
- 2417, 2423, 2437, 2441, 2447, 2459, 2467, 2473, 2477, 2503, 2521,
- 2531, 2539, 2543, 2549, 2551, 2557, 2579, 2591, 2593, 2609, 2617,
- 2621, 2633, 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687, 2689,
- 2693, 2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741, 2749, 2753,
- 2767, 2777, 2789, 2791, 2797, 2801, 2803, 2819, 2833, 2837, 2843,
- 2851, 2857, 2861, 2879, 2887, 2897, 2903, 2909, 2917, 2927, 2939,
- 2953, 2957, 2963, 2969, 2971, 2999, 3001, 3011, 3019, 3023, 3037,
- 3041, 3049, 3061, 3067, 3079, 3083, 3089, 3109, 3119, 3121, 3137,
- 3163, 3167, 3169, 3181, 3187, 3191, 3203, 3209, 3217, 3221, 3229,
- 3251, 3253, 3257, 3259, 3271, 3299, 3301, 3307, 3313, 3319, 3323,
- 3329, 3331, 3343, 3347, 3359, 3361, 3371, 3373, 3389, 3391, 3407,
- 3413, 3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499, 3511,
- 3517, 3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559, 3571, 3581,
- 3583, 3593, 3607, 3613, 3617, 3623, 3631, 3637, 3643, 3659, 3671,
- 3673, 3677, 3691, 3697, 3701, 3709, 3719, 3727, 3733, 3739, 3761,
- 3767, 3769, 3779, 3793, 3797, 3803, 3821, 3823, 3833, 3847, 3851,
- 3853, 3863, 3877, 3881, 3889, 3907, 3911, 3917, 3919, 3923, 3929,
- 3931, 3943, 3947, 3967, 3989, 4001, 4003, 4007, 4013, 4019, 4021,
- 4027, 4049, 4051, 4057, 4073, 4079, 4091, 4093, 4099, 4111, 4127,
- 4129, 4133, 4139, 4153, 4157, 4159, 4177, 4201, 4211, 4217, 4219,
- 4229, 4231, 4241, 4243, 4253, 4259, 4261, 4271, 4273, 4283, 4289,
- 4297, 4327, 4337, 4339, 4349, 4357, 4363, 4373, 4391, 4397, 4409,
- 4421, 4423, 4441, 4447, 4451, 4457, 4463, 4481, 4483, 4493, 4507,
- 4513, 4517, 4519, 4523, 4547, 4549, 4561, 4567, 4583, 4591, 4597,
- 4603, 4621, 4637, 4639, 4643, 4649, 4651, 4657, 4663, 4673, 4679,
- 4691, 4703, 4721, 4723, 4729, 4733, 4751, 4759, 4783, 4787, 4789,
- 4793, 4799, 4801, 4813, 4817, 4831, 4861, 4871, 4877, 4889, 4903,
- 4909, 4919, 4931, 4933, 4937, 4943, 4951, 4957, 4967, 4969, 4973,
- 4987, 4993, 4999, 5003, 5009, 5011, 5021, 5023, 5039, 5051, 5059,
- 5077, 5081, 5087, 5099, 5101, 5107, 5113, 5119, 5147, 5153, 5167,
- 5171, 5179, 5189, 5197, 5209, 5227, 5231, 5233, 5237, 5261, 5273,
- 5279, 5281, 5297, 5303, 5309, 5323, 5333, 5347, 5351, 5381, 5387,
- 5393, 5399, 5407, 5413, 5417, 5419, 5431, 5437, 5441, 5443, 5449,
- 5471, 5477, 5479, 5483, 5501, 5503, 5507, 5519, 5521, 5527, 5531,
- 5557, 5563, 5569, 5573, 5581, 5591, 5623, 5639, 5641, 5647, 5651,
- 5653, 5657, 5659, 5669, 5683, 5689, 5693, 5701, 5711, 5717, 5737,
- 5741, 5743, 5749, 5779, 5783, 5791, 5801, 5807, 5813, 5821, 5827,
- 5839, 5843, 5849, 5851, 5857, 5861, 5867, 5869, 5879, 5881, 5897,
- 5903, 5923, 5927, 5939, 5953, 5981, 5987, 6007, 6011, 6029, 6037,
- 6043, 6047, 6053, 6067, 6073, 6079, 6089, 6091, 6101, 6113, 6121,
- 6131, 6133, 6143, 6151, 6163, 6173, 6197, 6199, 6203, 6211, 6217,
- 6221, 6229, 6247, 6257, 6263, 6269, 6271, 6277, 6287, 6299, 6301,
- 6311, 6317, 6323, 6329, 6337, 6343, 6353, 6359, 6361, 6367, 6373,
- 6379, 6389, 6397, 6421, 6427, 6449, 6451, 6469, 6473, 6481, 6491,
- 6521, 6529, 6547, 6551, 6553, 6563, 6569, 6571, 6577, 6581, 6599,
- 6607, 6619, 6637, 6653, 6659, 6661, 6673, 6679, 6689, 6691, 6701,
- 6703, 6709, 6719, 6733, 6737, 6761, 6763, 6779, 6781, 6791, 6793,
- 6803, 6823, 6827, 6829, 6833, 6841, 6857, 6863, 6869, 6871, 6883,
- 6899, 6907, 6911, 6917, 6947, 6949, 6959, 6961, 6967, 6971, 6977,
- 6983, 6991, 6997, 7001, 7013, 7019, 7027, 7039, 7043, 7057, 7069,
- 7079, 7103, 7109, 7121, 7127, 7129, 7151, 7159, 7177, 7187, 7193,
- 7207, 7211, 7213, 7219, 7229, 7237, 7243, 7247, 7253, 7283, 7297,
- 7307, 7309, 7321, 7331, 7333, 7349, 7351, 7369, 7393, 7411, 7417,
- 7433, 7451, 7457, 7459, 7477, 7481, 7487, 7489, 7499, 7507, 7517,
- 7523, 7529, 7537, 7541, 7547, 7549, 7559, 7561, 7573, 7577, 7583,
- 7589, 7591, 7603, 7607, 7621, 7639, 7643, 7649, 7669, 7673, 7681,
- 7687, 7691, 7699, 7703, 7717, 7723, 7727, 7741, 7753, 7757, 7759,
- 7789, 7793, 7817, 7823, 7829, 7841, 7853, 7867, 7873, 7877, 7879,
- 7883, 7901, 7907, 7919, 7927, 7933, 7937, 7949, 7951, 7963, 7993,
- 8009, 8011, 8017, 8039, 8053, 8059, 8069, 8081, 8087, 8089, 8093,
- 8101, 8111, 8117, 8123, 8147, 8161, 8167, 8171, 8179, 8191, 8209,
- 8219, 8221, 8231, 8233, 8237, 8243, 8263, 8269, 8273, 8287, 8291,
- 8293, 8297, 8311, 8317, 8329, 8353, 8363, 8369, 8377, 8387, 8389,
- 8419, 8423, 8429, 8431, 8443, 8447, 8461, 8467, 8501, 8513, 8521,
- 8527, 8537, 8539, 8543, 8563, 8573, 8581, 8597, 8599, 8609, 8623,
- 8627, 8629, 8641, 8647, 8663, 8669, 8677, 8681, 8689, 8693, 8699,
- 8707, 8713, 8719, 8731, 8737, 8741, 8747, 8753, 8761, 8779, 8783,
- 8803, 8807, 8819, 8821, 8831, 8837, 8839, 8849, 8861, 8863, 8867,
- 8887, 8893, 8923, 8929, 8933, 8941, 8951, 8963, 8969, 8971, 8999,
- 9001, 9007, 9011, 9013, 9029, 9041, 9043, 9049, 9059, 9067, 9091,
- 9103, 9109, 9127, 9133, 9137, 9151, 9157, 9161, 9173, 9181, 9187,
- 9199, 9203, 9209, 9221, 9227, 9239, 9241, 9257, 9277, 9281, 9283,
- 9293, 9311, 9319, 9323, 9337, 9341, 9343, 9349, 9371, 9377, 9391,
- 9397, 9403, 9413, 9419, 9421, 9431, 9433, 9437, 9439, 9461, 9463,
- 9467, 9473, 9479, 9491, 9497, 9511, 9521, 9533, 9539, 9547, 9551,
- 9587, 9601, 9613, 9619, 9623, 9629, 9631, 9643, 9649, 9661, 9677,
- 9679, 9689, 9697, 9719, 9721, 9733, 9739, 9743, 9749, 9767, 9769,
- 9781, 9787, 9791, 9803, 9811, 9817, 9829, 9833, 9839, 9851, 9857,
- 9859, 9871, 9883, 9887, 9901, 9907, 9923, 9929, 9931, 9941, 9949,
- 9967, 9973, 10007, 10009, 10037, 10039, 10061, 10067, 10069, 10079,
- 10091, 10093, 10099, 10103, 10111, 10133, 10139, 10141, 10151, 10159,
- 10163, 10169, 10177, 10181, 10193, 10211, 10223, 10243, 10247, 10253,
- 10259, 10267, 10271, 10273, 10289, 10301, 10303, 10313, 10321, 10331,
- 10333, 10337, 10343, 10357, 10369, 10391, 10399, 10427, 10429, 10433,
- 10453, 10457, 10459, 10463, 10477, 10487, 10499, 10501, 10513, 10529,
- 10531, 10559, 10567, 10589, 10597, 10601, 10607, 10613, 10627, 10631,
- 10639, 10651, 10657, 10663, 10667, 10687, 10691, 10709, 10711, 10723,
- 10729, 10733, 10739, 10753, 10771, 10781, 10789, 10799, 10831, 10837,
- 10847, 10853, 10859, 10861, 10867, 10883, 10889, 10891, 10903, 10909,
- 10937, 10939, 10949, 10957, 10973, 10979, 10987, 10993, 11003, 11027,
- 11047, 11057, 11059, 11069, 11071, 11083, 11087, 11093, 11113, 11117,
- 11119, 11131, 11149, 11159, 11161, 11171, 11173, 11177, 11197, 11213,
- 11239, 11243, 11251, 11257, 11261, 11273, 11279, 11287, 11299, 11311,
- 11317, 11321, 11329, 11351, 11353, 11369, 11383, 11393, 11399, 11411,
- 11423, 11437, 11443, 11447, 11467, 11471, 11483, 11489, 11491, 11497,
- 11503, 11519, 11527, 11549, 11551, 11579, 11587, 11593, 11597, 11617,
- 11621, 11633, 11657, 11677, 11681, 11689, 11699, 11701, 11717, 11719,
- 11731, 11743, 11777, 11779, 11783, 11789, 11801, 11807, 11813, 11821,
- 11827, 11831, 11833, 11839, 11863, 11867, 11887, 11897, 11903, 11909,
- 11923, 11927, 11933, 11939, 11941, 11953, 11959, 11969, 11971, 11981,
- 11987, 12007, 12011, 12037, 12041, 12043, 12049, 12071, 12073, 12097,
- 12101, 12107, 12109, 12113, 12119, 12143, 12149, 12157, 12161, 12163,
- 12197, 12203, 12211, 12227, 12239, 12241, 12251, 12253, 12263, 12269,
- 12277, 12281, 12289, 12301, 12323, 12329, 12343, 12347, 12373, 12377,
- 12379, 12391, 12401, 12409, 12413, 12421, 12433, 12437, 12451, 12457,
- 12473, 12479, 12487, 12491, 12497, 12503, 12511, 12517, 12527, 12539,
- 12541, 12547, 12553, 12569, 12577, 12583, 12589, 12601, 12611, 12613,
- 12619, 12637, 12641, 12647, 12653, 12659, 12671, 12689, 12697, 12703,
- 12713, 12721, 12739, 12743, 12757, 12763, 12781, 12791, 12799, 12809,
- 12821, 12823, 12829, 12841, 12853, 12889, 12893, 12899, 12907, 12911,
- 12917, 12919, 12923, 12941, 12953, 12959, 12967, 12973, 12979, 12983,
- 13001, 13003, 13007, 13009, 13033, 13037, 13043, 13049, 13063, 13093,
- 13099, 13103, 13109, 13121, 13127, 13147, 13151, 13159, 13163, 13171,
- 13177, 13183, 13187, 13217, 13219, 13229, 13241, 13249, 13259, 13267,
- 13291, 13297, 13309, 13313, 13327, 13331, 13337, 13339, 13367, 13381,
- 13397, 13399, 13411, 13417, 13421, 13441, 13451, 13457, 13463, 13469,
- 13477, 13487, 13499, 13513, 13523, 13537, 13553, 13567, 13577, 13591,
- 13597, 13613, 13619, 13627, 13633, 13649, 13669, 13679, 13681, 13687,
- 13691, 13693, 13697, 13709, 13711, 13721, 13723, 13729, 13751, 13757,
- 13759, 13763, 13781, 13789, 13799, 13807, 13829, 13831, 13841, 13859,
- 13873, 13877, 13879, 13883, 13901, 13903, 13907, 13913, 13921, 13931,
- 13933, 13963, 13967, 13997, 13999, 14009, 14011, 14029, 14033, 14051,
- 14057, 14071, 14081, 14083, 14087, 14107, 14143, 14149, 14153, 14159,
- 14173, 14177, 14197, 14207, 14221, 14243, 14249, 14251, 14281, 14293,
- 14303, 14321, 14323, 14327, 14341, 14347, 14369, 14387, 14389, 14401,
- 14407, 14411, 14419, 14423, 14431, 14437, 14447, 14449, 14461, 14479,
- 14489, 14503, 14519, 14533, 14537, 14543, 14549, 14551, 14557, 14561,
- 14563, 14591, 14593, 14621, 14627, 14629, 14633, 14639, 14653, 14657,
- 14669, 14683, 14699, 14713, 14717, 14723, 14731, 14737, 14741, 14747,
- 14753, 14759, 14767, 14771, 14779, 14783, 14797, 14813, 14821, 14827,
- 14831, 14843, 14851, 14867, 14869, 14879, 14887, 14891, 14897, 14923,
- 14929, 14939, 14947, 14951, 14957, 14969, 14983, 15013, 15017, 15031,
- 15053, 15061, 15073, 15077, 15083, 15091, 15101, 15107, 15121, 15131,
- 15137, 15139, 15149, 15161, 15173, 15187, 15193, 15199, 15217, 15227,
- 15233, 15241, 15259, 15263, 15269, 15271, 15277, 15287, 15289, 15299,
- 15307, 15313, 15319, 15329, 15331, 15349, 15359, 15361, 15373, 15377,
- 15383, 15391, 15401, 15413, 15427, 15439, 15443, 15451, 15461, 15467,
- 15473, 15493, 15497, 15511, 15527, 15541, 15551, 15559, 15569, 15581,
- 15583, 15601, 15607, 15619, 15629, 15641, 15643, 15647, 15649, 15661,
- 15667, 15671, 15679, 15683, 15727, 15731, 15733, 15737, 15739, 15749,
- 15761, 15767, 15773, 15787, 15791, 15797, 15803, 15809, 15817, 15823,
- 15859, 15877, 15881, 15887, 15889, 15901, 15907, 15913, 15919, 15923,
- 15937, 15959, 15971, 15973, 15991, 16001, 16007, 16033, 16057, 16061,
- 16063, 16067, 16069, 16073, 16087, 16091, 16097, 16103, 16111, 16127,
- 16139, 16141, 16183, 16187, 16189, 16193, 16217, 16223, 16229, 16231,
- 16249, 16253, 16267, 16273, 16301, 16319, 16333, 16339, 16349, 16361,
- 16363, 16369, 16381, 16411, 16417, 16421, 16427, 16433, 16447, 16451,
- 16453, 16477, 16481, 16487, 16493, 16519, 16529, 16547, 16553, 16561,
- 16567, 16573, 16603, 16607, 16619, 16631, 16633, 16649, 16651, 16657,
- 16661, 16673, 16691, 16693, 16699, 16703, 16729, 16741, 16747, 16759,
- 16763, 16787, 16811, 16823, 16829, 16831, 16843, 16871, 16879, 16883,
- 16889, 16901, 16903, 16921, 16927, 16931, 16937, 16943, 16963, 16979,
- 16981, 16987, 16993, 17011, 17021, 17027, 17029, 17033, 17041, 17047,
- 17053, 17077, 17093, 17099, 17107, 17117, 17123, 17137, 17159, 17167,
- 17183, 17189, 17191, 17203, 17207, 17209, 17231, 17239, 17257, 17291,
- 17293, 17299, 17317, 17321, 17327, 17333, 17341, 17351, 17359, 17377,
- 17383, 17387, 17389, 17393, 17401, 17417, 17419, 17431, 17443, 17449,
- 17467, 17471, 17477, 17483, 17489, 17491, 17497, 17509, 17519, 17539,
- 17551, 17569, 17573, 17579, 17581, 17597, 17599, 17609, 17623, 17627,
- 17657, 17659, 17669, 17681, 17683, 17707, 17713, 17729, 17737, 17747,
- 17749, 17761, 17783, 17789, 17791, 17807, 17827, 17837, 17839, 17851,
- 17863, 17881, 17891, 17903, 17909, 17911, 17921, 17923, 17929, 17939,
- 17957, 17959, 17971, 17977, 17981, 17987, 17989, 18013, 18041, 18043,
- 18047, 18049, 18059, 18061, 18077, 18089, 18097, 18119, 18121, 18127,
- 18131, 18133, 18143, 18149, 18169, 18181, 18191, 18199, 18211, 18217,
- 18223, 18229, 18233, 18251, 18253, 18257, 18269, 18287, 18289, 18301,
- 18307, 18311, 18313, 18329, 18341, 18353, 18367, 18371, 18379, 18397,
- 18401, 18413, 18427, 18433, 18439, 18443, 18451, 18457, 18461, 18481,
- 18493, 18503, 18517, 18521, 18523, 18539, 18541, 18553, 18583, 18587,
- 18593, 18617, 18637, 18661, 18671, 18679, 18691, 18701, 18713, 18719,
- 18731, 18743, 18749, 18757, 18773, 18787, 18793, 18797, 18803, 18839,
- 18859, 18869, 18899, 18911, 18913, 18917, 18919, 18947, 18959, 18973,
- 18979, 19001, 19009, 19013, 19031, 19037, 19051, 19069, 19073, 19079,
- 19081, 19087, 19121, 19139, 19141, 19157, 19163, 19181, 19183, 19207,
- 19211, 19213, 19219, 19231, 19237, 19249, 19259, 19267, 19273, 19289,
- 19301, 19309, 19319, 19333, 19373, 19379, 19381, 19387, 19391, 19403,
- 19417, 19421, 19423, 19427, 19429, 19433, 19441, 19447, 19457, 19463,
- 19469, 19471, 19477, 19483, 19489, 19501, 19507, 19531, 19541, 19543,
- 19553, 19559, 19571, 19577, 19583, 19597, 19603, 19609, 19661, 19681,
- 19687, 19697, 19699, 19709, 19717, 19727, 19739, 19751, 19753, 19759,
- 19763, 19777, 19793, 19801, 19813, 19819, 19841, 19843, 19853, 19861,
- 19867, 19889, 19891, 19913, 19919, 19927, 19937, 19949, 19961, 19963,
- 19973, 19979, 19991, 19993, 19997, 20011, 20021, 20023, 20029, 20047,
- 20051, 20063, 20071, 20089, 20101, 20107, 20113, 20117, 20123, 20129,
- 20143, 20147, 20149, 20161, 20173, 20177, 20183, 20201, 20219, 20231,
- 20233, 20249, 20261, 20269, 20287, 20297, 20323, 20327, 20333, 20341,
- 20347, 20353, 20357, 20359, 20369, 20389, 20393, 20399, 20407, 20411,
- 20431, 20441, 20443, 20477, 20479, 20483, 20507, 20509, 20521, 20533,
- 20543, 20549, 20551, 20563, 20593, 20599, 20611, 20627, 20639, 20641,
- 20663, 20681, 20693, 20707, 20717, 20719, 20731, 20743, 20747, 20749,
- 20753, 20759, 20771, 20773, 20789, 20807, 20809, 20849, 20857, 20873,
- 20879, 20887, 20897, 20899, 20903, 20921, 20929, 20939, 20947, 20959,
- 20963, 20981, 20983, 21001, 21011, 21013, 21017, 21019, 21023, 21031,
- 21059, 21061, 21067, 21089, 21101, 21107, 21121, 21139, 21143, 21149,
- 21157, 21163, 21169, 21179, 21187, 21191, 21193, 21211, 21221, 21227,
- 21247, 21269, 21277, 21283, 21313, 21317, 21319, 21323, 21341, 21347,
- 21377, 21379, 21383, 21391, 21397, 21401, 21407, 21419, 21433, 21467,
- 21481, 21487, 21491, 21493, 21499, 21503, 21517, 21521, 21523, 21529,
- 21557, 21559, 21563, 21569, 21577, 21587, 21589, 21599, 21601, 21611,
- 21613, 21617, 21647, 21649, 21661, 21673, 21683, 21701, 21713, 21727,
- 21737, 21739, 21751, 21757, 21767, 21773, 21787, 21799, 21803, 21817,
- 21821, 21839, 21841, 21851, 21859, 21863, 21871, 21881, 21893, 21911,
- 21929, 21937, 21943, 21961, 21977, 21991, 21997, 22003, 22013, 22027,
- 22031, 22037, 22039, 22051, 22063, 22067, 22073, 22079, 22091, 22093,
- 22109, 22111, 22123, 22129, 22133, 22147, 22153, 22157, 22159, 22171,
- 22189, 22193, 22229, 22247, 22259, 22271, 22273, 22277, 22279, 22283,
- 22291, 22303, 22307, 22343, 22349, 22367, 22369, 22381, 22391, 22397,
- 22409, 22433, 22441, 22447, 22453, 22469, 22481, 22483, 22501, 22511,
- 22531, 22541, 22543, 22549, 22567, 22571, 22573, 22613, 22619, 22621,
- 22637, 22639, 22643, 22651, 22669, 22679, 22691, 22697, 22699, 22709,
- 22717, 22721, 22727, 22739, 22741, 22751, 22769, 22777, 22783, 22787,
- 22807, 22811, 22817, 22853, 22859, 22861, 22871, 22877, 22901, 22907,
- 22921, 22937, 22943, 22961, 22963, 22973, 22993, 23003, 23011, 23017,
- 23021, 23027, 23029, 23039, 23041, 23053, 23057, 23059, 23063, 23071,
- 23081, 23087, 23099, 23117, 23131, 23143, 23159, 23167, 23173, 23189,
- 23197, 23201, 23203, 23209, 23227, 23251, 23269, 23279, 23291, 23293,
- 23297, 23311, 23321, 23327, 23333, 23339, 23357, 23369, 23371, 23399,
- 23417, 23431, 23447, 23459, 23473, 23497, 23509, 23531, 23537, 23539,
- 23549, 23557, 23561, 23563, 23567, 23581, 23593, 23599, 23603, 23609,
- 23623, 23627, 23629, 23633, 23663, 23669, 23671, 23677, 23687, 23689,
- 23719, 23741, 23743, 23747, 23753, 23761, 23767, 23773, 23789, 23801,
- 23813, 23819, 23827, 23831, 23833, 23857, 23869, 23873, 23879, 23887,
- 23893, 23899, 23909, 23911, 23917, 23929, 23957, 23971, 23977, 23981,
- 23993, 24001, 24007, 24019, 24023, 24029, 24043, 24049, 24061, 24071,
- 24077, 24083, 24091, 24097, 24103, 24107, 24109, 24113, 24121, 24133,
- 24137, 24151, 24169, 24179, 24181, 24197, 24203, 24223, 24229, 24239,
- 24247, 24251, 24281, 24317, 24329, 24337, 24359, 24371, 24373, 24379,
- 24391, 24407, 24413, 24419, 24421, 24439, 24443, 24469, 24473, 24481,
- 24499, 24509, 24517, 24527, 24533, 24547, 24551, 24571, 24593, 24611,
- 24623, 24631, 24659, 24671, 24677, 24683, 24691, 24697, 24709, 24733,
- 24749, 24763, 24767, 24781, 24793, 24799, 24809, 24821, 24841, 24847,
- 24851, 24859, 24877, 24889, 24907, 24917, 24919, 24923, 24943, 24953,
- 24967, 24971, 24977, 24979, 24989, 25013, 25031, 25033, 25037, 25057,
- 25073, 25087, 25097, 25111, 25117, 25121, 25127, 25147, 25153, 25163,
- 25169, 25171, 25183, 25189, 25219, 25229, 25237, 25243, 25247, 25253,
- 25261, 25301, 25303, 25307, 25309, 25321, 25339, 25343, 25349, 25357,
- 25367, 25373, 25391, 25409, 25411, 25423, 25439, 25447, 25453, 25457,
- 25463, 25469, 25471, 25523, 25537, 25541, 25561, 25577, 25579, 25583,
- 25589, 25601, 25603, 25609, 25621, 25633, 25639, 25643, 25657, 25667,
- 25673, 25679, 25693, 25703, 25717, 25733, 25741, 25747, 25759, 25763,
- 25771, 25793, 25799, 25801, 25819, 25841, 25847, 25849, 25867, 25873,
- 25889, 25903, 25913, 25919, 25931, 25933, 25939, 25943, 25951, 25969,
- 25981, 25997, 25999, 26003, 26017, 26021, 26029, 26041, 26053, 26083,
- 26099, 26107, 26111, 26113, 26119, 26141, 26153, 26161, 26171, 26177,
- 26183, 26189, 26203, 26209, 26227, 26237, 26249, 26251, 26261, 26263,
- 26267, 26293, 26297, 26309, 26317, 26321, 26339, 26347, 26357, 26371,
- 26387, 26393, 26399, 26407, 26417, 26423, 26431, 26437, 26449, 26459,
- 26479, 26489, 26497, 26501, 26513, 26539, 26557, 26561, 26573, 26591,
- 26597, 26627, 26633, 26641, 26647, 26669, 26681, 26683, 26687, 26693,
- 26699, 26701, 26711, 26713, 26717, 26723, 26729, 26731, 26737, 26759,
- 26777, 26783, 26801, 26813, 26821, 26833, 26839, 26849, 26861, 26863,
- 26879, 26881, 26891, 26893, 26903, 26921, 26927, 26947, 26951, 26953,
- 26959, 26981, 26987, 26993, 27011, 27017, 27031, 27043, 27059, 27061,
- 27067, 27073, 27077, 27091, 27103, 27107, 27109, 27127, 27143, 27179,
- 27191, 27197, 27211, 27239, 27241, 27253, 27259, 27271, 27277, 27281,
- 27283, 27299, 27329, 27337, 27361, 27367, 27397, 27407, 27409, 27427,
- 27431, 27437, 27449, 27457, 27479, 27481, 27487, 27509, 27527, 27529,
- 27539, 27541, 27551, 27581, 27583, 27611, 27617, 27631, 27647, 27653,
- 27673, 27689, 27691, 27697, 27701, 27733, 27737, 27739, 27743, 27749,
- 27751, 27763, 27767, 27773, 27779, 27791, 27793, 27799, 27803, 27809,
- 27817, 27823, 27827, 27847, 27851, 27883, 27893, 27901, 27917, 27919,
- 27941, 27943, 27947, 27953, 27961, 27967, 27983, 27997, 28001, 28019,
- 28027, 28031, 28051, 28057, 28069, 28081, 28087, 28097, 28099, 28109,
- 28111, 28123, 28151, 28163, 28181, 28183, 28201, 28211, 28219, 28229,
- 28277, 28279, 28283, 28289, 28297, 28307, 28309, 28319, 28349, 28351,
- 28387, 28393, 28403, 28409, 28411, 28429, 28433, 28439, 28447, 28463,
- 28477, 28493, 28499, 28513, 28517, 28537, 28541, 28547, 28549, 28559,
- 28571, 28573, 28579, 28591, 28597, 28603, 28607, 28619, 28621, 28627,
- 28631, 28643, 28649, 28657, 28661, 28663, 28669, 28687, 28697, 28703,
- 28711, 28723, 28729, 28751, 28753, 28759, 28771, 28789, 28793, 28807,
- 28813, 28817, 28837, 28843, 28859, 28867, 28871, 28879, 28901, 28909,
- 28921, 28927, 28933, 28949, 28961, 28979, 29009, 29017, 29021, 29023,
- 29027, 29033, 29059, 29063, 29077, 29101, 29123, 29129, 29131, 29137,
- 29147, 29153, 29167, 29173, 29179, 29191, 29201, 29207, 29209, 29221,
- 29231, 29243, 29251, 29269, 29287, 29297, 29303, 29311, 29327, 29333,
- 29339, 29347, 29363, 29383, 29387, 29389, 29399, 29401, 29411, 29423,
- 29429, 29437, 29443, 29453, 29473, 29483, 29501, 29527, 29531, 29537,
- 29567, 29569, 29573, 29581, 29587, 29599, 29611, 29629, 29633, 29641,
- 29663, 29669, 29671, 29683, 29717, 29723, 29741, 29753, 29759, 29761,
- 29789, 29803, 29819, 29833, 29837, 29851, 29863, 29867, 29873, 29879,
- 29881, 29917, 29921, 29927, 29947, 29959, 29983, 29989, 30011, 30013,
- 30029, 30047, 30059, 30071, 30089, 30091, 30097, 30103, 30109, 30113,
- 30119, 30133, 30137, 30139, 30161, 30169, 30181, 30187, 30197, 30203,
- 30211, 30223, 30241, 30253, 30259, 30269, 30271, 30293, 30307, 30313,
- 30319, 30323, 30341, 30347, 30367, 30389, 30391, 30403, 30427, 30431,
- 30449, 30467, 30469, 30491, 30493, 30497, 30509, 30517, 30529, 30539,
- 30553, 30557, 30559, 30577, 30593, 30631, 30637, 30643, 30649, 30661,
- 30671, 30677, 30689, 30697, 30703, 30707, 30713, 30727, 30757, 30763,
- 30773, 30781, 30803, 30809, 30817, 30829, 30839, 30841, 30851, 30853,
- 30859, 30869, 30871, 30881, 30893, 30911, 30931, 30937, 30941, 30949,
- 30971, 30977, 30983, 31013, 31019, 31033, 31039, 31051, 31063, 31069,
- 31079, 31081, 31091, 31121, 31123, 31139, 31147, 31151, 31153, 31159,
- 31177, 31181, 31183, 31189, 31193, 31219, 31223, 31231, 31237, 31247,
- 31249, 31253, 31259, 31267, 31271, 31277, 31307, 31319, 31321, 31327,
- 31333, 31337, 31357, 31379, 31387, 31391, 31393, 31397, 31469, 31477,
- 31481, 31489, 31511, 31513, 31517, 31531, 31541, 31543, 31547, 31567,
- 31573, 31583, 31601, 31607, 31627, 31643, 31649, 31657, 31663, 31667,
- 31687, 31699, 31721, 31723, 31727, 31729, 31741, 31751, 31769, 31771,
- 31793, 31799, 31817, 31847, 31849, 31859, 31873, 31883, 31891, 31907,
- 31957, 31963, 31973, 31981, 31991, 32003, 32009, 32027, 32029, 32051,
- 32057, 32059, 32063, 32069, 32077, 32083, 32089, 32099, 32117, 32119,
- 32141, 32143, 32159, 32173, 32183, 32189, 32191, 32203, 32213, 32233,
- 32237, 32251, 32257, 32261, 32297, 32299, 32303, 32309, 32321, 32323,
- 32327, 32341, 32353, 32359, 32363, 32369, 32371, 32377, 32381, 32401,
- 32411, 32413, 32423, 32429, 32441, 32443, 32467, 32479, 32491, 32497,
- 32503, 32507, 32531, 32533, 32537, 32561, 32563, 32569, 32573, 32579,
- 32587, 32603, 32609, 32611, 32621, 32633, 32647, 32653, 32687, 32693,
- 32707, 32713, 32717, 32719, 32749, 32771, 32779, 32783, 32789, 32797,
- 32801, 32803, 32831, 32833, 32839, 32843, 32869, 32887, 32909, 32911,
- 32917, 32933, 32939, 32941, 32957, 32969, 32971, 32983, 32987, 32993,
- 32999, 33013, 33023, 33029, 33037, 33049, 33053, 33071, 33073, 33083,
- 33091, 33107, 33113, 33119, 33149, 33151, 33161, 33179, 33181, 33191,
- 33199, 33203, 33211, 33223, 33247, 33287, 33289, 33301, 33311, 33317,
- 33329, 33331, 33343, 33347, 33349, 33353, 33359, 33377, 33391, 33403,
- 33409, 33413, 33427, 33457, 33461, 33469, 33479, 33487, 33493, 33503,
- 33521, 33529, 33533, 33547, 33563, 33569, 33577, 33581, 33587, 33589,
- 33599, 33601, 33613, 33617, 33619, 33623, 33629, 33637, 33641, 33647,
- 33679, 33703, 33713, 33721, 33739, 33749, 33751, 33757, 33767, 33769,
- 33773, 33791, 33797, 33809, 33811, 33827, 33829, 33851, 33857, 33863,
- 33871, 33889, 33893, 33911, 33923, 33931, 33937, 33941, 33961, 33967,
- 33997, 34019, 34031, 34033, 34039, 34057, 34061, 34123, 34127, 34129,
- 34141, 34147, 34157, 34159, 34171, 34183, 34211, 34213, 34217, 34231,
- 34253, 34259, 34261, 34267, 34273, 34283, 34297, 34301, 34303, 34313,
- 34319, 34327, 34337, 34351, 34361, 34367, 34369, 34381, 34403, 34421,
- 34429, 34439, 34457, 34469, 34471, 34483, 34487, 34499, 34501, 34511,
- 34513, 34519, 34537, 34543, 34549, 34583, 34589, 34591, 34603, 34607,
- 34613, 34631, 34649, 34651, 34667, 34673, 34679, 34687, 34693, 34703,
- 34721, 34729, 34739, 34747, 34757, 34759, 34763, 34781, 34807, 34819,
- 34841, 34843, 34847, 34849, 34871, 34877, 34883, 34897, 34913, 34919,
- 34939, 34949, 34961, 34963, 34981, 35023, 35027, 35051, 35053, 35059,
- 35069, 35081, 35083, 35089, 35099, 35107, 35111, 35117, 35129, 35141,
- 35149, 35153, 35159, 35171, 35201, 35221, 35227, 35251, 35257, 35267,
- 35279, 35281, 35291, 35311, 35317, 35323, 35327, 35339, 35353, 35363,
- 35381, 35393, 35401, 35407, 35419, 35423, 35437, 35447, 35449, 35461,
- 35491, 35507, 35509, 35521, 35527, 35531, 35533, 35537, 35543, 35569,
- 35573, 35591, 35593, 35597, 35603, 35617, 35671, 35677, 35729, 35731,
- 35747, 35753, 35759, 35771, 35797, 35801, 35803, 35809, 35831, 35837,
- 35839, 35851, 35863, 35869, 35879, 35897, 35899, 35911, 35923, 35933,
- 35951, 35963, 35969, 35977, 35983, 35993, 35999, 36007, 36011, 36013,
- 36017, 36037, 36061, 36067, 36073, 36083, 36097, 36107, 36109, 36131,
- 36137, 36151, 36161, 36187, 36191, 36209, 36217, 36229, 36241, 36251,
- 36263, 36269, 36277, 36293, 36299, 36307, 36313, 36319, 36341, 36343,
- 36353, 36373, 36383, 36389, 36433, 36451, 36457, 36467, 36469, 36473,
- 36479, 36493, 36497, 36523, 36527, 36529, 36541, 36551, 36559, 36563,
- 36571, 36583, 36587, 36599, 36607, 36629, 36637, 36643, 36653, 36671,
- 36677, 36683, 36691, 36697, 36709, 36713, 36721, 36739, 36749, 36761,
- 36767, 36779, 36781, 36787, 36791, 36793, 36809, 36821, 36833, 36847,
- 36857, 36871, 36877, 36887, 36899, 36901, 36913, 36919, 36923, 36929,
- 36931, 36943, 36947, 36973, 36979, 36997, 37003, 37013, 37019, 37021,
- 37039, 37049, 37057, 37061, 37087, 37097, 37117, 37123, 37139, 37159,
- 37171, 37181, 37189, 37199, 37201, 37217, 37223, 37243, 37253, 37273,
- 37277, 37307, 37309, 37313, 37321, 37337, 37339, 37357, 37361, 37363,
- 37369, 37379, 37397, 37409, 37423, 37441, 37447, 37463, 37483, 37489,
- 37493, 37501, 37507, 37511, 37517, 37529, 37537, 37547, 37549, 37561,
- 37567, 37571, 37573, 37579, 37589, 37591, 37607, 37619, 37633, 37643,
- 37649, 37657, 37663, 37691, 37693, 37699, 37717, 37747, 37781, 37783,
- 37799, 37811, 37813, 37831, 37847, 37853, 37861, 37871, 37879, 37889,
- 37897, 37907, 37951, 37957, 37963, 37967, 37987, 37991, 37993, 37997,
- 38011, 38039, 38047, 38053, 38069, 38083, 38113, 38119, 38149, 38153,
- 38167, 38177, 38183, 38189, 38197, 38201, 38219, 38231, 38237, 38239,
- 38261, 38273, 38281, 38287, 38299, 38303, 38317, 38321, 38327, 38329,
- 38333, 38351, 38371, 38377, 38393, 38431, 38447, 38449, 38453, 38459,
- 38461, 38501, 38543, 38557, 38561, 38567, 38569, 38593, 38603, 38609,
- 38611, 38629, 38639, 38651, 38653, 38669, 38671, 38677, 38693, 38699,
- 38707, 38711, 38713, 38723, 38729, 38737, 38747, 38749, 38767, 38783,
- 38791, 38803, 38821, 38833, 38839, 38851, 38861, 38867, 38873]
-
-
-def _prime_from_seed(seed):
- ROUNDS = 7
-
- def _window(s, primes):
- w = [0] * 4096
- for i in primes:
- rem = s % i
- if rem != 0:
- rem = i - rem
- for j in range(rem, len(w), i):
- w[j] = 1
- return w
-
- # Set LSB, and top two bits.
- candidate = chr(ord(seed[0]) | 192) + seed[1:-1] + chr(ord(seed[-1]) | 1)
- candidate = int(binascii.b2a_hex(candidate), 16)
- assert len(bin(candidate)[2:]) == len(seed) * 8
- w = _window(candidate, _PRIMES[:4096])
- for i, bit in enumerate(w):
- if not bit:
- if rsa.prime.randomized_primality_testing(candidate + i, ROUNDS):
- return candidate + i
- return None
-
-
-#
-# TEST VECTORS.
-#
-_ENCRYPT_INPUTS = (
- ('OAEP', 'SHA1', 768),
- ('OAEP', 'SHA256', 768),
- ('OAEP', 'SHA256', 1024),
- ('PKCS1-ES', 'NONE', 768),
- ('PKCS1-ES', 'NONE', 2048),
- ('NULL', 'NONE', 768),
-)
-
-
-_SIGN_INPUTS = (
- ('PKCS1-SSA', 'SHA1', 768),
- ('PKCS1-SSA', 'SHA256', 768),
- ('PKCS1-SSA', 'SHA256', 1024),
- ('PKCS1-SSA', 'SHA384', 2048),
- ('PKCS1-SSA', 'SHA512', 2048),
- ('PKCS1-PSS', 'SHA1', 768),
- ('PKCS1-PSS', 'SHA256', 768),
- ('PKCS1-PSS', 'SHA256', 2048),
-)
-
-_VERIFY_INPUTS = (
- ('PKCS1-SSA', 'SHA1', 768),
- ('PKCS1-SSA', 'SHA256', 768),
- ('PKCS1-SSA', 'SHA256', 1024),
- ('PKCS1-SSA', 'SHA384', 2048),
- ('PKCS1-SSA', 'SHA512', 4096),
- ('PKCS1-PSS', 'SHA1', 768),
- ('PKCS1-PSS', 'SHA256', 768),
- ('PKCS1-PSS', 'SHA256', 2048),
- ('PKCS1-PSS', 'SHA256', 4096),
-)
-
-_KEYTEST_INPUTS = (
- (768,),
- (1024,),
- (2048,),
-)
-
-_KEYGEN_INPUTS = (
- (768, 65537, '', None),
- (1024, 65537, 'rsa_test', None),
- (2048, 65537, 'RSA key by vendor', 20811475686431332186511278472307159547870512766846593830860105577496044159545322178313772755518365593670114793803805067608811418757734989708137784444223785391864604211835387393923163468734914392307047296990698533218399115126417934050463597455237478939601236799120239663591264311485133747167378663829046579164891864068853210530642835833947569643788911200934265596274935082689832626616967124524353322373059893974744194447740045242468136414689225322177212281193879756355471091445748150740871146034049776312457888356154834233819876846764944450478069436248506560967902863015152471662817623176815923756421011384149834497587L),
- (2048, 65537, '', None),
-)
-
-# 2048-bit will be done in hardware (i.e. fast), rest are in software.
-# Sizes below correspond to RSA key size.
-_PRIMEGEN_INPUTS = (
- 768,
- 1024,
- 2048,
- 2048,
- 2048,
- 2048,
- 2048
-)
-
-def _encrypt_tests(tpm):
- msg = 'Hello CR50!'
-
- for data in _ENCRYPT_INPUTS:
- padding, hashing, key_len = data
- test_name = 'RSA-ENC:%s:%s:%d' % data
- cmd = _encrypt_cmd(_RSA_PADDING[padding], _HASH[hashing], key_len, msg)
- wrapped_response = tpm.command(tpm.wrap_ext_command(subcmd.RSA, cmd))
- ciphertext = tpm.unwrap_ext_response(subcmd.RSA, wrapped_response)
-
- cmd = _decrypt_cmd(_RSA_PADDING[padding], _HASH[hashing],
- key_len, ciphertext)
- wrapped_response = tpm.command(tpm.wrap_ext_command(subcmd.RSA, cmd))
- plaintext = tpm.unwrap_ext_response(subcmd.RSA, wrapped_response)
- if padding == 'NULL':
- # Check for leading zeros.
- if reduce(lambda x, y: x | y,
- map(ord, plaintext[:len(plaintext) - len(msg)])):
- raise subcmd.TpmTestError('%s error:%s%s' % (
- test_name, utils.hex_dump(msg), utils.hex_dump(plaintext)))
- else:
- plaintext = plaintext[len(plaintext) - len(msg):]
- if msg != plaintext:
- raise subcmd.TpmTestError('%s error:%s%s' % (
- test_name, utils.hex_dump(msg), utils.hex_dump(plaintext)))
- print('%sSUCCESS: %s' % (utils.cursor_back(), test_name))
-
-
-def _sign_tests(tpm):
- for data in _SIGN_INPUTS:
- msg = rsa.randnum.read_random_bits(256)
- padding, hashing, key_len = data
- test_name = 'RSA-SIGN:%s:%s:%d' % data
-
- key = _KEYS[key_len]
- verifier = _SIGNER[padding].new(key)
- h = _HASHER[hashing].new()
- h.update(msg)
-
- cmd = _sign_cmd(_RSA_PADDING[padding], _HASH[hashing], key_len, h.digest())
- wrapped_response = tpm.command(tpm.wrap_ext_command(subcmd.RSA, cmd))
- signature = tpm.unwrap_ext_response(subcmd.RSA, wrapped_response)
-
- signer = _SIGNER[padding].new(key)
- expected_signature = signer.sign(h)
-
- if not verifier.verify(h, signature):
- raise subcmd.TpmTestError('%s error' % (
- test_name,))
- print('%sSUCCESS: %s' % (utils.cursor_back(), test_name))
-
-
-def _verify_tests(tpm):
- for data in _VERIFY_INPUTS:
- msg = rsa.randnum.read_random_bits(256)
- padding, hashing, key_len = data
- test_name = 'RSA-VERIFY:%s:%s:%d' % data
-
- key = _KEYS[key_len]
- signer = _SIGNER[padding].new(key)
- h = _HASHER[hashing].new()
- h.update(msg)
- signature = signer.sign(h)
-
- cmd = _verify_cmd(_RSA_PADDING[padding], _HASH[hashing],
- key_len, signature, h.digest())
- wrapped_response = tpm.command(tpm.wrap_ext_command(subcmd.RSA, cmd))
- verified = tpm.unwrap_ext_response(subcmd.RSA, wrapped_response)
- expected = '\x01'
- if verified != expected:
- raise subcmd.TpmTestError('%s error:%s%s' % (
- test_name, utils.hex_dump(verified), utils.hex_dump(expected)))
- print('%sSUCCESS: %s' % (utils.cursor_back(), test_name))
-
-
-def _keytest_tests(tpm):
- for data in _KEYTEST_INPUTS:
- key_len, = data
- test_name = 'RSA-KEYTEST:%d' % data
- cmd = _keytest_cmd(key_len)
- wrapped_response = tpm.command(tpm.wrap_ext_command(subcmd.RSA, cmd))
- valid = tpm.unwrap_ext_response(subcmd.RSA, wrapped_response)
- expected = '\x01'
- if valid != expected:
- raise subcmd.TpmTestError('%s error:%s%s' % (
- test_name, utils.hex_dump(valid), utils.hex_dump(expected)))
- print('%sSUCCESS: %s' % (utils.cursor_back(), test_name))
-
-
-def _keygen_tests(tpm):
- for data in _KEYGEN_INPUTS:
- key_len, e, label, expected_N = data
- test_name = 'RSA-KEYGEN:%d:%d:%s' % data[:-1]
- cmd = _keygen_cmd(key_len, e, label)
-
- wrapped_response = tpm.command(tpm.wrap_ext_command(subcmd.RSA, cmd))
- result = tpm.unwrap_ext_response(subcmd.RSA, wrapped_response)
- result_len = len(result)
- if result_len != int(key_len / 8 * 1.5):
- raise subcmd.TpmTestError('%s error:%s' % (
- test_name, utils.hex_dump(result)))
-
- N = int(binascii.b2a_hex(result[0:result_len * 2 / 3]), 16)
- if expected_N and N != expected_N:
- raise subcmd.TpmTestError('%s error:%s' % (
- test_name, utils.hex_dump(result)))
- p = int(binascii.b2a_hex(result[result_len * 2 / 3:]), 16)
- q = N / p
- if not rsa.prime.is_prime(p):
- raise subcmd.TpmTestError('%s error:%s' % (
- test_name, utils.hex_dump(result)))
- if not rsa.prime.is_prime(q):
- raise subcmd.TpmTestError('%s error:%s' % (
- test_name, utils.hex_dump(result)))
- if p == q:
- raise subcmd.TpmTestError('%s error:%s' % (
- test_name, utils.hex_dump(result)))
- print('%sSUCCESS: %s' % (utils.cursor_back(), test_name))
-
-
-def _primegen_tests(tpm):
- for data in _PRIMEGEN_INPUTS:
- key_len = data
- test_name = 'RSA-PRIMEGEN:%d' % data
- seed = rsa.randnum.read_random_bits(key_len / 2)
- assert len(seed) == key_len / 16
- # dcrypto interface is little-endian.
- cmd = _primegen_cmd(seed[::-1])
-
- wrapped_response = tpm.command(tpm.wrap_ext_command(subcmd.RSA, cmd))
- result = tpm.unwrap_ext_response(subcmd.RSA, wrapped_response)
- result_len = len(result)
- if result_len != key_len / 16:
- raise subcmd.TpmTestError('%s error:%s' % (
- test_name, utils.hex_dump(result)))
-
- p = int(binascii.b2a_hex(result[::-1]), 16)
- if not rsa.prime.is_prime(p):
- raise subcmd.TpmTestError('%s error:%s' % (
- test_name, utils.hex_dump(result)))
- calculated = _prime_from_seed(seed)
- if p != calculated:
- raise subcmd.TpmTestError('%s error:%s' % (
- test_name, utils.hex_dump(result)))
- print('%sSUCCESS: %s' % (utils.cursor_back(), test_name))
-
-
-def _x509_verify_tests(tpm):
- test_name = 'RSA-X509-2048-VERIFY'
- cmd = _x509_verify_cmd(2048)
- wrapped_response = tpm.command(tpm.wrap_ext_command(subcmd.RSA, cmd))
- valid = tpm.unwrap_ext_response(subcmd.RSA, wrapped_response)
- expected = '\x01'
- if valid != expected:
- raise subcmd.TpmTestError('%s error:%s%s' % (
- test_name, utils.hex_dump(valid), utils.hex_dump(expected)))
- print('%sSUCCESS: %s' % (utils.cursor_back(), test_name))
-
-
-def rsa_test(tpm):
- _encrypt_tests(tpm)
- _sign_tests(tpm)
- _verify_tests(tpm)
- _keytest_tests(tpm)
- _keygen_tests(tpm)
- _primegen_tests(tpm)
- _x509_verify_tests(tpm)
diff --git a/test/tpm_test/subcmd.py b/test/tpm_test/subcmd.py
deleted file mode 100644
index 7260df0dd5..0000000000
--- a/test/tpm_test/subcmd.py
+++ /dev/null
@@ -1,19 +0,0 @@
-#!/usr/bin/env python2
-# Copyright 2015 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.
-
-"""Subcommand codes that specify the crypto module."""
-
-# Keep these codes in sync with include/tpm_vendor_cmds.h
-AES = 0
-HASH = 1
-RSA = 2
-ECC = 3
-FW_UPGRADE = 4
-HKDF = 5
-ECIES = 6
-DRBG_TEST = 50
-# The same exception class used by all tpmtest modules.
-class TpmTestError(Exception):
- pass
diff --git a/test/tpm_test/support.c b/test/tpm_test/support.c
deleted file mode 100644
index fbb4d0b6ab..0000000000
--- a/test/tpm_test/support.c
+++ /dev/null
@@ -1,218 +0,0 @@
-/* Copyright 2015 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.
- *
- * Based on Craig Heffner's version of Dec 27 2011, published on
- * https://github.com/devttys0/libmpsse
- *
- * Internal functions used by libmpsse.
- */
-
-#include <string.h>
-#include <stdlib.h>
-
-#if LIBFTDI1 == 1
-#include <libftdi1/ftdi.h>
-#else
-#include <ftdi.h>
-#endif
-
-#include "support.h"
-
-/* Write data to the FTDI chip */
-int raw_write(struct mpsse_context *mpsse, unsigned char *buf, int size)
-{
- int retval = MPSSE_FAIL;
-
- if (mpsse->mode && (ftdi_write_data(&mpsse->ftdi, buf, size) == size))
- retval = MPSSE_OK;
-
- return retval;
-}
-
-/* Read data from the FTDI chip */
-int raw_read(struct mpsse_context *mpsse, unsigned char *buf, int size)
-{
- int n = 0, r = 0;
-
- if (!mpsse->mode)
- return 0;
-
- while (n < size) {
- r = ftdi_read_data(&mpsse->ftdi, buf, size);
- if (r < 0)
- break;
- n += r;
- }
-
- if (mpsse->flush_after_read) {
- /*
- * Make sure the buffers are cleared after a read or
- * subsequent reads may fail. Is this needed anymore?
- * It slows down repetitive read operations by ~8%.
- */
- ftdi_usb_purge_rx_buffer(&mpsse->ftdi);
- }
-
- return n;
-}
-
-/* Sets the read and write timeout periods for bulk usb data transfers. */
-void set_timeouts(struct mpsse_context *mpsse, int timeout)
-{
- if (mpsse->mode) {
- mpsse->ftdi.usb_read_timeout = timeout;
- mpsse->ftdi.usb_write_timeout = timeout;
- }
-}
-
-/* Convert a frequency to a clock divisor */
-uint16_t freq2div(uint32_t system_clock, uint32_t freq)
-{
- return (((system_clock / freq) / 2) - 1);
-}
-
-/* Convert a clock divisor to a frequency */
-uint32_t div2freq(uint32_t system_clock, uint16_t div)
-{
- return (system_clock / ((1 + div) * 2));
-}
-
-/* Builds a buffer of commands + data blocks */
-unsigned char *build_block_buffer(struct mpsse_context *mpsse,
- uint8_t cmd,
- unsigned char *data, int size, int *buf_size)
-{
- unsigned char *buf = NULL;
- int i = 0, j = 0, k = 0, dsize = 0, num_blocks = 0, total_size =
- 0, xfer_size = 0;
- uint16_t rsize = 0;
-
- *buf_size = 0;
-
- /* Data block size is 1 in I2C, or when in bitmode */
- if (mpsse->mode == I2C || (cmd & MPSSE_BITMODE))
- xfer_size = 1;
- else
- xfer_size = mpsse->xsize;
-
- num_blocks = (size / xfer_size);
- if (size % xfer_size)
- num_blocks++;
-
- /*
- * The total size of the data will be the data size + the write
- * command
- */
- total_size = size + (CMD_SIZE * num_blocks);
-
- buf = malloc(total_size);
- if (!buf)
- return NULL;
-
- memset(buf, 0, total_size);
-
- for (j = 0; j < num_blocks; j++) {
- dsize = size - k;
- if (dsize > xfer_size)
- dsize = xfer_size;
-
- /* The reported size of this block is block size - 1 */
- rsize = dsize - 1;
-
- /* Copy in the command for this block */
- buf[i++] = cmd;
- buf[i++] = (rsize & 0xFF);
- if (!(cmd & MPSSE_BITMODE))
- buf[i++] = ((rsize >> 8) & 0xFF);
-
- /* On a write, copy the data to transmit after the command */
- if (cmd == mpsse->tx || cmd == mpsse->txrx) {
-
- memcpy(buf + i, data + k, dsize);
-
- /* i == offset into buf */
- i += dsize;
- /* k == offset into data */
- k += dsize;
- }
- }
-
- *buf_size = i;
-
- return buf;
-}
-
-/* Set the low bit pins high/low */
-int set_bits_low(struct mpsse_context *mpsse, int port)
-{
- char buf[CMD_SIZE] = { 0 };
-
- buf[0] = SET_BITS_LOW;
- buf[1] = port;
- buf[2] = mpsse->tris;
-
- return raw_write(mpsse, (unsigned char *)&buf, sizeof(buf));
-}
-
-/* Set the high bit pins high/low */
-int set_bits_high(struct mpsse_context *mpsse, int port)
-{
- char buf[CMD_SIZE] = { 0 };
-
- buf[0] = SET_BITS_HIGH;
- buf[1] = port;
- buf[2] = mpsse->trish;
-
- return raw_write(mpsse, (unsigned char *)&buf, sizeof(buf));
-}
-
-/* Set the GPIO pins high/low */
-int gpio_write(struct mpsse_context *mpsse, int pin, int direction)
-{
- int retval = MPSSE_FAIL;
-
- /*
- * The first four pins can't be changed unless we are in a stopped
- * status
- */
- if (pin < NUM_GPIOL_PINS && mpsse->status == STOPPED) {
- /* Convert pin number (0-3) to the corresponding pin bit */
- pin = (GPIO0 << pin);
-
- if (direction == HIGH) {
- mpsse->pstart |= pin;
- mpsse->pidle |= pin;
- mpsse->pstop |= pin;
- } else {
- mpsse->pstart &= ~pin;
- mpsse->pidle &= ~pin;
- mpsse->pstop &= ~pin;
- }
-
- retval = set_bits_low(mpsse, mpsse->pstop);
- } else if (pin >= NUM_GPIOL_PINS && pin < NUM_GPIO_PINS) {
- /* Convert pin number (4 - 11) to the corresponding pin bit */
- pin -= NUM_GPIOL_PINS;
-
- if (direction == HIGH)
- mpsse->gpioh |= (1 << pin);
- else
- mpsse->gpioh &= ~(1 << pin);
-
- retval = set_bits_high(mpsse, mpsse->gpioh);
- }
-
- return retval;
-}
-
-/* Checks if a given MPSSE context is valid. */
-int is_valid_context(struct mpsse_context *mpsse)
-{
- int retval = 0;
-
- if (mpsse != NULL && mpsse->open)
- retval = 1;
-
- return retval;
-}
diff --git a/test/tpm_test/support.h b/test/tpm_test/support.h
deleted file mode 100644
index 77316582cc..0000000000
--- a/test/tpm_test/support.h
+++ /dev/null
@@ -1,87 +0,0 @@
-/* Copyright 2015 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.
- *
- * Based on Craig Heffner's version of Dec 27 2011, published on
- * https://github.com/devttys0/libmpsse
- */
-
-#ifndef __EC_TEST_TPM_TEST_SUPPORT_H
-#define __EC_TEST_TPM_TEST_SUPPORT_H
-
-#include "mpsse.h"
-
-#define CMD_SIZE 3
-#define NUM_GPIOL_PINS 4
-#define NUM_GPIO_PINS 12
-#define LOW 0
-#define HIGH 1
-
-/* Supported MPSSE modes */
-enum modes {
- SPI0 = 1,
- SPI1 = 2,
- SPI2 = 3,
- SPI3 = 4,
- I2C = 5,
- GPIO = 6,
- BITBANG = 7,
-};
-
-enum low_bits_status {
- STARTED,
- STOPPED
-};
-
-enum pins {
- SK = 1,
- DO = 2,
- DI = 4,
- CS = 8,
- GPIO0 = 16,
- GPIO1 = 32,
- GPIO2 = 64,
- GPIO3 = 128
-};
-
-struct mpsse_context {
- char *description;
- struct ftdi_context ftdi;
- enum modes mode;
- enum low_bits_status status;
- int flush_after_read;
- int vid;
- int pid;
- int clock;
- int xsize;
- int open;
- int ftdi_initialized;
- int endianness;
- uint8_t tris;
- uint8_t pstart;
- uint8_t pstop;
- uint8_t pidle;
- uint8_t gpioh;
- uint8_t trish;
- uint8_t bitbang;
- uint8_t tx;
- uint8_t rx;
- uint8_t txrx;
- uint8_t tack;
- uint8_t rack;
-};
-
-int raw_write(struct mpsse_context *mpsse, unsigned char *buf, int size);
-int raw_read(struct mpsse_context *mpsse, unsigned char *buf, int size);
-void set_timeouts(struct mpsse_context *mpsse, int timeout);
-uint16_t freq2div(uint32_t system_clock, uint32_t freq);
-uint32_t div2freq(uint32_t system_clock, uint16_t div);
-unsigned char *build_block_buffer(struct mpsse_context *mpsse,
- uint8_t cmd,
- unsigned char *data, int size, int *buf_size);
-int set_bits_high(struct mpsse_context *mpsse, int port);
-int set_bits_low(struct mpsse_context *mpsse, int port);
-int gpio_write(struct mpsse_context *mpsse, int pin, int direction);
-int is_valid_context(struct mpsse_context *mpsse);
-
-#endif /* ! __EC_TEST_TPM_TEST_SUPPORT_H */
diff --git a/test/tpm_test/testlib/common.c b/test/tpm_test/testlib/common.c
deleted file mode 100644
index 35b07196aa..0000000000
--- a/test/tpm_test/testlib/common.c
+++ /dev/null
@@ -1,17 +0,0 @@
-/* Copyright 2016 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 "common.h"
-
-#include <assert.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <openssl/rand.h>
-
-void rand_bytes(void *buf, size_t num)
-{
- assert(RAND_bytes(buf, num) == 1);
-}
diff --git a/test/tpm_test/testlib/common.h b/test/tpm_test/testlib/common.h
deleted file mode 100644
index 9fdd7ebcae..0000000000
--- a/test/tpm_test/testlib/common.h
+++ /dev/null
@@ -1,18 +0,0 @@
-/* Copyright 2016 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.
- */
-
-#ifndef __EC_TEST_TPM_TEST_TESTLIB_COMMON_H
-#define __EC_TEST_TPM_TEST_TESTLIB_COMMON_H
-
-#include "dcrypto.h"
-
-#include <inttypes.h>
-#include <stdlib.h>
-#include <sys/param.h>
-
-void rand_bytes(void *buf, size_t num);
-
-#endif /* ! __EC_TEST_TPM_TEST_TESTLIB_COMMON_H */
-
diff --git a/test/tpm_test/testlib/trng.h b/test/tpm_test/testlib/trng.h
deleted file mode 100644
index 07c82f3333..0000000000
--- a/test/tpm_test/testlib/trng.h
+++ /dev/null
@@ -1,6 +0,0 @@
-/* Copyright 2016 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.
- */
-
-/* Dummy empty file, just to make test compilation work. */
diff --git a/test/tpm_test/testlib/util.h b/test/tpm_test/testlib/util.h
deleted file mode 100644
index 07c82f3333..0000000000
--- a/test/tpm_test/testlib/util.h
+++ /dev/null
@@ -1,6 +0,0 @@
-/* Copyright 2016 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.
- */
-
-/* Dummy empty file, just to make test compilation work. */
diff --git a/test/tpm_test/tpmtest.py b/test/tpm_test/tpmtest.py
deleted file mode 100755
index 11218cbcc6..0000000000
--- a/test/tpm_test/tpmtest.py
+++ /dev/null
@@ -1,179 +0,0 @@
-#!/usr/bin/env python2
-# Copyright 2015 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.
-
-"""Module for initializing and driving a SPI TPM."""
-
-from __future__ import print_function
-
-import getopt
-import os
-import struct
-import sys
-import traceback
-
-# Suppressing pylint warning about an import not at the top of the file. The
-# path needs to be set *before* the last import.
-# pylint: disable=C6204
-root_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
-sys.path.append(os.path.join(root_dir, '..', '..', 'build', 'tpm_test'))
-
-import crypto_test
-import drbg_test
-import ecc_test
-import ecies_test
-import ftdi_spi_tpm
-import hash_test
-import hkdf_test
-import rsa_test
-import subcmd
-import trng_test
-import upgrade_test
-
-# Extension command for dcypto testing
-EXT_CMD = 0xbaccd00a
-
-
-class TPM(object):
- """TPM accessor class.
-
- Object of this class allows to send valid and extended TPM commands (using
- the command() method. The wrap_command/unwrap_response methods provide a
- means of encapsulating extended commands in proper TPM data packets, as well
- as extracting extended command responses.
-
- Attributes:
- _handle: a ftdi_spi_tpm object, a USB/FTDI/SPI driver which allows
- communicate with a TPM connected over USB dongle.
- """
-
- HEADER_FMT = '>H2IH'
- STARTUP_CMD = '80 01 00 00 00 0c 00 00 01 44 00 00'
- STARTUP_RSP = ('80 01 00 00 00 0a 00 00 00 00',
- '80 01 00 00 00 0a 00 00 01 00')
-
- def __init__(self, freq=800*1000, debug_mode=False):
- self._debug_enabled = debug_mode
- self._handle = ftdi_spi_tpm
- if not self._handle.FtdiSpiInit(freq, debug_mode):
- raise subcmd.TpmTestError('Failed to connect')
-
- def validate(self, data_blob, response_mode=False):
- """Check if a data blob complies with TPM command/response header format."""
- (tag, size, cmd_code, _) = struct.unpack_from(
- self.HEADER_FMT, data_blob + ' ')
- prefix = 'Misformatted blob: '
- if tag not in (0x8001, 0x8002):
- raise subcmd.TpmTestError(prefix + 'bad tag value 0x%4.4x' % tag)
- if size != len(data_blob):
- raise subcmd.TpmTestError(prefix + 'size mismatch: header %d, actual %d'
- % (size, len(data_blob)))
- if size > 4096:
- raise subcmd.TpmTestError(prefix + 'invalid size %d' % size)
- if response_mode:
- # Startup response code, extension or vendor command response code
- if cmd_code == 0x100 or cmd_code == 0 or cmd_code == 0x500:
- return
- else:
- raise subcmd.TpmTestError(
- prefix + 'invalid response code 0x%x' % cmd_code)
- if cmd_code >= 0x11f and cmd_code <= 0x18f:
- return # This is a valid command
- if cmd_code == EXT_CMD:
- return # This is an extension command
- if cmd_code >= 0x20000000 and cmd_code <= 0x200001ff:
- return # this is vendor command
- raise subcmd.TpmTestError(prefix + 'invalid command code 0x%x' % cmd_code)
-
- def command(self, cmd_data):
- # Verify command header
- self.validate(cmd_data)
- response = self._handle.FtdiSendCommandAndWait(cmd_data)
- self.validate(response, response_mode=True)
- return response
-
- def wrap_ext_command(self, subcmd_code, cmd_body):
- return struct.pack(self.HEADER_FMT, 0x8001,
- len(cmd_body) + struct.calcsize(self.HEADER_FMT),
- EXT_CMD, subcmd_code) + cmd_body
-
- def unwrap_ext_response(self, expected_subcmd, response):
- """Verify basic validity and strip off TPM extended command header.
-
- Get the response generated by the device, as it came off the wire, verify
- that header fields match expectations, then strip off the extension
- command header and return the payload to the caller.
-
- Args:
- expected_subcmd: an int, up to 16 bits in size, the extension command
- this response is supposed to be for.
- response: a binary string, the actual response received over the wire.
- Returns:
- the binary string of the response payload, if validation succeeded.
- Raises:
- subcmd.TpmTestError: in case there are any validation problems, the
- error message describes the problem.
- """
- header_size = struct.calcsize(self.HEADER_FMT)
- tag, size, cmd, sub = struct.unpack(self.HEADER_FMT,
- response[:header_size])
- if tag != 0x8001:
- raise subcmd.TpmTestError('Wrong response tag: %4.4x' % tag)
- if cmd:
- raise subcmd.TpmTestError('Unexpected response command field: %8.8x' %
- cmd)
- if sub != expected_subcmd:
- raise subcmd.TpmTestError('Unexpected response subcommand field: %2.2x' %
- sub)
- if size != len(response):
- raise subcmd.TpmTestError('Size mismatch: header %d, actual %d' % (
- size, len(response)))
- return response[header_size:]
-
- def debug_enabled(self):
- return self._debug_enabled
-
-def usage():
- print ('Syntax: tpmtest.py [-d | -t | -h ]\n'
- ' -d - prints additional debug information during tests\n'
- ' -t - dump raw output from TRNG to /tmp/trng_output\n'
- ' -h - this help\n')
- return
-
-if __name__ == '__main__':
- try:
- opts, args = getopt.getopt(sys.argv[1:], 'dth','help')
- except getopt.GetoptError as err:
- print(str(err))
- usage()
- sys.exit(2)
- debug_needed = False
- trng_only = False
- for o, a in opts:
- if o == '-d':
- debug_needed = True
- elif o == '-t':
- trng_only = True
- elif o == '-h' or o == '--help':
- usage()
- sys.exit(0)
- try:
- t = TPM(debug_mode=debug_needed)
- if trng_only:
- trng_test.trng_test(t)
- sys.exit(1)
- crypto_test.crypto_tests(t, os.path.join(root_dir, 'crypto_test.xml'))
- drbg_test.drbg_test(t)
- ecc_test.ecc_test(t)
- ecies_test.ecies_test(t)
- hash_test.hash_test(t)
- hkdf_test.hkdf_test(t)
- rsa_test.rsa_test(t)
- upgrade_test.upgrade(t)
- except subcmd.TpmTestError as e:
- exc_file, exc_line = traceback.extract_tb(sys.exc_traceback)[-1][:2]
- print('\nError in %s:%s: ' % (os.path.basename(exc_file), exc_line), e)
- if debug_needed:
- traceback.print_exc()
- sys.exit(1)
diff --git a/test/tpm_test/trng_test.py b/test/tpm_test/trng_test.py
deleted file mode 100644
index aac2803076..0000000000
--- a/test/tpm_test/trng_test.py
+++ /dev/null
@@ -1,50 +0,0 @@
-#!/usr/bin/env python2
-# Copyright 2019 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.
-"""Tests for trng."""
-from __future__ import print_function
-import struct
-
-import subcmd
-import utils
-
-TRNG_TEST_FMT = '>H'
-TRNG_TEST_RSP_FMT = '>H2IH'
-TRNG_TEST_CC = 0x33
-TRNG_SAMPLE_SIZE = 1000 # minimal recommended by NIST is 1000 bytes per sample
-TRNG_SAMPLE_COUNT = 1000 # NIST require at least 1000000 of 8-bit samples
-
-def get_random_command(size):
- return struct.pack(TRNG_TEST_FMT, size)
-
-def get_random_command_rsp(size):
- return struct.pack(TRNG_TEST_RSP_FMT, 0x8001,
- struct.calcsize(TRNG_TEST_RSP_FMT) + size, 0, TRNG_TEST_CC)
-
-
-def trng_test(tpm):
- """Download entropy samples from TRNG
-
- Command structure, shared out of band with the test running on the target:
-
- field | size | note
- ===================================================================
- text_len | 2 | size of the text to process, big endian
-
- Args:
- tpm: a tpm object used to communicate with the device
-
- Raises:
- subcmd.TpmTestError: on unexpected target responses
- """
- with open('/tmp/trng_output', 'wb') as f:
- for x in range(0, TRNG_SAMPLE_COUNT):
- wrapped_response = tpm.command(tpm.wrap_ext_command(TRNG_TEST_CC,
- get_random_command(TRNG_SAMPLE_SIZE)))
- if wrapped_response[:12] != get_random_command_rsp(TRNG_SAMPLE_SIZE):
- raise subcmd.TpmTestError("Unexpected response to '%s': %s" %
- ("trng", utils.hex_dump(wrapped_response)))
- f.write(wrapped_response[12:])
- print('%s %d%%\r' %( utils.cursor_back(), (x/10)), end=""),
- print('%sSUCCESS: %s' % (utils.cursor_back(), 'trng'))
diff --git a/test/tpm_test/upgrade_test.py b/test/tpm_test/upgrade_test.py
deleted file mode 100644
index 35f8405ba7..0000000000
--- a/test/tpm_test/upgrade_test.py
+++ /dev/null
@@ -1,68 +0,0 @@
-#!/usr/bin/env python2
-# Copyright 2016 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.
-
-from __future__ import print_function
-
-import hashlib
-import os
-import struct
-
-import subcmd
-import utils
-
-
-def upgrade(tpm):
- """Exercise the upgrade command.
-
- The target expect the upgrade extension command to have the following
- structure:
-
- cmd 1 value of FW_UPGRADE
- digest 4 first 4 bytes of sha1 of the remainder of the message
- block_base 4 address of the block to write
- data var
-
- Args:
- tpm: a properly initialized tpmtest.TPM object
- Raises:
- subcmd.TpmTestError: In case of various test problems
- """
- cmd = struct.pack('>I', 0) # address
- cmd += struct.pack('>I', 0) # data (a noop)
- wrapped_response = tpm.command(tpm.wrap_ext_command(subcmd.FW_UPGRADE, cmd))
- base_str = tpm.unwrap_ext_response(subcmd.FW_UPGRADE, wrapped_response)
- if len(base_str) < 4:
- raise subcmd.TpmTestError('Initialization error %d' %
- ord(base_str[0]))
- base = struct.unpack_from('>4I', base_str)[3]
- if base == 0x44000:
- fname = 'build/cr50/RW/ec.RW_B.flat'
- elif base == 0x4000:
- fname = 'build/cr50/RW/ec.RW.flat'
- else:
- raise subcmd.TpmTestError('Unknown base address 0x%x' % base)
- fname = os.path.join(os.path.dirname(__file__), '../..', fname)
- data = open(fname, 'r').read()[:2000]
- transferred = 0
- block_size = 1024
-
- while transferred < len(data):
- tx_size = min(block_size, len(data) - transferred)
- chunk = data[transferred:transferred+tx_size]
- cmd = struct.pack('>I', base) # address
- h = hashlib.sha1()
- h.update(cmd)
- h.update(chunk)
- cmd = h.digest()[0:4] + cmd + chunk
- resp = tpm.unwrap_ext_response(subcmd.FW_UPGRADE,
- tpm.command(tpm.wrap_ext_command(
- subcmd.FW_UPGRADE, cmd)))
- code = ord(resp[0])
- if code:
- raise subcmd.TpmTestError('%x - resp %d' % (base, code))
- base += tx_size
- transferred += tx_size
-
- print('%sSUCCESS: Firmware upgrade' % (utils.cursor_back()))
diff --git a/test/tpm_test/utils.py b/test/tpm_test/utils.py
deleted file mode 100644
index 38cda2a1e2..0000000000
--- a/test/tpm_test/utils.py
+++ /dev/null
@@ -1,38 +0,0 @@
-#!/usr/bin/env python2
-# Copyright 2015 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.
-
-"""Support functions for extended command based testing."""
-
-import sys
-
-if hasattr(sys.stdout, 'isatty') and sys.stdout.isatty():
- cursor_back_cmd = '\x1b[1D' # Move one space to the left.
-else:
- cursor_back_cmd = ''
-
-
-def cursor_back():
- """Return a string which would move cursor one space left, if available.
-
- This is used to remove the remaining 'spinner' character after the test
- completes and its result is printed on the same line where the 'spinner' was
- spinning.
-
- """
- return cursor_back_cmd
-
-
-def hex_dump(binstr):
- """Convert binary string into its multiline hex representation."""
-
- dump_lines = ['',]
- i = 0
- while i < len(binstr):
- strsize = min(16, len(binstr) - i)
- hexstr = ' '.join('%2.2x' % ord(x) for x in binstr[i:i+strsize])
- dump_lines.append(hexstr)
- i += strsize
- dump_lines.append('')
- return '\n'.join(dump_lines)