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. int rc;
  20. printf("\n");
  21. // given a specific constant name, get and print its value
  22. char name[] = "CTR_COUNTER_BIG_ENDIAN";
  23. int value;
  24. rc = crypt_get_constant(name, &value);
  25. printf(" %s is %d \n", name, value);
  26. printf("\n");
  27. // get and print the length of the names (and values) list
  28. char *names_list;
  29. unsigned long names_list_len;
  30. rc = crypt_list_all_constants(NULL, &names_list_len);
  31. printf(" need to allocate %lu bytes \n", names_list_len);
  32. printf("\n");
  33. // get and print the names (and values) list
  34. names_list = malloc(names_list_len);
  35. rc = crypt_list_all_constants(names_list, &names_list_len);
  36. printf(" supported constants: \n%s \n", names_list);
  37. printf("\n");
  38. }
  39. /* $Source: $ */
  40. /* $Revision: $ */
  41. /* $Date: $ */