X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Futil%2Ftest_crypto_rsa.c;h=36c47005e5087cdceb6339cb44f926ac240a0dcb;hb=8b6b7febc5af8f10e308f41730ef3c8297f8e55e;hp=fc41dc24fbc66dfd7fd706e36b0d6e197530a560;hpb=c2d9d1e64c9801122caaa6b429fc67706db5c9d7;p=oweals%2Fgnunet.git diff --git a/src/util/test_crypto_rsa.c b/src/util/test_crypto_rsa.c index fc41dc24f..36c47005e 100644 --- a/src/util/test_crypto_rsa.c +++ b/src/util/test_crypto_rsa.c @@ -1,25 +1,31 @@ /* This file is part of GNUnet - Copyright (C) 2014,2015 Christian Grothoff (and other contributing authors) + Copyright (C) 2014,2015 GNUnet e.V. - GNUnet is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. - GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, If not, see + SPDX-License-Identifier: AGPL3.0-or-later */ /** * @file util/test_crypto_rsa.c * @brief testcase for utility functions for RSA cryptography * @author Sree Harsha Totakura + * @author Jeffrey Burdges */ #include "platform.h" +#include #include "gnunet_util_lib.h" #define KEY_SIZE 1024 @@ -31,11 +37,14 @@ main (int argc, { #define RND_BLK_SIZE 4096 unsigned char rnd_blk[RND_BLK_SIZE]; - struct GNUNET_CRYPTO_rsa_PrivateKey *priv; - struct GNUNET_CRYPTO_rsa_PublicKey *pub; - struct GNUNET_CRYPTO_rsa_BlindingKey *bkey; - struct GNUNET_CRYPTO_rsa_Signature *sig; - 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; @@ -48,20 +57,38 @@ main (int argc, RND_BLK_SIZE, &hash); priv = GNUNET_CRYPTO_rsa_private_key_create (KEY_SIZE); + priv_copy = GNUNET_CRYPTO_rsa_private_key_dup (priv); + GNUNET_assert (NULL != priv_copy); + GNUNET_assert (0 == GNUNET_CRYPTO_rsa_private_key_cmp (priv, priv_copy)); pub = GNUNET_CRYPTO_rsa_private_key_get_public (priv); + /* Encoding */ size_t size; char *enc; enc = NULL; size = GNUNET_CRYPTO_rsa_private_key_encode (priv, &enc); + + /* Decoding */ + GNUNET_CRYPTO_rsa_private_key_free (priv); + priv = NULL; + priv = GNUNET_CRYPTO_rsa_private_key_decode (enc, size); + GNUNET_assert (NULL != priv); + GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, + enc, size); + GNUNET_assert (NULL == GNUNET_CRYPTO_rsa_private_key_decode (enc, size)); + (void) fprintf (stderr, "The above warning is expected.\n"); GNUNET_free (enc); /* try ordinary sig first */ - sig = GNUNET_CRYPTO_rsa_sign (priv, - &hash, - sizeof (hash)); + sig = GNUNET_CRYPTO_rsa_sign_fdh (priv, + &hash); + sig_copy = GNUNET_CRYPTO_rsa_signature_dup (sig); + GNUNET_assert (NULL != sig); + GNUNET_assert (0 == GNUNET_CRYPTO_rsa_signature_cmp (sig, sig_copy)); + pub_copy = GNUNET_CRYPTO_rsa_public_key_dup (pub); + GNUNET_assert (NULL != pub_copy); GNUNET_assert (GNUNET_OK == - GNUNET_CRYPTO_rsa_verify (&hash, sig, pub)); + GNUNET_CRYPTO_rsa_verify (&hash, sig, pub_copy)); /* corrupt our hash and see if the signature is still valid */ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, &hash, sizeof (struct GNUNET_HashCode)); @@ -71,27 +98,30 @@ main (int argc, (void) fprintf (stderr, "The above warning is expected.\n"); 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 (priv, - blind_buf, - 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_signature_free (sig); + GNUNET_CRYPTO_rsa_signature_free (sig_copy); GNUNET_CRYPTO_rsa_private_key_free (priv); + GNUNET_CRYPTO_rsa_private_key_free (priv_copy); GNUNET_CRYPTO_rsa_public_key_free (pub); - GNUNET_CRYPTO_rsa_blinding_key_free (bkey); + GNUNET_CRYPTO_rsa_public_key_free (pub_copy); return 0; }