diff options
author | Christian Grothoff <christian@grothoff.org> | 2022-04-27 13:09:41 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2022-04-27 13:09:41 +0200 |
commit | d623cab1a351040cca8729540327f948eb3027aa (patch) | |
tree | 2c73e0b394926aa1ab328b05c49269227b941fe1 /src/util | |
parent | 1396afc13664e11fe869c1cfa2ad690df7856c21 (diff) | |
download | exchange-d623cab1a351040cca8729540327f948eb3027aa.tar.xz |
-work on p2p payments
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/Makefile.am | 3 | ||||
-rw-r--r-- | src/util/crypto_contract.c | 6 | ||||
-rw-r--r-- | src/util/test_crypto.c | 46 |
3 files changed, 54 insertions, 1 deletions
diff --git a/src/util/Makefile.am b/src/util/Makefile.am index b92c427b0..94edac021 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am @@ -147,8 +147,9 @@ test_amount_LDADD = \ test_crypto_SOURCES = \ test_crypto.c test_crypto_LDADD = \ + libtalerutil.la \ -lgnunetutil \ - libtalerutil.la + -ljansson test_payto_SOURCES = \ test_payto.c diff --git a/src/util/crypto_contract.c b/src/util/crypto_contract.c index fe6b1e6af..bcfe95239 100644 --- a/src/util/crypto_contract.c +++ b/src/util/crypto_contract.c @@ -278,6 +278,9 @@ TALER_CRYPTO_contract_encrypt_for_merge ( GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, &nonce, sizeof (nonce)); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Encrypting with key %s\n", + TALER_B2S (&key)); contract_encrypt (&nonce, &key, sizeof (key), @@ -315,6 +318,9 @@ TALER_CRYPTO_contract_decrypt_for_merge ( GNUNET_break (0); return NULL; } + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Decrypting with key %s\n", + TALER_B2S (&key)); if (GNUNET_OK != contract_decrypt (&key, sizeof (key), diff --git a/src/util/test_crypto.c b/src/util/test_crypto.c index a517b5bc3..186874e3c 100644 --- a/src/util/test_crypto.c +++ b/src/util/test_crypto.c @@ -438,6 +438,50 @@ test_merchant_sigs (void) } +static int +test_contracts (void) +{ + struct TALER_ContractDiffiePrivateP cpriv; + struct TALER_PurseContractPublicKeyP purse_pub; + struct TALER_PurseContractPrivateKeyP purse_priv; + void *econtract; + size_t econtract_size; + struct TALER_PurseMergePrivateKeyP mpriv_in; + struct TALER_PurseMergePrivateKeyP mpriv_out; + json_t *c; + + GNUNET_CRYPTO_ecdhe_key_create (&cpriv.ecdhe_priv); + GNUNET_CRYPTO_eddsa_key_create (&purse_priv.eddsa_priv); + GNUNET_CRYPTO_eddsa_key_get_public (&purse_priv.eddsa_priv, + &purse_pub.eddsa_pub); + memset (&mpriv_in, + 42, + sizeof (mpriv_in)); + c = json_pack ("{s:s}", "test", "value"); + GNUNET_assert (NULL != c); + TALER_CRYPTO_contract_encrypt_for_merge (&purse_pub, + &cpriv, + &mpriv_in, + c, + &econtract, + &econtract_size); + json_decref (c); + c = TALER_CRYPTO_contract_decrypt_for_merge (&cpriv, + &purse_pub, + econtract, + econtract_size, + &mpriv_out); + GNUNET_free (econtract); + if (NULL == c) + return 1; + json_decref (c); + if (0 != GNUNET_memcmp (&mpriv_in, + &mpriv_out)) + return 1; + return 0; +} + + int main (int argc, const char *const argv[]) @@ -454,6 +498,8 @@ main (int argc, return 4; if (0 != test_merchant_sigs ()) return 5; + if (0 != test_contracts ()) + return 6; return 0; } |