finish #3777 including testing
This commit is contained in:
parent
97e403bb66
commit
0a0feeea86
@ -441,6 +441,24 @@ TALER_link_decrypt_secret (const struct TALER_EncryptedLinkSecretP *secret_enc,
|
||||
struct TALER_LinkSecretP *secret);
|
||||
|
||||
|
||||
/**
|
||||
* Decrypt the shared @a secret from the information in the
|
||||
* encrypted link secret @e secret_enc using the transfer
|
||||
* public key and the coin's private key.
|
||||
*
|
||||
* @param secret_enc encrypted link secret
|
||||
* @param transfer_pub transfer public key
|
||||
* @param coin_priv coin private key
|
||||
* @param[out] secret set to the shared secret
|
||||
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
|
||||
*/
|
||||
int
|
||||
TALER_link_decrypt_secret2 (const struct TALER_EncryptedLinkSecretP *secret_enc,
|
||||
const struct TALER_TransferPublicKeyP *trans_pub,
|
||||
const union TALER_CoinSpendPrivateKeyP *coin_priv,
|
||||
struct TALER_LinkSecretP *secret);
|
||||
|
||||
|
||||
/**
|
||||
* Encrypt the shared @a secret to generate the encrypted link secret.
|
||||
* Also creates the transfer key.
|
||||
|
@ -333,7 +333,6 @@ TALER_test_coin_valid (const struct TALER_CoinPublicInfo *coin_public_info)
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Decrypt the shared @a secret from the information in the
|
||||
* encrypted link secret @e secret_enc using the transfer
|
||||
@ -373,6 +372,45 @@ TALER_link_decrypt_secret (const struct TALER_EncryptedLinkSecretP *secret_enc,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Decrypt the shared @a secret from the information in the
|
||||
* encrypted link secret @e secret_enc using the transfer
|
||||
* public key and the coin's private key.
|
||||
*
|
||||
* @param secret_enc encrypted link secret
|
||||
* @param transfer_pub transfer public key
|
||||
* @param coin_priv coin private key
|
||||
* @param[out] secret set to the shared secret
|
||||
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
|
||||
*/
|
||||
int
|
||||
TALER_link_decrypt_secret2 (const struct TALER_EncryptedLinkSecretP *secret_enc,
|
||||
const struct TALER_TransferPublicKeyP *trans_pub,
|
||||
const union TALER_CoinSpendPrivateKeyP *coin_priv,
|
||||
struct TALER_LinkSecretP *secret)
|
||||
{
|
||||
struct TALER_TransferSecretP transfer_secret;
|
||||
|
||||
if (GNUNET_OK !=
|
||||
GNUNET_CRYPTO_ecc_ecdh (&coin_priv->ecdhe_priv,
|
||||
&trans_pub->ecdhe_pub,
|
||||
&transfer_secret.key))
|
||||
{
|
||||
GNUNET_break (0);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
if (GNUNET_OK !=
|
||||
TALER_transfer_decrypt (secret_enc,
|
||||
&transfer_secret,
|
||||
secret))
|
||||
{
|
||||
GNUNET_break (0);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
return GNUNET_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Encrypt the shared @a secret to generate the encrypted link secret.
|
||||
* Also creates the transfer key.
|
||||
|
@ -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 */
|
||||
|
Loading…
Reference in New Issue
Block a user