diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-04-15 18:34:14 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-04-15 18:34:14 +0200 |
commit | 0a0feeea8679d96cf2b5679562654512d467f0c2 (patch) | |
tree | 550c28424dac2eaf6581c03468ed6124ed8fca1c /src/util/test_crypto.c | |
parent | 97e403bb665ccf736a840c28c717fa7b3dc8de30 (diff) |
finish #3777 including testing
Diffstat (limited to 'src/util/test_crypto.c')
-rw-r--r-- | src/util/test_crypto.c | 66 |
1 files changed, 62 insertions, 4 deletions
diff --git a/src/util/test_crypto.c b/src/util/test_crypto.c index 032127706..e95f25e90 100644 --- a/src/util/test_crypto.c +++ b/src/util/test_crypto.c @@ -24,9 +24,8 @@ #include "taler_crypto_lib.h" -int -main(int argc, - const char *const argv[]) +static int +test_basics () { struct TALER_EncryptedLinkSecretP secret_enc; struct TALER_TransferSecretP trans_sec; @@ -39,7 +38,6 @@ main(int argc, GNUNET_log_setup ("test-crypto", "WARNING", NULL); - /* FIXME: implement test... */ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, &secret, sizeof (secret)); @@ -78,4 +76,64 @@ main(int argc, return 0; } + +static int +test_high_level () +{ + struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; + struct TALER_LinkSecretP secret; + struct TALER_LinkSecretP secret2; + union TALER_CoinSpendPublicKeyP coin_pub; + union TALER_CoinSpendPrivateKeyP coin_priv; + struct TALER_TransferPrivateKeyP trans_priv; + struct TALER_TransferPublicKeyP trans_pub; + struct TALER_EncryptedLinkSecretP secret_enc; + + pk = GNUNET_CRYPTO_ecdsa_key_create (); + GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, + &secret, + sizeof (secret)); + GNUNET_CRYPTO_ecdsa_key_get_public (pk, + &coin_pub.ecdsa_pub); + GNUNET_assert (GNUNET_OK == + TALER_link_encrypt_secret (&secret, + &coin_pub, + &trans_priv, + &trans_pub, + &secret_enc)); + GNUNET_assert (GNUNET_OK == + TALER_link_decrypt_secret (&secret_enc, + &trans_priv, + &coin_pub, + &secret2)); + GNUNET_assert (0 == + memcmp (&secret, + &secret2, + sizeof (secret))); + coin_priv.ecdsa_priv = *pk; + GNUNET_assert (GNUNET_OK == + TALER_link_decrypt_secret2 (&secret_enc, + &trans_pub, + &coin_priv, + &secret2)); + GNUNET_assert (0 == + memcmp (&secret, + &secret2, + sizeof (secret))); + GNUNET_free (pk); + return 0; +} + + +int +main(int argc, + const char *const argv[]) +{ + if (0 != test_basics ()) + return 1; + if (0 != test_high_level ()) + return 1; + return 0; +} + /* end of test_crypto.c */ |