aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test-ecdsa.c37
1 files changed, 22 insertions, 15 deletions
diff --git a/tests/test-ecdsa.c b/tests/test-ecdsa.c
index cb590e5..8bccdfc 100644
--- a/tests/test-ecdsa.c
+++ b/tests/test-ecdsa.c
@@ -219,9 +219,13 @@ static int test_keygen_sign_verify(const hal_ecdsa_curve_t curve)
return 0;
}
+ printf("Generating key\n");
+
if ((err = hal_ecdsa_key_gen(&key, keybuf, sizeof(keybuf), curve)) != HAL_OK)
return printf("hal_ecdsa_key_gen() failed: %s\n", hal_error_string(err)), 0;
+ printf("Generating digest\n");
+
uint8_t hashbuf[hash_descriptor->digest_length];
{
@@ -242,10 +246,14 @@ static int test_keygen_sign_verify(const hal_ecdsa_curve_t curve)
uint8_t sigbuf[hash_descriptor->digest_length * 3];
size_t siglen;
+ printf("Signing\n");
+
if ((err = hal_ecdsa_sign(key, hashbuf, sizeof(hashbuf),
sigbuf, &siglen, sizeof(sigbuf), HAL_ECDSA_SIGNATURE_FORMAT_ASN1)) != HAL_OK)
return printf("hal_ecdsa_sign() failed: %s\n", hal_error_string(err)), 0;
+ printf("Verifying\n");
+
if ((err = hal_ecdsa_verify(key, hashbuf, sizeof(hashbuf),
sigbuf, siglen, HAL_ECDSA_SIGNATURE_FORMAT_ASN1)) != HAL_OK)
return printf("hal_ecdsa_verify() failed: %s\n", hal_error_string(err)), 0;
@@ -282,18 +290,6 @@ static void _time_check(const struct timeval t0, const int ok)
ok &= _ok; \
} while (0)
-/*
- * Run tests for one ECDSA curve.
- */
-
-static int test_ecdsa(const ecdsa_tc_t * const tc)
-
-{
- int ok = 1;
- time_check(test_against_static_vectors(tc));
- time_check(test_keygen_sign_verify(tc->curve));
- return ok;
-}
int main(int argc, char *argv[])
{
@@ -312,11 +308,22 @@ int main(int argc, char *argv[])
printf("\"%8.8s\" \"%4.4s\"\n\n", name, version);
+ int ok = 1;
+
+ /*
+ * Test vectors (where we have them).
+ */
for (int i = 0; i < sizeof(ecdsa_tc)/sizeof(*ecdsa_tc); i++)
- if (!test_ecdsa(&ecdsa_tc[i]))
- return 1;
+ time_check(test_against_static_vectors(&ecdsa_tc[i]));
+
+ /*
+ * Generate/sign/verify test for each curve.
+ */
+ time_check(test_keygen_sign_verify(HAL_ECDSA_CURVE_P256));
+ time_check(test_keygen_sign_verify(HAL_ECDSA_CURVE_P384));
+ time_check(test_keygen_sign_verify(HAL_ECDSA_CURVE_P521));
- return 0;
+ return !ok;
}
/*
thor Paul Selkirk <paul@psgd.org> 2018-02-27 18:04:39 +0100 committer Paul Selkirk <paul@psgd.org> 2018-04-19 18:59:01 -0400 Implement hash-based signatures, per draft-mcgrew-hash-sigs-08.txt' href='/sw/libhal/commit/tests/Makefile?h=modexpng&id=a478fe1230efae768c72b8cdb29e2887e4226312'>a478fe1
b3744cd
282617c












b3744cd
79559c5
5f152f5
f50805b

f50805b
8c427a7
f50805b
282617c

f50805b
64e5fe8
ab7d78b

dfc2522
ab7d78b
a478fe1

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