demo_crypt_sizes.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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_sizes.c
  14. Demo how to get various sizes to dynamic languages
  15. like Python - Larry Bugbee, February 2013
  16. */
  17. // in lieu of a header file
  18. int crypt_get_size(const char* namein, int *sizeout);
  19. int crypt_list_all_sizes(char *names_list,
  20. unsigned long *names_list_size);
  21. int main(void) {
  22. int rc;
  23. printf("\n");
  24. // given a specific size name, get and print its size
  25. char name[] = "ecc_key_struct_size";
  26. int size;
  27. rc = crypt_get_size(name, &size);
  28. printf(" %s is %d \n", name, size);
  29. printf("\n");
  30. // get and print the length of the names (and sizes) list
  31. char *sizes_list;
  32. unsigned long sizes_list_len;
  33. rc = crypt_list_all_sizes(NULL, &sizes_list_len);
  34. printf(" need to allocate %lu bytes \n", sizes_list_len);
  35. printf("\n");
  36. // get and print the names (and sizes) list
  37. sizes_list = malloc(sizes_list_len);
  38. rc = crypt_list_all_sizes(sizes_list, &sizes_list_len);
  39. printf(" supported sizes: %s \n", sizes_list);
  40. printf("\n");
  41. }
  42. /* $Source: $ */
  43. /* $Revision: $ */
  44. /* $Date: $ */