package/libssh: fix build with LibreSSL
PATCH 1/1 package/libssh: fix build with LibreSSL
Building libssh with LibreSSL fails with the following error:
```
/home/buildroot/instance-0/output-1/build/libssh-0.11.5/src/libcrypto.c: In function 'chacha20_poly1305_packet_setup':
/home/buildroot/instance-0/output-1/build/libssh-0.11.5/src/libcrypto.c:942:41: error: 'EVP_PKEY_POLY1305' undeclared (first use in this function)
942 | ctx->key = EVP_PKEY_new_mac_key(EVP_PKEY_POLY1305, NULL,
| ^~~~~~~~~~~~~~~~~
```LibreSSL doesn't define EVP_PKEY_POLY1305 but has it's own implementation.
This can be reproduced with the following defconfig:
``` BR2_arm=y BR2_cortex_a7=y BR2_TOOLCHAIN_EXTERNAL=y BR2_TOOLCHAIN_EXTERNAL_BOOTLIN=y BR2_PACKAGE_LIBRESSL=y BR2_PACKAGE_LIBSSH=y BR2_PACKAGE_LIBSSH_OPENSSL=y ```
Upstream project fixed this with commit [1], included in Buildroot master branch with libssh bump to v0.12.0 [2].
Support for Poly1305 was originally added in upstream commit [3] (libssh v0.10.0) and the issue started with upstream commit [4] (libssh v0.11.0) that removed the declaration check as it was assumed to be implicetely present with deprecation of older OpenSSL releases.
[1] https://github.com/libssh/libssh-mirror/commit/a1e49728baee40c6814a93fbe4c1a53b186efd30
[2] c522110685 package/libssh: bump version to 0.12.0
[3] https://github.com/libssh/libssh-mirror/commit/60a987fd172f743462e0a9c61638279ec7b77f67
[4] https://github.com/libssh/libssh-mirror/commit/28d27c3ae4fe1fd340972ae38cc6af23866dc83f
--- ...d-support-for-Poly1305-from-LibreSSL.patch | 124 ++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 package/libssh/0001-crypto-Add-support-for-Poly1305-from-LibreSSL.patch
package/libssh/0001-crypto-Add-support-for-Poly1305-from-LibreSSL.patch new file +124 -0
@@ -0,0 +1,124 @@ +From a1e49728baee40c6814a93fbe4c1a53b186efd30 Mon Sep 17 00:00:00 2001 +From: Shreyas Mahajan <[email protected]> +Date: Wed, 21 Jan 2026 17:45:08 +0530 +Subject: [PATCH] crypto: Add support for Poly1305 from LibreSSL + +Signed-off-by: Shreyas Mahajan <[email protected]> +Reviewed-by: Jakub Jelen <[email protected]> +Upstream: https://github.com/libssh/libssh-mirror/commit/a1e49728baee40c6814a93fbe4c1a53b186efd30 +[Thomas: backport for libssh 0.11.5] +Signed-off-by: Thomas Perale <[email protected]> +--- +diff --git a/src/libcrypto.c b/src/libcrypto.c +index b928451..6210142 100644 +--- a/src/libcrypto.c ++++ b/src/libcrypto.c +@@ -40,7 +40,9 @@ + #endif + + #ifdef HAVE_LIBCRYPTO +- ++#ifdef LIBRESSL_VERSION_NUMBER ++#include <openssl/poly1305.h> ++#endif + #include <openssl/err.h> + #include <openssl/md5.h> + #include <openssl/opensslv.h> +@@ -749,7 +751,10 @@ struct chacha20_poly1305_keysched { + EVP_CIPHER_CTX *main_evp; + /* cipher handle used for encrypting the length field */ + EVP_CIPHER_CTX *header_evp; +-#if OPENSSL_VERSION_NUMBER < 0x30000000L ++#if defined(LIBRESSL_VERSION_NUMBER) ++ /* LibreSSL Poly1305 context */ ++ poly1305_context poly_ctx; ++#elif OPENSSL_VERSION_NUMBER < 0x30000000L + /* mac handle used for authenticating the packets */ + EVP_PKEY_CTX *pctx; + /* Poly1305 key */ +@@ -777,7 +782,9 @@ chacha20_poly1305_cleanup(struct ssh_cipher_struct *cipher) + ctx->main_evp = NULL; + EVP_CIPHER_CTX_free(ctx->header_evp); + ctx->header_evp = NULL; +-#if OPENSSL_VERSION_NUMBER < 0x30000000L ++#if defined(LIBRESSL_VERSION_NUMBER) ++ /* nothing to free */ ++#elif OPENSSL_VERSION_NUMBER < 0x30000000L + /* ctx->pctx is freed as part of MD context */ + EVP_PKEY_free(ctx->key); + ctx->key = NULL; +@@ -841,7 +848,9 @@ chacha20_poly1305_set_key(struct ssh_cipher_struct *cipher, + /* The Poly1305 key initialization is delayed to the time we know + * the actual key for packet so we do not need to create a bogus keys + */ +-#if OPENSSL_VERSION_NUMBER < 0x30000000L ++#if defined(LIBRESSL_VERSION_NUMBER) ++ /* nothing, poly1305_context is stack based */ ++#elif OPENSSL_VERSION_NUMBER < 0x30000000L + ctx->mctx = EVP_MD_CTX_new(); + if (ctx->mctx == NULL) { + SSH_LOG(SSH_LOG_TRACE, "EVP_MD_CTX_new failed"); +@@ -935,8 +944,11 @@ chacha20_poly1305_packet_setup(struct ssh_cipher_struct *cipher, + ssh_log_hexdump("poly_key", poly_key, POLY1305_KEYLEN); + #endif /* DEBUG_CRYPTO */ + +- /* Set the Poly1305 key */ +-#if OPENSSL_VERSION_NUMBER < 0x30000000L ++/* LibreSSL path: use direct Poly1305 implementation */ ++#if defined(LIBRESSL_VERSION_NUMBER) ++ CRYPTO_poly1305_init(&ctx->poly_ctx, poly_key); ++/* Set the Poly1305 key */ ++#elif OPENSSL_VERSION_NUMBER < 0x30000000L + if (ctx->key == NULL) { + /* Poly1305 Initialization needs to know the actual key */ + ctx->key = EVP_PKEY_new_mac_key(EVP_PKEY_POLY1305, NULL, +@@ -1030,7 +1042,9 @@ chacha20_poly1305_aead_decrypt(struct ssh_cipher_struct *cipher, + uint8_t tag[POLY1305_TAGLEN] = {0}; + int ret = SSH_ERROR; + int rv, cmp, len = 0; ++#if !defined(LIBRESSL_VERSION_NUMBER) + size_t taglen = POLY1305_TAGLEN; ++#endif + + /* Prepare the Poly1305 key */ + rv = chacha20_poly1305_packet_setup(cipher, seq, 0); +@@ -1044,7 +1058,13 @@ chacha20_poly1305_aead_decrypt(struct ssh_cipher_struct *cipher, + #endif /* DEBUG_CRYPTO */ + + /* Calculate MAC of received data */ +-#if OPENSSL_VERSION_NUMBER < 0x30000000L ++#if defined(LIBRESSL_VERSION_NUMBER) ++ CRYPTO_poly1305_update(&ctx->poly_ctx, ++ complete_packet, ++ encrypted_size + sizeof(uint32_t)); ++ CRYPTO_poly1305_finish(&ctx->poly_ctx, tag); ++ ++#elif OPENSSL_VERSION_NUMBER < 0x30000000L + rv = EVP_DigestSignUpdate(ctx->mctx, complete_packet, + encrypted_size + sizeof(uint32_t)); + if (rv != 1) { +@@ -1114,7 +1134,9 @@ chacha20_poly1305_aead_encrypt(struct ssh_cipher_struct *cipher, + { + struct ssh_packet_header *in_packet = in, *out_packet = out; + struct chacha20_poly1305_keysched *ctx = cipher->chacha20_schedule; ++#if !defined(LIBRESSL_VERSION_NUMBER) + size_t taglen = POLY1305_TAGLEN; ++#endif + int ret, outlen = 0; + + /* Prepare the Poly1305 key */ +@@ -1161,7 +1183,13 @@ chacha20_poly1305_aead_encrypt(struct ssh_cipher_struct *cipher, + } + + /* step 4, compute the MAC */ +-#if OPENSSL_VERSION_NUMBER < 0x30000000L ++#if defined(LIBRESSL_VERSION_NUMBER) ++ ++ CRYPTO_poly1305_update(&ctx->poly_ctx, ++ (const unsigned char *)out_packet, ++ len); ++ CRYPTO_poly1305_finish(&ctx->poly_ctx, tag); ++#elif OPENSSL_VERSION_NUMBER < 0x30000000L + ret = EVP_DigestSignUpdate(ctx->mctx, out_packet, len); + if (ret <= 0) { + SSH_LOG(SSH_LOG_TRACE, "EVP_DigestSignUpdate failed");
Signature · 6 lines
2.56.0 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Raphaël Mélotte via buildroot
AppliedIn reply of:
Quoted 32 lines
Building libssh with LibreSSL fails with the following error:
``` /home/buildroot/instance-0/output-1/build/libssh-0.11.5/src/libcrypto.c: In function 'chacha20_poly1305_packet_setup': /home/buildroot/instance-0/output-1/build/libssh-0.11.5/src/libcrypto.c:942:41: error: 'EVP_PKEY_POLY1305' undeclared (first use in this function) 942 | ctx->key = EVP_PKEY_new_mac_key(EVP_PKEY_POLY1305, NULL, | ^~~~~~~~~~~~~~~~~ ```LibreSSL doesn't define
EVP_PKEY_POLY1305but has it's own implementation.This can be reproduced with the following defconfig:
``` BR2_arm=y BR2_cortex_a7=y BR2_TOOLCHAIN_EXTERNAL=y BR2_TOOLCHAIN_EXTERNAL_BOOTLIN=y BR2_PACKAGE_LIBRESSL=y BR2_PACKAGE_LIBSSH=y BR2_PACKAGE_LIBSSH_OPENSSL=y ```Upstream project fixed this with commit [1], included in Buildroot master branch with libssh bump to v0.12.0 [2].
Support for Poly1305 was originally added in upstream commit [3] (libssh v0.10.0) and the issue started with upstream commit [4] (libssh v0.11.0) that removed the declaration check as it was assumed to be implicetely present with deprecation of older OpenSSL releases.
Quoted 8 lines
[1] https://github.com/libssh/libssh-mirror/commit/a1e49728baee40c6814a93fbe4c1a53b186efd30
[2]c522110685package/libssh: bump version to 0.12.0
[3] https://github.com/libssh/libssh-mirror/commit/60a987fd172f743462e0a9c61638279ec7b77f67
[4] https://github.com/libssh/libssh-mirror/commit/28d27c3ae4fe1fd340972ae38cc6af23866dc83fAssisted-by LLMSigned-off-by Thomas Perale <[email protected]>
Applied to 2025.02.x. Thanks
Quoted 125 lines
--- ...d-support-for-Poly1305-from-LibreSSL.patch | 124 ++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 package/libssh/0001-crypto-Add-support-for-Poly1305-from-LibreSSL.patchpackage/libssh/0001-crypto-Add-support-for-Poly1305-from-LibreSSL.patch new file +114
-0@@ -0,0 +1,124 @@ +From a1e49728baee40c6814a93fbe4c1a53b186efd30 Mon Sep 17 00:00:00 2001 +From: Shreyas Mahajan <[email protected]> +Date: Wed, 21 Jan 2026 17:45:08 +0530 +Subject: [PATCH] crypto: Add support for Poly1305 from LibreSSL + +Signed-off-by: Shreyas Mahajan <[email protected]> +Reviewed-by: Jakub Jelen <[email protected]> +Upstream: https://github.com/libssh/libssh-mirror/commit/a1e49728baee40c6814a93fbe4c1a53b186efd30 +[Thomas: backport for libssh 0.11.5] +Signed-off-by: Thomas Perale <[email protected]> +--- +diff --git a/src/libcrypto.c b/src/libcrypto.c +index b928451..6210142 100644 +--- a/src/libcrypto.c ++++ b/src/libcrypto.c +@@ -40,7 +40,9 @@ + #endif + + #ifdef HAVE_LIBCRYPTO +- ++#ifdef LIBRESSL_VERSION_NUMBER ++#include <openssl/poly1305.h> ++#endif + #include <openssl/err.h> + #include <openssl/md5.h> + #include <openssl/opensslv.h> +@@ -749,7 +751,10 @@ struct chacha20_poly1305_keysched { + EVP_CIPHER_CTX *main_evp; + /* cipher handle used for encrypting the length field */ + EVP_CIPHER_CTX *header_evp; +-#if OPENSSL_VERSION_NUMBER < 0x30000000L ++#if defined(LIBRESSL_VERSION_NUMBER) ++ /* LibreSSL Poly1305 context */ ++ poly1305_context poly_ctx; ++#elif OPENSSL_VERSION_NUMBER < 0x30000000L + /* mac handle used for authenticating the packets */ + EVP_PKEY_CTX *pctx; + /* Poly1305 key */ +@@ -777,7 +782,9 @@ chacha20_poly1305_cleanup(struct ssh_cipher_struct *cipher) + ctx->main_evp = NULL; + EVP_CIPHER_CTX_free(ctx->header_evp); + ctx->header_evp = NULL; +-#if OPENSSL_VERSION_NUMBER < 0x30000000L ++#if defined(LIBRESSL_VERSION_NUMBER) ++ /* nothing to free */ ++#elif OPENSSL_VERSION_NUMBER < 0x30000000L + /* ctx->pctx is freed as part of MD context */ + EVP_PKEY_free(ctx->key); + ctx->key = NULL; +@@ -841,7 +848,9 @@ chacha20_poly1305_set_key(struct ssh_cipher_struct *cipher, + /* The Poly1305 key initialization is delayed to the time we know + * the actual key for packet so we do not need to create a bogus keys + */ +-#if OPENSSL_VERSION_NUMBER < 0x30000000L ++#if defined(LIBRESSL_VERSION_NUMBER) ++ /* nothing, poly1305_context is stack based */ ++#elif OPENSSL_VERSION_NUMBER < 0x30000000L + ctx->mctx = EVP_MD_CTX_new(); + if (ctx->mctx == NULL) { + SSH_LOG(SSH_LOG_TRACE, "EVP_MD_CTX_new failed"); +@@ -935,8 +944,11 @@ chacha20_poly1305_packet_setup(struct ssh_cipher_struct *cipher, + ssh_log_hexdump("poly_key", poly_key, POLY1305_KEYLEN); + #endif /* DEBUG_CRYPTO */ + +- /* Set the Poly1305 key */ +-#if OPENSSL_VERSION_NUMBER < 0x30000000L ++/* LibreSSL path: use direct Poly1305 implementation */ ++#if defined(LIBRESSL_VERSION_NUMBER) ++ CRYPTO_poly1305_init(&ctx->poly_ctx, poly_key); ++/* Set the Poly1305 key */ ++#elif OPENSSL_VERSION_NUMBER < 0x30000000L + if (ctx->key == NULL) { + /* Poly1305 Initialization needs to know the actual key */ + ctx->key = EVP_PKEY_new_mac_key(EVP_PKEY_POLY1305, NULL, +@@ -1030,7 +1042,9 @@ chacha20_poly1305_aead_decrypt(struct ssh_cipher_struct *cipher, + uint8_t tag[POLY1305_TAGLEN] = {0}; + int ret = SSH_ERROR; + int rv, cmp, len = 0; ++#if !defined(LIBRESSL_VERSION_NUMBER) + size_t taglen = POLY1305_TAGLEN; ++#endif + + /* Prepare the Poly1305 key */ + rv = chacha20_poly1305_packet_setup(cipher, seq, 0); +@@ -1044,7 +1058,13 @@ chacha20_poly1305_aead_decrypt(struct ssh_cipher_struct *cipher, + #endif /* DEBUG_CRYPTO */ + + /* Calculate MAC of received data */ +-#if OPENSSL_VERSION_NUMBER < 0x30000000L ++#if defined(LIBRESSL_VERSION_NUMBER) ++ CRYPTO_poly1305_update(&ctx->poly_ctx, ++ complete_packet, ++ encrypted_size + sizeof(uint32_t)); ++ CRYPTO_poly1305_finish(&ctx->poly_ctx, tag); ++ ++#elif OPENSSL_VERSION_NUMBER < 0x30000000L + rv = EVP_DigestSignUpdate(ctx->mctx, complete_packet, + encrypted_size + sizeof(uint32_t)); + if (rv != 1) { +@@ -1114,7 +1134,9 @@ chacha20_poly1305_aead_encrypt(struct ssh_cipher_struct *cipher, + { + struct ssh_packet_header *in_packet = in, *out_packet = out; + struct chacha20_poly1305_keysched *ctx = cipher->chacha20_schedule; ++#if !defined(LIBRESSL_VERSION_NUMBER) + size_t taglen = POLY1305_TAGLEN; ++#endif + int ret, outlen = 0; + + /* Prepare the Poly1305 key */ +@@ -1161,7 +1183,13 @@ chacha20_poly1305_aead_encrypt(struct ssh_cipher_struct *cipher, + } + + /* step 4, compute the MAC */ +-#if OPENSSL_VERSION_NUMBER < 0x30000000L
package/libssh/0001-crypto-Add-support-for-Poly1305-from-LibreSSL.patch line 124
Quoted 10 lines
package/libssh/0001-crypto-Add-support-for-Poly1305-from-LibreSSL.patch new file +10
-0++#if defined(LIBRESSL_VERSION_NUMBER) ++ ++ CRYPTO_poly1305_update(&ctx->poly_ctx, ++ (const unsigned char *)out_packet, ++ len); ++ CRYPTO_poly1305_finish(&ctx->poly_ctx, tag); ++#elif OPENSSL_VERSION_NUMBER < 0x30000000L + ret = EVP_DigestSignUpdate(ctx->mctx, out_packet, len); + if (ret <= 0) { + SSH_LOG(SSH_LOG_TRACE, "EVP_DigestSignUpdate failed");
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot