diff options
Diffstat (limited to 'test/rsa.c')
-rw-r--r-- | test/rsa.c | 49 |
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(); +} + |