demo_crypt_constants.c 1.6 KB

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