Skip to content

Commit 4a64f4f

Browse files
authored
Merge pull request #16 from david-cermak/feat/libssh_v0.12
feat(libssh): Update to support v0.12 upstream
2 parents 784e547 + 7c0ba17 commit 4a64f4f

7 files changed

Lines changed: 234 additions & 9 deletions

File tree

libssh/CMakeLists.txt

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
set(LIBSSH_VERSION "0.11.0")
1+
set(LIBSSH_VERSION "0.12.0")
22
set(LIBSSH_DIR "libssh-${LIBSSH_VERSION}")
33

44
set(libssh_SRCS
@@ -35,6 +35,7 @@ set(libssh_SRCS
3535
packet_crypt.c
3636
pcap.c
3737
pki.c
38+
pki_context.c
3839
pki_container_openssh.c
3940
poll.c
4041
session.c
@@ -44,6 +45,7 @@ set(libssh_SRCS
4445
threads.c
4546
ttyopts.c
4647
wrapper.c
48+
gzip.c
4749
external/bcrypt_pbkdf.c
4850
external/blowfish.c
4951
config_parser.c
@@ -68,6 +70,14 @@ ${libssh_SRCS}
6870
external/sc25519.c
6971
)
7072

73+
if(CONFIG_LIBSSH_SNTRUP761)
74+
set(libssh_SRCS
75+
${libssh_SRCS}
76+
sntrup761.c
77+
external/sntrup761.c
78+
)
79+
endif()
80+
7181
set(libssh_SRCS
7282
${libssh_SRCS}
7383
external/chacha.c
@@ -90,9 +100,20 @@ ${libssh_SRCS}
90100

91101
set(libssh_SRCS
92102
${libssh_SRCS}
103+
curve25519_fallback.c
93104
external/curve25519_ref.c
94105
)
95106

107+
if(CONFIG_LIBSSH_MLKEM)
108+
set(libssh_SRCS
109+
${libssh_SRCS}
110+
mlkem.c
111+
hybrid_mlkem.c
112+
mlkem_native.c
113+
external/libcrux_mlkem768_sha3.c
114+
)
115+
endif()
116+
96117
list(TRANSFORM libssh_SRCS PREPEND "${LIBSSH_DIR}/src/")
97118

98119
idf_component_register(SRCS ${libssh_SRCS}
@@ -114,3 +135,6 @@ endif()
114135

115136
set_source_files_properties(${LIBSSH_DIR}/src/external/bcrypt_pbkdf.c PROPERTIES COMPILE_OPTIONS "-Wno-unterminated-string-initialization")
116137
set_source_files_properties(${LIBSSH_DIR}/src/external/chacha.c PROPERTIES COMPILE_OPTIONS "-Wno-unterminated-string-initialization")
138+
if(CONFIG_LIBSSH_MLKEM)
139+
set_source_files_properties(${LIBSSH_DIR}/src/external/libcrux_mlkem768_sha3.c PROPERTIES COMPILE_OPTIONS "-Wno-declaration-after-statement")
140+
endif()

libssh/Kconfig

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
menu "libssh"
2+
3+
config LIBSSH_SNTRUP761
4+
bool "Enable SNTRUP761 (post-quantum) key exchange"
5+
default n
6+
help
7+
Enable the sntrup761x25519-sha512 hybrid key exchange
8+
algorithm. This adds significant stack usage due to the
9+
SNTRUP761 cryptographic operations. Disable to reduce the
10+
memory footprint on constrained devices.
11+
12+
config LIBSSH_MLKEM
13+
bool "Enable ML-KEM (post-quantum) key exchange"
14+
default n
15+
help
16+
Enable ML-KEM (Module-Lattice-based Key Exchange Mechanism)
17+
hybrid key exchange algorithms: mlkem768x25519-sha256 and
18+
mlkem768nistp256-sha256.
19+
20+
The ML-KEM implementation adds significant code size (~80 KB)
21+
and stack usage (~40 KB) due to the libcrux cryptographic
22+
library. Disable to reduce the memory footprint on
23+
constrained devices.
24+
25+
endmenu

libssh/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "0.11.0~1"
1+
version: "0.12.0"
22
url: https://github.com/david-cermak/libssh
33
license: LGPL-2.1
44
description: The component provides a general purpose SSH connectivity

libssh/install.sh

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
#!/bin/bash
22

33
# libssh installation script
4-
# This script downloads, extracts, and builds libssh from source
4+
# This script downloads, extracts, and patches libssh for the ESP-IDF port
55

66
set -e # Exit on any error
77

8+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
9+
810
# Configuration
9-
LIBSSH_VERSION="0.11.0"
11+
LIBSSH_VERSION="0.12.0"
1012
LIBSSH_URL="https://git.libssh.org/projects/libssh.git/snapshot/libssh-${LIBSSH_VERSION}.tar.xz"
1113
LIBSSH_DIR="libssh-${LIBSSH_VERSION}"
12-
INSTALL_DIR="/usr/local"
13-
14+
PATCH_DIR="${SCRIPT_DIR}/patches"
1415

1516
echo "Downloading libssh ${LIBSSH_VERSION}..."
1617

@@ -29,3 +30,17 @@ if ! tar -xf "libssh-${LIBSSH_VERSION}.tar.xz"; then
2930
fi
3031

3132
rm "libssh-${LIBSSH_VERSION}.tar.xz"
33+
34+
# Apply ESP-IDF port patches
35+
if [ -d "${PATCH_DIR}" ]; then
36+
for patch_file in "${PATCH_DIR}"/*.patch; do
37+
[ -f "$patch_file" ] || continue
38+
echo "Applying patch: $(basename "$patch_file")..."
39+
if ! patch -p0 < "$patch_file"; then
40+
echo "Failed to apply patch: $(basename "$patch_file")"
41+
exit 1
42+
fi
43+
done
44+
fi
45+
46+
echo "libssh ${LIBSSH_VERSION} installed successfully."

libssh/patches/esp_idf_port.patch

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
--- libssh-0.12.0/include/libssh/sntrup761.h 2026-02-10 10:35:23.000000000 +0100
2+
+++ libssh-0.12.0/include/libssh/sntrup761.h 2026-04-10 18:22:41.362169147 +0200
3+
@@ -31,7 +31,7 @@
4+
extern "C" {
5+
#endif
6+
7+
-#ifdef HAVE_CURVE25519
8+
+#if defined(HAVE_CURVE25519) && !defined(WITHOUT_SNTRUP761)
9+
#define HAVE_SNTRUP761 1
10+
#endif
11+
12+
--- libssh-0.12.0/src/kex.c 2026-02-10 10:35:23.000000000 +0100
13+
+++ libssh-0.12.0/src/kex.c 2026-04-10 18:10:37.885707940 +0200
14+
@@ -105,6 +105,7 @@
15+
#define SNTRUP761X25519 ""
16+
#endif /* HAVE_SNTRUP761 */
17+
18+
+#ifdef HAVE_MLKEM
19+
#ifdef HAVE_MLKEM1024
20+
#define HYBRID_MLKEM "mlkem768x25519-sha256," \
21+
"mlkem768nistp256-sha256," \
22+
@@ -113,6 +114,9 @@
23+
#define HYBRID_MLKEM "mlkem768x25519-sha256," \
24+
"mlkem768nistp256-sha256,"
25+
#endif /* HAVE_MLKEM1024 */
26+
+#else
27+
+#define HYBRID_MLKEM ""
28+
+#endif /* HAVE_MLKEM */
29+
30+
#ifdef HAVE_ECC
31+
#define ECDH "ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,"
32+
@@ -995,6 +999,7 @@
33+
return SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM;
34+
} else if (strcmp(kex, "sntrup761x25519-sha512") == 0) {
35+
return SSH_KEX_SNTRUP761X25519_SHA512;
36+
+#ifdef HAVE_MLKEM
37+
} else if (strcmp(kex, "mlkem768x25519-sha256") == 0) {
38+
return SSH_KEX_MLKEM768X25519_SHA256;
39+
} else if (strcmp(kex, "mlkem768nistp256-sha256") == 0) {
40+
@@ -1003,6 +1008,7 @@
41+
} else if (strcmp(kex, "mlkem1024nistp384-sha384") == 0) {
42+
return SSH_KEX_MLKEM1024NISTP384_SHA384;
43+
#endif
44+
+#endif /* HAVE_MLKEM */
45+
}
46+
/* should not happen. We should be getting only valid names at this stage */
47+
return 0;
48+
@@ -1057,6 +1063,7 @@
49+
ssh_client_sntrup761x25519_remove_callbacks(session);
50+
break;
51+
#endif
52+
+#ifdef HAVE_MLKEM
53+
case SSH_KEX_MLKEM768X25519_SHA256:
54+
case SSH_KEX_MLKEM768NISTP256_SHA256:
55+
#ifdef HAVE_MLKEM1024
56+
@@ -1064,6 +1071,9 @@
57+
#endif
58+
ssh_client_hybrid_mlkem_remove_callbacks(session);
59+
break;
60+
+#endif /* HAVE_MLKEM */
61+
+ default:
62+
+ break;
63+
}
64+
}
65+
66+
@@ -1663,6 +1673,7 @@
67+
}
68+
break;
69+
#endif /* HAVE_SNTRUP761 */
70+
+#ifdef HAVE_MLKEM
71+
case SSH_KEX_MLKEM768X25519_SHA256:
72+
case SSH_KEX_MLKEM768NISTP256_SHA256:
73+
#ifdef HAVE_MLKEM1024
74+
@@ -1679,6 +1690,7 @@
75+
goto error;
76+
}
77+
break;
78+
+#endif /* HAVE_MLKEM */
79+
default:
80+
/* Handle unsupported kex types - this should not happen in normal operation */
81+
rc = SSH_ERROR;
82+
@@ -1693,6 +1705,7 @@
83+
session->next_crypto->shared_secret,
84+
SHA512_DIGEST_LEN);
85+
break;
86+
+#ifdef HAVE_MLKEM
87+
case SSH_KEX_MLKEM768X25519_SHA256:
88+
case SSH_KEX_MLKEM768NISTP256_SHA256:
89+
#ifdef HAVE_MLKEM1024
90+
@@ -1700,6 +1713,7 @@
91+
#endif
92+
rc = ssh_buffer_pack(buf, "S", session->next_crypto->hybrid_shared_secret);
93+
break;
94+
+#endif /* HAVE_MLKEM */
95+
default:
96+
rc = ssh_buffer_pack(buf, "B", session->next_crypto->shared_secret);
97+
break;
98+
@@ -1922,6 +1936,7 @@
99+
k_string = ssh_make_padded_bignum_string(crypto->shared_secret,
100+
crypto->digest_len);
101+
break;
102+
+#ifdef HAVE_MLKEM
103+
case SSH_KEX_MLKEM768X25519_SHA256:
104+
case SSH_KEX_MLKEM768NISTP256_SHA256:
105+
#ifdef HAVE_MLKEM1024
106+
@@ -1929,6 +1944,7 @@
107+
#endif
108+
k_string = ssh_string_copy(crypto->hybrid_shared_secret);
109+
break;
110+
+#endif /* HAVE_MLKEM */
111+
default:
112+
k_string = ssh_make_bignum_string(crypto->shared_secret);
113+
break;
114+
--- libssh-0.12.0/src/client.c 2026-02-10 10:35:23.000000000 +0100
115+
+++ libssh-0.12.0/src/client.c 2026-04-10 18:10:37.885707940 +0200
116+
@@ -306,6 +306,7 @@
117+
rc = ssh_client_sntrup761x25519_init(session);
118+
break;
119+
#endif
120+
+#ifdef HAVE_MLKEM
121+
case SSH_KEX_MLKEM768X25519_SHA256:
122+
case SSH_KEX_MLKEM768NISTP256_SHA256:
123+
#ifdef HAVE_MLKEM1024
124+
@@ -313,6 +314,7 @@
125+
#endif
126+
rc = ssh_client_hybrid_mlkem_init(session);
127+
break;
128+
+#endif /* HAVE_MLKEM */
129+
default:
130+
rc = SSH_ERROR;
131+
}
132+
--- libssh-0.12.0/src/wrapper.c 2026-02-10 10:35:23.000000000 +0100
133+
+++ libssh-0.12.0/src/wrapper.c 2026-04-10 18:10:37.885707940 +0200
134+
@@ -625,6 +625,7 @@
135+
ssh_server_sntrup761x25519_init(session);
136+
break;
137+
#endif
138+
+#ifdef HAVE_MLKEM
139+
case SSH_KEX_MLKEM768X25519_SHA256:
140+
case SSH_KEX_MLKEM768NISTP256_SHA256:
141+
#ifdef HAVE_MLKEM1024
142+
@@ -632,6 +633,7 @@
143+
#endif
144+
ssh_server_hybrid_mlkem_init(session);
145+
break;
146+
+#endif /* HAVE_MLKEM */
147+
default:
148+
ssh_set_error(session,
149+
SSH_FATAL,

libssh/port/config.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
#define PACKAGE "libssh"
55

66
/* Version number of package */
7-
#define VERSION "0.11.0"
7+
#define VERSION "0.12.0"
88

99
#define SYSCONFDIR "etc"
10-
#define BINARYDIR "/home/david/repos/libssh-0.11.0/build_minimal"
11-
#define SOURCEDIR "/home/david/repos/libssh-0.11.0"
10+
#define BINARYDIR "/home/david/repos/libssh-0.12.0/build_minimal"
11+
#define SOURCEDIR "/home/david/repos/libssh-0.12.0"
1212

1313
/* Global bind configuration file path */
1414
#define GLOBAL_BIND_CONFIG "/etc/ssh/libssh_server_config"
15+
#define GLOBAL_CONF_DIR "/etc/ssh"
1516

1617
/* Global client configuration file path */
1718
#define GLOBAL_CLIENT_CONFIG "/etc/ssh/ssh_config"
@@ -259,6 +260,16 @@
259260
/* Define to 1 if you want to enable calltrace debug output */
260261
#define DEBUG_CALLTRACE 1
261262

263+
/* Define to 1 if you want to enable SNTRUP761 hybrid key exchange */
264+
#ifndef CONFIG_LIBSSH_SNTRUP761
265+
#define WITHOUT_SNTRUP761 1
266+
#endif
267+
268+
/* Define to 1 if you want to enable ML-KEM hybrid key exchange */
269+
#ifdef CONFIG_LIBSSH_MLKEM
270+
#define HAVE_MLKEM 1
271+
#endif
272+
262273
/* Define to 1 if you want to enable NaCl support */
263274
/* #undef WITH_NACL */
264275

libssh/port/idf_compat.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ int socketpair(int domain, int type, int protocol, int sv[2]);
1616

1717
// socket utils
1818
#define PF_UNIX AF_UNIX
19+
#define NI_NUMERICHOST AI_NUMERICHOST
1920

2021
// termios
2122
#ifndef IMAXBEL

0 commit comments

Comments
 (0)