* @file util/test_crypto_rsa.c
* @brief testcase for utility functions for RSA cryptography
* @author Sree Harsha Totakura <sreeharsha@totakura.in>
+ * @author Jeffrey Burdges <burdges@gnunet.org>
*/
#include "platform.h"
#include <gcrypt.h>
#define KEY_SIZE 1024
-gcry_error_t
-rsa_full_domain_hash (gcry_mpi_t *r,
- const struct GNUNET_HashCode *hash,
- const struct GNUNET_CRYPTO_rsa_PublicKey *pkey,
- size_t *rsize);
-
-
int
main (int argc,
char *argv[])
{
#define RND_BLK_SIZE 4096
unsigned char rnd_blk[RND_BLK_SIZE];
- struct GNUNET_CRYPTO_rsa_PrivateKey *priv;
- struct GNUNET_CRYPTO_rsa_PrivateKey *priv_copy;
- struct GNUNET_CRYPTO_rsa_PublicKey *pub;
- struct GNUNET_CRYPTO_rsa_PublicKey *pub_copy;
- struct GNUNET_CRYPTO_rsa_BlindingKey *bkey;
- struct GNUNET_CRYPTO_rsa_Signature *sig;
- struct GNUNET_CRYPTO_rsa_Signature *sig_copy;
- struct GNUNET_CRYPTO_rsa_Signature *bsig;
+ struct GNUNET_CRYPTO_RsaPrivateKey *priv;
+ struct GNUNET_CRYPTO_RsaPrivateKey *priv_copy;
+ struct GNUNET_CRYPTO_RsaPublicKey *pub;
+ struct GNUNET_CRYPTO_RsaPublicKey *pub_copy;
+ struct GNUNET_CRYPTO_RsaSignature *sig;
+ struct GNUNET_CRYPTO_RsaSignature *sig_copy;
+ struct GNUNET_CRYPTO_RsaSignature *bsig;
+ struct GNUNET_CRYPTO_RsaBlindingKeySecret bsec;
struct GNUNET_HashCode hash;
char *blind_buf;
size_t bsize;
- gcry_mpi_t v;
GNUNET_log_setup ("test-rsa", "WARNING", NULL);
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
(void) fprintf (stderr, "The above warning is expected.\n");
GNUNET_free (enc);
- /* test full domain hash size */
- GNUNET_assert (0 == rsa_full_domain_hash (&v, &hash, pub, NULL));
- GNUNET_assert (gcry_mpi_get_nbits(v) < KEY_SIZE);
- gcry_mpi_clear_highbit (v, gcry_mpi_get_nbits(v)-1); /* clear the set high bit */
- GNUNET_assert (gcry_mpi_get_nbits(v) > 3*KEY_SIZE/4);
- /* This test necessarily randomly fails with probability 2^(3 - KEY_SIZE/4) */
- gcry_mpi_release(v);
-
/* try ordinary sig first */
sig = GNUNET_CRYPTO_rsa_sign_fdh (priv,
&hash);
GNUNET_CRYPTO_rsa_signature_free (sig);
/* test blind signing */
- bkey = GNUNET_CRYPTO_rsa_blinding_key_create (KEY_SIZE);
- bsize = GNUNET_CRYPTO_rsa_blind (&hash,
- bkey,
- pub,
- &blind_buf);
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
+ &bsec,
+ sizeof (bsec));
+ GNUNET_CRYPTO_rsa_blind (&hash,
+ &bsec,
+ pub,
+ &blind_buf,&bsize);
GNUNET_assert (0 != bsize);
bsig = GNUNET_CRYPTO_rsa_sign_blinded (priv,
blind_buf,
bsize);
GNUNET_free (blind_buf);
sig = GNUNET_CRYPTO_rsa_unblind (bsig,
- bkey,
- pub);
+ &bsec,
+ pub);
GNUNET_CRYPTO_rsa_signature_free (bsig);
GNUNET_assert (GNUNET_OK ==
GNUNET_CRYPTO_rsa_verify (&hash, sig, pub));
GNUNET_CRYPTO_rsa_private_key_free (priv_copy);
GNUNET_CRYPTO_rsa_public_key_free (pub);
GNUNET_CRYPTO_rsa_public_key_free (pub_copy);
- GNUNET_CRYPTO_rsa_blinding_key_free (bkey);
return 0;
}