test_cpabe.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2002, 2003, 2004, 2006 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @author Martin Schanzenbach
  18. * @file util/test_crypto_abe.c
  19. * @brief test for ABE ciphers
  20. */
  21. #include "platform.h"
  22. #include "gnunet_util_lib.h"
  23. #include "gnunet_abe_lib.h"
  24. #define TESTSTRING "Hello World!"
  25. static int
  26. testAbecipher ()
  27. {
  28. struct GNUNET_ABE_AbeMasterKey *msk;
  29. struct GNUNET_ABE_AbeKey *key;
  30. char *result;
  31. char **attrs;
  32. int size;
  33. char *res;
  34. msk = GNUNET_ABE_cpabe_create_master_key ();
  35. size = GNUNET_ABE_cpabe_encrypt (TESTSTRING, strlen (TESTSTRING) + 1,
  36. "testattr", // Policy
  37. msk,
  38. (void *) &result);
  39. GNUNET_assert (-1 != size);
  40. attrs = GNUNET_malloc (2 * sizeof(char*));
  41. attrs[0] = "testattr";
  42. attrs[1] = NULL;
  43. key = GNUNET_ABE_cpabe_create_key (msk,
  44. attrs);
  45. size = GNUNET_ABE_cpabe_decrypt (result, size,
  46. key,
  47. (void *) &res);
  48. if (strlen (TESTSTRING) + 1 != size)
  49. {
  50. printf ("abeciphertest failed: decryptBlock returned %d\n", size);
  51. return 1;
  52. }
  53. if (0 != strcmp (res, TESTSTRING))
  54. {
  55. printf ("abeciphertest failed: %s != %s\n", res, TESTSTRING);
  56. return 1;
  57. }
  58. else
  59. return 0;
  60. }
  61. int
  62. main (int argc, char *argv[])
  63. {
  64. int failureCount = 0;
  65. GNUNET_log_setup ("test-crypto-abe", "WARNING", NULL);
  66. failureCount += testAbecipher ();
  67. if (failureCount != 0)
  68. {
  69. printf ("%d TESTS FAILED!\n", failureCount);
  70. return -1;
  71. }
  72. return 0;
  73. }
  74. /* end of test_crypto_aes.c */