test_crypto_kdf.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. Copyright (c) 2010 Jeffrey Burdges
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. /**
  20. * @file src/util/test_crypt_kdf.c
  21. * @brief Testcases for KDF mod n
  22. * @author Jeffrey Burdges <burdges@gnunet.org>
  23. */
  24. #include <gcrypt.h>
  25. #include "platform.h"
  26. #include "gnunet_crypto_lib.h"
  27. int
  28. main ()
  29. {
  30. #define RND_BLK_SIZE 4096
  31. unsigned char rnd_blk[RND_BLK_SIZE];
  32. int i;
  33. gcry_mpi_t r,n;
  34. GNUNET_log_setup ("test-crypto-kdf", "WARNING", NULL);
  35. GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
  36. rnd_blk,
  37. RND_BLK_SIZE);
  38. /* test full domain hash size */
  39. for (i=0; i<100; i++) {
  40. gcry_mpi_scan (&n,
  41. GCRYMPI_FMT_USG,
  42. rnd_blk, RND_BLK_SIZE,
  43. NULL);
  44. GNUNET_CRYPTO_kdf_mod_mpi (&r, n,
  45. "", 0,
  46. "", 0,
  47. "");
  48. GNUNET_assert( 0 > gcry_mpi_cmp(r,n) );
  49. /* Is it worth checking that it's not too small? */
  50. /* GNUNET_assert (gcry_mpi_get_nbits(r) > 3*RND_BLK_SIZE/4); */
  51. /* This test necessarily randomly fails with probability 2^(3 - RND_BLK_SIZE/4) */
  52. gcry_mpi_release(n);
  53. gcry_mpi_release(r);
  54. }
  55. return 0;
  56. }