mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-11 13:43:47 +01:00
crypto_format: Remove the return value from ed25519_signature_to_base64()
Also remove all checks for the return value, which were redundant anyway, because the function never failed. Part of 29660.
This commit is contained in:
parent
e3124fef54
commit
ce5e38642d
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user