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
9
* Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
12
/* Implements ECC over Z/pZ for curve y^2 = x^3 - 3x + b
14
* All curves taken from NIST recommendation paper of July 1999
15
* Available at http://csrc.nist.gov/cryptval/dss.htm
20
@file ecc_ansi_x963_export.c
21
ECC Crypto, Tom St Denis
26
/** ECC X9.63 (Sec. 4.3.6) uncompressed export
27
@param key Key to export
28
@param out [out] destination of export
29
@param outlen [in/out] Length of destination and final output size
30
Return CRYPT_OK on success
32
int ecc_ansi_x963_export(ecc_key *key, unsigned char *out, unsigned long *outlen)
34
unsigned char buf[ECC_BUF_SIZE];
37
LTC_ARGCHK(key != NULL);
38
LTC_ARGCHK(out != NULL);
39
LTC_ARGCHK(outlen != NULL);
41
if (ltc_ecc_is_valid_idx(key->idx) == 0) {
42
return CRYPT_INVALID_ARG;
44
numlen = key->dp->size;
46
if (*outlen < (1 + 2*numlen)) {
47
*outlen = 1 + 2*numlen;
48
return CRYPT_BUFFER_OVERFLOW;
55
zeromem(buf, sizeof(buf));
56
mp_to_unsigned_bin(key->pubkey.x, buf + (numlen - mp_unsigned_bin_size(key->pubkey.x)));
57
XMEMCPY(out+1, buf, numlen);
60
zeromem(buf, sizeof(buf));
61
mp_to_unsigned_bin(key->pubkey.y, buf + (numlen - mp_unsigned_bin_size(key->pubkey.y)));
62
XMEMCPY(out+1+numlen, buf, numlen);
64
*outlen = 1 + 2*numlen;
70
/* $Source: /cvs/libtom/libtomcrypt/src/pk/ecc/ecc_ansi_x963_export.c,v $ */
71
/* $Revision: 1.4 $ */
72
/* $Date: 2006/12/04 02:50:11 $ */