diff options
Diffstat (limited to 'src/ltc/pk')
-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 |
6 files changed, 105 insertions, 143 deletions
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$ */ |