Refactor crypto subcommands into their own python module.

BRANCH=none
TEST=tpmtest.py passes
BUG=chrome-os-partner:43025,chrome-os-partner:47524
Signed-off-by: nagendra modadugu <ngm@google.com>

Change-Id: I48f426176f17c57c723104d19c963b228f16d985
Reviewed-on: https://chromium-review.googlesource.com/318915
Commit-Ready: Nagendra Modadugu <ngm@google.com>
Tested-by: Nagendra Modadugu <ngm@google.com>
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
This commit is contained in:
nagendra modadugu
2015-12-17 10:32:11 -08:00
committed by chrome-bot
parent f72decc804
commit 6a29ca187a
3 changed files with 14 additions and 7 deletions

View File

@@ -10,11 +10,9 @@ from __future__ import print_function
import struct
import xml.etree.ElementTree as ET
import subcmd
import utils
# Extension 'cryptography' subcommand codes:
AES = 0
# Basic crypto operations
DECRYPT = 0
ENCRYPT = 1
@@ -99,7 +97,7 @@ class CryptoD(object):
self.submodes = submodes
SUPPORTED_MODES = {
'AES': CryptoD(AES, {
'AES': CryptoD(subcmd.AES, {
'ECB': 0,
'CTR': 1,
'CBC': 2,

View File

@@ -10,10 +10,9 @@ from __future__ import print_function
import hashlib
import struct
import subcmd
import utils
HASH = 1
# Hash command modes
CMD_START = 0
CMD_CONT = 1
@@ -92,7 +91,7 @@ def hash_test(tpm):
cmd += '%c' % handle # Ignored for single shots
cmd += struct.pack('>H', len(text))
cmd += text
wrapped_response = tpm.command(tpm.wrap_ext_command(HASH, cmd))
wrapped_response = tpm.command(tpm.wrap_ext_command(subcmd.HASH, cmd))
if hash_cmd in (CMD_START, CMD_CONT):
if hash_cmd == CMD_START:
contexts[handle] = hash_func()

10
test/tpm_test/subcmd.py Normal file
View File

@@ -0,0 +1,10 @@
#!/usr/bin/python
# 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/extension.h.
AES = 0
HASH = 1