comparison der_put_multi_integer.c @ 143:5d99163f7e32 libtomcrypt-orig

import of libtomcrypt 0.99
author Matt Johnston <matt@ucc.asn.au>
date Sun, 19 Dec 2004 11:34:45 +0000
parents
children
comparison
equal deleted inserted replaced
15:6362d3854bb4 143:5d99163f7e32
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
14 /* store multiple mp_ints in DER INTEGER format to the dst, will not
15 * overflow the length you give it [outlen] and store the number of
16 * bytes used in [outlen]
17 */
18 int der_put_multi_integer(unsigned char *dst, unsigned long *outlen,
19 mp_int *num, ...)
20 {
21 va_list args;
22 mp_int *next;
23 unsigned long wrote, len;
24 int err;
25
26 _ARGCHK(dst != NULL);
27 _ARGCHK(outlen != NULL);
28
29 /* setup va list */
30 next = num;
31 len = *outlen;
32 wrote = 0;
33 va_start(args, num);
34
35 while (next != NULL) {
36 if ((err = der_encode_integer(next, dst, outlen)) != CRYPT_OK) {
37 va_end(args);
38 return err;
39 }
40 wrote += *outlen;
41 dst += *outlen;
42 len -= *outlen;
43 *outlen = len;
44 next = va_arg(args, mp_int*);
45 }
46 va_end(args);
47 *outlen = wrote;
48 return CRYPT_OK;
49 }