1
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
3
* LibTomCrypt is a library that provides various cryptographic
4
* algorithms in a highly modular and flexible manner.
6
* The library is free for all purposes without any express
9
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
15
DSA implementation, import a DSA key, Tom St Denis
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
27
int dsa_import(const unsigned char *in, unsigned long inlen, dsa_key *key)
29
unsigned char flags[1];
32
LTC_ARGCHK(in != NULL);
33
LTC_ARGCHK(key != NULL);
36
if (mp_init_multi(&key->p, &key->g, &key->q, &key->x, &key->y, NULL) != MP_OKAY) {
41
if ((err = der_decode_sequence_multi(in, inlen,
42
LTC_ASN1_BIT_STRING, 1UL, flags,
43
LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) {
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) {
58
key->type = PK_PRIVATE;
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) {
69
key->type = PK_PUBLIC;
71
key->qord = mp_unsigned_bin_size(&key->q);
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;
81
mp_clear_multi(&key->p, &key->g, &key->q, &key->x, &key->y, NULL);
87
/* $Source: /cvs/libtom/libtomcrypt/src/pk/dsa/dsa_import.c,v $ */
88
/* $Revision: 1.7 $ */
89
/* $Date: 2005/06/08 23:31:17 $ */