diff options
| author | kristopher tate <kris.tate+github@gmail.com> | 2018-09-06 12:24:53 +0900 |
|---|---|---|
| committer | kristopher tate <kris.tate+github@gmail.com> | 2018-09-06 12:24:53 +0900 |
| commit | 15d30b967af3c4bd4d22a9e746c14b52b7974ba4 (patch) | |
| tree | f7188e0d76eb20d1d721d9891fe361088b8efe29 /std | |
| parent | d1855a0e931706d84a81c0213994067bd9f2fc7f (diff) | |
| download | zig-15d30b967af3c4bd4d22a9e746c14b52b7974ba4.tar.gz zig-15d30b967af3c4bd4d22a9e746c14b52b7974ba4.zip | |
std/crypto/x25519.zig: add test for `createPublicKey`;
Diffstat (limited to 'std')
| -rw-r--r-- | std/crypto/x25519.zig | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/std/crypto/x25519.zig b/std/crypto/x25519.zig index 9a9df30962..41b2ff0959 100644 --- a/std/crypto/x25519.zig +++ b/std/crypto/x25519.zig @@ -4,6 +4,7 @@ const std = @import("../index.zig"); const builtin = @import("builtin"); +const fmt = std.fmt; const Endian = builtin.Endian; const readInt = std.mem.readInt; @@ -573,6 +574,16 @@ const Fe = struct { } }; +test "x25519 public key calculation from secret key" { + var sk: [32]u8 = undefined; + var pk_expected: [32]u8 = undefined; + var pk_calculated: [32]u8 = undefined; + try fmt.hexToBytes(sk[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166"); + try fmt.hexToBytes(pk_expected[0..], "f1814f0e8ff1043d8a44d25babff3cedcae6c22c3edaa48f857ae70de2baae50"); + std.debug.assert(X25519.createPublicKey(pk_calculated[0..], sk)); + std.debug.assert(std.mem.eql(u8, pk_calculated, pk_expected)); +} + test "x25519 rfc7748 vector1" { const secret_key = "\xa5\x46\xe3\x6b\xf0\x52\x7c\x9d\x3b\x16\x15\x4b\x82\x46\x5e\xdd\x62\x14\x4c\x0a\xc1\xfc\x5a\x18\x50\x6a\x22\x44\xba\x44\x9a\xc4"; const public_key = "\xe6\xdb\x68\x67\x58\x30\x30\xdb\x35\x94\xc1\xa4\x24\xb1\x5f\x7c\x72\x66\x24\xec\x26\xb3\x35\x3b\x10\xa9\x03\xa6\xd0\xab\x1c\x4c"; |
