From 1f81a6f936c0200d3d92286f3126ba672dba5781 Mon Sep 17 00:00:00 2001 From: Gaurav Shah Date: Sat, 6 Feb 2010 14:34:31 -0800 Subject: [PATCH] Refactor code from test/ to utils/ since they are not just used by tests. Also, adds a simple analog of verify_data. BUG=none TEST=none Review URL: http://codereview.chromium.org/578025 --- {tests => include}/signature_digest.h | 0 {tests => include}/verify_data.h | 0 tests/Makefile | 11 +++-------- tests/run_tests.sh | 10 +++++----- utils/Makefile | 12 ++++++++++-- utils/sign_data.sh | 13 +++++++++++++ {tests => utils}/signature_digest.c | 0 {tests => utils}/verify_data.c | 0 8 files changed, 31 insertions(+), 15 deletions(-) rename {tests => include}/signature_digest.h (100%) rename {tests => include}/verify_data.h (100%) create mode 100755 utils/sign_data.sh rename {tests => utils}/signature_digest.c (100%) rename {tests => utils}/verify_data.c (100%) diff --git a/tests/signature_digest.h b/include/signature_digest.h similarity index 100% rename from tests/signature_digest.h rename to include/signature_digest.h diff --git a/tests/verify_data.h b/include/verify_data.h similarity index 100% rename from tests/verify_data.h rename to include/verify_data.h diff --git a/tests/Makefile b/tests/Makefile index ba50eccbd9..ba4c4a64f2 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -2,19 +2,14 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -SRCS=sha_tests.c verify_data.c signature_digest.c +SRCS=sha_tests.c OBJS=$(SRCS:.c=.o) LIBS=$(TOP)/crypto/libcrypto.a $(TOP)/common/libcommon.a -tests: sha_tests verify_data signature_digest +tests: sha_tests -sha_tests: sha_tests.c +sha_tests: sha_tests.c $(CC) $(CFLAGS) -DNDEBUG $(INCLUDES) $< -o $@ $(LIBS) -verify_data: verify_data.c digest_utility.o - $(CC) $(CFLAGS) -DNDEBUG $(INCLUDES) $< -o $@ $(LIBS) - -signature_digest: signature_digest.c - $(CC) $(CFLAGS) -DNDEBUG $(INCLUDES) $< -o $@ $(LIBS) clean: rm -f $(OBJS) sha_tests verify_data signature_digest diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 7fe68fe098..e5ee196cc5 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -11,7 +11,7 @@ hash_algos=( sha1 sha256 sha512 ) key_lengths=( 1024 2048 4096 8192 ) TEST_FILE=test_file TEST_FILE_SIZE=1000000 -UTILDIR=../utils/ +UTIL_DIR=../utils/ # Generate RSA test keys of various lengths. function generate_keys { @@ -21,7 +21,7 @@ function generate_keys { # Generate self-signed certificate from key. openssl req -batch -new -x509 -key key_rsa$i.pem -out key_rsa$i.crt # Generate pre-processed key for use by RSA signature verification code. - ${UTILDIR}/dumpRSAPublicKey key_rsa$i.crt > key_rsa$i.keyb + ${UTIL_DIR}/dumpRSAPublicKey key_rsa$i.crt > key_rsa$i.keyb done } @@ -33,8 +33,8 @@ function generate_signatures { do for hashalgo in ${hash_algos[@]} do - ./signature_digest $algorithmcounter $1 | openssl rsautl -sign -pkcs \ - -inkey key_rsa${keylen}.pem > $1.rsa${keylen}\_${hashalgo}.sig + ${UTIL_DIR}/signature_digest $algorithmcounter $1 | openssl rsautl -sign \ + -pkcs -inkey key_rsa${keylen}.pem > $1.rsa${keylen}\_${hashalgo}.sig let algorithmcounter=algorithmcounter+1 done done @@ -47,7 +47,7 @@ function test_signatures { for hashalgo in ${hash_algos[@]} do echo "For RSA-$keylen and $hashalgo:" - ./verify_data $algorithmcounter key_rsa${keylen}.keyb \ + ${UTIL_DIR}/verify_data $algorithmcounter key_rsa${keylen}.keyb \ ${TEST_FILE}.rsa${keylen}\_${hashalgo}.sig ${TEST_FILE} let algorithmcounter=algorithmcounter+1 done diff --git a/utils/Makefile b/utils/Makefile index 85735832ce..d72aaf4721 100644 --- a/utils/Makefile +++ b/utils/Makefile @@ -3,10 +3,18 @@ # found in the LICENSE file. LIBS=-lcrypto +FIRMWARELIBS=$(TOP)/crypto/libcrypto.a $(TOP)/common/libcommon.a -all: dumpRSAPublicKey +all: dumpRSAPublicKey verify_data signature_digest dumpRSAPublicKey: dumpRSAPublicKey.c $(CC) $(CFLAGS) $(LIBS) $< -o $@ + +verify_data: verify_data.c + $(CC) $(CFLAGS) -DNDEBUG $(INCLUDES) $< -o $@ $(FIRMWARELIBS) + +signature_digest: signature_digest.c + $(CC) $(CFLAGS) -DNDEBUG $(INCLUDES) $< -o $@ $(FIRMWARELIBS) + clean: - rm -f dumpRSAPublicKey + rm -f dumpRSAPublicKey verify_data signature_digest diff --git a/utils/sign_data.sh b/utils/sign_data.sh new file mode 100755 index 0000000000..bd9e1be245 --- /dev/null +++ b/utils/sign_data.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# Copyright (c) 2010 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. + +if [ $# -ne 3 ] +then + echo "Usage: `basename $0` " + exit -1 +fi + +./signature_digest $1 $3 | openssl rsautl -sign -pkcs -inkey $2 diff --git a/tests/signature_digest.c b/utils/signature_digest.c similarity index 100% rename from tests/signature_digest.c rename to utils/signature_digest.c diff --git a/tests/verify_data.c b/utils/verify_data.c similarity index 100% rename from tests/verify_data.c rename to utils/verify_data.c