basic tests for crypto functions
This commit is contained in:
parent
2f6a4bb11c
commit
1fcd1873f0
@ -136,15 +136,19 @@ TALER_transfer_decrypt (const struct TALER_EncryptedLinkSecretP *secret_enc,
|
|||||||
{
|
{
|
||||||
struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
|
struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
|
||||||
struct GNUNET_CRYPTO_SymmetricSessionKey skey;
|
struct GNUNET_CRYPTO_SymmetricSessionKey skey;
|
||||||
|
ssize_t s;
|
||||||
|
|
||||||
GNUNET_assert (sizeof (struct TALER_EncryptedLinkSecretP) ==
|
GNUNET_assert (sizeof (struct TALER_EncryptedLinkSecretP) ==
|
||||||
sizeof (struct TALER_LinkSecretP));
|
sizeof (struct TALER_LinkSecretP));
|
||||||
derive_transfer_key (trans_sec, &iv, &skey);
|
derive_transfer_key (trans_sec, &iv, &skey);
|
||||||
return GNUNET_CRYPTO_symmetric_decrypt (secret_enc,
|
s = GNUNET_CRYPTO_symmetric_decrypt (secret_enc,
|
||||||
sizeof (struct TALER_LinkSecretP),
|
sizeof (struct TALER_LinkSecretP),
|
||||||
&skey,
|
&skey,
|
||||||
&iv,
|
&iv,
|
||||||
secret);
|
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_SymmetricInitializationVector iv;
|
||||||
struct GNUNET_CRYPTO_SymmetricSessionKey skey;
|
struct GNUNET_CRYPTO_SymmetricSessionKey skey;
|
||||||
|
ssize_t s;
|
||||||
|
|
||||||
GNUNET_assert (sizeof (struct TALER_EncryptedLinkSecretP) ==
|
GNUNET_assert (sizeof (struct TALER_EncryptedLinkSecretP) ==
|
||||||
sizeof (struct TALER_LinkSecretP));
|
sizeof (struct TALER_LinkSecretP));
|
||||||
derive_transfer_key (trans_sec, &iv, &skey);
|
derive_transfer_key (trans_sec, &iv, &skey);
|
||||||
return GNUNET_CRYPTO_symmetric_encrypt (secret,
|
s = GNUNET_CRYPTO_symmetric_encrypt (secret,
|
||||||
sizeof (struct TALER_LinkSecretP),
|
sizeof (struct TALER_LinkSecretP),
|
||||||
&skey,
|
&skey,
|
||||||
&iv,
|
&iv,
|
||||||
secret_enc);
|
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]);
|
GNUNET_assert (input->blinding_key_enc == (const char *) &input[1]);
|
||||||
derive_refresh_key (secret, &iv, &skey);
|
derive_refresh_key (secret, &iv, &skey);
|
||||||
if (GNUNET_OK !=
|
if (buf_size !=
|
||||||
GNUNET_CRYPTO_symmetric_decrypt (input->coin_priv_enc,
|
GNUNET_CRYPTO_symmetric_decrypt (input->coin_priv_enc,
|
||||||
buf_size,
|
buf_size,
|
||||||
&skey,
|
&skey,
|
||||||
@ -254,7 +262,7 @@ TALER_refresh_encrypt (const struct TALER_RefreshLinkDecrypted *input,
|
|||||||
b_buf,
|
b_buf,
|
||||||
b_buf_size);
|
b_buf_size);
|
||||||
|
|
||||||
if (GNUNET_OK !=
|
if (buf_size !=
|
||||||
GNUNET_CRYPTO_symmetric_encrypt (buf,
|
GNUNET_CRYPTO_symmetric_encrypt (buf,
|
||||||
buf_size,
|
buf_size,
|
||||||
&skey,
|
&skey,
|
||||||
|
@ -31,10 +31,10 @@ main(int argc,
|
|||||||
struct TALER_EncryptedLinkSecretP secret_enc;
|
struct TALER_EncryptedLinkSecretP secret_enc;
|
||||||
struct TALER_TransferSecretP trans_sec;
|
struct TALER_TransferSecretP trans_sec;
|
||||||
struct TALER_LinkSecretP secret;
|
struct TALER_LinkSecretP secret;
|
||||||
|
struct TALER_LinkSecretP secret2;
|
||||||
struct TALER_RefreshLinkEncrypted *rl_enc;
|
struct TALER_RefreshLinkEncrypted *rl_enc;
|
||||||
struct TALER_RefreshLinkDecrypted rl;
|
struct TALER_RefreshLinkDecrypted rl;
|
||||||
struct GNUNET_CRYPTO_EcdhePrivateKey *pk;
|
struct TALER_RefreshLinkDecrypted *rld;
|
||||||
|
|
||||||
|
|
||||||
GNUNET_log_setup ("test-crypto",
|
GNUNET_log_setup ("test-crypto",
|
||||||
"WARNING",
|
"WARNING",
|
||||||
@ -43,26 +43,38 @@ main(int argc,
|
|||||||
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
|
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
|
||||||
&secret,
|
&secret,
|
||||||
sizeof (secret));
|
sizeof (secret));
|
||||||
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
|
|
||||||
&trans_sec,
|
|
||||||
sizeof (trans_sec));
|
|
||||||
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
|
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
|
||||||
&rl.coin_priv,
|
&rl.coin_priv,
|
||||||
sizeof (rl.coin_priv));
|
sizeof (rl.coin_priv));
|
||||||
rl.blinding_key.rsa_blinding_key = GNUNET_CRYPTO_rsa_blinding_key_create ();
|
rl.blinding_key.rsa_blinding_key = GNUNET_CRYPTO_rsa_blinding_key_create (1024);
|
||||||
rl_enc = TALER_refresh_link_encrypt (&rl,
|
rl_enc = TALER_refresh_encrypt (&rl,
|
||||||
&secret);
|
&secret);
|
||||||
|
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
|
||||||
|
&trans_sec,
|
||||||
|
sizeof (trans_sec));
|
||||||
GNUNET_assert (GNUNET_OK ==
|
GNUNET_assert (GNUNET_OK ==
|
||||||
TALER_transfer_encrypt (&secret,
|
TALER_transfer_encrypt (&secret,
|
||||||
&trans_sec,
|
&trans_sec,
|
||||||
&secret_enc));
|
&secret_enc));
|
||||||
pk = GNUNET_CRYPTO_ecdhe_key_create ();
|
GNUNET_assert (GNUNET_OK ==
|
||||||
#if 0
|
TALER_transfer_decrypt (&secret_enc,
|
||||||
.../.ecdhe_private_key = *pk;
|
&trans_sec,
|
||||||
#endif
|
&secret2));
|
||||||
|
GNUNET_assert (0 == memcmp (&secret,
|
||||||
GNUNET_CRYPTO_rsa_blinding_key_free (rl.blinding_key);
|
&secret2,
|
||||||
GNUNET_free (pk);
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user