Browse Source

fixup `x25519_import()`

bring x25519_import() in line with its ed25519 counterpart
Steffen Jaeckel 6 years ago
parent
commit
3540fd713c
3 changed files with 4 additions and 14 deletions
  1. 1 1
      src/pk/ed25519/ed25519_import.c
  2. 2 12
      src/pk/x25519/x25519_import.c
  3. 1 1
      tests/x25519_test.c

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

+ 2 - 12
src/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;

+ 1 - 1
tests/x25519_test.c

@@ -199,7 +199,7 @@ static int _x25519_compat_test(void)
 
    buflen = sizeof(buf);
    DO(x25519_export(buf, &buflen, PK_PUBLIC, &priv));
-   DO(x25519_import(buf, buflen, &pub));
+   DO(x25519_set_key(NULL, 0, buf, buflen, &pub));
 
    buflen = sizeof(buf);
    DO(x25519_export(buf, &buflen, PK_PUBLIC | PK_STD, &priv));