aboutsummaryrefslogtreecommitdiff
path: root/tests/rsa_padding_test.c
diff options
context:
space:
mode:
authorGaurav Shah <gauravsh@google.com>2010-02-24 16:41:32 -0800
committerGaurav Shah <gauravsh@google.com>2010-02-24 16:41:32 -0800
commit7d122e2a47145ef535163744daa55cec54e12b16 (patch)
treef1fcfb7abb6e10729ec5a6631e3e205ef99d391c /tests/rsa_padding_test.c
parent08df9b88a36b7a351305a06b2849c5fcdac54135 (diff)
downloadvboot_reference-7d122e2a47145ef535163744daa55cec54e12b16.tar.gz
Add a test for RSA PKCS #1 v1.5 signature verification.
This test checks that signatures with improper padding do not get accepted by the RSA signature verification implementation. Review URL: http://codereview.chromium.org/661038
Diffstat (limited to 'tests/rsa_padding_test.c')
-rw-r--r--tests/rsa_padding_test.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/rsa_padding_test.c b/tests/rsa_padding_test.c
new file mode 100644
index 00000000..7706ba8a
--- /dev/null
+++ b/tests/rsa_padding_test.c
@@ -0,0 +1,45 @@
+/* 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.
+ */
+
+#include "rsa_padding_test.h"
+
+#include <stdio.h>
+
+#include "file_keys.h"
+#include "rsa_utility.h"
+
+int main(int argc, char* argv[]) {
+ int i;
+ int error = 0;
+ RSAPublicKey* key;
+ if (argc != 2) {
+ fprintf(stderr, "Usage: %s <test public key>\n", argv[0]);
+ return 1;
+ }
+ key = RSAPublicKeyFromFile(argv[1]);
+ if (!key) {
+ fprintf(stderr, "Couldn't read RSA public key for the test.\n");
+ return 1;
+ }
+
+ /* The first test signature is valid. */
+ if (!RSA_verify(key, signatures[0], RSA1024NUMBYTES, 0,
+ test_message_sha1_hash)) {
+ fprintf(stderr, "RSA Padding Test vector 0 FAILED!\n");
+ error = 255; /* Test failure. */
+ }
+ /* All other signatures should fail verification. */
+ for (i = 1; i < sizeof(signatures) / sizeof(signatures[0]); i++) {
+ if (RSA_verify(key, signatures[i], RSA1024NUMBYTES, 0,
+ test_message_sha1_hash)) {
+ fprintf(stderr, "RSA Padding Test vector %d FAILED!\n", i);
+ error = 255; /* Test failure. */
+ }
+ }
+ if (!error)
+ fprintf(stderr, "RSA Padding Test PASSED for all test vectors.");
+
+ return error;
+}