comparison libtomcrypt/src/pk/dsa/dsa_import.c @ 382:0cbe8f6dbf9e

propagate from branch 'au.asn.ucc.matt.ltc.dropbear' (head 2af22fb4e878750b88f80f90d439b316d229796f) to branch 'au.asn.ucc.matt.dropbear' (head 02c413252c90e9de8e03d91e9939dde3029f5c0a)
author Matt Johnston <matt@ucc.asn.au>
date Thu, 11 Jan 2007 02:41:05 +0000
parents 1b9e69c058d2
children f849a5ca2efc
comparison
equal deleted inserted replaced
379:b66a00272a90 382:0cbe8f6dbf9e
4 * algorithms in a highly modular and flexible manner. 4 * algorithms in a highly modular and flexible manner.
5 * 5 *
6 * The library is free for all purposes without any express 6 * The library is free for all purposes without any express
7 * guarantee it works. 7 * guarantee it works.
8 * 8 *
9 * Tom St Denis, [email protected], http://libtomcrypt.org 9 * Tom St Denis, [email protected], http://libtomcrypt.com
10 */ 10 */
11 #include "tomcrypt.h" 11 #include "tomcrypt.h"
12 12
13 /** 13 /**
14 @file dsa_import.c 14 @file dsa_import.c
29 unsigned char flags[1]; 29 unsigned char flags[1];
30 int err; 30 int err;
31 31
32 LTC_ARGCHK(in != NULL); 32 LTC_ARGCHK(in != NULL);
33 LTC_ARGCHK(key != NULL); 33 LTC_ARGCHK(key != NULL);
34 LTC_ARGCHK(ltc_mp.name != NULL);
34 35
35 /* init key */ 36 /* init key */
36 if (mp_init_multi(&key->p, &key->g, &key->q, &key->x, &key->y, NULL) != MP_OKAY) { 37 if (mp_init_multi(&key->p, &key->g, &key->q, &key->x, &key->y, NULL) != CRYPT_OK) {
37 return CRYPT_MEM; 38 return CRYPT_MEM;
38 } 39 }
39 40
40 /* get key type */ 41 /* get key type */
41 if ((err = der_decode_sequence_multi(in, inlen, 42 if ((err = der_decode_sequence_multi(in, inlen,
45 } 46 }
46 47
47 if (flags[0] == 1) { 48 if (flags[0] == 1) {
48 if ((err = der_decode_sequence_multi(in, inlen, 49 if ((err = der_decode_sequence_multi(in, inlen,
49 LTC_ASN1_BIT_STRING, 1UL, flags, 50 LTC_ASN1_BIT_STRING, 1UL, flags,
50 LTC_ASN1_INTEGER, 1UL, &key->g, 51 LTC_ASN1_INTEGER, 1UL, key->g,
51 LTC_ASN1_INTEGER, 1UL, &key->p, 52 LTC_ASN1_INTEGER, 1UL, key->p,
52 LTC_ASN1_INTEGER, 1UL, &key->q, 53 LTC_ASN1_INTEGER, 1UL, key->q,
53 LTC_ASN1_INTEGER, 1UL, &key->y, 54 LTC_ASN1_INTEGER, 1UL, key->y,
54 LTC_ASN1_INTEGER, 1UL, &key->x, 55 LTC_ASN1_INTEGER, 1UL, key->x,
55 LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) { 56 LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) {
56 goto error; 57 goto error;
57 } 58 }
58 key->type = PK_PRIVATE; 59 key->type = PK_PRIVATE;
59 } else { 60 } else {
60 if ((err = der_decode_sequence_multi(in, inlen, 61 if ((err = der_decode_sequence_multi(in, inlen,
61 LTC_ASN1_BIT_STRING, 1UL, flags, 62 LTC_ASN1_BIT_STRING, 1UL, flags,
62 LTC_ASN1_INTEGER, 1UL, &key->g, 63 LTC_ASN1_INTEGER, 1UL, key->g,
63 LTC_ASN1_INTEGER, 1UL, &key->p, 64 LTC_ASN1_INTEGER, 1UL, key->p,
64 LTC_ASN1_INTEGER, 1UL, &key->q, 65 LTC_ASN1_INTEGER, 1UL, key->q,
65 LTC_ASN1_INTEGER, 1UL, &key->y, 66 LTC_ASN1_INTEGER, 1UL, key->y,
66 LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) { 67 LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) {
67 goto error; 68 goto error;
68 } 69 }
69 key->type = PK_PUBLIC; 70 key->type = PK_PUBLIC;
70 } 71 }
71 key->qord = mp_unsigned_bin_size(&key->q); 72 key->qord = mp_unsigned_bin_size(key->q);
72 73
73 if (key->qord >= MDSA_MAX_GROUP || key->qord <= 15 || 74 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 (unsigned long)key->qord >= mp_unsigned_bin_size(key->p) || (mp_unsigned_bin_size(key->p) - key->qord) >= MDSA_DELTA) {
75 err = CRYPT_INVALID_PACKET; 76 err = CRYPT_INVALID_PACKET;
76 goto error; 77 goto error;
77 } 78 }
78 79
79 return CRYPT_OK; 80 return CRYPT_OK;
80 error: 81 error:
81 mp_clear_multi(&key->p, &key->g, &key->q, &key->x, &key->y, NULL); 82 mp_clear_multi(key->p, key->g, key->q, key->x, key->y, NULL);
82 return err; 83 return err;
83 } 84 }
84 85
85 #endif 86 #endif
86 87
87 /* $Source: /cvs/libtom/libtomcrypt/src/pk/dsa/dsa_import.c,v $ */ 88 /* $Source: /cvs/libtom/libtomcrypt/src/pk/dsa/dsa_import.c,v $ */
88 /* $Revision: 1.7 $ */ 89 /* $Revision: 1.12 $ */
89 /* $Date: 2005/06/08 23:31:17 $ */ 90 /* $Date: 2006/03/31 14:15:35 $ */