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
13 Import a PKCS-style Katja key, Tom St Denis
19 Import an KatjaPublicKey or KatjaPrivateKey [two-prime only, only support >= 1024-bit keys, defined in PKCS #1 v2.1]
20 @param in The packet to import from
21 @param inlen It's length (octets)
22 @param key [out] Destination for newly imported key
23 @return CRYPT_OK if successful, upon error allocated memory is freed
25 int katja_import(const unsigned char *in, unsigned long inlen, katja_key *key)
30 LTC_ARGCHK(in != NULL);
31 LTC_ARGCHK(key != NULL);
32 LTC_ARGCHK(ltc_mp.name != NULL);
35 if ((err = mp_init_multi(&zero, &key->d, &key->N, &key->dQ,
36 &key->dP, &key->qP, &key->p, &key->q, &key->pq, NULL)) != CRYPT_OK) {
40 if ((err = der_decode_sequence_multi(in, inlen,
41 LTC_ASN1_INTEGER, 1UL, key->N,
42 LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) {
46 if (mp_cmp_d(key->N, 0) == LTC_MP_EQ) {
47 /* it's a private key */
48 if ((err = der_decode_sequence_multi(in, inlen,
49 LTC_ASN1_INTEGER, 1UL, zero,
50 LTC_ASN1_INTEGER, 1UL, key->N,
51 LTC_ASN1_INTEGER, 1UL, key->d,
52 LTC_ASN1_INTEGER, 1UL, key->p,
53 LTC_ASN1_INTEGER, 1UL, key->q,
54 LTC_ASN1_INTEGER, 1UL, key->dP,
55 LTC_ASN1_INTEGER, 1UL, key->dQ,
56 LTC_ASN1_INTEGER, 1UL, key->qP,
57 LTC_ASN1_INTEGER, 1UL, key->pq,
58 LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) {
61 key->type = PK_PRIVATE;
63 /* public we have N */
64 key->type = PK_PUBLIC;
69 mp_clear_multi(zero, key->d, key->N, key->dQ, key->dP,
70 key->qP, key->p, key->q, key->pq, NULL);
77 /* ref: $Format:%D$ */
78 /* git commit: $Format:%H$ */
79 /* commit time: $Format:%ai$ */