瀏覽代碼

rename ed25519_set_key to ed25519_import_raw

Steffen Jaeckel 6 年之前
父節點
當前提交
44a18342ba
共有 4 個文件被更改,包括 54 次插入71 次删除
  1. 1 4
      src/headers/tomcrypt_pk.h
  2. 51 0
      src/pk/ed25519/ed25519_import_raw.c
  3. 0 65
      src/pk/ed25519/ed25519_set_key.c
  4. 2 2
      tests/ed25519_test.c

+ 1 - 4
src/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,

+ 51 - 0
src/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$ */

+ 0 - 65
src/pk/ed25519/ed25519_set_key.c

@@ -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$ */

+ 2 - 2
tests/ed25519_test.c

@@ -201,7 +201,7 @@ static int _rfc_8032_7_1_test(void)
       DO(base16_decode(rfc_8032_7_1[n].message, XSTRLEN(rfc_8032_7_1[n].message), msg, &mlen));
       siglen = sizeof(sig);
       DO(base16_decode(rfc_8032_7_1[n].signature, XSTRLEN(rfc_8032_7_1[n].signature), sig, &siglen));
-      DO(ed25519_set_key(sec, slen, pub, plen, &key));
+      DO(ed25519_import_raw(sec, slen, PK_PRIVATE, &key));
       buflen = sizeof(buf);
       DO(ed25519_sign(msg, mlen, buf, &buflen, &key));
       DO(do_compare_testvector(buf, buflen, sig, siglen, "Ed25519 RFC8032 7.1 - sign", n));
@@ -214,7 +214,7 @@ static int _rfc_8032_7_1_test(void)
       DO(base16_decode(rfc_8032_7_1[n].message, XSTRLEN(rfc_8032_7_1[n].message), msg, &mlen));
       siglen = sizeof(sig);
       DO(base16_decode(rfc_8032_7_1[n].signature, XSTRLEN(rfc_8032_7_1[n].signature), sig, &siglen));
-      DO(ed25519_set_key(NULL, 0, pub, plen, &key2));
+      DO(ed25519_import_raw(pub, plen, PK_PUBLIC, &key2));
       DO(ed25519_verify(msg, mlen, sig, siglen, &ret, &key2));
       DO(do_compare_testvector(&ret, sizeof(ret), &should, sizeof(should), "Ed25519 RFC8032 7.1 - verify w/ pubkey", n));