demo_crypt_constants.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* LibTomCrypt, modular cryptographic library -- Tom St Denis
  2. *
  3. * LibTomCrypt is a library that provides various cryptographic
  4. * algorithms in a highly modular and flexible manner.
  5. *
  6. * The library is free for all purposes without any express
  7. * guarantee it works.
  8. *
  9. * Tom St Denis, [email protected], http://libtom.org
  10. */
  11. #include "tomcrypt.h"
  12. /**
  13. @file demo_crypt_constants.c
  14. Demo how to get various constants to dynamic languages
  15. like Python
  16. Larry Bugbee, February 2013
  17. */
  18. int main(void) {
  19. // given a specific constant name, get and print its value
  20. char name[] = "CTR_COUNTER_BIG_ENDIAN";
  21. int value;
  22. if (crypt_get_constant(name, &value) != 0)
  23. exit(EXIT_FAILURE);
  24. printf("\n %s is %d \n\n", name, value);
  25. // get and print the length of the names (and values) list
  26. char *names_list;
  27. unsigned long names_list_len;
  28. if (crypt_list_all_constants(NULL, &names_list_len) != 0)
  29. exit(EXIT_FAILURE);
  30. printf(" need to allocate %lu bytes \n\n", names_list_len);
  31. // get and print the names (and values) list
  32. if ((names_list = malloc(names_list_len)) == NULL)
  33. exit(EXIT_FAILURE);
  34. if (crypt_list_all_constants(names_list, &names_list_len) != 0)
  35. exit(EXIT_FAILURE);
  36. printf(" supported constants:\n\n%s\n\n", names_list);
  37. free(names_list);
  38. return 0;
  39. }
  40. /* $Source$ */
  41. /* $Revision$ */
  42. /* $Date$ */