comparison dsa_export.c @ 0:d7da3b1e1540 libtomcrypt

put back the 0.95 makefile which was inadvertently merged over
author Matt Johnston <matt@ucc.asn.au>
date Mon, 31 May 2004 18:21:40 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:d7da3b1e1540
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 "mycrypt.h"
12
13 #ifdef MDSA
14
15 int dsa_export(unsigned char *out, unsigned long *outlen, int type, dsa_key *key)
16 {
17 unsigned long y, z;
18 int err;
19
20 _ARGCHK(out != NULL);
21 _ARGCHK(outlen != NULL);
22 _ARGCHK(key != NULL);
23
24 /* can we store the static header? */
25 if (*outlen < (PACKET_SIZE + 1 + 2)) {
26 return CRYPT_BUFFER_OVERFLOW;
27 }
28
29 if (type == PK_PRIVATE && key->type != PK_PRIVATE) {
30 return CRYPT_PK_TYPE_MISMATCH;
31 }
32
33 if (type != PK_PUBLIC && type != PK_PRIVATE) {
34 return CRYPT_INVALID_ARG;
35 }
36
37 /* store header */
38 packet_store_header(out, PACKET_SECT_DSA, PACKET_SUB_KEY);
39 y = PACKET_SIZE;
40
41 /* store g, p, q, qord */
42 out[y++] = type;
43 out[y++] = (key->qord>>8)&255;
44 out[y++] = key->qord & 255;
45
46 OUTPUT_BIGNUM(&key->g,out,y,z);
47 OUTPUT_BIGNUM(&key->p,out,y,z);
48 OUTPUT_BIGNUM(&key->q,out,y,z);
49
50 /* public exponent */
51 OUTPUT_BIGNUM(&key->y,out,y,z);
52
53 if (type == PK_PRIVATE) {
54 OUTPUT_BIGNUM(&key->x,out,y,z);
55 }
56
57 *outlen = y;
58 return CRYPT_OK;
59 }
60
61 #endif
62