1/* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 * 3 * LibTomCrypt is a library that provides various cryptographic 4 * algorithms in a highly modular and flexible manner. 5 * 6 * The library is free for all purposes without any express 7 * guarantee it works. 8 * 9 * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com 10 */ 11 12/* Implements ECC over Z/pZ for curve y^2 = x^3 - 3x + b 13 * 14 * All curves taken from NIST recommendation paper of July 1999 15 * Available at http://csrc.nist.gov/cryptval/dss.htm 16 */ 17#include "tomcrypt.h" 18 19/** 20 @file ecc_ansi_x963_export.c 21 ECC Crypto, Tom St Denis 22*/ 23 24#ifdef MECC 25 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 31*/ 32int ecc_ansi_x963_export(ecc_key *key, unsigned char *out, unsigned long *outlen) 33{ 34 unsigned char buf[ECC_BUF_SIZE]; 35 unsigned long numlen; 36 37 LTC_ARGCHK(key != NULL); 38 LTC_ARGCHK(out != NULL); 39 LTC_ARGCHK(outlen != NULL); 40 41 if (ltc_ecc_is_valid_idx(key->idx) == 0) { 42 return CRYPT_INVALID_ARG; 43 } 44 numlen = key->dp->size; 45 46 if (*outlen < (1 + 2*numlen)) { 47 *outlen = 1 + 2*numlen; 48 return CRYPT_BUFFER_OVERFLOW; 49 } 50 51 /* store byte 0x04 */ 52 out[0] = 0x04; 53 54 /* pad and store x */ 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); 58 59 /* pad and store y */ 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); 63 64 *outlen = 1 + 2*numlen; 65 return CRYPT_OK; 66} 67 68#endif 69 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 $ */ 73