perf_crypto_symmetric.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 Christian Grothoff
  18. * @file util/perf_crypto_symmetric.c
  19. * @brief measure performance of encryption function
  20. */
  21. #include "platform.h"
  22. #include "gnunet_util_lib.h"
  23. #include <gauger.h>
  24. static void
  25. perfEncrypt ()
  26. {
  27. unsigned int i;
  28. char buf[64 * 1024];
  29. char rbuf[64 * 1024];
  30. struct GNUNET_CRYPTO_SymmetricSessionKey sk;
  31. struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
  32. GNUNET_CRYPTO_symmetric_create_session_key (&sk);
  33. memset (buf, 1, sizeof (buf));
  34. for (i = 0; i < 1024; i++)
  35. {
  36. memset (&iv, (int8_t) i, sizeof (iv));
  37. GNUNET_CRYPTO_symmetric_encrypt (buf, sizeof (buf),
  38. &sk, &iv,
  39. rbuf);
  40. GNUNET_CRYPTO_symmetric_decrypt (rbuf, sizeof (buf),
  41. &sk, &iv,
  42. buf);
  43. }
  44. memset (rbuf, 1, sizeof (rbuf));
  45. GNUNET_assert (0 == memcmp (rbuf, buf, sizeof (buf)));
  46. }
  47. int
  48. main (int argc, char *argv[])
  49. {
  50. struct GNUNET_TIME_Absolute start;
  51. start = GNUNET_TIME_absolute_get ();
  52. perfEncrypt ();
  53. printf ("Encrypt perf took %s\n",
  54. GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start),
  55. GNUNET_YES));
  56. GAUGER ("UTIL", "Symmetric encryption",
  57. 64 * 1024 / (1 +
  58. GNUNET_TIME_absolute_get_duration
  59. (start).rel_value_us / 1000LL), "kb/ms");
  60. return 0;
  61. }
  62. /* end of perf_crypto_aes.c */