comparison src/pk/asn1/der/der_get_multi_integer.c @ 191:1c15b283127b libtomcrypt-orig

Import of libtomcrypt 1.02 with manual path rename rearrangement etc
author Matt Johnston <matt@ucc.asn.au>
date Fri, 06 May 2005 13:23:02 +0000
parents
children
comparison
equal deleted inserted replaced
143:5d99163f7e32 191:1c15b283127b
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 "tomcrypt.h"
13
14 /**
15 @file der_get_multi_integer.c
16 ASN.1 DER, read multiple integers, Tom St Denis
17 */
18
19
20 #ifdef LTC_DER
21
22 /* will read multiple DER INTEGER encoded mp_ints from src
23 * of upto [inlen] bytes. It will store the number of bytes
24 * read back into [inlen].
25 */
26 /**
27 Read multiple mp_int integers one after another
28 @param src The DER encoded integers
29 @param inlen [in] The length of the src buffer, [out] the amount of bytes read
30 @param num The first mp_int to decode
31 @param ... A NULL terminated list of mp_ints to decode
32 @return CRYPT_OK if successful
33 */
34 int der_get_multi_integer(const unsigned char *src, unsigned long *inlen,
35 mp_int *num, ...)
36 {
37 va_list args;
38 mp_int *next;
39 unsigned long wrote, len;
40 int err;
41
42 LTC_ARGCHK(src != NULL);
43 LTC_ARGCHK(inlen != NULL);
44
45 /* setup va list */
46 next = num;
47 len = *inlen;
48 wrote = 0;
49 va_start(args, num);
50
51 while (next != NULL) {
52 if ((err = der_decode_integer(src, inlen, next)) != CRYPT_OK) {
53 va_end(args);
54 return err;
55 }
56 wrote += *inlen;
57 src += *inlen;
58 len -= *inlen;
59 *inlen = len;
60 next = va_arg(args, mp_int*);
61 }
62 va_end(args);
63 *inlen = wrote;
64 return CRYPT_OK;
65 }
66
67 #endif