Mercurial > dropbear
comparison src/pk/asn1/der/der_put_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_put_multi_integer.c | |
16 ASN.1 DER, store multiple integers, Tom St Denis | |
17 */ | |
18 | |
19 | |
20 #ifdef LTC_DER | |
21 | |
22 /* store multiple mp_ints in DER INTEGER format to the out, will not | |
23 * overflow the length you give it [outlen] and store the number of | |
24 * bytes used in [outlen] | |
25 */ | |
26 /** | |
27 Store multiple mp_int integers one after another | |
28 @param out [out] The destination for the DER encoded integers | |
29 @param outlen [in/out] The max size and resulting size of the DER encoded integers | |
30 @param num The first mp_int to encode | |
31 @param ... A NULL terminated list of mp_ints to encode | |
32 @return CRYPT_OK if successful | |
33 */ | |
34 int der_put_multi_integer(unsigned char *out, unsigned long *outlen, | |
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(out != NULL); | |
43 LTC_ARGCHK(outlen != NULL); | |
44 | |
45 /* setup va list */ | |
46 next = num; | |
47 len = *outlen; | |
48 wrote = 0; | |
49 va_start(args, num); | |
50 | |
51 while (next != NULL) { | |
52 if ((err = der_encode_integer(next, out, outlen)) != CRYPT_OK) { | |
53 va_end(args); | |
54 return err; | |
55 } | |
56 wrote += *outlen; | |
57 out += *outlen; | |
58 len -= *outlen; | |
59 *outlen = len; | |
60 next = va_arg(args, mp_int*); | |
61 } | |
62 va_end(args); | |
63 *outlen = wrote; | |
64 return CRYPT_OK; | |
65 } | |
66 | |
67 #endif |