diff options
author | gregor herrmann <gregoa@debian.org> | 2020-02-03 14:40:08 +0100 |
---|---|---|
committer | gregor herrmann <gregoa@debian.org> | 2020-02-03 14:40:08 +0100 |
commit | ec4052bb7a24e8c6a205aff978130401d77834be (patch) | |
tree | 1c2dc45692c6a4fb3fb6620bffb6f7c558746c39 /src | |
parent | 5e6f4cc496e693139420e6b7883c1489cbf27a2a (diff) | |
parent | 8adbf26faac651d79f6b5a78952b2ef39de5c9a0 (diff) |
New upstream version 0.067
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile | 6 | ||||
-rw-r--r-- | src/Makefile.nmake | 8 | ||||
-rw-r--r-- | src/ltc/headers/tomcrypt_mac.h | 1 | ||||
-rw-r--r-- | src/ltc/headers/tomcrypt_pk.h | 10 | ||||
-rw-r--r-- | src/ltc/math/ltm_desc.c | 12 | ||||
-rw-r--r-- | src/ltc/pk/ed25519/ed25519_import.c | 2 | ||||
-rw-r--r-- | src/ltc/pk/ed25519/ed25519_import_raw.c | 51 | ||||
-rw-r--r-- | src/ltc/pk/ed25519/ed25519_set_key.c | 65 | ||||
-rw-r--r-- | src/ltc/pk/x25519/x25519_import.c | 14 | ||||
-rw-r--r-- | src/ltc/pk/x25519/x25519_import_raw.c | 51 | ||||
-rw-r--r-- | src/ltc/pk/x25519/x25519_set_key.c | 65 |
11 files changed, 124 insertions, 161 deletions
diff --git a/src/Makefile b/src/Makefile index 4f7da679..83ec0217 100644 --- a/src/Makefile +++ b/src/Makefile @@ -119,8 +119,8 @@ ltc/pk/ecc/ltc_ecc_is_point_at_infinity.o ltc/pk/ecc/ltc_ecc_map.o ltc/pk/ecc/lt ltc/pk/ecc/ltc_ecc_mulmod.o ltc/pk/ecc/ltc_ecc_mulmod_timing.o ltc/pk/ecc/ltc_ecc_points.o \ ltc/pk/ecc/ltc_ecc_projective_add_point.o ltc/pk/ecc/ltc_ecc_projective_dbl_point.o \ ltc/pk/ecc/ltc_ecc_verify_key.o ltc/pk/ed25519/ed25519_export.o ltc/pk/ed25519/ed25519_import.o \ -ltc/pk/ed25519/ed25519_import_pkcs8.o ltc/pk/ed25519/ed25519_import_x509.o ltc/pk/ed25519/ed25519_make_key.o \ -ltc/pk/ed25519/ed25519_set_key.o ltc/pk/ed25519/ed25519_sign.o ltc/pk/ed25519/ed25519_verify.o \ +ltc/pk/ed25519/ed25519_import_pkcs8.o ltc/pk/ed25519/ed25519_import_raw.o ltc/pk/ed25519/ed25519_import_x509.o \ +ltc/pk/ed25519/ed25519_make_key.o ltc/pk/ed25519/ed25519_sign.o ltc/pk/ed25519/ed25519_verify.o \ ltc/pk/pkcs1/pkcs_1_i2osp.o ltc/pk/pkcs1/pkcs_1_mgf1.o ltc/pk/pkcs1/pkcs_1_oaep_decode.o \ ltc/pk/pkcs1/pkcs_1_oaep_encode.o ltc/pk/pkcs1/pkcs_1_os2ip.o ltc/pk/pkcs1/pkcs_1_pss_decode.o \ ltc/pk/pkcs1/pkcs_1_pss_encode.o ltc/pk/pkcs1/pkcs_1_v1_5_decode.o ltc/pk/pkcs1/pkcs_1_v1_5_encode.o \ @@ -129,7 +129,7 @@ ltc/pk/rsa/rsa_exptmod.o ltc/pk/rsa/rsa_get_size.o ltc/pk/rsa/rsa_import.o ltc/p ltc/pk/rsa/rsa_import_x509.o ltc/pk/rsa/rsa_key.o ltc/pk/rsa/rsa_make_key.o ltc/pk/rsa/rsa_set.o \ ltc/pk/rsa/rsa_sign_hash.o ltc/pk/rsa/rsa_sign_saltlen_get.o ltc/pk/rsa/rsa_verify_hash.o \ ltc/pk/x25519/x25519_export.o ltc/pk/x25519/x25519_import.o ltc/pk/x25519/x25519_import_pkcs8.o \ -ltc/pk/x25519/x25519_import_x509.o ltc/pk/x25519/x25519_make_key.o ltc/pk/x25519/x25519_set_key.o \ +ltc/pk/x25519/x25519_import_raw.o ltc/pk/x25519/x25519_import_x509.o ltc/pk/x25519/x25519_make_key.o \ ltc/pk/x25519/x25519_shared_secret.o ltc/prngs/chacha20.o ltc/prngs/fortuna.o ltc/prngs/rc4.o \ ltc/prngs/rng_get_bytes.o ltc/prngs/rng_make_prng.o ltc/prngs/sober128.o ltc/prngs/sprng.o \ ltc/prngs/yarrow.o ltc/stream/chacha/chacha_crypt.o ltc/stream/chacha/chacha_done.o \ diff --git a/src/Makefile.nmake b/src/Makefile.nmake index 3762335a..8ef804c4 100644 --- a/src/Makefile.nmake +++ b/src/Makefile.nmake @@ -126,8 +126,8 @@ ltc/pk/ecc/ltc_ecc_is_point_at_infinity.obj ltc/pk/ecc/ltc_ecc_map.obj ltc/pk/ec ltc/pk/ecc/ltc_ecc_mulmod.obj ltc/pk/ecc/ltc_ecc_mulmod_timing.obj ltc/pk/ecc/ltc_ecc_points.obj \ ltc/pk/ecc/ltc_ecc_projective_add_point.obj ltc/pk/ecc/ltc_ecc_projective_dbl_point.obj \ ltc/pk/ecc/ltc_ecc_verify_key.obj ltc/pk/ed25519/ed25519_export.obj ltc/pk/ed25519/ed25519_import.obj \ -ltc/pk/ed25519/ed25519_import_pkcs8.obj ltc/pk/ed25519/ed25519_import_x509.obj ltc/pk/ed25519/ed25519_make_key.obj \ -ltc/pk/ed25519/ed25519_set_key.obj ltc/pk/ed25519/ed25519_sign.obj ltc/pk/ed25519/ed25519_verify.obj \ +ltc/pk/ed25519/ed25519_import_pkcs8.obj ltc/pk/ed25519/ed25519_import_raw.obj ltc/pk/ed25519/ed25519_import_x509.obj \ +ltc/pk/ed25519/ed25519_make_key.obj ltc/pk/ed25519/ed25519_sign.obj ltc/pk/ed25519/ed25519_verify.obj \ ltc/pk/pkcs1/pkcs_1_i2osp.obj ltc/pk/pkcs1/pkcs_1_mgf1.obj ltc/pk/pkcs1/pkcs_1_oaep_decode.obj \ ltc/pk/pkcs1/pkcs_1_oaep_encode.obj ltc/pk/pkcs1/pkcs_1_os2ip.obj ltc/pk/pkcs1/pkcs_1_pss_decode.obj \ ltc/pk/pkcs1/pkcs_1_pss_encode.obj ltc/pk/pkcs1/pkcs_1_v1_5_decode.obj ltc/pk/pkcs1/pkcs_1_v1_5_encode.obj \ @@ -136,8 +136,8 @@ ltc/pk/rsa/rsa_exptmod.obj ltc/pk/rsa/rsa_get_size.obj ltc/pk/rsa/rsa_import.obj ltc/pk/rsa/rsa_import_pkcs8.obj ltc/pk/rsa/rsa_import_x509.obj ltc/pk/rsa/rsa_key.obj \ ltc/pk/rsa/rsa_make_key.obj ltc/pk/rsa/rsa_set.obj ltc/pk/rsa/rsa_sign_hash.obj ltc/pk/rsa/rsa_sign_saltlen_get.obj \ ltc/pk/rsa/rsa_verify_hash.obj ltc/pk/x25519/x25519_export.obj ltc/pk/x25519/x25519_import.obj \ -ltc/pk/x25519/x25519_import_pkcs8.obj ltc/pk/x25519/x25519_import_x509.obj ltc/pk/x25519/x25519_make_key.obj \ -ltc/pk/x25519/x25519_set_key.obj ltc/pk/x25519/x25519_shared_secret.obj ltc/prngs/chacha20.obj \ +ltc/pk/x25519/x25519_import_pkcs8.obj ltc/pk/x25519/x25519_import_raw.obj ltc/pk/x25519/x25519_import_x509.obj \ +ltc/pk/x25519/x25519_make_key.obj ltc/pk/x25519/x25519_shared_secret.obj ltc/prngs/chacha20.obj \ ltc/prngs/fortuna.obj ltc/prngs/rc4.obj ltc/prngs/rng_get_bytes.obj ltc/prngs/rng_make_prng.obj \ ltc/prngs/sober128.obj ltc/prngs/sprng.obj ltc/prngs/yarrow.obj ltc/stream/chacha/chacha_crypt.obj \ ltc/stream/chacha/chacha_done.obj ltc/stream/chacha/chacha_ivctr32.obj ltc/stream/chacha/chacha_ivctr64.obj \ diff --git a/src/ltc/headers/tomcrypt_mac.h b/src/ltc/headers/tomcrypt_mac.h index cafb9a09..4b46a38d 100644 --- a/src/ltc/headers/tomcrypt_mac.h +++ b/src/ltc/headers/tomcrypt_mac.h @@ -11,7 +11,6 @@ typedef struct Hmac_state { hash_state md; int hash; - hash_state hashstate; unsigned char key[MAXBLOCKSIZE]; } hmac_state; diff --git a/src/ltc/headers/tomcrypt_pk.h b/src/ltc/headers/tomcrypt_pk.h index a58e6000..050e1393 100644 --- a/src/ltc/headers/tomcrypt_pk.h +++ b/src/ltc/headers/tomcrypt_pk.h @@ -349,15 +349,12 @@ typedef struct { /** Ed25519 Signature API */ int ed25519_make_key(prng_state *prng, int wprng, curve25519_key *key); -int ed25519_set_key(const unsigned char *sk, unsigned long sklen, - const unsigned char *pk, unsigned long pklen, - curve25519_key *key); - int ed25519_export( unsigned char *out, unsigned long *outlen, int which, const curve25519_key *key); int ed25519_import(const unsigned char *in, unsigned long inlen, curve25519_key *key); +int ed25519_import_raw(const unsigned char *in, unsigned long inlen, int which, curve25519_key *key); int ed25519_import_x509(const unsigned char *in, unsigned long inlen, curve25519_key *key); int ed25519_import_pkcs8(const unsigned char *in, unsigned long inlen, const void *pwd, unsigned long pwdlen, @@ -374,15 +371,12 @@ int ed25519_verify(const unsigned char *msg, unsigned long msglen, /** X25519 Key-Exchange API */ int x25519_make_key(prng_state *prng, int wprng, curve25519_key *key); -int x25519_set_key(const unsigned char *k, unsigned long klen, - const unsigned char *u, unsigned long ulen, - curve25519_key *key); - int x25519_export( unsigned char *out, unsigned long *outlen, int which, const curve25519_key *key); int x25519_import(const unsigned char *in, unsigned long inlen, curve25519_key *key); +int x25519_import_raw(const unsigned char *in, unsigned long inlen, int which, curve25519_key *key); int x25519_import_x509(const unsigned char *in, unsigned long inlen, curve25519_key *key); int x25519_import_pkcs8(const unsigned char *in, unsigned long inlen, const void *pwd, unsigned long pwdlen, diff --git a/src/ltc/math/ltm_desc.c b/src/ltc/math/ltm_desc.c index 432ab5b8..2ff71adb 100644 --- a/src/ltc/math/ltm_desc.c +++ b/src/ltc/math/ltm_desc.c @@ -13,6 +13,9 @@ #ifdef LTM_DESC #include <tommath.h> +#if !defined(PRIVATE_MP_WARRAY) && !defined(BN_MP_PRIME_IS_PRIME_C) +#include <stdbool.h> +#endif static const struct { mp_err mpi_code; @@ -447,11 +450,16 @@ static int exptmod(void *a, void *b, void *c, void *d) static int isprime(void *a, int b, int *c) { int err; +#if defined(PRIVATE_MP_WARRAY) || defined(BN_MP_PRIME_IS_PRIME_C) + int res; +#else + bool res; +#endif LTC_ARGCHK(a != NULL); LTC_ARGCHK(c != NULL); b = mp_prime_rabin_miller_trials(mp_count_bits(a)); - err = mpi_to_ltc_error(mp_prime_is_prime(a, b, c)); - *c = (*c == MP_YES) ? LTC_MP_YES : LTC_MP_NO; + err = mpi_to_ltc_error(mp_prime_is_prime(a, b, &res)); + *c = res ? LTC_MP_YES : LTC_MP_NO; return err; } diff --git a/src/ltc/pk/ed25519/ed25519_import.c b/src/ltc/pk/ed25519/ed25519_import.c index e9a05927..069bd240 100644 --- a/src/ltc/pk/ed25519/ed25519_import.c +++ b/src/ltc/pk/ed25519/ed25519_import.c @@ -10,7 +10,7 @@ /** @file ed25519_import.c - Import a Ed25519 key from a binary packet, Steffen Jaeckel + Import a Ed25519 key from a SubjectPublicKeyInfo, Steffen Jaeckel */ #ifdef LTC_CURVE25519 diff --git a/src/ltc/pk/ed25519/ed25519_import_raw.c b/src/ltc/pk/ed25519/ed25519_import_raw.c new file mode 100644 index 00000000..b717ef1d --- /dev/null +++ b/src/ltc/pk/ed25519/ed25519_import_raw.c @@ -0,0 +1,51 @@ +/* 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" + +/** + @file ed25519_import_raw.c + Set the parameters of an Ed25519 key, Steffen Jaeckel +*/ + +#ifdef LTC_CURVE25519 + +/** + Set the parameters of an Ed25519 key + + @param in The key + @param inlen The length of the key + @param which Which type of key (PK_PRIVATE or PK_PUBLIC) + @param key [out] Destination of the key + @return CRYPT_OK if successful +*/ +int ed25519_import_raw(const unsigned char *in, unsigned long inlen, int which, curve25519_key *key) +{ + LTC_ARGCHK(in != NULL); + LTC_ARGCHK(inlen == 32uL); + LTC_ARGCHK(key != NULL); + + if (which == PK_PRIVATE) { + XMEMCPY(key->priv, in, sizeof(key->priv)); + tweetnacl_crypto_sk_to_pk(key->pub, key->priv); + } else if (which == PK_PUBLIC) { + XMEMCPY(key->pub, in, sizeof(key->pub)); + } else { + return CRYPT_INVALID_ARG; + } + key->algo = PKA_ED25519; + key->type = which; + + return CRYPT_OK; +} + +#endif + +/* ref: $Format:%D$ */ +/* git commit: $Format:%H$ */ +/* commit time: $Format:%ai$ */ diff --git a/src/ltc/pk/ed25519/ed25519_set_key.c b/src/ltc/pk/ed25519/ed25519_set_key.c deleted file mode 100644 index de68e69d..00000000 --- a/src/ltc/pk/ed25519/ed25519_set_key.c +++ /dev/null @@ -1,65 +0,0 @@ -/* 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" - -/** - @file ed25519_set_ku.c - Set the parameters of an Ed25519 key, Steffen Jaeckel -*/ - -#ifdef LTC_CURVE25519 - -/** - Set the parameters of an Ed25519 key - - In case sk and pk are given it is validated that pk is really the - corresponding public part of the key pair. - - @param sk The secret key - @param sklen The length of sk - @param pk The public key - @param pklen The length of pk - @param key [out] Destination of the key - @return CRYPT_OK if successful -*/ -int ed25519_set_key(const unsigned char *sk, unsigned long sklen, - const unsigned char *pk, unsigned long pklen, - curve25519_key *key) -{ - LTC_ARGCHK(key != NULL); - - if (sk != NULL) { - LTC_ARGCHK(sklen == 32uL); - XMEMCPY(key->priv, sk, sizeof(key->priv)); - tweetnacl_crypto_sk_to_pk(key->pub, key->priv); - if (pk != NULL) { - LTC_ARGCHK(pklen == 32uL); - if (XMEM_NEQ(pk, key->pub, sizeof(key->pub)) != 0) { - zeromem(key, sizeof(*key)); - return CRYPT_INVALID_ARG; - } - } - key->type = PK_PRIVATE; - } else if (pk != NULL) { - LTC_ARGCHK(pklen == 32uL); - XMEMCPY(key->pub, pk, sizeof(key->pub)); - key->type = PK_PUBLIC; - } else { - return CRYPT_INVALID_ARG; - } - key->algo = PKA_ED25519; - - return CRYPT_OK; -} - -#endif - -/* ref: $Format:%D$ */ -/* git commit: $Format:%H$ */ -/* commit time: $Format:%ai$ */ diff --git a/src/ltc/pk/x25519/x25519_import.c b/src/ltc/pk/x25519/x25519_import.c index f62b383c..65185637 100644 --- a/src/ltc/pk/x25519/x25519_import.c +++ b/src/ltc/pk/x25519/x25519_import.c @@ -10,13 +10,13 @@ /** @file x25519_import.c - Import a X25519 key from a binary packet, Steffen Jaeckel + Import a X25519 key from a SubjectPublicKeyInfo, Steffen Jaeckel */ #ifdef LTC_CURVE25519 /** - Import a X25519 key from a binary packet + Import a X25519 key @param in The packet to read @param inlen The length of the input packet @param key [out] Where to import the key to @@ -30,16 +30,6 @@ int x25519_import(const unsigned char *in, unsigned long inlen, curve25519_key * LTC_ARGCHK(in != NULL); LTC_ARGCHK(key != NULL); - /* There's only one case where the inlen is equal to the pubkey-size - * and that's a raw pubkey, so let's just do a raw import. - */ - if (inlen == sizeof(key->pub)) { - XMEMCPY(key->pub, in, sizeof(key->pub)); - key->type = PK_PUBLIC; - key->algo = PKA_X25519; - return CRYPT_OK; - } - key_len = sizeof(key->pub); if ((err = x509_decode_subject_public_key_info(in, inlen, PKA_X25519, key->pub, &key_len, LTC_ASN1_EOL, NULL, 0uL)) == CRYPT_OK) { key->type = PK_PUBLIC; diff --git a/src/ltc/pk/x25519/x25519_import_raw.c b/src/ltc/pk/x25519/x25519_import_raw.c new file mode 100644 index 00000000..01090850 --- /dev/null +++ b/src/ltc/pk/x25519/x25519_import_raw.c @@ -0,0 +1,51 @@ +/* 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" + +/** + @file x25519_import_raw.c + Set the parameters of a X25519 key, Steffen Jaeckel +*/ + +#ifdef LTC_CURVE25519 + +/** + Set the parameters of a X25519 key + + @param in The key + @param inlen The length of the key + @param which Which type of key (PK_PRIVATE or PK_PUBLIC) + @param key [out] Destination of the key + @return CRYPT_OK if successful +*/ +int x25519_import_raw(const unsigned char *in, unsigned long inlen, int which, curve25519_key *key) +{ + LTC_ARGCHK(in != NULL); + LTC_ARGCHK(inlen == 32uL); + LTC_ARGCHK(key != NULL); + + if (which == PK_PRIVATE) { + XMEMCPY(key->priv, in, sizeof(key->priv)); + tweetnacl_crypto_scalarmult_base(key->pub, key->priv); + } else if (which == PK_PUBLIC) { + XMEMCPY(key->pub, in, sizeof(key->pub)); + } else { + return CRYPT_INVALID_ARG; + } + key->algo = PKA_X25519; + key->type = which; + + return CRYPT_OK; +} + +#endif + +/* ref: $Format:%D$ */ +/* git commit: $Format:%H$ */ +/* commit time: $Format:%ai$ */ diff --git a/src/ltc/pk/x25519/x25519_set_key.c b/src/ltc/pk/x25519/x25519_set_key.c deleted file mode 100644 index df276e17..00000000 --- a/src/ltc/pk/x25519/x25519_set_key.c +++ /dev/null @@ -1,65 +0,0 @@ -/* 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" - -/** - @file x25519_set_ku.c - Set the parameters of a X25519 key, Steffen Jaeckel -*/ - -#ifdef LTC_CURVE25519 - -/** - Set the parameters of a X25519 key - - In case k and u are given it is validated that u is really the - corresponding public part of the key pair - - @param k The k value (a.k.a scalar or private part) - @param klen The length of k - @param u The u-coordinate (a.k.a public part) - @param ulen The length of u - @param key [out] Destination of the key - @return CRYPT_OK if successful -*/ -int x25519_set_key(const unsigned char *k, unsigned long klen, - const unsigned char *u, unsigned long ulen, - curve25519_key *key) -{ - LTC_ARGCHK(key != NULL); - - if (k != NULL) { - LTC_ARGCHK(klen == 32uL); - XMEMCPY(key->priv, k, sizeof(key->priv)); - tweetnacl_crypto_scalarmult_base(key->pub, key->priv); - if (u != NULL) { - LTC_ARGCHK(ulen == 32uL); - if (XMEM_NEQ(u, key->pub, sizeof(key->pub)) != 0) { - zeromem(key, sizeof(*key)); - return CRYPT_INVALID_ARG; - } - } - key->type = PK_PRIVATE; - } else if (u != NULL) { - LTC_ARGCHK(ulen == 32uL); - XMEMCPY(key->pub, u, sizeof(key->pub)); - key->type = PK_PUBLIC; - } else { - return CRYPT_INVALID_ARG; - } - key->algo = PKA_X25519; - - return CRYPT_OK; -} - -#endif - -/* ref: $Format:%D$ */ -/* git commit: $Format:%H$ */ -/* commit time: $Format:%ai$ */ |