-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.c
66 lines (55 loc) · 1.45 KB
/
test.c
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
#include <openssl/crypto.h>
#include <openssl/evp.h>
#include <assert.h>
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include "test-vectors.h"
#if OPENSSL_VERSION_NUMBER < 0x10101000L
# error "OpenSSL version does not support EdDSA."
#endif
int
main(void)
{
EVP_PKEY_CTX *pctx = NULL;
EVP_MD_CTX *ctx;
EVP_PKEY *pkey;
const struct test_vector *t;
unsigned char *msg, *pub, *sig;
size_t msglen, publen, siglen;
int rc, i, n, m;
for (t = tests, i = 0; t->pub && t->sig; t++, i++) {
msg = (unsigned char *)t_msg;
msglen = strlen(t_msg);
pub = OPENSSL_hexstr2buf(t->pub, (long *)&publen);
assert(msg != pub);
sig = OPENSSL_hexstr2buf(t->sig, (long *)&siglen);
assert(sig != pub);
ctx = EVP_MD_CTX_new();
assert(ctx != NULL);
pkey = EVP_PKEY_new_raw_public_key(EVP_PKEY_ED25519,
NULL, pub, publen);
assert(pkey != NULL);
rc = EVP_DigestVerifyInit(ctx, &pctx, NULL, NULL, pkey);
assert(rc == 1);
rc = EVP_DigestVerify(ctx, sig, siglen, msg, msglen);
if (rc == 0)
fprintf(stderr, "Verify test %3d: fail ", i);
else if (rc == 1)
fprintf(stderr, "Verify test %3d: success", i);
else
assert("Some error" == NULL);
n = i / 14;
m = i % 14;
if (n >= 8 || m >= 8)
fprintf(stderr, " ( must fail ) %s\n", rc == 1 ? "<---" : "");
if (n < 8 && m < 8)
fprintf(stderr, " (may succeed)\n");
EVP_MD_CTX_free(ctx);
EVP_PKEY_free(pkey);
free(pub);
free(sig);
}
return 0;
}