demo_crypt_sizes.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. int main(void) {
  18. int rc;
  19. printf("\n");
  20. // given a specific size name, get and print its size
  21. char name[] = "ecc_key_struct_size";
  22. int size;
  23. rc = crypt_get_size(name, &size);
  24. printf(" %s is %d \n", name, size);
  25. printf("\n");
  26. // get and print the length of the names (and sizes) list
  27. char *sizes_list;
  28. unsigned long sizes_list_len;
  29. rc = crypt_list_all_sizes(NULL, &sizes_list_len);
  30. printf(" need to allocate %lu bytes \n", sizes_list_len);
  31. printf("\n");
  32. // get and print the names (and sizes) list
  33. sizes_list = malloc(sizes_list_len);
  34. rc = crypt_list_all_sizes(sizes_list, &sizes_list_len);
  35. printf(" supported sizes: %s \n", sizes_list);
  36. printf("\n");
  37. }
  38. /* $Source: $ */
  39. /* $Revision: $ */
  40. /* $Date: $ */