basic tests for crypto functions

This commit is contained in:
Christian Grothoff 2015-04-13 18:57:37 +02:00
parent 2f6a4bb11c
commit 1fcd1873f0
2 changed files with 47 additions and 27 deletions

View File

@ -136,15 +136,19 @@ TALER_transfer_decrypt (const struct TALER_EncryptedLinkSecretP *secret_enc,
{
struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
struct GNUNET_CRYPTO_SymmetricSessionKey skey;
ssize_t s;
GNUNET_assert (sizeof (struct TALER_EncryptedLinkSecretP) ==
sizeof (struct TALER_LinkSecretP));
derive_transfer_key (trans_sec, &iv, &skey);
return GNUNET_CRYPTO_symmetric_decrypt (secret_enc,
sizeof (struct TALER_LinkSecretP),
&skey,
&iv,
secret);
s = GNUNET_CRYPTO_symmetric_decrypt (secret_enc,
sizeof (struct TALER_LinkSecretP),
&skey,
&iv,
secret);
if (sizeof (struct TALER_LinkSecretP) != s)
return GNUNET_SYSERR;
return GNUNET_OK;
}
@ -164,15 +168,19 @@ TALER_transfer_encrypt (const struct TALER_LinkSecretP *secret,
{
struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
struct GNUNET_CRYPTO_SymmetricSessionKey skey;
ssize_t s;
GNUNET_assert (sizeof (struct TALER_EncryptedLinkSecretP) ==
sizeof (struct TALER_LinkSecretP));
derive_transfer_key (trans_sec, &iv, &skey);
return GNUNET_CRYPTO_symmetric_encrypt (secret,
sizeof (struct TALER_LinkSecretP),
&skey,
&iv,
secret_enc);
s = GNUNET_CRYPTO_symmetric_encrypt (secret,
sizeof (struct TALER_LinkSecretP),
&skey,
&iv,
secret_enc);
if (sizeof (struct TALER_LinkSecretP) != s)
return GNUNET_SYSERR;
return GNUNET_OK;
}
@ -196,7 +204,7 @@ TALER_refresh_decrypt (const struct TALER_RefreshLinkEncrypted *input,
GNUNET_assert (input->blinding_key_enc == (const char *) &input[1]);
derive_refresh_key (secret, &iv, &skey);
if (GNUNET_OK !=
if (buf_size !=
GNUNET_CRYPTO_symmetric_decrypt (input->coin_priv_enc,
buf_size,
&skey,
@ -254,7 +262,7 @@ TALER_refresh_encrypt (const struct TALER_RefreshLinkDecrypted *input,
b_buf,
b_buf_size);
if (GNUNET_OK !=
if (buf_size !=
GNUNET_CRYPTO_symmetric_encrypt (buf,
buf_size,
&skey,

View File

@ -31,10 +31,10 @@ main(int argc,
struct TALER_EncryptedLinkSecretP secret_enc;
struct TALER_TransferSecretP trans_sec;
struct TALER_LinkSecretP secret;
struct TALER_LinkSecretP secret2;
struct TALER_RefreshLinkEncrypted *rl_enc;
struct TALER_RefreshLinkDecrypted rl;
struct GNUNET_CRYPTO_EcdhePrivateKey *pk;
struct TALER_RefreshLinkDecrypted *rld;
GNUNET_log_setup ("test-crypto",
"WARNING",
@ -43,26 +43,38 @@ main(int argc,
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
&secret,
sizeof (secret));
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
&trans_sec,
sizeof (trans_sec));
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
&rl.coin_priv,
sizeof (rl.coin_priv));
rl.blinding_key.rsa_blinding_key = GNUNET_CRYPTO_rsa_blinding_key_create ();
rl_enc = TALER_refresh_link_encrypt (&rl,
&secret);
rl.blinding_key.rsa_blinding_key = GNUNET_CRYPTO_rsa_blinding_key_create (1024);
rl_enc = TALER_refresh_encrypt (&rl,
&secret);
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
&trans_sec,
sizeof (trans_sec));
GNUNET_assert (GNUNET_OK ==
TALER_transfer_encrypt (&secret,
&trans_sec,
&secret_enc));
pk = GNUNET_CRYPTO_ecdhe_key_create ();
#if 0
.../.ecdhe_private_key = *pk;
#endif
GNUNET_CRYPTO_rsa_blinding_key_free (rl.blinding_key);
GNUNET_free (pk);
GNUNET_assert (GNUNET_OK ==
TALER_transfer_decrypt (&secret_enc,
&trans_sec,
&secret2));
GNUNET_assert (0 == memcmp (&secret,
&secret2,
sizeof (secret)));
rld = TALER_refresh_decrypt (rl_enc,
&secret2);
GNUNET_assert (NULL != rld);
GNUNET_assert (0 == memcmp (&rld->coin_priv,
&rl.coin_priv,
sizeof (union TALER_CoinSpendPrivateKeyP)));
GNUNET_assert (0 ==
GNUNET_CRYPTO_rsa_blinding_key_cmp (rl.blinding_key.rsa_blinding_key,
rld->blinding_key.rsa_blinding_key));
GNUNET_CRYPTO_rsa_blinding_key_free (rld->blinding_key.rsa_blinding_key);
GNUNET_free (rld);
GNUNET_CRYPTO_rsa_blinding_key_free (rl.blinding_key.rsa_blinding_key);
return 0;
}