summaryrefslogtreecommitdiffhomepage
path: root/tests/custom/05_crypto/04_keygen
blob: 97a94b8d9026b6e7c55d62ba7266a2656308acf6 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
-- Testcase --
{%
	import { pk as pk_mbedtls } from 'crypto_mbedtls';
	import { pk as pk_openssl } from 'crypto_openssl';
	import { test_keygen } from './files/keygen.uc';

	curves = [
		'P-192',
		'P-224',
		'P-256',
		'P-384',
		'P-521',
		'brainpoolP256r1',
		'brainpoolP384r1',
		'brainpoolP512r1',
		'secp192k1',
		'secp224k1',
		'secp256k1',
	];


	for (c in curves) {
		test_keygen(pk_openssl, pk_mbedtls, "EC", "SHA256", c);
		test_keygen(pk_mbedtls, pk_openssl, "EC", "SHA256", c);
	}
	test_keygen(pk_openssl, pk_mbedtls, "RSA", "SHA256", 2048);
	test_keygen(pk_mbedtls, pk_openssl, "RSA", "SHA256", 2048);

	test_keygen(pk_openssl, pk_openssl, "ED25519", null);
%}
-- End --

-- Expect stdout --
true
true
true
true
true
true
true
true
true
true
true
true
true
true
true
true
true
true
true
true
true
true
true
true
true
-- End --

-- Expect stderr --
-- End --

-- File keygen.uc --
export
function test_keygen(pk_init, other_pk_init, type, md_alg, ...args)
{
	let pk = pk_init();
	let res = pk.keygen(type, ...args);
	let pkey = pk.get_public_key();
	const data = "Message";
	const signature = pk.sign(md_alg, data);

	let other_pk = other_pk_init();
	other_pk.set_public_key(pkey);

	const verify = other_pk.verify(md_alg, data, signature);
	print(verify, '\n');
};
-- End --