]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Make the EdDSA exact-length contract explicit
authorOndřej Surý <ondrej@isc.org>
Mon, 10 Aug 2026 14:44:09 +0000 (16:44 +0200)
committerOndřej Surý <ondrej@sury.org>
Wed, 12 Aug 2026 11:25:48 +0000 (13:25 +0200)
Now that raw_key_to_ossl() rejects anything but the exact key length,
passing the length by reference and writing it back on success only
obscures that contract.  Take the length by value and derive the
buffer bookkeeping from the algorithm's fixed key size.

lib/dns/openssleddsa_link.c

index 796975f1f633d5462de48198d6802f9665eda831..b77a11fd3fb845788a300fbdf234b4ce33a92b70 100644 (file)
@@ -77,13 +77,13 @@ openssleddsa_alg_info(unsigned int key_alg) {
 
 static isc_result_t
 raw_key_to_ossl(const eddsa_alginfo_t *alginfo, int private,
-               const unsigned char *key, size_t *key_len, EVP_PKEY **pkey) {
+               const unsigned char *key, size_t key_len, EVP_PKEY **pkey) {
        isc_result_t result;
        int pkey_type = alginfo->pkey_type;
        size_t len = alginfo->key_size;
 
        result = (private ? DST_R_INVALIDPRIVATEKEY : DST_R_INVALIDPUBLICKEY);
-       if (*key_len != len) {
+       if (key_len != len) {
                return result;
        }
 
@@ -96,7 +96,6 @@ raw_key_to_ossl(const eddsa_alginfo_t *alginfo, int private,
                return dst__openssl_toresult(result);
        }
 
-       *key_len = len;
        return ISC_R_SUCCESS;
 }
 
@@ -348,7 +347,6 @@ static isc_result_t
 openssleddsa_fromdns(dst_key_t *key, isc_buffer_t *data) {
        const eddsa_alginfo_t *alginfo = openssleddsa_alg_info(key->key_alg);
        isc_region_t r;
-       size_t len;
        EVP_PKEY *pkey = NULL;
 
        REQUIRE(alginfo != NULL);
@@ -358,12 +356,11 @@ openssleddsa_fromdns(dst_key_t *key, isc_buffer_t *data) {
                return ISC_R_SUCCESS;
        }
 
-       len = r.length;
-       RETERR(raw_key_to_ossl(alginfo, 0, r.base, &len, &pkey));
+       RETERR(raw_key_to_ossl(alginfo, 0, r.base, r.length, &pkey));
 
-       isc_buffer_forward(data, len);
+       isc_buffer_forward(data, alginfo->key_size);
        key->keydata.pkeypair.pub = pkey;
-       key->key_size = len * 8;
+       key->key_size = alginfo->key_size * 8;
        return ISC_R_SUCCESS;
 }
 
@@ -436,7 +433,6 @@ openssleddsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) {
        int i, privkey_index = -1;
        const char *label = NULL;
        EVP_PKEY *pkey = NULL;
-       size_t len;
        isc_mem_t *mctx = key->mctx;
 
        REQUIRE(alginfo != NULL);
@@ -492,9 +488,8 @@ openssleddsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) {
                CLEANUP(DST_R_INVALIDPRIVATEKEY);
        }
 
-       len = priv.elements[privkey_index].length;
        CHECK(raw_key_to_ossl(alginfo, 1, priv.elements[privkey_index].data,
-                             &len, &pkey));
+                             priv.elements[privkey_index].length, &pkey));
        /* Check that the public component matches if given */
        if (pub != NULL && EVP_PKEY_eq(pkey, pub->keydata.pkeypair.pub) != 1) {
                CLEANUP(DST_R_INVALIDPRIVATEKEY);
@@ -502,7 +497,7 @@ openssleddsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) {
 
        key->keydata.pkeypair.priv = pkey;
        key->keydata.pkeypair.pub = pkey;
-       key->key_size = len * 8;
+       key->key_size = alginfo->key_size * 8;
        pkey = NULL;
        result = ISC_R_SUCCESS;
 
@@ -620,7 +615,7 @@ check_algorithm(unsigned char algorithm) {
        }
 
        INSIST(alginfo != NULL);
-       CHECK(raw_key_to_ossl(alginfo, 0, key, &key_len, &pkey));
+       CHECK(raw_key_to_ossl(alginfo, 0, key, key_len, &pkey));
 
        /*
         * Check that we can verify the signature.