comparison src/pk/dsa/dsa_import.c @ 191:1c15b283127b libtomcrypt-orig

Import of libtomcrypt 1.02 with manual path rename rearrangement etc
author Matt Johnston <matt@ucc.asn.au>
date Fri, 06 May 2005 13:23:02 +0000
parents
children 39d5d58461d6
comparison
equal deleted inserted replaced
143:5d99163f7e32 191:1c15b283127b
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 long x, y;
30 int err;
31
32 LTC_ARGCHK(in != NULL);
33 LTC_ARGCHK(key != NULL);
34
35 /* check length */
36 if ((1+2+PACKET_SIZE) > inlen) {
37 return CRYPT_INVALID_PACKET;
38 }
39
40 /* check type */
41 if ((err = packet_valid_header((unsigned char *)in, PACKET_SECT_DSA, PACKET_SUB_KEY)) != CRYPT_OK) {
42 return err;
43 }
44 y = PACKET_SIZE;
45
46 /* init key */
47 if (mp_init_multi(&key->p, &key->g, &key->q, &key->x, &key->y, NULL) != MP_OKAY) {
48 return CRYPT_MEM;
49 }
50
51 /* read type/qord */
52 key->type = in[y++];
53 key->qord = ((unsigned)in[y]<<8)|((unsigned)in[y+1]);
54 y += 2;
55
56 /* input publics */
57 INPUT_BIGNUM(&key->g,in,x,y, inlen);
58 INPUT_BIGNUM(&key->p,in,x,y, inlen);
59 INPUT_BIGNUM(&key->q,in,x,y, inlen);
60 INPUT_BIGNUM(&key->y,in,x,y, inlen);
61 if (key->type == PK_PRIVATE) {
62 INPUT_BIGNUM(&key->x,in,x,y, inlen);
63 }
64
65 return CRYPT_OK;
66 error:
67 mp_clear_multi(&key->p, &key->g, &key->q, &key->x, &key->y, NULL);
68 return err;
69 }
70
71 #endif