pub/ed25519.c: Don't return the `h1' private-key portion if it's not wanted.
authorMark Wooding <mdw@distorted.org.uk>
Wed, 10 May 2017 20:17:27 +0000 (21:17 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 14 May 2017 13:58:42 +0000 (14:58 +0100)
Saves making a temporary buffer in `ed25519_pubkey'.

pub/ed25519.c

index 830e5de..4680a53 100644 (file)
@@ -389,7 +389,7 @@ static void unpack_key(scaf_piece a[NPIECE], octet h1[32],
   sha512_init(&h); sha512_hash(&h, k, ksz); sha512_done(&h, b);
   b[0] &= 0xf8u; b[31] = (b[31]&0x3f) | 0x40;
   scaf_load(a, b, 32, NPIECE, PIECEWD);
-  memcpy(h1, b + 32, 32);
+  if (h1) memcpy(h1, b + 32, 32);
 }
 
 /*----- Main code ---------------------------------------------------------*/
@@ -409,9 +409,8 @@ void ed25519_pubkey(octet K[ED25519_PUBSZ], const void *k, size_t ksz)
 {
   scaf_piece a[NPIECE];
   f25519 AX, AY, AZ;
-  octet h1[32];
 
-  unpack_key(a, h1, k, ksz);
+  unpack_key(a, 0, k, ksz);
   ptmul(&AX, &AY, &AZ, a, BX, BY, BZ);
   ptencode(K, &AX, &AY, &AZ);
 }