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 Export Katja PKCS-style keys, Tom St Denis
19 This will export either an KatjaPublicKey or KatjaPrivateKey
20 @param out [out] Destination of the packet
21 @param outlen [in/out] The max size and resulting size of the packet
22 @param type The type of exported key (PK_PRIVATE or PK_PUBLIC)
23 @param key The Katja key to export
24 @return CRYPT_OK if successful
26 int katja_export(unsigned char *out, unsigned long *outlen, int type, katja_key *key)
31 LTC_ARGCHK(out != NULL);
32 LTC_ARGCHK(outlen != NULL);
33 LTC_ARGCHK(key != NULL);
36 if (!(key->type == PK_PRIVATE) && (type == PK_PRIVATE)) {
37 return CRYPT_PK_INVALID_TYPE;
40 if (type == PK_PRIVATE) {
43 Version, n, d, p, q, d mod (p-1), d mod (q - 1), 1/q mod p, pq
45 if ((err = der_encode_sequence_multi(out, outlen,
46 LTC_ASN1_SHORT_INTEGER, 1UL, &zero,
47 LTC_ASN1_INTEGER, 1UL, key->N,
48 LTC_ASN1_INTEGER, 1UL, key->d,
49 LTC_ASN1_INTEGER, 1UL, key->p,
50 LTC_ASN1_INTEGER, 1UL, key->q,
51 LTC_ASN1_INTEGER, 1UL, key->dP,
52 LTC_ASN1_INTEGER, 1UL, key->dQ,
53 LTC_ASN1_INTEGER, 1UL, key->qP,
54 LTC_ASN1_INTEGER, 1UL, key->pq,
55 LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) {
59 /* clear zero and return */
63 return der_encode_sequence_multi(out, outlen,
64 LTC_ASN1_INTEGER, 1UL, key->N,
65 LTC_ASN1_EOL, 0UL, NULL);
71 /* ref: $Format:%D$ */
72 /* git commit: $Format:%H$ */
73 /* commit time: $Format:%ai$ */