]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
openssl: Add conditional macros around SHA_CTX for AWS-LC
authorGerardo Ravago <gcr@amazon.com>
Thu, 15 Feb 2024 15:42:36 +0000 (10:42 -0500)
committerTobias Brunner <tobias@strongswan.org>
Mon, 19 Feb 2024 09:01:51 +0000 (10:01 +0100)
AWS-LC is a BoringSSL-based libcrypto implementation. SHA_CTX is declared with
the hash data specified as an array rather than as a field in upstream OpenSSL.
Since AWS-LC builds against C99, we are unable to handle this with anonymous
unions like BoringSSL. The workaround I propose is to add these conditional
macros around the accessors within openssl_sha1_prf. After this change,
everything builds successfully with AWS-LC headers.

Closes strongswan/strongswan#2103

src/libstrongswan/plugins/openssl/openssl_sha1_prf.c

index 364fe891f96a7c0208744df11551f452c3ed4fec..f2fc6974f2b1cb3a6e316183e413ed32988cf664 100644 (file)
@@ -58,12 +58,19 @@ METHOD(prf_t, get_bytes, bool,
        if (bytes)
        {
                uint32_t *hash = (uint32_t*)bytes;
-
+#ifndef OPENSSL_IS_AWSLC
                hash[0] = htonl(this->ctx.h0);
                hash[1] = htonl(this->ctx.h1);
                hash[2] = htonl(this->ctx.h2);
                hash[3] = htonl(this->ctx.h3);
                hash[4] = htonl(this->ctx.h4);
+#else
+               hash[0] = htonl(this->ctx.h[0]);
+               hash[1] = htonl(this->ctx.h[1]);
+               hash[2] = htonl(this->ctx.h[2]);
+               hash[3] = htonl(this->ctx.h[3]);
+               hash[4] = htonl(this->ctx.h[4]);
+#endif
        }
 
        return TRUE;
@@ -104,6 +111,7 @@ METHOD(prf_t, set_key, bool,
        {
                return FALSE;
        }
+#ifndef OPENSSL_IS_AWSLC
        if (key.len >= 4)
        {
                this->ctx.h0 ^= untoh32(key.ptr);
@@ -124,6 +132,28 @@ METHOD(prf_t, set_key, bool,
        {
                this->ctx.h4 ^= untoh32(key.ptr + 16);
        }
+#else
+       if (key.len >= 4)
+       {
+               this->ctx.h[0] ^= untoh32(key.ptr);
+       }
+       if (key.len >= 8)
+       {
+               this->ctx.h[1] ^= untoh32(key.ptr + 4);
+       }
+       if (key.len >= 12)
+       {
+               this->ctx.h[2] ^= untoh32(key.ptr + 8);
+       }
+       if (key.len >= 16)
+       {
+               this->ctx.h[3] ^= untoh32(key.ptr + 12);
+       }
+       if (key.len >= 20)
+       {
+               this->ctx.h[4] ^= untoh32(key.ptr + 16);
+       }
+#endif
        return TRUE;
 }