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
10 /* Implements ECC over Z/pZ for curve y^2 = x^3 - 3x + b
12 * All curves taken from NIST recommendation paper of July 1999
13 * Available at http://csrc.nist.gov/cryptval/dss.htm
19 ECC Crypto, Tom St Denis
25 Export an ECC key as a binary packet
26 @param out [out] Destination for the key
27 @param outlen [in/out] Max size and resulting size of the exported key
28 @param type The type of key you want to export (PK_PRIVATE or PK_PUBLIC)
29 @param key The key to export
30 @return CRYPT_OK if successful
32 int ecc_export(unsigned char *out, unsigned long *outlen, int type, ecc_key *key)
35 unsigned char flags[1];
36 unsigned long key_size;
38 LTC_ARGCHK(out != NULL);
39 LTC_ARGCHK(outlen != NULL);
40 LTC_ARGCHK(key != NULL);
43 if (key->type != PK_PRIVATE && type == PK_PRIVATE) {
44 return CRYPT_PK_TYPE_MISMATCH;
47 if (ltc_ecc_is_valid_idx(key->idx) == 0) {
48 return CRYPT_INVALID_ARG;
51 /* we store the NIST byte size */
52 key_size = key->dp->size;
54 if (type == PK_PRIVATE) {
56 err = der_encode_sequence_multi(out, outlen,
57 LTC_ASN1_BIT_STRING, 1UL, flags,
58 LTC_ASN1_SHORT_INTEGER, 1UL, &key_size,
59 LTC_ASN1_INTEGER, 1UL, key->pubkey.x,
60 LTC_ASN1_INTEGER, 1UL, key->pubkey.y,
61 LTC_ASN1_INTEGER, 1UL, key->k,
62 LTC_ASN1_EOL, 0UL, NULL);
65 err = der_encode_sequence_multi(out, outlen,
66 LTC_ASN1_BIT_STRING, 1UL, flags,
67 LTC_ASN1_SHORT_INTEGER, 1UL, &key_size,
68 LTC_ASN1_INTEGER, 1UL, key->pubkey.x,
69 LTC_ASN1_INTEGER, 1UL, key->pubkey.y,
70 LTC_ASN1_EOL, 0UL, NULL);
77 /* ref: $Format:%D$ */
78 /* git commit: $Format:%H$ */
79 /* commit time: $Format:%ai$ */