summaryrefslogtreecommitdiff
path: root/test/rsa.c
diff options
context:
space:
mode:
authorNicolas Boichat <drinkcat@google.com>2016-11-09 11:22:01 +0800
committerchrome-bot <chrome-bot@chromium.org>2016-11-09 21:14:17 -0800
commitf44bc369824ee4c14c5d0987673e27e6510843bc (patch)
tree94db55f42a43f1d6af7301d2287720251f3f8d53 /test/rsa.c
parent92d91adbdb38e5639c200ad65c4651274a8d07f9 (diff)
downloadchrome-ec-f44bc369824ee4c14c5d0987673e27e6510843bc.tar.gz
test/rsa: Add test for RSA signature checking
This tests RSA 2048 with public exponent F4 (65537). BRANCH=none BUG=chromium:663631 TEST=make run-rsa3 Change-Id: I195a349bb9a862606971054adc9ac3b56a817fe7 Reviewed-on: https://chromium-review.googlesource.com/408129 Commit-Ready: Nicolas Boichat <drinkcat@chromium.org> Tested-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
Diffstat (limited to 'test/rsa.c')
-rw-r--r--test/rsa.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/test/rsa.c b/test/rsa.c
new file mode 100644
index 0000000000..946515b0a2
--- /dev/null
+++ b/test/rsa.c
@@ -0,0 +1,49 @@
+/* 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.
+ *
+ * Tests RSA implementation.
+ */
+
+#include "console.h"
+#include "common.h"
+#include "rsa.h"
+#include "test_util.h"
+#include "util.h"
+
+#include "rsa2048-F4.h"
+
+void run_test(void)
+{
+ int good;
+ uint32_t rsa_workbuf[3 * RSANUMBYTES/4];
+
+ good = rsa_verify(rsa_key, sig, hash, rsa_workbuf);
+ if (!good) {
+ ccprintf("RSA verify FAILED\n");
+ test_fail();
+ return;
+ }
+ ccprintf("RSA verify OK\n");
+
+ /* Test with a wrong hash */
+ good = rsa_verify(rsa_key, sig, hash_wrong, rsa_workbuf);
+ if (good) {
+ ccprintf("RSA verify OK (expected fail)\n");
+ test_fail();
+ return;
+ }
+ ccprintf("RSA verify FAILED (as expected)\n");
+
+ /* Test with a wrong signature */
+ good = rsa_verify(rsa_key, sig+1, hash, rsa_workbuf);
+ if (good) {
+ ccprintf("RSA verify OK (expected fail)\n");
+ test_fail();
+ return;
+ }
+ ccprintf("RSA verify FAILED (as expected)\n");
+
+ test_pass();
+}
+