summaryrefslogtreecommitdiff
path: root/test/rsa.c
blob: 7170e2ff15963d681dd99628bc967699580653b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* 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
#if CONFIG_RSA_KEY_SIZE == 3072
#include "rsa3072-3.h"
#else
#include "rsa2048-3.h"
#endif
#else
#include "rsa2048-F4.h"
#endif

static uint32_t rsa_workbuf[3 * RSANUMBYTES/4];

void run_test(int argc, char **argv)
{
	int good;

	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();
}