sizes.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. /* given a specific size name, get and print its size */
  19. char name[] = "ecc_key";
  20. unsigned int size;
  21. char *sizes_list;
  22. unsigned int sizes_list_len;
  23. if(crypt_get_size(name, &size) != 0)
  24. exit(EXIT_FAILURE);
  25. printf("\n size of '%s' is %u \n\n", name, size);
  26. /* get and print the length of the names (and sizes) list */
  27. if(crypt_list_all_sizes(NULL, &sizes_list_len) != 0)
  28. exit(EXIT_FAILURE);
  29. printf(" need to allocate %u bytes \n\n", sizes_list_len);
  30. /* get and print the names (and sizes) list */
  31. sizes_list = malloc(sizes_list_len);
  32. if(crypt_list_all_sizes(sizes_list, &sizes_list_len) != 0)
  33. exit(EXIT_FAILURE);
  34. printf(" supported sizes:\n\n%s\n\n", sizes_list);
  35. return 0;
  36. }
  37. /* $Source: $ */
  38. /* $Revision: $ */
  39. /* $Date: $ */