]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
crypto_format: Remove the return value from ed25519_signature_to_base64()
authorteor <teor@torproject.org>
Fri, 5 Apr 2019 05:08:54 +0000 (15:08 +1000)
committerteor <teor@torproject.org>
Fri, 5 Apr 2019 05:17:19 +0000 (15:17 +1000)
Also remove all checks for the return value, which were redundant anyway,
because the function never failed.

Part of 29660.

src/feature/hs/hs_descriptor.c
src/feature/relay/router.c
src/lib/crypt_ops/crypto_format.c
src/lib/crypt_ops/crypto_format.h
src/test/test_crypto.c
src/test/test_hs_descriptor.c

index 2793597028e8561174111707133f95f6f1c56161..b526da66612abdd316d9db9c2119a71b91f1afd4 100644 (file)
@@ -1082,11 +1082,7 @@ desc_encode_v3(const hs_descriptor_t *desc,
       tor_free(encoded_str);
       goto err;
     }
-    if (ed25519_signature_to_base64(ed_sig_b64, &sig) < 0) {
-      log_warn(LD_BUG, "Can't base64 encode descriptor signature!");
-      tor_free(encoded_str);
-      goto err;
-    }
+    ed25519_signature_to_base64(ed_sig_b64, &sig);
     /* Create the signature line. */
     smartlist_add_asprintf(lines, "%s %s", str_signature, ed_sig_b64);
   }
index 837465cfe938dc3dd44420a89a7b14b50379b883..ac4b3b7a024a01b936281d783f678b43cf055270 100644 (file)
@@ -2974,8 +2974,7 @@ router_dump_router_to_string(routerinfo_t *router,
     if (ed25519_sign(&sig, (const uint8_t*)digest, DIGEST256_LEN,
                      signing_keypair) < 0)
       goto err;
-    if (ed25519_signature_to_base64(buf, &sig) < 0)
-      goto err;
+    ed25519_signature_to_base64(buf, &sig);
 
     smartlist_add_asprintf(chunks, "%s\n", buf);
   }
@@ -3249,8 +3248,7 @@ extrainfo_dump_to_string(char **s_out, extrainfo_t *extrainfo,
     if (ed25519_sign(&ed_sig, (const uint8_t*)sha256_digest, DIGEST256_LEN,
                      signing_keypair) < 0)
       goto err;
-    if (ed25519_signature_to_base64(buf, &ed_sig) < 0)
-      goto err;
+    ed25519_signature_to_base64(buf, &ed_sig);
 
     smartlist_add_asprintf(chunks, "%s\n", buf);
   }
index 800f4ad5bc05c43fa0d10937d462f3fbde22d6cb..269e6d9da93e82a57342b7eda18f6957c35bfd19 100644 (file)
@@ -223,17 +223,20 @@ ed25519_public_to_base64(char *output,
 
 /** Encode the signature <b>sig</b> into the buffer at <b>output</b>,
  * which must have space for ED25519_SIG_BASE64_LEN bytes of encoded signature,
- * plus one byte for a terminating NUL.  Return 0 on success, -1 on failure.
+ * plus one byte for a terminating NUL.
+ * Can not fail.
  */
-int
+void
 ed25519_signature_to_base64(char *output,
                             const ed25519_signature_t *sig)
 {
   char buf[256];
   int n = base64_encode_nopad(buf, sizeof(buf), sig->sig, ED25519_SIG_LEN);
+  /* These asserts should always succeed, unless there is a bug in
+   * base64_encode_nopad(). */
   tor_assert(n == ED25519_SIG_BASE64_LEN);
+  tor_assert(buf[ED25519_SIG_BASE64_LEN] == '\0');
   memcpy(output, buf, ED25519_SIG_BASE64_LEN+1);
-  return 0;
 }
 
 /** Try to decode the string <b>input</b> into an ed25519 signature. On
index 41c2b06ec882e6070b1ca77eea4f5552c88e5a01..b4b3aa189c4b1b4da3789a4979ee8dd759ecc7ab 100644 (file)
@@ -39,8 +39,8 @@ const char *ed25519_fmt(const struct ed25519_public_key_t *pkey);
 
 int ed25519_signature_from_base64(struct ed25519_signature_t *sig,
                                   const char *input);
-int ed25519_signature_to_base64(char *output,
-                                const struct ed25519_signature_t *sig);
+void ed25519_signature_to_base64(char *output,
+                                 const struct ed25519_signature_t *sig);
 
 void digest_to_base64(char *d64, const char *digest);
 int digest_from_base64(char *digest, const char *d64);
index 5f53ba688ecb2e95ad55dc8ffc34dadc9da72882..08dfb6bcddce0e85fd282de0af164568040f8c3e 100644 (file)
@@ -2461,7 +2461,7 @@ test_crypto_ed25519_encode(void *arg)
   tt_mem_op(kp.pubkey.pubkey, OP_EQ, pk.pubkey, ED25519_PUBKEY_LEN);
 
   tt_int_op(0, OP_EQ, ed25519_sign(&sig1, (const uint8_t*)"ABC", 3, &kp));
-  tt_int_op(0, OP_EQ, ed25519_signature_to_base64(buf, &sig1));
+  ed25519_signature_to_base64(buf, &sig1);
   tt_int_op(0, OP_EQ, ed25519_signature_from_base64(&sig2, buf));
   tt_mem_op(sig1.sig, OP_EQ, sig2.sig, ED25519_SIG_LEN);
 
index 09c6c3e70023b82d71f99cc25676ac1572770668..86965d7d6698fd4eb4fda82d35cb12b2e9b21998 100644 (file)
@@ -739,8 +739,7 @@ test_desc_signature(void *arg)
   ret = ed25519_sign_prefixed(&sig, (const uint8_t *) data, strlen(data),
                               "Tor onion service descriptor sig v3", &kp);
   tt_int_op(ret, OP_EQ, 0);
-  ret = ed25519_signature_to_base64(sig_b64, &sig);
-  tt_int_op(ret, OP_EQ, 0);
+  ed25519_signature_to_base64(sig_b64, &sig);
   /* Build the descriptor that should be valid. */
   tor_asprintf(&desc, "%ssignature %s\n", data, sig_b64);
   ret = desc_sig_is_valid(sig_b64, &kp.pubkey, desc, strlen(desc));