diff options
Diffstat (limited to 'src/ltc/pk/ecc')
36 files changed, 70 insertions, 87 deletions
diff --git a/src/ltc/pk/ecc/ecc.c b/src/ltc/pk/ecc/ecc.c index 802097f4..50470ee2 100644 --- a/src/ltc/pk/ecc/ecc.c +++ b/src/ltc/pk/ecc/ecc.c @@ -7,7 +7,7 @@ * guarantee it works. */ -#include "tomcrypt.h" +#include "tomcrypt_private.h" /** @file ecc.c diff --git a/src/ltc/pk/ecc/ecc_ansi_x963_export.c b/src/ltc/pk/ecc/ecc_ansi_x963_export.c index b752b6b5..ebecf24d 100644 --- a/src/ltc/pk/ecc/ecc_ansi_x963_export.c +++ b/src/ltc/pk/ecc/ecc_ansi_x963_export.c @@ -7,7 +7,7 @@ * guarantee it works. */ -#include "tomcrypt.h" +#include "tomcrypt_private.h" /** @file ecc_ansi_x963_export.c @@ -24,41 +24,7 @@ */ int ecc_ansi_x963_export(const ecc_key *key, unsigned char *out, unsigned long *outlen) { - unsigned char buf[ECC_BUF_SIZE]; - unsigned long numlen, xlen, ylen; - - LTC_ARGCHK(key != NULL); - LTC_ARGCHK(out != NULL); - LTC_ARGCHK(outlen != NULL); - - numlen = key->dp.size; - xlen = mp_unsigned_bin_size(key->pubkey.x); - ylen = mp_unsigned_bin_size(key->pubkey.y); - - if (xlen > numlen || ylen > numlen || sizeof(buf) < numlen) { - return CRYPT_BUFFER_OVERFLOW; - } - - if (*outlen < (1 + 2*numlen)) { - *outlen = 1 + 2*numlen; - return CRYPT_BUFFER_OVERFLOW; - } - - /* store byte 0x04 */ - out[0] = 0x04; - - /* pad and store x */ - zeromem(buf, sizeof(buf)); - mp_to_unsigned_bin(key->pubkey.x, buf + (numlen - xlen)); - XMEMCPY(out+1, buf, numlen); - - /* pad and store y */ - zeromem(buf, sizeof(buf)); - mp_to_unsigned_bin(key->pubkey.y, buf + (numlen - ylen)); - XMEMCPY(out+1+numlen, buf, numlen); - - *outlen = 1 + 2*numlen; - return CRYPT_OK; + return ecc_get_key(out, outlen, PK_PUBLIC, key); } #endif diff --git a/src/ltc/pk/ecc/ecc_ansi_x963_import.c b/src/ltc/pk/ecc/ecc_ansi_x963_import.c index 12b034da..6dbdd215 100644 --- a/src/ltc/pk/ecc/ecc_ansi_x963_import.c +++ b/src/ltc/pk/ecc/ecc_ansi_x963_import.c @@ -7,7 +7,7 @@ * guarantee it works. */ -#include "tomcrypt.h" +#include "tomcrypt_private.h" /** @file ecc_ansi_x963_import.c diff --git a/src/ltc/pk/ecc/ecc_decrypt_key.c b/src/ltc/pk/ecc/ecc_decrypt_key.c index 6ce93d52..8c29a174 100644 --- a/src/ltc/pk/ecc/ecc_decrypt_key.c +++ b/src/ltc/pk/ecc/ecc_decrypt_key.c @@ -7,7 +7,7 @@ * guarantee it works. */ -#include "tomcrypt.h" +#include "tomcrypt_private.h" /** @file ecc_decrypt_key.c diff --git a/src/ltc/pk/ecc/ecc_encrypt_key.c b/src/ltc/pk/ecc/ecc_encrypt_key.c index e0beb692..17201df6 100644 --- a/src/ltc/pk/ecc/ecc_encrypt_key.c +++ b/src/ltc/pk/ecc/ecc_encrypt_key.c @@ -7,7 +7,7 @@ * guarantee it works. */ -#include "tomcrypt.h" +#include "tomcrypt_private.h" /** @file ecc_encrypt_key.c @@ -43,11 +43,6 @@ int ecc_encrypt_key(const unsigned char *in, unsigned long inlen, LTC_ARGCHK(outlen != NULL); LTC_ARGCHK(key != NULL); - /* check that wprng/cipher/hash are not invalid */ - if ((err = prng_is_valid(wprng)) != CRYPT_OK) { - return err; - } - if ((err = hash_is_valid(hash)) != CRYPT_OK) { return err; } diff --git a/src/ltc/pk/ecc/ecc_export.c b/src/ltc/pk/ecc/ecc_export.c index eab854a5..268e4306 100644 --- a/src/ltc/pk/ecc/ecc_export.c +++ b/src/ltc/pk/ecc/ecc_export.c @@ -7,7 +7,7 @@ * guarantee it works. */ -#include "tomcrypt.h" +#include "tomcrypt_private.h" /** @file ecc_export.c diff --git a/src/ltc/pk/ecc/ecc_export_openssl.c b/src/ltc/pk/ecc/ecc_export_openssl.c index 4f47dd39..08056fea 100644 --- a/src/ltc/pk/ecc/ecc_export_openssl.c +++ b/src/ltc/pk/ecc/ecc_export_openssl.c @@ -7,7 +7,7 @@ * guarantee it works. */ -#include "tomcrypt.h" +#include "tomcrypt_private.h" #ifdef LTC_MECC diff --git a/src/ltc/pk/ecc/ecc_free.c b/src/ltc/pk/ecc/ecc_free.c index 47d31297..d15709e9 100644 --- a/src/ltc/pk/ecc/ecc_free.c +++ b/src/ltc/pk/ecc/ecc_free.c @@ -7,7 +7,7 @@ * guarantee it works. */ -#include "tomcrypt.h" +#include "tomcrypt_private.h" /** @file ecc_free.c diff --git a/src/ltc/pk/ecc/ecc_get_curve.c b/src/ltc/pk/ecc/ecc_get_curve.c index 7f038621..a2f52b0a 100644 --- a/src/ltc/pk/ecc/ecc_get_curve.c +++ b/src/ltc/pk/ecc/ecc_get_curve.c @@ -7,7 +7,7 @@ * guarantee it works. */ -#include "tomcrypt.h" +#include "tomcrypt_private.h" #ifdef LTC_MECC diff --git a/src/ltc/pk/ecc/ecc_get_key.c b/src/ltc/pk/ecc/ecc_get_key.c index 2154e7f5..abae6da1 100644 --- a/src/ltc/pk/ecc/ecc_get_key.c +++ b/src/ltc/pk/ecc/ecc_get_key.c @@ -7,7 +7,7 @@ * guarantee it works. */ -#include "tomcrypt.h" +#include "tomcrypt_private.h" #ifdef LTC_MECC diff --git a/src/ltc/pk/ecc/ecc_get_oid_str.c b/src/ltc/pk/ecc/ecc_get_oid_str.c new file mode 100644 index 00000000..70386c62 --- /dev/null +++ b/src/ltc/pk/ecc/ecc_get_oid_str.c @@ -0,0 +1,32 @@ +/* LibTomCrypt, modular cryptographic library -- Tom St Denis + * + * LibTomCrypt is a library that provides various cryptographic + * algorithms in a highly modular and flexible manner. + * + * The library is free for all purposes without any express + * guarantee it works. + */ + +#include "tomcrypt_private.h" + +#ifdef LTC_MECC + +/** Extract OID as a string from ECC key + @param out [out] destination buffer + @param outlen [in/out] Length of destination buffer and final output size (without terminating NUL byte) + @param key The ECC key + Return CRYPT_OK on success +*/ + +int ecc_get_oid_str(char *out, unsigned long *outlen, const ecc_key *key) +{ + LTC_ARGCHK(key != NULL); + + return pk_oid_num_to_str(key->dp.oid, key->dp.oidlen, out, outlen); +} + +#endif + +/* ref: $Format:%D$ */ +/* git commit: $Format:%H$ */ +/* commit time: $Format:%ai$ */ diff --git a/src/ltc/pk/ecc/ecc_get_size.c b/src/ltc/pk/ecc/ecc_get_size.c index 3f5810cc..3dada78a 100644 --- a/src/ltc/pk/ecc/ecc_get_size.c +++ b/src/ltc/pk/ecc/ecc_get_size.c @@ -7,7 +7,7 @@ * guarantee it works. */ -#include "tomcrypt.h" +#include "tomcrypt_private.h" /** @file ecc_get_size.c diff --git a/src/ltc/pk/ecc/ecc_import.c b/src/ltc/pk/ecc/ecc_import.c index 6deea284..e691add5 100644 --- a/src/ltc/pk/ecc/ecc_import.c +++ b/src/ltc/pk/ecc/ecc_import.c @@ -7,7 +7,7 @@ * guarantee it works. */ -#include "tomcrypt.h" +#include "tomcrypt_private.h" /** @file ecc_import.c diff --git a/src/ltc/pk/ecc/ecc_import_openssl.c b/src/ltc/pk/ecc/ecc_import_openssl.c index a9e25a6b..bf34c080 100644 --- a/src/ltc/pk/ecc/ecc_import_openssl.c +++ b/src/ltc/pk/ecc/ecc_import_openssl.c @@ -7,7 +7,7 @@ * guarantee it works. */ -#include "tomcrypt.h" +#include "tomcrypt_private.h" #ifdef LTC_MECC @@ -149,9 +149,8 @@ int ecc_import_openssl(const unsigned char *in, unsigned long inlen, ecc_key *ke goto success; } - /* ### 5. backward compatibility - try to load old-DER format */ - - if ((err = ecc_import(in, inlen, key)) != CRYPT_OK) { goto error; } + /* ### 5. all attempts failed */ + goto error; success: err = CRYPT_OK; diff --git a/src/ltc/pk/ecc/ecc_import_pkcs8.c b/src/ltc/pk/ecc/ecc_import_pkcs8.c index 8097eab6..4bf9fbcf 100644 --- a/src/ltc/pk/ecc/ecc_import_pkcs8.c +++ b/src/ltc/pk/ecc/ecc_import_pkcs8.c @@ -7,7 +7,7 @@ * guarantee it works. */ -#include "tomcrypt.h" +#include "tomcrypt_private.h" #ifdef LTC_MECC diff --git a/src/ltc/pk/ecc/ecc_import_x509.c b/src/ltc/pk/ecc/ecc_import_x509.c index e57b156f..1427e982 100644 --- a/src/ltc/pk/ecc/ecc_import_x509.c +++ b/src/ltc/pk/ecc/ecc_import_x509.c @@ -6,7 +6,7 @@ * The library is free for all purposes without any express * guarantee it works. */ -#include "tomcrypt.h" +#include "tomcrypt_private.h" #ifdef LTC_MECC diff --git a/src/ltc/pk/ecc/ecc_make_key.c b/src/ltc/pk/ecc/ecc_make_key.c index 16660174..da595850 100644 --- a/src/ltc/pk/ecc/ecc_make_key.c +++ b/src/ltc/pk/ecc/ecc_make_key.c @@ -7,7 +7,7 @@ * guarantee it works. */ -#include "tomcrypt.h" +#include "tomcrypt_private.h" /** @file ecc_make_key.c @@ -49,11 +49,6 @@ int ecc_generate_key(prng_state *prng, int wprng, ecc_key *key) LTC_ARGCHK(key != NULL); LTC_ARGCHK(key->dp.size > 0); - /* good prng? */ - if ((err = prng_is_valid(wprng)) != CRYPT_OK) { - return err; - } - /* ECC key pair generation according to FIPS-186-4 (B.4.2 Key Pair Generation by Testing Candidates): * the generated private key k should be the range [1, order-1] * a/ N = bitlen(order) diff --git a/src/ltc/pk/ecc/ecc_set_dp.c b/src/ltc/pk/ecc/ecc_set_dp.c index cecca68d..4c4f4877 100644 --- a/src/ltc/pk/ecc/ecc_set_dp.c +++ b/src/ltc/pk/ecc/ecc_set_dp.c @@ -7,7 +7,7 @@ * guarantee it works. */ -#include "tomcrypt.h" +#include "tomcrypt_private.h" #ifdef LTC_MECC diff --git a/src/ltc/pk/ecc/ecc_set_dp_internal.c b/src/ltc/pk/ecc/ecc_set_dp_internal.c index eca70313..cf9020bf 100644 --- a/src/ltc/pk/ecc/ecc_set_dp_internal.c +++ b/src/ltc/pk/ecc/ecc_set_dp_internal.c @@ -7,7 +7,7 @@ * guarantee it works. */ -#include "tomcrypt.h" +#include "tomcrypt_private.h" #ifdef LTC_MECC diff --git a/src/ltc/pk/ecc/ecc_set_key.c b/src/ltc/pk/ecc/ecc_set_key.c index 9fabcf2e..75e047b7 100644 --- a/src/ltc/pk/ecc/ecc_set_key.c +++ b/src/ltc/pk/ecc/ecc_set_key.c @@ -7,7 +7,7 @@ * guarantee it works. */ -#include "tomcrypt.h" +#include "tomcrypt_private.h" #ifdef LTC_MECC diff --git a/src/ltc/pk/ecc/ecc_shared_secret.c b/src/ltc/pk/ecc/ecc_shared_secret.c index afb86919..bdefd021 100644 --- a/src/ltc/pk/ecc/ecc_shared_secret.c +++ b/src/ltc/pk/ecc/ecc_shared_secret.c @@ -7,7 +7,7 @@ * guarantee it works. */ -#include "tomcrypt.h" +#include "tomcrypt_private.h" /** @file ecc_shared_secret.c diff --git a/src/ltc/pk/ecc/ecc_sign_hash.c b/src/ltc/pk/ecc/ecc_sign_hash.c index 027ad7af..360807ec 100644 --- a/src/ltc/pk/ecc/ecc_sign_hash.c +++ b/src/ltc/pk/ecc/ecc_sign_hash.c @@ -7,7 +7,7 @@ * guarantee it works. */ -#include "tomcrypt.h" +#include "tomcrypt_private.h" #ifdef LTC_MECC @@ -36,10 +36,6 @@ static int _ecc_sign_hash(const unsigned char *in, unsigned long inlen, return CRYPT_PK_NOT_PRIVATE; } - if ((err = prng_is_valid(wprng)) != CRYPT_OK) { - return err; - } - /* init the bignums */ if ((err = mp_init_multi(&r, &s, &e, NULL)) != CRYPT_OK) { return err; diff --git a/src/ltc/pk/ecc/ecc_sizes.c b/src/ltc/pk/ecc/ecc_sizes.c index 165c849c..f57f02b5 100644 --- a/src/ltc/pk/ecc/ecc_sizes.c +++ b/src/ltc/pk/ecc/ecc_sizes.c @@ -7,7 +7,7 @@ * guarantee it works. */ -#include "tomcrypt.h" +#include "tomcrypt_private.h" /** @file ecc_sizes.c diff --git a/src/ltc/pk/ecc/ecc_verify_hash.c b/src/ltc/pk/ecc/ecc_verify_hash.c index 5127953a..f2a58940 100644 --- a/src/ltc/pk/ecc/ecc_verify_hash.c +++ b/src/ltc/pk/ecc/ecc_verify_hash.c @@ -7,7 +7,7 @@ * guarantee it works. */ -#include "tomcrypt.h" +#include "tomcrypt_private.h" #ifdef LTC_MECC diff --git a/src/ltc/pk/ecc/ltc_ecc_export_point.c b/src/ltc/pk/ecc/ltc_ecc_export_point.c index 84750c80..c64e6b60 100644 --- a/src/ltc/pk/ecc/ltc_ecc_export_point.c +++ b/src/ltc/pk/ecc/ltc_ecc_export_point.c @@ -7,7 +7,7 @@ * guarantee it works. */ -#include "tomcrypt.h" +#include "tomcrypt_private.h" #ifdef LTC_MECC diff --git a/src/ltc/pk/ecc/ltc_ecc_import_point.c b/src/ltc/pk/ecc/ltc_ecc_import_point.c index 7e103f47..2b776f6e 100644 --- a/src/ltc/pk/ecc/ltc_ecc_import_point.c +++ b/src/ltc/pk/ecc/ltc_ecc_import_point.c @@ -7,7 +7,7 @@ * guarantee it works. */ -#include "tomcrypt.h" +#include "tomcrypt_private.h" #ifdef LTC_MECC diff --git a/src/ltc/pk/ecc/ltc_ecc_is_point.c b/src/ltc/pk/ecc/ltc_ecc_is_point.c index 46e1a6d4..efd954b8 100644 --- a/src/ltc/pk/ecc/ltc_ecc_is_point.c +++ b/src/ltc/pk/ecc/ltc_ecc_is_point.c @@ -7,7 +7,7 @@ * guarantee it works. */ -#include "tomcrypt.h" +#include "tomcrypt_private.h" #ifdef LTC_MECC diff --git a/src/ltc/pk/ecc/ltc_ecc_is_point_at_infinity.c b/src/ltc/pk/ecc/ltc_ecc_is_point_at_infinity.c index faf7631d..85bd47a1 100644 --- a/src/ltc/pk/ecc/ltc_ecc_is_point_at_infinity.c +++ b/src/ltc/pk/ecc/ltc_ecc_is_point_at_infinity.c @@ -7,7 +7,7 @@ * guarantee it works. */ -#include "tomcrypt.h" +#include "tomcrypt_private.h" #ifdef LTC_MECC diff --git a/src/ltc/pk/ecc/ltc_ecc_map.c b/src/ltc/pk/ecc/ltc_ecc_map.c index 3c57019f..14ec47e2 100644 --- a/src/ltc/pk/ecc/ltc_ecc_map.c +++ b/src/ltc/pk/ecc/ltc_ecc_map.c @@ -7,7 +7,7 @@ * guarantee it works. */ -#include "tomcrypt.h" +#include "tomcrypt_private.h" /** @file ltc_ecc_map.c diff --git a/src/ltc/pk/ecc/ltc_ecc_mul2add.c b/src/ltc/pk/ecc/ltc_ecc_mul2add.c index a2dcf5f2..c9913ff3 100644 --- a/src/ltc/pk/ecc/ltc_ecc_mul2add.c +++ b/src/ltc/pk/ecc/ltc_ecc_mul2add.c @@ -7,7 +7,7 @@ * guarantee it works. */ -#include "tomcrypt.h" +#include "tomcrypt_private.h" /** @file ltc_ecc_mul2add.c diff --git a/src/ltc/pk/ecc/ltc_ecc_mulmod.c b/src/ltc/pk/ecc/ltc_ecc_mulmod.c index ec8ba9cf..d6f038d3 100644 --- a/src/ltc/pk/ecc/ltc_ecc_mulmod.c +++ b/src/ltc/pk/ecc/ltc_ecc_mulmod.c @@ -7,7 +7,7 @@ * guarantee it works. */ -#include "tomcrypt.h" +#include "tomcrypt_private.h" /** @file ltc_ecc_mulmod.c diff --git a/src/ltc/pk/ecc/ltc_ecc_mulmod_timing.c b/src/ltc/pk/ecc/ltc_ecc_mulmod_timing.c index 9ff37d83..a10285d1 100644 --- a/src/ltc/pk/ecc/ltc_ecc_mulmod_timing.c +++ b/src/ltc/pk/ecc/ltc_ecc_mulmod_timing.c @@ -7,7 +7,7 @@ * guarantee it works. */ -#include "tomcrypt.h" +#include "tomcrypt_private.h" /** @file ltc_ecc_mulmod_timing.c diff --git a/src/ltc/pk/ecc/ltc_ecc_points.c b/src/ltc/pk/ecc/ltc_ecc_points.c index 4a890fdc..cf029db4 100644 --- a/src/ltc/pk/ecc/ltc_ecc_points.c +++ b/src/ltc/pk/ecc/ltc_ecc_points.c @@ -7,7 +7,7 @@ * guarantee it works. */ -#include "tomcrypt.h" +#include "tomcrypt_private.h" /** @file ltc_ecc_points.c diff --git a/src/ltc/pk/ecc/ltc_ecc_projective_add_point.c b/src/ltc/pk/ecc/ltc_ecc_projective_add_point.c index eff35c93..8bd91c13 100644 --- a/src/ltc/pk/ecc/ltc_ecc_projective_add_point.c +++ b/src/ltc/pk/ecc/ltc_ecc_projective_add_point.c @@ -7,7 +7,7 @@ * guarantee it works. */ -#include "tomcrypt.h" +#include "tomcrypt_private.h" /** @file ltc_ecc_projective_add_point.c diff --git a/src/ltc/pk/ecc/ltc_ecc_projective_dbl_point.c b/src/ltc/pk/ecc/ltc_ecc_projective_dbl_point.c index 1b46457b..da6d5150 100644 --- a/src/ltc/pk/ecc/ltc_ecc_projective_dbl_point.c +++ b/src/ltc/pk/ecc/ltc_ecc_projective_dbl_point.c @@ -7,7 +7,7 @@ * guarantee it works. */ -#include "tomcrypt.h" +#include "tomcrypt_private.h" /* ### Point doubling in Jacobian coordinate system ### * diff --git a/src/ltc/pk/ecc/ltc_ecc_verify_key.c b/src/ltc/pk/ecc/ltc_ecc_verify_key.c index 3d763415..b75af104 100644 --- a/src/ltc/pk/ecc/ltc_ecc_verify_key.c +++ b/src/ltc/pk/ecc/ltc_ecc_verify_key.c @@ -7,7 +7,7 @@ * guarantee it works. */ -#include "tomcrypt.h" +#include "tomcrypt_private.h" /* origin of this code - OLPC */ |