1 |
BEGIN { $| = 1; print "1..1621\n"; } |
2 |
|
3 |
use Crypt::Ed25519; |
4 |
|
5 |
# test vectors generated from ed25519's website sign.input via extract-sign.input |
6 |
|
7 |
my @tv = unpack "(a32 a32 a64 w/a*)*", do { |
8 |
open my $fh, "<:raw", "t/sign.input" |
9 |
or die "t/sign.input: $!"; |
10 |
local $/; |
11 |
readline $fh |
12 |
}; |
13 |
|
14 |
print "ok 1\n"; |
15 |
|
16 |
my $i = 1; |
17 |
|
18 |
while (@tv) { |
19 |
my ($seed, $pub, $s, $m) = splice @tv, -4, 4; |
20 |
|
21 |
my $pub_ = Crypt::Ed25519::eddsa_public_key $seed; |
22 |
print $pub_ eq $pub ? "" : "not ", "ok ", ++$i, "\n"; |
23 |
|
24 |
my ($pub__, $priv) = Crypt::Ed25519::generate_keypair $seed; |
25 |
print $pub_ eq $pub__ ? "" : "not ", "ok ", ++$i, "\n"; |
26 |
|
27 |
my $s_ = Crypt::Ed25519::eddsa_sign $m, $pub, $seed; |
28 |
print $s eq $s_ ? "" : "not ", "ok ", ++$i, "\n"; |
29 |
|
30 |
my $s__ = Crypt::Ed25519::sign $m, $pub, $priv; |
31 |
print $s eq $s_ ? "" : "not ", "ok ", ++$i, "\n"; |
32 |
|
33 |
my $valid = Crypt::Ed25519::eddsa_verify $m, $pub, $s; |
34 |
print $valid ? "" : "not ", "ok ", ++$i, "\n"; |
35 |
|
36 |
my $notvalid = !Crypt::Ed25519::eddsa_verify "x$m", $pub, $s; |
37 |
print $notvalid ? "" : "not ", "ok ", ++$i, "\n"; |
38 |
} |
39 |
|