Files
OpenCellular/test/rsa.c
Nicolas Boichat d7178e9b5f test/rsa: Add test for RSA with public exponent 3
This tests RSA 2048 with public exponent 3.

BRANCH=none
BUG=chromium:663631
TEST=make run-rsa3

Change-Id: I979ad4a23de6baba63aba037d2713b74fed4737f
Reviewed-on: https://chromium-review.googlesource.com/408130
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2016-11-10 21:28:29 -08:00

54 lines
1.1 KiB
C

/* 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"
#ifdef TEST_RSA3
#include "rsa2048-3.h"
#else
#include "rsa2048-F4.h"
#endif
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();
}