Package list libcryptx-perl / e110d2e
x25519 - rfc7748 test vectors Karel Miko 1 year, 8 months ago
2 changed file(s) with 27 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
283283
284284 Export raw public/private key
285285
286 my $private_pem = $pk->export_key_raw('private');
287 #or
288 my $public_pem = $pk->export_key_raw('public');
286 my $private_bytes = $pk->export_key_raw('private');
287 #or
288 my $public_bytes = $pk->export_key_raw('public');
289289
290290 =head2 shared_secret
291291
00 use strict;
11 use warnings;
2 use Test::More tests => 65;
2 use Test::More tests => 69;
33
44 use Crypt::PK::X25519;
55 use Crypt::Misc qw(read_rawfile);
143143 my $ss2 = $sk2->shared_secret($pk1);
144144 is(unpack("H*",$ss1), unpack("H*",$ss2), 'shared_secret');
145145 }
146
147
148 # rfc7748 test vectors
149 {
150 my $sk = Crypt::PK::X25519->new->import_key_raw(pack("H*", "a546e36bf0527c9d3b16154b82465edd62144c0ac1fc5a18506a2244ba449ac4"), 'private');
151 my $pk = Crypt::PK::X25519->new->import_key_raw(pack("H*", "e6db6867583030db3594c1a424b15f7c726624ec26b3353b10a903a6d0ab1c4c"), 'public');
152 is(unpack("H*", $sk->shared_secret($pk)), "c3da55379de9c6908e94ea4df28d084f32eccf03491c71f754b4075577a28552");
153 }
154 {
155 my $sk = Crypt::PK::X25519->new->import_key_raw(pack("H*", "4b66e9d4d1b4673c5ad22691957d6af5c11b6421e0ea01d42ca4169e7918ba0d"), 'private');
156 my $pk = Crypt::PK::X25519->new->import_key_raw(pack("H*", "e5210f12786811d3f4b7959d0538ae2c31dbe7106fc03c3efc4cd549c715a493"), 'public');
157 is(unpack("H*", $sk->shared_secret($pk)), "95cbde9476e8907d7aade45cb4b873f88b595a68799fa152e6f8f7647aac7957");
158 }
159 {
160 my $sk = Crypt::PK::X25519->new->import_key_raw(pack("H*", "77076d0a7318a57d3c16c17251b26645df4c2f87ebc0992ab177fba51db92c2a"), 'private');
161 my $pk = Crypt::PK::X25519->new->import_key_raw(pack("H*", "de9edb7d7b7dc1b4d35b61c2ece435373f8343c85b78674dadfc7e146f882b4f"), 'public');
162 is(unpack("H*", $sk->shared_secret($pk)), "4a5d9d5ba4ce2de1728e3bf480350f25e07e21c947d19e3376f09b3c1e161742");
163 }
164 {
165 my $sk = Crypt::PK::X25519->new->import_key_raw(pack("H*", "5dab087e624a8a4b79e17f8b83800ee66f3bb1292618b6fd1c2f8b27ff88e0eb"), 'private');
166 my $pk = Crypt::PK::X25519->new->import_key_raw(pack("H*", "8520f0098930a754748b7ddcb43ef75a0dbf3a0d26381af4eba4a98eaa9b4e6a"), 'public');
167 is(unpack("H*", $sk->shared_secret($pk)), "4a5d9d5ba4ce2de1728e3bf480350f25e07e21c947d19e3376f09b3c1e161742");
168 }