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
18 @file ecc_ansi_x963_export.c
19 ECC Crypto, Tom St Denis
24 /** ECC X9.63 (Sec. 4.3.6) uncompressed export
25 @param key Key to export
26 @param out [out] destination of export
27 @param outlen [in/out] Length of destination and final output size
28 Return CRYPT_OK on success
30 int ecc_ansi_x963_export(ecc_key *key, unsigned char *out, unsigned long *outlen)
32 unsigned char buf[ECC_BUF_SIZE];
33 unsigned long numlen, xlen, ylen;
35 LTC_ARGCHK(key != NULL);
36 LTC_ARGCHK(outlen != NULL);
38 if (ltc_ecc_is_valid_idx(key->idx) == 0) {
39 return CRYPT_INVALID_ARG;
41 numlen = key->dp->size;
42 xlen = mp_unsigned_bin_size(key->pubkey.x);
43 ylen = mp_unsigned_bin_size(key->pubkey.y);
45 if (xlen > numlen || ylen > numlen || sizeof(buf) < numlen) {
46 return CRYPT_BUFFER_OVERFLOW;
49 if (*outlen < (1 + 2*numlen)) {
50 *outlen = 1 + 2*numlen;
51 return CRYPT_BUFFER_OVERFLOW;
54 LTC_ARGCHK(out != NULL);
60 zeromem(buf, sizeof(buf));
61 mp_to_unsigned_bin(key->pubkey.x, buf + (numlen - xlen));
62 XMEMCPY(out+1, buf, numlen);
65 zeromem(buf, sizeof(buf));
66 mp_to_unsigned_bin(key->pubkey.y, buf + (numlen - ylen));
67 XMEMCPY(out+1+numlen, buf, numlen);
69 *outlen = 1 + 2*numlen;
75 /* ref: $Format:%D$ */
76 /* git commit: $Format:%H$ */
77 /* commit time: $Format:%ai$ */