diff options
author | Jack Lloyd <jack@randombit.net> | 2017-06-08 15:21:09 -0400 |
---|---|---|
committer | Jack Lloyd <jack@randombit.net> | 2017-06-08 15:21:09 -0400 |
commit | c3a97f3f02c06bfbaa673a2e2555dd9b312f87a7 (patch) | |
tree | c4ed34fab5fec8e048843187b233655d941a87bb /src/tests | |
parent | 9676ed62cbe913be9a7d8701bf12691079820c8c (diff) |
Add FFI test and test data from PGP draft
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/data/pubkey/ed25519.vec | 16 | ||||
-rw-r--r-- | src/tests/test_ffi.cpp | 68 |
2 files changed, 83 insertions, 1 deletions
diff --git a/src/tests/data/pubkey/ed25519.vec b/src/tests/data/pubkey/ed25519.vec index 00835370c..e85679b6d 100644 --- a/src/tests/data/pubkey/ed25519.vec +++ b/src/tests/data/pubkey/ed25519.vec @@ -4,7 +4,7 @@ Privkey = 9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60 Pubkey = d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a -Msg = +Msg = Signature = e5564300c360ac729086e2cc806e828a84877f1eb8e5d974d873e065224901555fb8821590a33bacc61e39701cf9b46bd25bf5f0595bbe24655141438e7a100b Privkey = 4ccd089b28ff96da9db6c346ec114e0f5b8a319f35aba624da8cf6ed4fb8a6fb @@ -3292,3 +3292,17 @@ Pubkey = 30b20fb320b00e77c4e0a8eb3730af3c0b1c5f5ed9ee2b0562707e4f55c4938b Msg = 606144b7d4f96bef7f112b6d41bcb500d2136c134ceda220e24d0f1524eca12c30f2b102c7f378d6bba259c5b4a5ef8ec9309d5c8da7e8d2ded3792aeeea2108f77d66b23045938ed64751f20d48326be2fb99628cfb1873d7dd27581c105ec13249a952a50784b8b34cb3b2c1a004fa8b628a0767fa9abf058d955df85d134a0fc7f4b7d7fb0c8d31bce345dd0a4282145afb2ff19751f2cc3a1caea242baaf538749bf388000e3dc1d739359dfebae64ae1e10fb6fc17cc9fb950535c2de129587a86859b7be36dfe9b6c1141b25e0915c8d4aa1cceae7046b3d7cfa940bc98d4d69fc5a30dde1dee42fb5272281bf8f8e7f3e1a04397fb4f3adefc57532ddbde36833a676e6f39c82aff6bf4832ec971e03be3829c02a203c82d9eb8c1630ee9693f45d26f5f51a3103ca64d468eceac1b29af4c42eb216d76ec8994836b4bec76489ca5070680c2c2eb457210a77c47fdcbf600172073a53f1453bb5c80439c882f0736de40637b4f5ab1f761ff355c6e9bd4abde7560d5fc113c830159a1b77c4e87bc2c69880a40c5805ecc8aaaf57575bccd8177fc6b83569233c0f5ca223ac4013ca106cac2854706aead714fa29f2860a5f9753268a3671d9f59cde6048cf0b8986050f7f549e4fd7557f2fc3fcdccddcefda586a64b3006e5825f27ca31687caf663bd90a05b1152d7c88d7f1051a9d791748651d888a6a12f22d6c8c3f78c2b86eaf5394b4ef7eefb89797b25e542dc93102d021a1d0bed6a7dcdd8102b8f0430a0bc21d904a3c9346c018343dd9937cb35250007a284825db08e9a11fee31cff7a314c48c42d8b314acc27822af03d1954c7cc8bf9ad4e9e98f4ad4efb355288daa8c90de9037e64a7861f5ee43ada9f0fccde34d0bcf50288550f700f215a7944a5380e2a8e3f04f2b4f5 Signature = d083333fb84e79c9b33e55e8192d571ffc8dc50745b6b5fdd8c44d92a63fd178c4e57c2ab3a1211c0ba2d39da30b06629d8d1cc1d9f2593263d524fa5a2ebc03 +# From draft-koch-eddsa-for-openpgp-04 + +Hash = SHA-256 +Privkey = 1a8b1ff05ded48e18bf50166c664ab023ea70003d78d9e41f5758a91d850f8d2 +Pubkey = 3f098994bdd916ed4053197934e4a87c80733a1280d62f8010992e43ee3b2406 +Msg = 4f70656e504750040016080006050255f95f9504ff0000000c +Signature = 56f90cca98e2102637bd983fdb16c131dfd27ed82bf4dde5606e0d756aed3366d09c4fa11527f038e0f57f2201d82f2ea2c9033265fa6ceb489e854bae61b404 + +# Same test as above but with Msg replaced by the SHA-256 pre-hash +Hash = Pure +Privkey = 1a8b1ff05ded48e18bf50166c664ab023ea70003d78d9e41f5758a91d850f8d2 +Pubkey = 3f098994bdd916ed4053197934e4a87c80733a1280d62f8010992e43ee3b2406 +Msg = f6220a3f757814f4c2176ffbb68b00249cd4ccdc059c4b34ad871f30b1740280 +Signature = 56f90cca98e2102637bd983fdb16c131dfd27ed82bf4dde5606e0d756aed3366d09c4fa11527f038e0f57f2201d82f2ea2c9033265fa6ceb489e854bae61b404 diff --git a/src/tests/test_ffi.cpp b/src/tests/test_ffi.cpp index 0e238ab1e..75fe337f3 100644 --- a/src/tests/test_ffi.cpp +++ b/src/tests/test_ffi.cpp @@ -391,6 +391,10 @@ class FFI_Unit_Tests : public Test results.push_back(ffi_test_elgamal(rng)); #endif +#if defined(BOTAN_HAS_ED25519) + results.push_back(ffi_test_ed25519(rng)); +#endif + TEST_FFI_OK(botan_rng_destroy, (rng)); results.push_back(result); @@ -1381,6 +1385,70 @@ class FFI_Unit_Tests : public Test return result; } + Test::Result ffi_test_ed25519(botan_rng_t rng) + { + Test::Result result("FFI Ed25519"); + + botan_pubkey_t pub; + botan_privkey_t priv; + + // From draft-koch-eddsa-for-openpgp-04 + const std::vector<uint8_t> seed = Botan::hex_decode( + "1a8b1ff05ded48e18bf50166c664ab023ea70003d78d9e41f5758a91d850f8d2"); + const std::vector<uint8_t> pubkey = Botan::hex_decode( + "3f098994bdd916ed4053197934e4a87c80733a1280d62f8010992e43ee3b2406"); + const std::vector<uint8_t> message = Botan::hex_decode( + "4f70656e504750040016080006050255f95f9504ff0000000c"); + const std::vector<uint8_t> exp_sig = Botan::hex_decode( + "56f90cca98e2102637bd983fdb16c131dfd27ed82bf4dde5606e0d756aed3366" + "d09c4fa11527f038e0f57f2201d82f2ea2c9033265fa6ceb489e854bae61b404"); + + TEST_FFI_OK(botan_privkey_load_ed25519, (&priv, seed.data())); + + uint8_t retr_privkey[64]; + TEST_FFI_OK(botan_privkey_ed25519_get_privkey, (priv, retr_privkey)); + + result.test_eq(nullptr, "Public key matches", retr_privkey + 32, 32, + pubkey.data(), pubkey.size()); + + TEST_FFI_OK(botan_privkey_export_pubkey, (&pub, priv)); + + uint8_t retr_pubkey[32]; + TEST_FFI_OK(botan_pubkey_ed25519_get_pubkey, (pub, retr_pubkey)); + result.test_eq(nullptr, "Public key matches", retr_pubkey, 32, + pubkey.data(), pubkey.size()); + + //TEST_FFI_OK(botan_pubkey_load_ed25519, (&pub, pubkey.data())); + + botan_pk_op_sign_t signer; + std::vector<uint8_t> signature; + + if(TEST_FFI_OK(botan_pk_op_sign_create, (&signer, priv, "SHA-256", 0))) + { + TEST_FFI_OK(botan_pk_op_sign_update, (signer, message.data(), message.size())); + + signature.resize(128); + size_t sig_len = signature.size(); + TEST_FFI_OK(botan_pk_op_sign_finish, (signer, rng, signature.data(), &sig_len)); + signature.resize(sig_len); + + TEST_FFI_OK(botan_pk_op_sign_destroy, (signer)); + } + + result.test_eq("Expected signature", signature, exp_sig); + + botan_pk_op_verify_t verifier; + + if(TEST_FFI_OK(botan_pk_op_verify_create, (&verifier, pub, "SHA-256", 0))) + { + TEST_FFI_OK(botan_pk_op_verify_update, (verifier, message.data(), message.size())); + TEST_FFI_OK(botan_pk_op_verify_finish, (verifier, signature.data(), signature.size())); + } + + + return result; + } + Test::Result ffi_test_elgamal(botan_rng_t rng) { Test::Result result("FFI ELGAMAL"); |