der_get_multi_integer.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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://libtomcrypt.org
  10. */
  11. #include <stdarg.h>
  12. #include "mycrypt.h"
  13. /* will read multiple DER INTEGER encoded mp_ints from src
  14. * of upto [inlen] bytes. It will store the number of bytes
  15. * read back into [inlen].
  16. */
  17. int der_get_multi_integer(const unsigned char *src, unsigned long *inlen,
  18. mp_int *num, ...)
  19. {
  20. va_list args;
  21. mp_int *next;
  22. unsigned long wrote, len;
  23. int err;
  24. _ARGCHK(src != NULL);
  25. _ARGCHK(inlen != NULL);
  26. /* setup va list */
  27. next = num;
  28. len = *inlen;
  29. wrote = 0;
  30. va_start(args, num);
  31. while (next != NULL) {
  32. if ((err = der_decode_integer(src, inlen, next)) != CRYPT_OK) {
  33. va_end(args);
  34. return err;
  35. }
  36. wrote += *inlen;
  37. src += *inlen;
  38. len -= *inlen;
  39. *inlen = len;
  40. next = va_arg(args, mp_int*);
  41. }
  42. va_end(args);
  43. *inlen = wrote;
  44. return CRYPT_OK;
  45. }