Mercurial > dropbear
comparison libtomcrypt/src/pk/dsa/dsa_import.c @ 297:79bf1023cf11 agent-client
propagate from branch 'au.asn.ucc.matt.dropbear' (head 0501e6f661b5415eb76f3b312d183c3adfbfb712)
to branch 'au.asn.ucc.matt.dropbear.cli-agent' (head 01038174ec27245b51bd43a66c01ad930880f67b)
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 21 Mar 2006 16:20:59 +0000 |
parents | 1b9e69c058d2 |
children | 0cbe8f6dbf9e |
comparison
equal
deleted
inserted
replaced
225:ca7e76d981d9 | 297:79bf1023cf11 |
---|---|
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 "tomcrypt.h" | |
12 | |
13 /** | |
14 @file dsa_import.c | |
15 DSA implementation, import a DSA key, Tom St Denis | |
16 */ | |
17 | |
18 #ifdef MDSA | |
19 | |
20 /** | |
21 Import a DSA key | |
22 @param in The binary packet to import from | |
23 @param inlen The length of the binary packet | |
24 @param key [out] Where to store the imported key | |
25 @return CRYPT_OK if successful, upon error this function will free all allocated memory | |
26 */ | |
27 int dsa_import(const unsigned char *in, unsigned long inlen, dsa_key *key) | |
28 { | |
29 unsigned char flags[1]; | |
30 int err; | |
31 | |
32 LTC_ARGCHK(in != NULL); | |
33 LTC_ARGCHK(key != NULL); | |
34 | |
35 /* init key */ | |
36 if (mp_init_multi(&key->p, &key->g, &key->q, &key->x, &key->y, NULL) != MP_OKAY) { | |
37 return CRYPT_MEM; | |
38 } | |
39 | |
40 /* get key type */ | |
41 if ((err = der_decode_sequence_multi(in, inlen, | |
42 LTC_ASN1_BIT_STRING, 1UL, flags, | |
43 LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) { | |
44 goto error; | |
45 } | |
46 | |
47 if (flags[0] == 1) { | |
48 if ((err = der_decode_sequence_multi(in, inlen, | |
49 LTC_ASN1_BIT_STRING, 1UL, flags, | |
50 LTC_ASN1_INTEGER, 1UL, &key->g, | |
51 LTC_ASN1_INTEGER, 1UL, &key->p, | |
52 LTC_ASN1_INTEGER, 1UL, &key->q, | |
53 LTC_ASN1_INTEGER, 1UL, &key->y, | |
54 LTC_ASN1_INTEGER, 1UL, &key->x, | |
55 LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) { | |
56 goto error; | |
57 } | |
58 key->type = PK_PRIVATE; | |
59 } else { | |
60 if ((err = der_decode_sequence_multi(in, inlen, | |
61 LTC_ASN1_BIT_STRING, 1UL, flags, | |
62 LTC_ASN1_INTEGER, 1UL, &key->g, | |
63 LTC_ASN1_INTEGER, 1UL, &key->p, | |
64 LTC_ASN1_INTEGER, 1UL, &key->q, | |
65 LTC_ASN1_INTEGER, 1UL, &key->y, | |
66 LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) { | |
67 goto error; | |
68 } | |
69 key->type = PK_PUBLIC; | |
70 } | |
71 key->qord = mp_unsigned_bin_size(&key->q); | |
72 | |
73 if (key->qord >= MDSA_MAX_GROUP || key->qord <= 15 || | |
74 key->qord >= mp_unsigned_bin_size(&key->p) || (mp_unsigned_bin_size(&key->p) - key->qord) >= MDSA_DELTA) { | |
75 err = CRYPT_INVALID_PACKET; | |
76 goto error; | |
77 } | |
78 | |
79 return CRYPT_OK; | |
80 error: | |
81 mp_clear_multi(&key->p, &key->g, &key->q, &key->x, &key->y, NULL); | |
82 return err; | |
83 } | |
84 | |
85 #endif | |
86 | |
87 /* $Source: /cvs/libtom/libtomcrypt/src/pk/dsa/dsa_import.c,v $ */ | |
88 /* $Revision: 1.7 $ */ | |
89 /* $Date: 2005/06/08 23:31:17 $ */ |