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
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 ba50ecc..ba4c4a6 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 7fe68fe..e5ee196 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -11,7 +11,7 @@
 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 @@
     # 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 @@
   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 @@
     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 8573583..d72aaf4 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 0000000..bd9e1be
--- /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` <algorithm> <key file> <input file>"
+  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