ssh.h
Go to the documentation of this file.
1 /**
2  * @file ssh.h
3  * @brief Secure Shell (SSH)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2019-2026 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneSSH Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.6.6
29  **/
30 
31 #ifndef _SSH_H
32 #define _SSH_H
33 
34 //Dependencies
35 #include "ssh_config.h"
36 #include "ssh_legacy.h"
37 #include "ssh_types.h"
38 #include "ssh_cert_parse.h"
39 #include "core/net.h"
40 #include "core/crypto.h"
43 #include "hash/hash_algorithms.h"
44 #include "mac/mac_algorithms.h"
45 #include "aead/aead_algorithms.h"
47 #include "ecc/ec.h"
48 
49 
50 /*
51  * CycloneSSH Open is licensed under GPL version 2. In particular:
52  *
53  * - If you link your program to CycloneSSH Open, the result is a derivative
54  * work that can only be distributed under the same GPL license terms.
55  *
56  * - If additions or changes to CycloneSSH Open are made, the result is a
57  * derivative work that can only be distributed under the same license terms.
58  *
59  * - The GPL license requires that you make the source code available to
60  * whoever you make the binary available to.
61  *
62  * - If you sell or distribute a hardware product that runs CycloneSSH Open,
63  * the GPL license requires you to provide public and full access to all
64  * source code on a nondiscriminatory basis.
65  *
66  * If you fully understand and accept the terms of the GPL license, then edit
67  * the os_port_config.h header and add the following directive:
68  *
69  * #define GPL_LICENSE_TERMS_ACCEPTED
70  */
71 
72 #ifndef GPL_LICENSE_TERMS_ACCEPTED
73  #error Before compiling CycloneSSH Open, you must accept the terms of the GPL license
74 #endif
75 
76 //Version string
77 #define CYCLONE_SSH_VERSION_STRING "2.6.6"
78 //Major version
79 #define CYCLONE_SSH_MAJOR_VERSION 2
80 //Minor version
81 #define CYCLONE_SSH_MINOR_VERSION 6
82 //Revision number
83 #define CYCLONE_SSH_REV_NUMBER 6
84 
85 //Identification string
86 #define CYCLONE_SSH_ID "SSH-2.0-CycloneSSH_" CYCLONE_SSH_VERSION_STRING
87 
88 //SSH support
89 #ifndef SSH_SUPPORT
90  #define SSH_SUPPORT ENABLED
91 #elif (SSH_SUPPORT != ENABLED && SSH_SUPPORT != DISABLED)
92  #error SSH_SUPPORT parameter is not valid
93 #endif
94 
95 //SSH client support
96 #ifndef SSH_CLIENT_SUPPORT
97  #define SSH_CLIENT_SUPPORT ENABLED
98 #elif (SSH_CLIENT_SUPPORT != ENABLED && SSH_CLIENT_SUPPORT != DISABLED)
99  #error SSH_CLIENT_SUPPORT parameter is not valid
100 #endif
101 
102 //SSH server support
103 #ifndef SSH_SERVER_SUPPORT
104  #define SSH_SERVER_SUPPORT ENABLED
105 #elif (SSH_SERVER_SUPPORT != ENABLED && SSH_SERVER_SUPPORT != DISABLED)
106  #error SSH_SERVER_SUPPORT parameter is not valid
107 #endif
108 
109 //Public key authentication support
110 #ifndef SSH_PUBLIC_KEY_AUTH_SUPPORT
111  #define SSH_PUBLIC_KEY_AUTH_SUPPORT ENABLED
112 #elif (SSH_PUBLIC_KEY_AUTH_SUPPORT != ENABLED && SSH_PUBLIC_KEY_AUTH_SUPPORT != DISABLED)
113  #error SSH_PUBLIC_KEY_AUTH_SUPPORT parameter is not valid
114 #endif
115 
116 //Password authentication support
117 #ifndef SSH_PASSWORD_AUTH_SUPPORT
118  #define SSH_PASSWORD_AUTH_SUPPORT ENABLED
119 #elif (SSH_PASSWORD_AUTH_SUPPORT != ENABLED && SSH_PASSWORD_AUTH_SUPPORT != DISABLED)
120  #error SSH_PASSWORD_AUTH_SUPPORT parameter is not valid
121 #endif
122 
123 //Encrypted private key support (OpenSSH format)
124 #ifndef SSH_ENCRYPTED_KEY_SUPPORT
125  #define SSH_ENCRYPTED_KEY_SUPPORT DISABLED
126 #elif (SSH_ENCRYPTED_KEY_SUPPORT != ENABLED && SSH_ENCRYPTED_KEY_SUPPORT != DISABLED)
127  #error SSH_ENCRYPTED_KEY_SUPPORT parameter is not valid
128 #endif
129 
130 //Certificate support (OpenSSH format)
131 #ifndef SSH_CERT_SUPPORT
132  #define SSH_CERT_SUPPORT DISABLED
133 #elif (SSH_CERT_SUPPORT != ENABLED && SSH_CERT_SUPPORT != DISABLED)
134  #error SSH_CERT_SUPPORT parameter is not valid
135 #endif
136 
137 //Extension negotiation mechanism
138 #ifndef SSH_EXT_INFO_SUPPORT
139  #define SSH_EXT_INFO_SUPPORT ENABLED
140 #elif (SSH_EXT_INFO_SUPPORT != ENABLED && SSH_EXT_INFO_SUPPORT != DISABLED)
141  #error SSH_EXT_INFO_SUPPORT parameter is not valid
142 #endif
143 
144 //"server-sig-algs" extension support
145 #ifndef SSH_SERVER_SIG_ALGS_EXT_SUPPORT
146  #define SSH_SERVER_SIG_ALGS_EXT_SUPPORT ENABLED
147 #elif (SSH_SERVER_SIG_ALGS_EXT_SUPPORT != ENABLED && SSH_SERVER_SIG_ALGS_EXT_SUPPORT != DISABLED)
148  #error SSH_SERVER_SIG_ALGS_EXT_SUPPORT parameter is not valid
149 #endif
150 
151 //"global-requests-ok" extension support
152 #ifndef SSH_GLOBAL_REQ_OK_EXT_SUPPORT
153  #define SSH_GLOBAL_REQ_OK_EXT_SUPPORT DISABLED
154 #elif (SSH_GLOBAL_REQ_OK_EXT_SUPPORT != ENABLED && SSH_GLOBAL_REQ_OK_EXT_SUPPORT != DISABLED)
155  #error SSH_GLOBAL_REQ_OK_EXT_SUPPORT parameter is not valid
156 #endif
157 
158 //Strict key exchange extension support
159 #ifndef SSH_KEX_STRICT_SUPPORT
160  #define SSH_KEX_STRICT_SUPPORT ENABLED
161 #elif (SSH_KEX_STRICT_SUPPORT != ENABLED && SSH_KEX_STRICT_SUPPORT != DISABLED)
162  #error SSH_KEX_STRICT_SUPPORT parameter is not valid
163 #endif
164 
165 //Signature generation/verification callback functions
166 #ifndef SSH_SIGN_CALLBACK_SUPPORT
167  #define SSH_SIGN_CALLBACK_SUPPORT DISABLED
168 #elif (SSH_SIGN_CALLBACK_SUPPORT != ENABLED && SSH_SIGN_CALLBACK_SUPPORT != DISABLED)
169  #error SSH_SIGN_CALLBACK_SUPPORT parameter is not valid
170 #endif
171 
172 //ECDH callback functions
173 #ifndef SSH_ECDH_CALLBACK_SUPPORT
174  #define SSH_ECDH_CALLBACK_SUPPORT DISABLED
175 #elif (SSH_ECDH_CALLBACK_SUPPORT != ENABLED && SSH_ECDH_CALLBACK_SUPPORT != DISABLED)
176  #error SSH_ECDH_CALLBACK_SUPPORT parameter is not valid
177 #endif
178 
179 //Maximum number of keys the SSH entity can load
180 #ifndef SSH_MAX_HOST_KEYS
181  #define SSH_MAX_HOST_KEYS 3
182 #elif (SSH_MAX_HOST_KEYS < 1)
183  #error SSH_MAX_HOST_KEYS parameter is not valid
184 #endif
185 
186 //Maximum number of simultaneous connections
187 #ifndef SSH_MAX_CONNECTIONS
188  #define SSH_MAX_CONNECTIONS 10
189 #elif (SSH_MAX_CONNECTIONS < 1)
190  #error SSH_MAX_CONNECTIONS parameter is not valid
191 #endif
192 
193 //Maximum number of global request callbacks that can be attached
194 #ifndef SSH_MAX_GLOBAL_REQ_CALLBACKS
195  #define SSH_MAX_GLOBAL_REQ_CALLBACKS 3
196 #elif (SSH_MAX_GLOBAL_REQ_CALLBACKS < 1)
197  #error SSH_MAX_GLOBAL_REQ_CALLBACKS parameter is not valid
198 #endif
199 
200 //Maximum number of channel request callbacks that can be attached
201 #ifndef SSH_MAX_CHANNEL_REQ_CALLBACKS
202  #define SSH_MAX_CHANNEL_REQ_CALLBACKS 3
203 #elif (SSH_MAX_CHANNEL_REQ_CALLBACKS < 1)
204  #error SSH_MAX_CHANNEL_REQ_CALLBACKS parameter is not valid
205 #endif
206 
207 //Maximum number of channel open callbacks that can be attached
208 #ifndef SSH_MAX_CHANNEL_OPEN_CALLBACKS
209  #define SSH_MAX_CHANNEL_OPEN_CALLBACKS 1
210 #elif (SSH_MAX_CHANNEL_OPEN_CALLBACKS < 1)
211  #error SSH_MAX_CHANNEL_OPEN_CALLBACKS parameter is not valid
212 #endif
213 
214 //Maximum number of connection open callbacks that can be attached
215 #ifndef SSH_MAX_CONN_OPEN_CALLBACKS
216  #define SSH_MAX_CONN_OPEN_CALLBACKS 1
217 #elif (SSH_MAX_CONN_OPEN_CALLBACKS < 1)
218  #error SSH_MAX_CONN_OPEN_CALLBACKS parameter is not valid
219 #endif
220 
221 //Maximum number of connection close callbacks that can be attached
222 #ifndef SSH_MAX_CONN_CLOSE_CALLBACKS
223  #define SSH_MAX_CONN_CLOSE_CALLBACKS 1
224 #elif (SSH_MAX_CONN_CLOSE_CALLBACKS < 1)
225  #error SSH_MAX_CONN_CLOSE_CALLBACKS parameter is not valid
226 #endif
227 
228 //Maximum number of authentication attempts
229 #ifndef SSH_MAX_AUTH_ATTEMPTS
230  #define SSH_MAX_AUTH_ATTEMPTS 10
231 #elif (SSH_MAX_AUTH_ATTEMPTS < 1 && SSH_MAX_AUTH_ATTEMPTS > 20)
232  #error SSH_MAX_AUTH_ATTEMPTS parameter is not valid
233 #endif
234 
235 //Maximum packet size
236 #ifndef SSH_MAX_PACKET_SIZE
237  #define SSH_MAX_PACKET_SIZE 2048
238 #elif (SSH_MAX_PACKET_SIZE < 128)
239  #error SSH_MAX_PACKET_SIZE parameter is not valid
240 #endif
241 
242 //Size of channel TX/RX buffers
243 #ifndef SSH_CHANNEL_BUFFER_SIZE
244  #define SSH_CHANNEL_BUFFER_SIZE 2048
245 #elif (SSH_CHANNEL_BUFFER_SIZE < 128)
246  #error SSH_CHANNEL_BUFFER_SIZE parameter is not valid
247 #endif
248 
249 //Maximum length of identification string
250 #ifndef SSH_MAX_ID_LEN
251  #define SSH_MAX_ID_LEN 80
252 #elif (SSH_MAX_ID_LEN < 1)
253  #error SSH_MAX_ID_LEN parameter is not valid
254 #endif
255 
256 //Maximum length of user name
257 #ifndef SSH_MAX_USERNAME_LEN
258  #define SSH_MAX_USERNAME_LEN 32
259 #elif (SSH_MAX_USERNAME_LEN < 0)
260  #error SSH_MAX_USERNAME_LEN parameter is not valid
261 #endif
262 
263 //Maximum length of password
264 #ifndef SSH_MAX_PASSWORD_LEN
265  #define SSH_MAX_PASSWORD_LEN 32
266 #elif (SSH_MAX_PASSWORD_LEN < 0)
267  #error SSH_MAX_PASSWORD_LEN parameter is not valid
268 #endif
269 
270 //Maximum length of password change prompt
271 #ifndef SSH_MAX_PASSWORD_CHANGE_PROMPT_LEN
272  #define SSH_MAX_PASSWORD_CHANGE_PROMPT_LEN 0
273 #elif (SSH_MAX_PASSWORD_CHANGE_PROMPT_LEN < 0)
274  #error SSH_MAX_PASSWORD_CHANGE_PROMPT_LEN parameter is not valid
275 #endif
276 
277 //Encrypt-then-MAC mode support
278 #ifndef SSH_ETM_SUPPORT
279  #define SSH_ETM_SUPPORT DISABLED
280 #elif (SSH_ETM_SUPPORT != ENABLED && SSH_ETM_SUPPORT != DISABLED)
281  #error SSH_ETM_SUPPORT parameter is not valid
282 #endif
283 
284 //Stream cipher support (insecure)
285 #ifndef SSH_STREAM_CIPHER_SUPPORT
286  #define SSH_STREAM_CIPHER_SUPPORT DISABLED
287 #elif (SSH_STREAM_CIPHER_SUPPORT != ENABLED && SSH_STREAM_CIPHER_SUPPORT != DISABLED)
288  #error SSH_STREAM_CIPHER_SUPPORT parameter is not valid
289 #endif
290 
291 //CBC cipher mode support (weak)
292 #ifndef SSH_CBC_CIPHER_SUPPORT
293  #define SSH_CBC_CIPHER_SUPPORT DISABLED
294 #elif (SSH_CBC_CIPHER_SUPPORT != ENABLED && SSH_CBC_CIPHER_SUPPORT != DISABLED)
295  #error SSH_CBC_CIPHER_SUPPORT parameter is not valid
296 #endif
297 
298 //CTR cipher mode support
299 #ifndef SSH_CTR_CIPHER_SUPPORT
300  #define SSH_CTR_CIPHER_SUPPORT ENABLED
301 #elif (SSH_CTR_CIPHER_SUPPORT != ENABLED && SSH_CTR_CIPHER_SUPPORT != DISABLED)
302  #error SSH_CTR_CIPHER_SUPPORT parameter is not valid
303 #endif
304 
305 //GCM AEAD support (OpenSSH variant)
306 #ifndef SSH_GCM_CIPHER_SUPPORT
307  #define SSH_GCM_CIPHER_SUPPORT ENABLED
308 #elif (SSH_GCM_CIPHER_SUPPORT != ENABLED && SSH_GCM_CIPHER_SUPPORT != DISABLED)
309  #error SSH_GCM_CIPHER_SUPPORT parameter is not valid
310 #endif
311 
312 //GCM AEAD support (RFC 5647 variant)
313 #ifndef SSH_RFC5647_SUPPORT
314  #define SSH_RFC5647_SUPPORT DISABLED
315 #elif (SSH_RFC5647_SUPPORT != ENABLED && SSH_RFC5647_SUPPORT != DISABLED)
316  #error SSH_RFC5647_SUPPORT parameter is not valid
317 #endif
318 
319 //ChaCha20Poly1305 AEAD support
320 #ifndef SSH_CHACHA20_POLY1305_SUPPORT
321  #define SSH_CHACHA20_POLY1305_SUPPORT DISABLED
322 #elif (SSH_CHACHA20_POLY1305_SUPPORT != ENABLED && SSH_CHACHA20_POLY1305_SUPPORT != DISABLED)
323  #error SSH_CHACHA20_POLY1305_SUPPORT parameter is not valid
324 #endif
325 
326 //Legacy RC4 cipher support (insecure)
327 #ifndef SSH_RC4_SUPPORT
328  #define SSH_RC4_SUPPORT DISABLED
329 #elif (SSH_RC4_SUPPORT != ENABLED && SSH_RC4_SUPPORT != DISABLED)
330  #error SSH_RC4_SUPPORT parameter is not valid
331 #endif
332 
333 //RC4 128-bit cipher support (insecure)
334 #ifndef SSH_RC4_128_SUPPORT
335  #define SSH_RC4_128_SUPPORT DISABLED
336 #elif (SSH_RC4_128_SUPPORT != ENABLED && SSH_RC4_128_SUPPORT != DISABLED)
337  #error SSH_RC4_128_SUPPORT parameter is not valid
338 #endif
339 
340 //RC4 256-bit cipher support (insecure)
341 #ifndef SSH_RC4_256_SUPPORT
342  #define SSH_RC4_256_SUPPORT DISABLED
343 #elif (SSH_RC4_256_SUPPORT != ENABLED && SSH_RC4_256_SUPPORT != DISABLED)
344  #error SSH_RC4_256_SUPPORT parameter is not valid
345 #endif
346 
347 //CAST-128 cipher support (insecure)
348 #ifndef SSH_CAST128_SUPPORT
349  #define SSH_CAST128_SUPPORT DISABLED
350 #elif (SSH_CAST128_SUPPORT != ENABLED && SSH_CAST128_SUPPORT != DISABLED)
351  #error SSH_CAST128_SUPPORT parameter is not valid
352 #endif
353 
354 //IDEA cipher support (insecure)
355 #ifndef SSH_IDEA_SUPPORT
356  #define SSH_IDEA_SUPPORT DISABLED
357 #elif (SSH_IDEA_SUPPORT != ENABLED && SSH_IDEA_SUPPORT != DISABLED)
358  #error SSH_IDEA_SUPPORT parameter is not valid
359 #endif
360 
361 //Blowfish cipher support (insecure)
362 #ifndef SSH_BLOWFISH_SUPPORT
363  #define SSH_BLOWFISH_SUPPORT DISABLED
364 #elif (SSH_BLOWFISH_SUPPORT != ENABLED && SSH_BLOWFISH_SUPPORT != DISABLED)
365  #error SSH_BLOWFISH_SUPPORT parameter is not valid
366 #endif
367 
368 //Triple DES cipher support (weak)
369 #ifndef SSH_3DES_SUPPORT
370  #define SSH_3DES_SUPPORT DISABLED
371 #elif (SSH_3DES_SUPPORT != ENABLED && SSH_3DES_SUPPORT != DISABLED)
372  #error SSH_3DES_SUPPORT parameter is not valid
373 #endif
374 
375 //AES 128-bit cipher support
376 #ifndef SSH_AES_128_SUPPORT
377  #define SSH_AES_128_SUPPORT ENABLED
378 #elif (SSH_AES_128_SUPPORT != ENABLED && SSH_AES_128_SUPPORT != DISABLED)
379  #error SSH_AES_128_SUPPORT parameter is not valid
380 #endif
381 
382 //AES 192-bit cipher support
383 #ifndef SSH_AES_192_SUPPORT
384  #define SSH_AES_192_SUPPORT ENABLED
385 #elif (SSH_AES_192_SUPPORT != ENABLED && SSH_AES_192_SUPPORT != DISABLED)
386  #error SSH_AES_192_SUPPORT parameter is not valid
387 #endif
388 
389 //AES 256-bit cipher support
390 #ifndef SSH_AES_256_SUPPORT
391  #define SSH_AES_256_SUPPORT ENABLED
392 #elif (SSH_AES_256_SUPPORT != ENABLED && SSH_AES_256_SUPPORT != DISABLED)
393  #error SSH_AES_256_SUPPORT parameter is not valid
394 #endif
395 
396 //Twofish 128-bit cipher support
397 #ifndef SSH_TWOFISH_128_SUPPORT
398  #define SSH_TWOFISH_128_SUPPORT DISABLED
399 #elif (SSH_TWOFISH_128_SUPPORT != ENABLED && SSH_TWOFISH_128_SUPPORT != DISABLED)
400  #error SSH_TWOFISH_128_SUPPORT parameter is not valid
401 #endif
402 
403 //Twofish 192-bit cipher support
404 #ifndef SSH_TWOFISH_192_SUPPORT
405  #define SSH_TWOFISH_192_SUPPORT DISABLED
406 #elif (SSH_TWOFISH_192_SUPPORT != ENABLED && SSH_TWOFISH_192_SUPPORT != DISABLED)
407  #error SSH_TWOFISH_192_SUPPORT parameter is not valid
408 #endif
409 
410 //Twofish 256-bit cipher support
411 #ifndef SSH_TWOFISH_256_SUPPORT
412  #define SSH_TWOFISH_256_SUPPORT DISABLED
413 #elif (SSH_TWOFISH_256_SUPPORT != ENABLED && SSH_TWOFISH_256_SUPPORT != DISABLED)
414  #error SSH_TWOFISH_256_SUPPORT parameter is not valid
415 #endif
416 
417 //Serpent 128-bit cipher support
418 #ifndef SSH_SERPENT_128_SUPPORT
419  #define SSH_SERPENT_128_SUPPORT DISABLED
420 #elif (SSH_SERPENT_128_SUPPORT != ENABLED && SSH_SERPENT_128_SUPPORT != DISABLED)
421  #error SSH_SERPENT_128_SUPPORT parameter is not valid
422 #endif
423 
424 //Serpent 192-bit cipher support
425 #ifndef SSH_SERPENT_192_SUPPORT
426  #define SSH_SERPENT_192_SUPPORT DISABLED
427 #elif (SSH_SERPENT_192_SUPPORT != ENABLED && SSH_SERPENT_192_SUPPORT != DISABLED)
428  #error SSH_SERPENT_192_SUPPORT parameter is not valid
429 #endif
430 
431 //Serpent 256-bit cipher support
432 #ifndef SSH_SERPENT_256_SUPPORT
433  #define SSH_SERPENT_256_SUPPORT DISABLED
434 #elif (SSH_SERPENT_256_SUPPORT != ENABLED && SSH_SERPENT_256_SUPPORT != DISABLED)
435  #error SSH_SERPENT_256_SUPPORT parameter is not valid
436 #endif
437 
438 //Camellia 128-bit cipher support
439 #ifndef SSH_CAMELLIA_128_SUPPORT
440  #define SSH_CAMELLIA_128_SUPPORT DISABLED
441 #elif (SSH_CAMELLIA_128_SUPPORT != ENABLED && SSH_CAMELLIA_128_SUPPORT != DISABLED)
442  #error SSH_CAMELLIA_128_SUPPORT parameter is not valid
443 #endif
444 
445 //Camellia 192-bit cipher support
446 #ifndef SSH_CAMELLIA_192_SUPPORT
447  #define SSH_CAMELLIA_192_SUPPORT DISABLED
448 #elif (SSH_CAMELLIA_192_SUPPORT != ENABLED && SSH_CAMELLIA_192_SUPPORT != DISABLED)
449  #error SSH_CAMELLIA_192_SUPPORT parameter is not valid
450 #endif
451 
452 //Camellia 256-bit cipher support
453 #ifndef SSH_CAMELLIA_256_SUPPORT
454  #define SSH_CAMELLIA_256_SUPPORT DISABLED
455 #elif (SSH_CAMELLIA_256_SUPPORT != ENABLED && SSH_CAMELLIA_256_SUPPORT != DISABLED)
456  #error SSH_CAMELLIA_256_SUPPORT parameter is not valid
457 #endif
458 
459 //SEED cipher support (weak)
460 #ifndef SSH_SEED_SUPPORT
461  #define SSH_SEED_SUPPORT DISABLED
462 #elif (SSH_SEED_SUPPORT != ENABLED && SSH_SEED_SUPPORT != DISABLED)
463  #error SSH_SEED_SUPPORT parameter is not valid
464 #endif
465 
466 //MD5 hash support (insecure)
467 #ifndef SSH_MD5_SUPPORT
468  #define SSH_MD5_SUPPORT DISABLED
469 #elif (SSH_MD5_SUPPORT != ENABLED && SSH_MD5_SUPPORT != DISABLED)
470  #error SSH_MD5_SUPPORT parameter is not valid
471 #endif
472 
473 //MD5/96 hash support (insecure)
474 #ifndef SSH_MD5_96_SUPPORT
475  #define SSH_MD5_96_SUPPORT DISABLED
476 #elif (SSH_MD5_96_SUPPORT != ENABLED && SSH_MD5_96_SUPPORT != DISABLED)
477  #error SSH_MD5_96_SUPPORT parameter is not valid
478 #endif
479 
480 //RIPEMD-160 hash support (weak)
481 #ifndef SSH_RIPEMD160_SUPPORT
482  #define SSH_RIPEMD160_SUPPORT DISABLED
483 #elif (SSH_RIPEMD160_SUPPORT != ENABLED && SSH_RIPEMD160_SUPPORT != DISABLED)
484  #error SSH_RIPEMD160_SUPPORT parameter is not valid
485 #endif
486 
487 //SHA-1 hash support (weak)
488 #ifndef SSH_SHA1_SUPPORT
489  #define SSH_SHA1_SUPPORT ENABLED
490 #elif (SSH_SHA1_SUPPORT != ENABLED && SSH_SHA1_SUPPORT != DISABLED)
491  #error SSH_SHA1_SUPPORT parameter is not valid
492 #endif
493 
494 //SHA-1/96 hash support (insecure)
495 #ifndef SSH_SHA1_96_SUPPORT
496  #define SSH_SHA1_96_SUPPORT DISABLED
497 #elif (SSH_SHA1_96_SUPPORT != ENABLED && SSH_SHA1_96_SUPPORT != DISABLED)
498  #error SSH_SHA1_96_SUPPORT parameter is not valid
499 #endif
500 
501 //SHA-224 hash support (weak)
502 #ifndef SSH_SHA224_SUPPORT
503  #define SSH_SHA224_SUPPORT DISABLED
504 #elif (SSH_SHA224_SUPPORT != ENABLED && SSH_SHA224_SUPPORT != DISABLED)
505  #error SSH_SHA224_SUPPORT parameter is not valid
506 #endif
507 
508 //SHA-256 hash support
509 #ifndef SSH_SHA256_SUPPORT
510  #define SSH_SHA256_SUPPORT ENABLED
511 #elif (SSH_SHA256_SUPPORT != ENABLED && SSH_SHA256_SUPPORT != DISABLED)
512  #error SSH_SHA256_SUPPORT parameter is not valid
513 #endif
514 
515 //SHA-384 hash support
516 #ifndef SSH_SHA384_SUPPORT
517  #define SSH_SHA384_SUPPORT ENABLED
518 #elif (SSH_SHA384_SUPPORT != ENABLED && SSH_SHA384_SUPPORT != DISABLED)
519  #error SSH_SHA384_SUPPORT parameter is not valid
520 #endif
521 
522 //SHA-512 hash support
523 #ifndef SSH_SHA512_SUPPORT
524  #define SSH_SHA512_SUPPORT ENABLED
525 #elif (SSH_SHA512_SUPPORT != ENABLED && SSH_SHA512_SUPPORT != DISABLED)
526  #error SSH_SHA512_SUPPORT parameter is not valid
527 #endif
528 
529 //RSA key exchange support
530 #ifndef SSH_RSA_KEX_SUPPORT
531  #define SSH_RSA_KEX_SUPPORT DISABLED
532 #elif (SSH_RSA_KEX_SUPPORT != ENABLED && SSH_RSA_KEX_SUPPORT != DISABLED)
533  #error SSH_RSA_KEX_SUPPORT parameter is not valid
534 #endif
535 
536 //Diffie-Hellman key exchange support
537 #ifndef SSH_DH_KEX_SUPPORT
538  #define SSH_DH_KEX_SUPPORT ENABLED
539 #elif (SSH_DH_KEX_SUPPORT != ENABLED && SSH_DH_KEX_SUPPORT != DISABLED)
540  #error SSH_DH_KEX_SUPPORT parameter is not valid
541 #endif
542 
543 //DH GEX key exchange support
544 #ifndef SSH_DH_GEX_KEX_SUPPORT
545  #define SSH_DH_GEX_KEX_SUPPORT DISABLED
546 #elif (SSH_DH_GEX_KEX_SUPPORT != ENABLED && SSH_DH_GEX_KEX_SUPPORT != DISABLED)
547  #error SSH_DH_GEX_KEX_SUPPORT parameter is not valid
548 #endif
549 
550 //ECDH key exchange support
551 #ifndef SSH_ECDH_KEX_SUPPORT
552  #define SSH_ECDH_KEX_SUPPORT ENABLED
553 #elif (SSH_ECDH_KEX_SUPPORT != ENABLED && SSH_ECDH_KEX_SUPPORT != DISABLED)
554  #error SSH_ECDH_KEX_SUPPORT parameter is not valid
555 #endif
556 
557 //Pure post-quantum key exchange support
558 #ifndef SSH_KEM_KEX_SUPPORT
559  #define SSH_KEM_KEX_SUPPORT DISABLED
560 #elif (SSH_KEM_KEX_SUPPORT != ENABLED && SSH_KEM_KEX_SUPPORT != DISABLED)
561  #error SSH_KEM_KEX_SUPPORT parameter is not valid
562 #endif
563 
564 //Post-quantum hybrid key exchange support
565 #ifndef SSH_HYBRID_KEX_SUPPORT
566  #define SSH_HYBRID_KEX_SUPPORT DISABLED
567 #elif (SSH_HYBRID_KEX_SUPPORT != ENABLED && SSH_HYBRID_KEX_SUPPORT != DISABLED)
568  #error SSH_HYBRID_KEX_SUPPORT parameter is not valid
569 #endif
570 
571 //RSA signature support
572 #ifndef SSH_RSA_SIGN_SUPPORT
573  #define SSH_RSA_SIGN_SUPPORT ENABLED
574 #elif (SSH_RSA_SIGN_SUPPORT != ENABLED && SSH_RSA_SIGN_SUPPORT != DISABLED)
575  #error SSH_RSA_SIGN_SUPPORT parameter is not valid
576 #endif
577 
578 //DSA signature support
579 #ifndef SSH_DSA_SIGN_SUPPORT
580  #define SSH_DSA_SIGN_SUPPORT ENABLED
581 #elif (SSH_DSA_SIGN_SUPPORT != ENABLED && SSH_DSA_SIGN_SUPPORT != DISABLED)
582  #error SSH_DSA_SIGN_SUPPORT parameter is not valid
583 #endif
584 
585 //ECDSA signature support
586 #ifndef SSH_ECDSA_SIGN_SUPPORT
587  #define SSH_ECDSA_SIGN_SUPPORT ENABLED
588 #elif (SSH_ECDSA_SIGN_SUPPORT != ENABLED && SSH_ECDSA_SIGN_SUPPORT != DISABLED)
589  #error SSH_ECDSA_SIGN_SUPPORT parameter is not valid
590 #endif
591 
592 //Ed25519 signature support
593 #ifndef SSH_ED25519_SIGN_SUPPORT
594  #define SSH_ED25519_SIGN_SUPPORT ENABLED
595 #elif (SSH_ED25519_SIGN_SUPPORT != ENABLED && SSH_ED25519_SIGN_SUPPORT != DISABLED)
596  #error SSH_ED25519_SIGN_SUPPORT parameter is not valid
597 #endif
598 
599 //Ed448 signature support
600 #ifndef SSH_ED448_SIGN_SUPPORT
601  #define SSH_ED448_SIGN_SUPPORT DISABLED
602 #elif (SSH_ED448_SIGN_SUPPORT != ENABLED && SSH_ED448_SIGN_SUPPORT != DISABLED)
603  #error SSH_ED448_SIGN_SUPPORT parameter is not valid
604 #endif
605 
606 //ML-DSA-44 signature support
607 #ifndef SSH_MLDSA44_SIGN_SUPPORT
608  #define SSH_MLDSA44_SIGN_SUPPORT DISABLED
609 #elif (SSH_MLDSA44_SIGN_SUPPORT != ENABLED && SSH_MLDSA44_SIGN_SUPPORT != DISABLED)
610  #error SSH_MLDSA44_SIGN_SUPPORT parameter is not valid
611 #endif
612 
613 //ML-DSA-65 signature support
614 #ifndef SSH_MLDSA65_SIGN_SUPPORT
615  #define SSH_MLDSA65_SIGN_SUPPORT DISABLED
616 #elif (SSH_MLDSA65_SIGN_SUPPORT != ENABLED && SSH_MLDSA65_SIGN_SUPPORT != DISABLED)
617  #error SSH_MLDSA65_SIGN_SUPPORT parameter is not valid
618 #endif
619 
620 //ML-DSA-87 signature support
621 #ifndef SSH_MLDSA87_SIGN_SUPPORT
622  #define SSH_MLDSA87_SIGN_SUPPORT DISABLED
623 #elif (SSH_MLDSA87_SIGN_SUPPORT != ENABLED && SSH_MLDSA87_SIGN_SUPPORT != DISABLED)
624  #error SSH_MLDSA87_SIGN_SUPPORT parameter is not valid
625 #endif
626 
627 //NIST P-256 elliptic curve support
628 #ifndef SSH_NISTP256_SUPPORT
629  #define SSH_NISTP256_SUPPORT ENABLED
630 #elif (SSH_NISTP256_SUPPORT != ENABLED && SSH_NISTP256_SUPPORT != DISABLED)
631  #error SSH_NISTP256_SUPPORT parameter is not valid
632 #endif
633 
634 //NIST P-384 elliptic curve support
635 #ifndef SSH_NISTP384_SUPPORT
636  #define SSH_NISTP384_SUPPORT ENABLED
637 #elif (SSH_NISTP384_SUPPORT != ENABLED && SSH_NISTP384_SUPPORT != DISABLED)
638  #error SSH_NISTP384_SUPPORT parameter is not valid
639 #endif
640 
641 //NIST P-521 elliptic curve support
642 #ifndef SSH_NISTP521_SUPPORT
643  #define SSH_NISTP521_SUPPORT ENABLED
644 #elif (SSH_NISTP521_SUPPORT != ENABLED && SSH_NISTP521_SUPPORT != DISABLED)
645  #error SSH_NISTP521_SUPPORT parameter is not valid
646 #endif
647 
648 //Curve25519 elliptic curve support
649 #ifndef SSH_CURVE25519_SUPPORT
650  #define SSH_CURVE25519_SUPPORT ENABLED
651 #elif (SSH_CURVE25519_SUPPORT != ENABLED && SSH_CURVE25519_SUPPORT != DISABLED)
652  #error SSH_CURVE25519_SUPPORT parameter is not valid
653 #endif
654 
655 //Curve448 elliptic curve support
656 #ifndef SSH_CURVE448_SUPPORT
657  #define SSH_CURVE448_SUPPORT DISABLED
658 #elif (SSH_CURVE448_SUPPORT != ENABLED && SSH_CURVE448_SUPPORT != DISABLED)
659  #error SSH_CURVE448_SUPPORT parameter is not valid
660 #endif
661 
662 //ML-KEM-768 key encapsulation mechanism support
663 #ifndef SSH_MLKEM768_SUPPORT
664  #define SSH_MLKEM768_SUPPORT DISABLED
665 #elif (SSH_MLKEM768_SUPPORT != ENABLED && SSH_MLKEM768_SUPPORT != DISABLED)
666  #error SSH_MLKEM768_SUPPORT parameter is not valid
667 #endif
668 
669 //ML-KEM-1024 key encapsulation mechanism support
670 #ifndef SSH_MLKEM1024_SUPPORT
671  #define SSH_MLKEM1024_SUPPORT DISABLED
672 #elif (SSH_MLKEM1024_SUPPORT != ENABLED && SSH_MLKEM1024_SUPPORT != DISABLED)
673  #error SSH_MLKEM1024_SUPPORT parameter is not valid
674 #endif
675 
676 //Streamlined NTRU Prime 761 key encapsulation mechanism support
677 #ifndef SSH_SNTRUP761_SUPPORT
678  #define SSH_SNTRUP761_SUPPORT DISABLED
679 #elif (SSH_SNTRUP761_SUPPORT != ENABLED && SSH_SNTRUP761_SUPPORT != DISABLED)
680  #error SSH_SNTRUP761_SUPPORT parameter is not valid
681 #endif
682 
683 //Key logging (for debugging purpose only)
684 #ifndef SSH_KEY_LOG_SUPPORT
685  #define SSH_KEY_LOG_SUPPORT DISABLED
686 #elif (SSH_KEY_LOG_SUPPORT != ENABLED && SSH_KEY_LOG_SUPPORT != DISABLED)
687  #error SSH_KEY_LOG_SUPPORT parameter is not valid
688 #endif
689 
690 //Maximum number of transient RSA keys that can be loaded
691 #ifndef SSH_MAX_RSA_KEYS
692  #define SSH_MAX_RSA_KEYS 2
693 #elif (SSH_MAX_RSA_KEYS < 1)
694  #error SSH_MAX_RSA_KEYS parameter is not valid
695 #endif
696 
697 //Maximum number of Diffie-Hellman groups that can be loaded
698 #ifndef SSH_MAX_DH_GEX_GROUPS
699  #define SSH_MAX_DH_GEX_GROUPS 2
700 #elif (SSH_MAX_DH_GEX_GROUPS < 1)
701  #error SSH_MAX_DH_GEX_GROUPS parameter is not valid
702 #endif
703 
704 //Minimum acceptable size for Diffie-Hellman prime modulus
705 #ifndef SSH_MIN_DH_MODULUS_SIZE
706  #define SSH_MIN_DH_MODULUS_SIZE 1024
707 #elif (SSH_MIN_DH_MODULUS_SIZE < 1024)
708  #error SSH_MIN_DH_MODULUS_SIZE parameter is not valid
709 #endif
710 
711 //Preferred size for Diffie-Hellman prime modulus
712 #ifndef SSH_PREFERRED_DH_MODULUS_SIZE
713  #define SSH_PREFERRED_DH_MODULUS_SIZE 2048
714 #elif (SSH_PREFERRED_DH_MODULUS_SIZE < SSH_MIN_DH_MODULUS_SIZE)
715  #error SSH_PREFERRED_DH_MODULUS_SIZE parameter is not valid
716 #endif
717 
718 //Maximum acceptable size for Diffie-Hellman prime modulus
719 #ifndef SSH_MAX_DH_MODULUS_SIZE
720  #define SSH_MAX_DH_MODULUS_SIZE 3072
721 #elif (SSH_MAX_DH_MODULUS_SIZE < SSH_PREFERRED_DH_MODULUS_SIZE)
722  #error SSH_MAX_DH_MODULUS_SIZE parameter is not valid
723 #endif
724 
725 //Minimum acceptable size for RSA modulus
726 #ifndef SSH_MIN_RSA_MODULUS_SIZE
727  #define SSH_MIN_RSA_MODULUS_SIZE 1024
728 #elif (SSH_MIN_RSA_MODULUS_SIZE < 1024)
729  #error SSH_MIN_RSA_MODULUS_SIZE parameter is not valid
730 #endif
731 
732 //Maximum acceptable size for RSA modulus
733 #ifndef SSH_MAX_RSA_MODULUS_SIZE
734  #define SSH_MAX_RSA_MODULUS_SIZE 4096
735 #elif (SSH_MAX_RSA_MODULUS_SIZE < SSH_MIN_RSA_MODULUS_SIZE)
736  #error SSH_MAX_RSA_MODULUS_SIZE parameter is not valid
737 #endif
738 
739 //Minimum acceptable size for DSA prime modulus
740 #ifndef SSH_MIN_DSA_MODULUS_SIZE
741  #define SSH_MIN_DSA_MODULUS_SIZE 1024
742 #elif (SSH_MIN_DSA_MODULUS_SIZE < 1024)
743  #error SSH_MIN_DSA_MODULUS_SIZE parameter is not valid
744 #endif
745 
746 //Maximum acceptable size for DSA prime modulus
747 #ifndef SSH_MAX_DSA_MODULUS_SIZE
748  #define SSH_MAX_DSA_MODULUS_SIZE 4096
749 #elif (SSH_MAX_DSA_MODULUS_SIZE < SSH_MIN_DSA_MODULUS_SIZE)
750  #error SSH_MAX_DSA_MODULUS_SIZE parameter is not valid
751 #endif
752 
753 //Allocate memory block
754 #ifndef sshAllocMem
755  #define sshAllocMem(size) osAllocMem(size)
756 #endif
757 
758 //Deallocate memory block
759 #ifndef sshFreeMem
760  #define sshFreeMem(p) osFreeMem(p)
761 #endif
762 
763 //HMAC support
764 #if (SSH_STREAM_CIPHER_SUPPORT == ENABLED)
765  #define SSH_HMAC_SUPPORT ENABLED
766 #elif (SSH_CBC_CIPHER_SUPPORT == ENABLED)
767  #define SSH_HMAC_SUPPORT ENABLED
768 #elif (SSH_CTR_CIPHER_SUPPORT == ENABLED)
769  #define SSH_HMAC_SUPPORT ENABLED
770 #else
771  #define SSH_HMAC_SUPPORT DISABLED
772 #endif
773 
774 //Maximum key size (encryption algorithms)
775 #if (SSH_CHACHA20_POLY1305_SUPPORT == ENABLED)
776  #define SSH_MAX_ENC_KEY_SIZE 64
777 #else
778  #define SSH_MAX_ENC_KEY_SIZE 32
779 #endif
780 
781 //Maximum block size (encryption algorithms)
782 #if (SSH_AES_128_SUPPORT == ENABLED)
783  #define SSH_MAX_CIPHER_BLOCK_SIZE AES_BLOCK_SIZE
784 #elif (SSH_AES_192_SUPPORT == ENABLED)
785  #define SSH_MAX_CIPHER_BLOCK_SIZE AES_BLOCK_SIZE
786 #elif (SSH_AES_256_SUPPORT == ENABLED)
787  #define SSH_MAX_CIPHER_BLOCK_SIZE AES_BLOCK_SIZE
788 #elif (SSH_TWOFISH_128_SUPPORT == ENABLED)
789  #define SSH_MAX_CIPHER_BLOCK_SIZE TWOFISH_BLOCK_SIZE
790 #elif (SSH_TWOFISH_192_SUPPORT == ENABLED)
791  #define SSH_MAX_CIPHER_BLOCK_SIZE TWOFISH_BLOCK_SIZE
792 #elif (SSH_TWOFISH_256_SUPPORT == ENABLED)
793  #define SSH_MAX_CIPHER_BLOCK_SIZE TWOFISH_BLOCK_SIZE
794 #elif (SSH_SERPENT_128_SUPPORT == ENABLED)
795  #define SSH_MAX_CIPHER_BLOCK_SIZE SERPENT_BLOCK_SIZE
796 #elif (SSH_SERPENT_192_SUPPORT == ENABLED)
797  #define SSH_MAX_CIPHER_BLOCK_SIZE SERPENT_BLOCK_SIZE
798 #elif (SSH_SERPENT_256_SUPPORT == ENABLED)
799  #define SSH_MAX_CIPHER_BLOCK_SIZE SERPENT_BLOCK_SIZE
800 #elif (SSH_CAMELLIA_128_SUPPORT == ENABLED)
801  #define SSH_MAX_CIPHER_BLOCK_SIZE CAMELLIA_BLOCK_SIZE
802 #elif (SSH_CAMELLIA_192_SUPPORT == ENABLED)
803  #define SSH_MAX_CIPHER_BLOCK_SIZE CAMELLIA_BLOCK_SIZE
804 #elif (SSH_CAMELLIA_256_SUPPORT == ENABLED)
805  #define SSH_MAX_CIPHER_BLOCK_SIZE CAMELLIA_BLOCK_SIZE
806 #elif (SSH_SEED_SUPPORT == ENABLED)
807  #define SSH_MAX_CIPHER_BLOCK_SIZE SEED_BLOCK_SIZE
808 #elif (SSH_CAST128_SUPPORT == ENABLED)
809  #define SSH_MAX_CIPHER_BLOCK_SIZE CAST128_BLOCK_SIZE
810 #elif (SSH_IDEA_SUPPORT == ENABLED)
811  #define SSH_MAX_CIPHER_BLOCK_SIZE IDEA_BLOCK_SIZE
812 #elif (SSH_BLOWFISH_SUPPORT == ENABLED)
813  #define SSH_MAX_CIPHER_BLOCK_SIZE BLOWFISH_BLOCK_SIZE
814 #else
815  #define SSH_MAX_CIPHER_BLOCK_SIZE DES3_BLOCK_SIZE
816 #endif
817 
818 //Maximum digest size (MAC algorithms)
819 #if (SSH_SHA512_SUPPORT == ENABLED)
820  #define SSH_MAX_HASH_DIGEST_SIZE SHA512_DIGEST_SIZE
821 #elif (SSH_SHA384_SUPPORT == ENABLED)
822  #define SSH_MAX_HASH_DIGEST_SIZE SHA384_DIGEST_SIZE
823 #elif (SSH_SHA256_SUPPORT == ENABLED)
824  #define SSH_MAX_HASH_DIGEST_SIZE SHA256_DIGEST_SIZE
825 #elif (SSH_SHA1_SUPPORT == ENABLED || SSH_SHA1_96_SUPPORT == ENABLED)
826  #define SSH_MAX_HASH_DIGEST_SIZE SHA1_DIGEST_SIZE
827 #elif (SSH_RIPEMD160_SUPPORT == ENABLED)
828  #define SSH_MAX_HASH_DIGEST_SIZE RIPEMD160_DIGEST_SIZE
829 #else
830  #define SSH_MAX_HASH_DIGEST_SIZE MD5_DIGEST_SIZE
831 #endif
832 
833 //Maximum shared secret length (RSA key exchange)
834 #if (SSH_RSA_KEX_SUPPORT == ENABLED)
835  #define SSH_MAX_RSA_SHARED_SECRET_LEN ((SSH_MAX_RSA_MODULUS_SIZE + 47) / 8)
836 #else
837  #define SSH_MAX_RSA_SHARED_SECRET_LEN 0
838 #endif
839 
840 //Maximum shared secret length (Diffie-Hellman key exchange)
841 #if (SSH_DH_KEX_SUPPORT == ENABLED || SSH_DH_GEX_KEX_SUPPORT == ENABLED)
842  #define SSH_MAX_DH_SHARED_SECRET_LEN ((SSH_MAX_DH_MODULUS_SIZE + 47) / 8)
843 #else
844  #define SSH_MAX_DH_SHARED_SECRET_LEN 0
845 #endif
846 
847 //Maximum shared secret length (ECDH key exchange)
848 #if (SSH_ECDH_KEX_SUPPORT == ENABLED && SSH_NISTP521_SUPPORT == ENABLED)
849  #define SSH_MAX_ECDH_SHARED_SECRET_LEN 71
850 #elif (SSH_ECDH_KEX_SUPPORT == ENABLED && SSH_CURVE448_SUPPORT == ENABLED)
851  #define SSH_MAX_ECDH_SHARED_SECRET_LEN 61
852 #elif (SSH_ECDH_KEX_SUPPORT == ENABLED && SSH_NISTP384_SUPPORT == ENABLED)
853  #define SSH_MAX_ECDH_SHARED_SECRET_LEN 53
854 #else
855  #define SSH_MAX_ECDH_SHARED_SECRET_LEN 37
856 #endif
857 
858 //Maximum shared secret length (pure post quantum key exchange)
859 #if (SSH_KEM_KEX_SUPPORT == ENABLED)
860  #define SSH_MAX_KEM_SHARED_SECRET_LEN 36
861 #else
862  #define SSH_MAX_KEM_SHARED_SECRET_LEN 0
863 #endif
864 
865 //Maximum shared secret length (post quantum hybrid key exchange)
866 #if (SSH_HYBRID_KEX_SUPPORT == ENABLED && SSH_SNTRUP761_SUPPORT == ENABLED)
867  #define SSH_MAX_HYBRID_SHARED_SECRET_LEN 68
868 #elif (SSH_HYBRID_KEX_SUPPORT == ENABLED && SSH_MLKEM1024_SUPPORT == ENABLED)
869  #define SSH_MAX_HYBRID_SHARED_SECRET_LEN 68
870 #elif (SSH_HYBRID_KEX_SUPPORT == ENABLED && SSH_MLKEM768_SUPPORT == ENABLED)
871  #define SSH_MAX_HYBRID_SHARED_SECRET_LEN 52
872 #else
873  #define SSH_MAX_HYBRID_SHARED_SECRET_LEN 0
874 #endif
875 
876 //Maximum shared secret length
877 #if (SSH_MAX_RSA_SHARED_SECRET_LEN >= SSH_MAX_DH_SHARED_SECRET_LEN && \
878  SSH_MAX_RSA_SHARED_SECRET_LEN >= SSH_MAX_ECDH_SHARED_SECRET_LEN && \
879  SSH_MAX_RSA_SHARED_SECRET_LEN >= SSH_MAX_KEM_SHARED_SECRET_LEN && \
880  SSH_MAX_RSA_SHARED_SECRET_LEN >= SSH_MAX_HYBRID_SHARED_SECRET_LEN)
881  #define SSH_MAX_SHARED_SECRET_LEN SSH_MAX_RSA_SHARED_SECRET_LEN
882 #elif (SSH_MAX_DH_SHARED_SECRET_LEN >= SSH_MAX_RSA_SHARED_SECRET_LEN && \
883  SSH_MAX_DH_SHARED_SECRET_LEN >= SSH_MAX_ECDH_SHARED_SECRET_LEN && \
884  SSH_MAX_DH_SHARED_SECRET_LEN >= SSH_MAX_KEM_SHARED_SECRET_LEN && \
885  SSH_MAX_DH_SHARED_SECRET_LEN >= SSH_MAX_HYBRID_SHARED_SECRET_LEN)
886  #define SSH_MAX_SHARED_SECRET_LEN SSH_MAX_DH_SHARED_SECRET_LEN
887 #elif (SSH_MAX_ECDH_SHARED_SECRET_LEN >= SSH_MAX_RSA_SHARED_SECRET_LEN && \
888  SSH_MAX_ECDH_SHARED_SECRET_LEN >= SSH_MAX_DH_SHARED_SECRET_LEN && \
889  SSH_MAX_ECDH_SHARED_SECRET_LEN >= SSH_MAX_KEM_SHARED_SECRET_LEN && \
890  SSH_MAX_ECDH_SHARED_SECRET_LEN >= SSH_MAX_HYBRID_SHARED_SECRET_LEN)
891  #define SSH_MAX_SHARED_SECRET_LEN SSH_MAX_ECDH_SHARED_SECRET_LEN
892 #elif (SSH_MAX_KEM_SHARED_SECRET_LEN >= SSH_MAX_RSA_SHARED_SECRET_LEN && \
893  SSH_MAX_KEM_SHARED_SECRET_LEN >= SSH_MAX_DH_SHARED_SECRET_LEN && \
894  SSH_MAX_KEM_SHARED_SECRET_LEN >= SSH_MAX_ECDH_SHARED_SECRET_LEN && \
895  SSH_MAX_KEM_SHARED_SECRET_LEN >= SSH_MAX_HYBRID_SHARED_SECRET_LEN)
896  #define SSH_MAX_SHARED_SECRET_LEN SSH_MAX_KEM_SHARED_SECRET_LEN
897 #else
898  #define SSH_MAX_SHARED_SECRET_LEN SSH_MAX_HYBRID_SHARED_SECRET_LEN
899 #endif
900 
901 //Application specific context
902 #ifndef SSH_CONTEXT_PRIVATE
903  #define SSH_CONTEXT_PRIVATE
904 #endif
905 
906 //Application specific context
907 #ifndef SSH_CONNECTION_PRIVATE
908  #define SSH_CONNECTION_PRIVATE
909 #endif
910 
911 //Application specific context
912 #ifndef SSH_CHANNEL_PRIVATE
913  #define SSH_CHANNEL_PRIVATE
914 #endif
915 
916 //SSH port number
917 #define SSH_PORT 22
918 
919 //Cookie size
920 #define SSH_COOKIE_SIZE 16
921 //Data overhead caused by mpint encoding
922 #define SSH_MAX_MPINT_OVERHEAD 5
923 //Data overhead caused by packet encryption
924 #define SSH_MAX_PACKET_OVERHEAD 128
925 
926 //Size of buffer used for input/output operations
927 #define SSH_BUFFER_SIZE (SSH_MAX_PACKET_SIZE + SSH_MAX_PACKET_OVERHEAD)
928 
929 //Forward declaration of SshContext structure
930 struct _SshContext;
931 #define SshContext struct _SshContext
932 
933 //Forward declaration of SshConnection structure
934 struct _SshConnection;
935 #define SshConnection struct _SshConnection
936 
937 //Forward declaration of SshChannel structure
938 struct _SshChannel;
939 #define SshChannel struct _SshChannel
940 
941 //C++ guard
942 #ifdef __cplusplus
943 extern "C" {
944 #endif
945 
946 
947 /**
948  * @brief Mode of operation
949  **/
950 
951 typedef enum
952 {
956 
957 
958 /**
959  * @brief Authentication status
960  **/
961 
962 typedef enum
963 {
968 
969 
970 /**
971  * @brief Flags used by read and write functions
972  **/
973 
974 typedef enum
975 {
976  SSH_FLAG_EOF = 0x0100,
981  SSH_FLAG_DELAY = 0x8000
983 
984 //The SSH_FLAG_BREAK macro causes the read function to stop reading
985 //data whenever the specified break character is encountered
986 #define SSH_FLAG_BREAK(c) (SSH_FLAG_BREAK_CHAR | LSB(c))
987 
988 
989 /**
990  * @brief SSH message types
991  **/
992 
993 typedef enum
994 {
1049  SSH_MSG_PONG = 193
1051 
1052 
1053 /**
1054  * @brief Disconnection messages reason codes
1055  **/
1056 
1057 typedef enum
1058 {
1075 
1076 
1077 /**
1078  * @brief Channel connection failure reason codes
1079  **/
1080 
1081 typedef enum
1082 {
1088 
1089 
1090 /**
1091  * @brief SSH connection state
1092  **/
1093 
1094 typedef enum
1095 {
1130 
1131 
1132 /**
1133  * @brief SSH channel state
1134  **/
1135 
1136 typedef enum
1137 {
1143 
1144 
1145 /**
1146  * @brief SSH request states
1147  **/
1148 
1149 typedef enum
1150 {
1156 
1157 
1158 /**
1159  * @brief SSH channel events
1160  **/
1161 
1162 typedef enum
1163 {
1173 } SshChannelEvent;
1174 
1175 
1176 /**
1177  * @brief Transient RSA key (for RSA key exchange)
1178  **/
1179 
1180 typedef struct
1181 {
1182  uint_t modulusSize; ///<Length of the modulus, in bits
1183  const char_t *publicKey; ///<RSA public key (PEM, SSH2 or OpenSSH format)
1184  size_t publicKeyLen; ///<Length of the RSA public key
1185  const char_t *privateKey; ///<RSA private key (PEM or OpenSSH format)
1186  size_t privateKeyLen; ///<Length of the RSA private key
1187  char_t password[SSH_MAX_PASSWORD_LEN + 1]; ///<Password used to decrypt the private key
1188 } SshRsaKey;
1189 
1190 
1191 /**
1192  * @brief Diffie-Hellman group
1193  **/
1194 
1195 typedef struct
1196 {
1197  uint_t dhModulusSize; ///<Length of the prime modulus, in bits
1198  const char_t *dhParams; ///<Diffie-Hellman parameters (PEM format)
1199  size_t dhParamsLen; ///<Length of the Diffie-Hellman parameters
1200 } SshDhGexGroup;
1201 
1202 
1203 /**
1204  * @brief Host key
1205  **/
1206 
1207 typedef struct
1208 {
1209  const char_t *keyFormatId; ///<Key format identifier
1210  const char_t *publicKey; ///<Public key (PEM, SSH2 or OpenSSH format)
1211  size_t publicKeyLen; ///<Length of the public key
1212  const char_t *privateKey; ///<Private key (PEM or OpenSSH format)
1213  size_t privateKeyLen; ///<Length of the private key
1214  char_t password[SSH_MAX_PASSWORD_LEN + 1]; ///<Password used to decrypt the private key
1215 #if (SSH_CLIENT_SUPPORT == ENABLED)
1216  const char_t *publicKeyAlgo; ///<Public key algorithm to use during user authentication
1217 #endif
1218 } SshHostKey;
1219 
1220 
1221 /**
1222  * @brief Host key algorithm
1223  **/
1224 
1225 typedef struct
1226 {
1227  const char_t *publicKeyAlgo; ///<Public key algorithm
1228  const char_t *keyFormatId; ///<Key format identifier
1229  const char_t *signFormatId; ///<Signature format identifier
1230 } SshHostKeyAlgo;
1231 
1232 
1233 /**
1234  * @brief Host key verification callback function
1235  **/
1236 
1238  const uint8_t *hostKey, size_t hostKeyLen);
1239 
1240 
1241 /**
1242  * @brief Certificate verification callback function
1243  **/
1244 
1246  const SshCertificate *cert);
1247 
1248 
1249 /**
1250  * @brief CA public key verification callback function
1251  **/
1252 
1254  const uint8_t *publicKey, size_t publicKeyLen);
1255 
1256 
1257 /**
1258  * @brief Public key authentication callback function
1259  **/
1260 
1262  const char_t *user, const uint8_t *publicKey, size_t publicKeyLen);
1263 
1264 
1265 /**
1266  * @brief Certificate authentication callback function
1267  **/
1268 
1270  const char_t *user, const SshCertificate *cert);
1271 
1272 
1273 /**
1274  * @brief Password authentication callback function
1275  **/
1276 
1278  const char_t *user, const char_t *password, size_t passwordLen);
1279 
1280 
1281 /**
1282  * @brief Password change callback function
1283  **/
1284 
1286  const char_t *user, const char_t *oldPassword, size_t oldPasswordLen,
1287  const char_t *newPassword, size_t newPasswordLen);
1288 
1289 
1290 /**
1291  * @brief Signature generation callback function
1292  **/
1293 
1295  const char_t *publicKeyAlgo, const SshHostKey *hostKey,
1297  uint8_t *p, size_t *written);
1298 
1299 
1300 /**
1301  * @brief Signature verification callback function
1302  **/
1303 
1305  const SshString *publicKeyAlgo, const SshBinaryString *publicKeyBlob,
1307  const SshBinaryString *signatureBlob);
1308 
1309 
1310 /**
1311  * @brief ECDH key pair generation callback
1312  **/
1313 
1315  const char_t *kexAlgo, EcPublicKey *publicKey);
1316 
1317 
1318 /**
1319  * @brief ECDH shared secret calculation callback
1320  **/
1321 
1323  const char_t *kexAlgo, const EcPublicKey *publicKey, uint8_t *output,
1324  size_t *outputLen);
1325 
1326 
1327 /**
1328  * @brief Global request callback function
1329  **/
1330 
1332  const SshString *name, const uint8_t *data, size_t length, void *param);
1333 
1334 
1335 /**
1336  * @brief Channel request callback function
1337  **/
1338 
1340  const SshString *type, const uint8_t *data, size_t length, void *param);
1341 
1342 
1343 /**
1344  * @brief Channel open callback function
1345  **/
1346 
1348  const SshString *type, uint32_t senderChannel, uint32_t initialWindowSize,
1349  uint32_t maxPacketSize, const uint8_t *data, size_t length, void *param);
1350 
1351 
1352 /**
1353  * @brief Connection open callback function
1354  **/
1355 
1357  void *param);
1358 
1359 
1360 /**
1361  * @brief Connection close callback function
1362  **/
1363 
1365  void *param);
1366 
1367 
1368 /**
1369  * @brief Key logging callback function (for debugging purpose only)
1370  **/
1371 
1373  const char_t *key);
1374 
1375 
1376 /**
1377  * @brief Encryption engine
1378  **/
1379 
1380 typedef struct
1381 {
1382  CipherMode cipherMode; ///<Cipher mode of operation
1383  const CipherAlgo *cipherAlgo; ///<Cipher algorithm
1384  CipherContext cipherContext; ///<Cipher context
1385  const HashAlgo *hashAlgo; ///<Hash algorithm for MAC operations
1386  HmacContext *hmacContext; ///<HMAC context
1387  size_t macSize; ///<Size of the MAC tag, in bytes
1388  bool_t etm; ///<Encrypt-then-MAC
1389  uint8_t iv[SSH_MAX_CIPHER_BLOCK_SIZE]; ///<Initialization vector
1390  uint8_t encKey[SSH_MAX_ENC_KEY_SIZE]; ///<Encryption key
1391  size_t encKeyLen; ///<Length of the encryption key, in bytes
1392  uint8_t macKey[SSH_MAX_HASH_DIGEST_SIZE]; ///<Integrity key
1393  uint8_t seqNum[4]; ///<Sequence number
1394 #if (SSH_GCM_CIPHER_SUPPORT == ENABLED || SSH_RFC5647_SUPPORT == ENABLED)
1395  GcmContext gcmContext; ///<GCM context
1396 #endif
1397 #if (SSH_CHACHA20_POLY1305_SUPPORT == ENABLED)
1398  uint8_t aad[4]; ///<Additional authenticated data
1399 #endif
1401 
1402 
1403 /**
1404  * @brief SSH channel buffer
1405  **/
1406 
1407 typedef struct
1408 {
1410  size_t length;
1411  size_t threshold;
1412  size_t writePos;
1413  size_t readPos;
1415 
1416 
1417 /**
1418  * @brief SSH channel
1419  **/
1420 
1422 {
1423  SshChannelState state; ///<Channel state
1424  SshRequestState requestState; ///<Channel request state
1425  SshContext *context; ///<SSH context
1426  SshConnection *connection; ///<SSH connection
1431  systime_t timeout; ///<Timeout value
1432  uint32_t localChannelNum; ///<Local channel number
1433  uint32_t remoteChannelNum; ///<Remote channel number
1434  uint32_t maxPacketSize; ///<Maximum packet size
1437  size_t txWindowSize; ///<TX flow-control window
1438  size_t rxWindowSize; ///<RX flow-control window
1439  size_t rxWindowSizeInc; ///<Window size increment
1440  bool_t channelSuccessSent; ///<An SSH_MSG_CHANNEL_SUCCESS message has been sent
1441  bool_t eofRequest; ///<Channel EOF request
1442  bool_t eofSent; ///<An SSH_MSG_CHANNEL_EOF message has been sent
1443  bool_t eofReceived; ///<An SSH_MSG_CHANNEL_EOF message has been received
1444  bool_t closeRequest; ///<Channel close request
1445  bool_t closeSent; ///<An SSH_MSG_CHANNEL_CLOSE message has been sent
1446  bool_t closeReceived; ///<An SSH_MSG_CHANNEL_CLOSE message has been received
1447  int32_t exitStatus; ///<Exit status of the command
1448  bool_t exitStatusSent; ///<An SSH_MSG_CHANNEL_REQUEST with the exit status has been sent
1449  SSH_CHANNEL_PRIVATE ///<Application specific context
1450 };
1451 
1452 
1453 /**
1454  * @brief SSH connection
1455  **/
1456 
1458 {
1459  SshConnectionState state; ///<Connection state
1460  SshRequestState requestState; ///<Global request state
1461  SshContext *context; ///<SSH context
1462  Socket *socket; ///<Underlying socket
1463  systime_t timestamp; ///<Time stamp to manage connection timeout
1464 
1465  char_t remoteId[SSH_MAX_ID_LEN + 1]; ///<Peer's identification string
1466  uint8_t cookie[SSH_COOKIE_SIZE]; ///<Random value generated by the sender
1467  char_t user[SSH_MAX_USERNAME_LEN + 1]; ///<User name
1468 
1469 #if (SSH_SERVER_SUPPORT == ENABLED && SSH_PASSWORD_AUTH_SUPPORT == ENABLED)
1470  char_t passwordChangePrompt[SSH_MAX_PASSWORD_CHANGE_PROMPT_LEN + 1]; ///<Password change prompt string
1471 #endif
1472 
1473  const char_t *kexAlgo; ///<Selected key exchange algorithm name
1474  const char_t *serverHostKeyAlgo; ///<Selected server's host key algorithm name
1475  const char_t *clientEncAlgo; ///<Selected client's encryption algorithm name
1476  const char_t *serverEncAlgo; ///<Selected server's encryption algorithm name
1477  const char_t *clientMacAlgo; ///<Selected client's MAC algorithm name
1478  const char_t *serverMacAlgo; ///<Selected server's MAC algorithm name
1479  const char_t *clientCompressAlgo; ///<Selected client's encryption algorithm name
1480  const char_t *serverCompressAlgo; ///<Selected server's encryption algorithm name
1481  int_t hostKeyIndex; ///<Index of the selected host key
1482 #if (SSH_RSA_KEX_SUPPORT == ENABLED)
1483  int_t rsaKeyIndex; ///<Index of the transient RSA key to use
1484  uint8_t *serverHostKey; ///<Server's host key
1485  size_t serverHostKeyLen; ///<Length of the server's host key, in bytes
1486 #endif
1487 #if (SSH_DH_GEX_KEX_SUPPORT == ENABLED)
1488  int_t dhGexGroupIndex; ///<Index of the selected Diffie-Hellman group
1489 #endif
1490 
1491  uint8_t sessionId[SSH_MAX_HASH_DIGEST_SIZE]; ///<Session identifier
1492  size_t sessionIdLen; ///<Length of the session identifier, in bytes
1493  uint8_t h[SSH_MAX_HASH_DIGEST_SIZE]; ///<Exchange hash H
1494  size_t hLen; ///<Length of the exchange hash, in bytes
1495  uint8_t k[SSH_MAX_SHARED_SECRET_LEN]; ///<Shared secret K
1496  size_t kLen; ///<Length of the shared secret, in bytes
1497 
1498  const HashAlgo *hashAlgo; ///<Exchange hash algorithm
1499  HashContext hashContext; ///<Exchange hash context
1500 #if (SSH_HMAC_SUPPORT == ENABLED)
1501  HmacContext hmacContext; ///<HMAC context
1502 #endif
1503 #if (SSH_DH_KEX_SUPPORT == ENABLED || SSH_DH_GEX_KEX_SUPPORT == ENABLED)
1504  DhContext dhContext; ///<Diffie-Hellman context
1505 #endif
1506 #if (SSH_ECDH_KEX_SUPPORT == ENABLED || SSH_HYBRID_KEX_SUPPORT == ENABLED)
1507  EcdhContext ecdhContext; ///<ECDH context
1508 #endif
1509 #if (SSH_HYBRID_KEX_SUPPORT == ENABLED)
1510  KemContext kemContext; ///<KEM context
1511 #endif
1512 
1513  SshEncryptionEngine encryptionEngine; ///<Encryption engine
1514  SshEncryptionEngine decryptionEngine; ///<Decryption engine
1515 
1516  bool_t kexInitSent; ///<An SSH_MSG_KEXINIT message has been sent
1517  bool_t kexInitReceived; ///<An SSH_MSG_KEXINIT message has been received
1518  bool_t newKeysSent; ///<An SSH_MSG_NEWKEYS message has been sent
1519  bool_t newKeysReceived; ///<An SSH_MSG_NEWKEYS message has been received
1520  bool_t disconnectRequest; ///<Request for disconnection
1521  bool_t disconnectSent; ///<An SSH_MSG_DISCONNECT message has been sent
1522  bool_t disconnectReceived; ///<An SSH_MSG_DISCONNECT message has been received
1523  bool_t wrongGuess; ///<A wrong guessed key exchange packet follows
1524  uint_t authAttempts; ///<Number of authentication attempts
1525  bool_t publicKeyOk; ///<The provided host key is acceptable
1526  uint32_t localChannelNum; ///<Current channel number
1527 
1528 #if (SSH_EXT_INFO_SUPPORT == ENABLED)
1529  bool_t extInfoReceived; ///<"ext-info-c" or "ext-info-s" indicator has been received
1530 #endif
1531 #if (SSH_KEX_STRICT_SUPPORT == ENABLED)
1532  bool_t kexStrictReceived; ///<"strict KEX" pseudo-algorithm received
1533 #endif
1534 
1535  uint8_t buffer[SSH_BUFFER_SIZE]; ///<Internal buffer
1536  size_t txBufferLen; ///<Number of bytes that are pending to be sent
1537  size_t txBufferPos; ///<Current position in TX buffer
1538  size_t rxBufferLen; ///<Number of bytes available for reading
1539  size_t rxBufferPos; ///<Current position in RX buffer
1540  SSH_CONNECTION_PRIVATE ///<Application specific context
1541 };
1542 
1543 
1544 /**
1545  * @brief SSH context
1546  **/
1547 
1549 {
1550  SshOperationMode mode; ///<Mode of operation (client or server)
1551  uint_t numConnections; ///<Maximum number of SSH connections
1552  SshConnection *connections; ///<SSH connections
1553  uint_t numChannels; ///<Maximum number of SSH channels
1554  SshChannel *channels; ///<SSH channels
1555  const PrngAlgo *prngAlgo; ///<Pseudo-random number generator to be used
1556  void *prngContext; ///<Pseudo-random number generator context
1557  SshHostKey hostKeys[SSH_MAX_HOST_KEYS]; ///<List of host keys
1558 
1559 #if (SSH_CLIENT_SUPPORT == ENABLED)
1562 #endif
1563 
1564 #if (SSH_SERVER_SUPPORT == ENABLED && SSH_RSA_KEX_SUPPORT == ENABLED)
1565  SshRsaKey rsaKeys[SSH_MAX_RSA_KEYS]; ///<Transient RSA keys (for RSA key exchange)
1566 #endif
1567 #if (SSH_SERVER_SUPPORT == ENABLED && SSH_DH_GEX_KEX_SUPPORT == ENABLED)
1569 #endif
1570 
1571  SshHostKeyVerifyCallback hostKeyVerifyCallback; ///<Host key verification callback
1572 #if (SSH_CERT_SUPPORT == ENABLED)
1573  SshCertVerifyCallback certVerifyCallback; ///<Certificate verification callback
1574  SshCaPublicKeyVerifyCallback caPublicKeyVerifyCallback; ///<CA public key verification callback
1575 #endif
1576 #if (SSH_PUBLIC_KEY_AUTH_SUPPORT == ENABLED)
1577  SshPublicKeyAuthCallback publicKeyAuthCallback; ///<Public key authentication callback
1578 #endif
1579 #if (SSH_PUBLIC_KEY_AUTH_SUPPORT == ENABLED && SSH_CERT_SUPPORT == ENABLED)
1580  SshCertAuthCallback certAuthCallback; ///<Certificate authentication callback
1581 #endif
1582 #if (SSH_PASSWORD_AUTH_SUPPORT == ENABLED)
1583  SshPasswordAuthCallback passwordAuthCallback; ///<Password authentication callback
1585 #endif
1586 #if (SSH_SIGN_CALLBACK_SUPPORT == ENABLED)
1587  SshSignGenCallback signGenCallback; ///<Signature generation callback
1588  SshSignVerifyCallback signVerifyCallback; ///<Signature verification callback
1589 #endif
1590 #if (SSH_ECDH_CALLBACK_SUPPORT == ENABLED)
1591  SshEcdhKeyPairGenCallback ecdhKeyPairGenCallback; ///<ECDH key pair generation callback
1592  SshEcdhSharedSecretCalcCallback ecdhSharedSecretCalcCallback; ///<ECDH shared secret calculation callback
1593 #endif
1595  void *globalReqParam[SSH_MAX_GLOBAL_REQ_CALLBACKS]; ///<Opaque pointer passed to the global request callback
1597  void *channelReqParam[SSH_MAX_CHANNEL_REQ_CALLBACKS]; ///<Opaque pointer passed to the channel request callback
1599  void *channelOpenParam[SSH_MAX_CHANNEL_OPEN_CALLBACKS]; ///<Opaque pointer passed to the channel open callback
1601  void *connectionOpenParam[SSH_MAX_CONN_OPEN_CALLBACKS]; ///<Opaque pointer passed to the connection open callback
1603  void *connectionCloseParam[SSH_MAX_CONN_CLOSE_CALLBACKS]; ///<Opaque pointer passed to the connection close callback
1604 #if (SSH_KEY_LOG_SUPPORT == ENABLED)
1605  SshKeyLogCallback keyLogCallback; ///<Key logging callback (for debugging purpose only)
1606 #endif
1607 
1608  OsMutex mutex; ///<Mutex preventing simultaneous access to the context
1609  OsEvent event; ///<Event object used to poll the sockets
1610  SocketEventDesc eventDesc[SSH_MAX_CONNECTIONS + 1]; ///<The events the application is interested in
1611  SSH_CONTEXT_PRIVATE ///<Application specific context
1612 };
1613 
1614 
1615 /**
1616  * @brief Structure describing channel events
1617  **/
1618 
1619 typedef struct
1620 {
1621  SshChannel *channel; ///<Handle to a channel to monitor
1622  uint_t eventMask; ///<Requested events
1623  uint_t eventFlags; ///<Returned events
1625 
1626 
1627 //SSH related functions
1628 error_t sshInit(SshContext *context, SshConnection *connections,
1629  uint_t numConnections, SshChannel *channels, uint_t numChannels);
1630 
1632 
1633 error_t sshSetPrng(SshContext *context, const PrngAlgo *prngAlgo,
1634  void *prngContext);
1635 
1636 error_t sshSetUsername(SshContext *context, const char_t *username);
1637 error_t sshSetPassword(SshContext *context, const char_t *password);
1638 
1640  SshHostKeyVerifyCallback callback);
1641 
1643  SshCertVerifyCallback callback);
1644 
1646  SshCaPublicKeyVerifyCallback callback);
1647 
1649  SshPublicKeyAuthCallback callback);
1650 
1652  SshCertAuthCallback callback);
1653 
1655  SshPasswordAuthCallback callback);
1656 
1658  SshPasswordChangeCallback callback);
1659 
1661  SshSignGenCallback callback);
1662 
1664  SshSignVerifyCallback callback);
1665 
1667  SshEcdhKeyPairGenCallback callback);
1668 
1671 
1673  SshGlobalReqCallback callback, void *param);
1674 
1676  SshGlobalReqCallback callback);
1677 
1679  SshChannelReqCallback callback, void *param);
1680 
1682  SshChannelReqCallback callback);
1683 
1685  SshChannelOpenCallback callback, void *param);
1686 
1688  SshChannelOpenCallback callback);
1689 
1691  SshConnectionOpenCallback callback, void *param);
1692 
1694  SshConnectionOpenCallback callback);
1695 
1697  SshConnectionCloseCallback callback, void *param);
1698 
1700  SshConnectionCloseCallback callback);
1701 
1703  SshKeyLogCallback callback);
1704 
1705 error_t sshLoadRsaKey(SshContext *context, uint_t index,
1706  const char_t *publicKey, size_t publicKeyLen, const char_t *privateKey,
1707  size_t privateKeyLen, const char_t *password);
1708 
1709 error_t sshUnloadRsaKey(SshContext *context, uint_t index);
1710 
1711 error_t sshLoadDhGexGroup(SshContext *context, uint_t index,
1712  const char_t *dhParams, size_t dhParamsLen);
1713 
1714 error_t sshUnloadDhGexGroup(SshContext *context, uint_t index);
1715 
1716 error_t sshLoadHostKey(SshContext *context, uint_t index,
1717  const char_t *publicKey, size_t publicKeyLen, const char_t *privateKey,
1718  size_t privateKeyLen, const char_t *password);
1719 
1720 error_t sshUnloadHostKey(SshContext *context, uint_t index);
1721 
1723  const char_t *cert, size_t certLen, const char_t *privateKey,
1724  size_t privateKeyLen, const char_t *password);
1725 
1727 
1729  const char_t *prompt);
1730 
1732 
1734 
1735 error_t sshWriteChannel(SshChannel *channel, const void *data, size_t length,
1736  size_t *written, uint_t flags);
1737 
1738 error_t sshReadChannel(SshChannel *channel, void *data, size_t size,
1739  size_t *received, uint_t flags);
1740 
1742  OsEvent *extEvent, systime_t timeout);
1743 
1744 error_t sshSetExitStatus(SshChannel *channel, int32_t exitStatus);
1745 
1748 void sshDeleteChannel(SshChannel *channel);
1749 
1750 void sshDeinit(SshContext *context);
1751 
1752 //C++ guard
1753 #ifdef __cplusplus
1754 }
1755 #endif
1756 
1757 #endif
uint8_t h[SSH_MAX_HASH_DIGEST_SIZE]
Exchange hash H.
Definition: ssh.h:1493
const PrngAlgo * prngAlgo
Pseudo-random number generator to be used.
Definition: ssh.h:1555
bool_t closeSent
An SSH_MSG_CHANNEL_CLOSE message has been sent.
Definition: ssh.h:1445
@ SSH_FLAG_WAIT_ALL
Definition: ssh.h:977
SocketEventDesc eventDesc[SSH_MAX_CONNECTIONS+1]
The events the application is interested in.
Definition: ssh.h:1610
SshEcdhKeyPairGenCallback ecdhKeyPairGenCallback
ECDH key pair generation callback.
Definition: ssh.h:1591
size_t privateKeyLen
Length of the RSA private key.
Definition: ssh.h:1186
error_t(* SshChannelReqCallback)(SshChannel *channel, const SshString *type, const uint8_t *data, size_t length, void *param)
Channel request callback function.
Definition: ssh.h:1339
systime_t timeout
Timeout value.
Definition: ssh.h:1431
@ SSH_MSG_KEX_DH_REPLY
Definition: ssh.h:1012
@ SSH_OPEN_RESOURCE_SHORTAGE
Definition: ssh.h:1086
size_t rxWindowSizeInc
Window size increment.
Definition: ssh.h:1439
Collection of key exchange algorithms.
Generic hash algorithm context.
#define SSH_MAX_CONN_CLOSE_CALLBACKS
Definition: ssh.h:223
int bool_t
Definition: compiler_port.h:63
uint8_t sessionId[]
Definition: tls.h:1942
HMAC algorithm context.
Definition: hmac.h:59
@ SSH_CONN_STATE_USER_AUTH_REPLY
Definition: ssh.h:1125
const char_t * clientEncAlgo
Selected client's encryption algorithm name.
Definition: ssh.h:1475
SshOperationMode
Mode of operation.
Definition: ssh.h:952
@ SSH_CONN_STATE_OPEN
Definition: ssh.h:1127
@ SSH_CONN_STATE_KEX_KEM_REPLY
Definition: ssh.h:1113
error_t sshLoadHostKey(SshContext *context, uint_t index, const char_t *publicKey, size_t publicKeyLen, const char_t *privateKey, size_t privateKeyLen, const char_t *password)
Load entity's host key.
Definition: ssh.c:1353
void * globalReqParam[SSH_MAX_GLOBAL_REQ_CALLBACKS]
Opaque pointer passed to the global request callback.
Definition: ssh.h:1595
SshGlobalReqCallback globalReqCallback[SSH_MAX_GLOBAL_REQ_CALLBACKS]
Global request callbacks.
Definition: ssh.h:1594
@ SSH_CHANNEL_EVENT_CONNECTED
Definition: ssh.h:1165
const char_t * clientMacAlgo
Selected client's MAC algorithm name.
Definition: ssh.h:1477
uint_t eventMask
Requested events.
Definition: ssh.h:1622
error_t sshUnloadDhGexGroup(SshContext *context, uint_t index)
Unload Diffie-Hellman group.
Definition: ssh.c:1311
error_t sshInit(SshContext *context, SshConnection *connections, uint_t numConnections, SshChannel *channels, uint_t numChannels)
SSH context initialization.
Definition: ssh.c:58
@ SSH_MSG_USERAUTH_PASSWD_CHANGEREQ
Definition: ssh.h:1031
error_t sshLoadCertificate(SshContext *context, uint_t index, const char_t *cert, size_t certLen, const char_t *privateKey, size_t privateKeyLen, const char_t *password)
Load entity's certificate.
Definition: ssh.c:1678
SshChannelState
SSH channel state.
Definition: ssh.h:1137
size_t serverHostKeyLen
Length of the server's host key, in bytes.
Definition: ssh.h:1485
signed int int_t
Definition: compiler_port.h:56
@ SSH_CONN_STATE_KEX_HYBRID_INIT
Definition: ssh.h:1114
@ SSH_AUTH_STATUS_FAILURE
Definition: ssh.h:964
error_t sshSetExitStatus(SshChannel *channel, int32_t exitStatus)
Set exit status.
Definition: ssh.c:2491
error_t(* SshCaPublicKeyVerifyCallback)(SshConnection *connection, const uint8_t *publicKey, size_t publicKeyLen)
CA public key verification callback function.
Definition: ssh.h:1253
void(* SshConnectionCloseCallback)(SshConnection *connection, void *param)
Connection close callback function.
Definition: ssh.h:1364
Binary string.
Definition: ssh_types.h:67
@ SSH_CONN_STATE_KEX_DH_GEX_REQUEST
Definition: ssh.h:1106
void(* SshKeyLogCallback)(SshConnection *connection, const char_t *key)
Key logging callback function (for debugging purpose only)
Definition: ssh.h:1372
const char_t * privateKey
Private key (PEM or OpenSSH format)
Definition: ssh.h:1212
#define PrngAlgo
Definition: crypto.h:1140
error_t sshSetPrng(SshContext *context, const PrngAlgo *prngAlgo, void *prngContext)
Set the pseudo-random number generator to be used.
Definition: ssh.c:193
@ SSH_CONN_STATE_SERVER_EXT_INFO_2
Definition: ssh.h:1120
void * connectionOpenParam[SSH_MAX_CONN_OPEN_CALLBACKS]
Opaque pointer passed to the connection open callback.
Definition: ssh.h:1601
const char_t * publicKeyAlgo
Public key algorithm.
Definition: ssh.h:1227
@ SSH_CONN_STATE_KEX_RSA_SECRET
Definition: ssh.h:1102
bool_t closeReceived
An SSH_MSG_CHANNEL_CLOSE message has been received.
Definition: ssh.h:1446
SshChannelEvent
SSH channel events.
Definition: ssh.h:1163
uint8_t p
Definition: ndp.h:300
const HashAlgo * hashAlgo
Hash algorithm for MAC operations.
Definition: ssh.h:1385
size_t rxBufferLen
Number of bytes available for reading.
Definition: ssh.h:1538
uint8_t message[]
Definition: chap.h:154
SshContext * context
SSH context.
Definition: ssh.h:1425
@ SSH_CONN_STATE_SERVICE_ACCEPT
Definition: ssh.h:1122
@ SSH_MSG_KEX_HYBRID_INIT
Definition: ssh.h:1022
@ SSH_AUTH_STATUS_SUCCESS
Definition: ssh.h:965
Collection of cipher algorithms.
@ SSH_DISCONNECT_COMPRESSION_ERROR
Definition: ssh.h:1064
@ SSH_FLAG_BREAK_CHAR
Definition: ssh.h:978
#define SSH_MAX_CHANNEL_OPEN_CALLBACKS
Definition: ssh.h:209
uint8_t data[]
Definition: ethernet.h:224
error_t(* SshCertAuthCallback)(SshConnection *connection, const char_t *user, const SshCertificate *cert)
Certificate authentication callback function.
Definition: ssh.h:1269
@ SSH_DISCONNECT_MAC_ERROR
Definition: ssh.h:1063
SshSignVerifyCallback signVerifyCallback
Signature verification callback.
Definition: ssh.h:1588
size_t txBufferPos
Current position in TX buffer.
Definition: ssh.h:1537
Event object.
const char_t * publicKey
RSA public key (PEM, SSH2 or OpenSSH format)
Definition: ssh.h:1183
Generic cipher algorithm context.
@ SSH_MSG_CHANNEL_FAILURE
Definition: ssh.h:1047
GcmContext gcmContext
GCM context.
Definition: ssh.h:1395
OsEvent event
Event object used to poll the sockets.
Definition: ssh.h:1609
size_t threshold
Definition: ssh.h:1411
error_t sshUnloadCertificate(SshContext *context, uint_t index)
Unload entity's certificate.
Definition: ssh.c:1899
size_t macSize
Size of the MAC tag, in bytes.
Definition: ssh.h:1387
uint_t eventFlags
Returned events.
Definition: ssh.h:1623
size_t rxWindowSize
RX flow-control window.
Definition: ssh.h:1438
error_t sshRegisterEcdhSharedSecretCalcCallback(SshContext *context, SshEcdhSharedSecretCalcCallback callback)
Register ECDH shared secret calculation callback function.
Definition: ssh.c:586
SshConnectionState
SSH connection state.
Definition: ssh.h:1095
void * channelReqParam[SSH_MAX_CHANNEL_REQ_CALLBACKS]
Opaque pointer passed to the channel request callback.
Definition: ssh.h:1597
uint8_t type
Definition: coap_common.h:176
@ SSH_MSG_CHANNEL_SUCCESS
Definition: ssh.h:1046
bool_t eofRequest
Channel EOF request.
Definition: ssh.h:1441
@ SSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLE
Definition: ssh.h:1067
Transient RSA key (for RSA key exchange)
Definition: ssh.h:1181
error_t sshUnregisterConnectionOpenCallback(SshContext *context, SshConnectionOpenCallback callback)
Unregister connection open callback function.
Definition: ssh.c:926
SshConnectionCloseCallback connectionCloseCallback[SSH_MAX_CONN_CLOSE_CALLBACKS]
Connection close callback function.
Definition: ssh.h:1602
SshChannel * channel
Handle to a channel to monitor.
Definition: ssh.h:1621
SshChannelBuffer txBuffer
TX buffer.
Definition: ssh.h:1435
char_t name[]
@ SSH_MSG_CHANNEL_OPEN_CONFIRMATION
Definition: ssh.h:1038
@ SSH_MSG_REQUEST_FAILURE
Definition: ssh.h:1036
size_t txBufferLen
Number of bytes that are pending to be sent.
Definition: ssh.h:1536
size_t txWindowSize
TX flow-control window.
Definition: ssh.h:1437
#define SSH_MAX_SHARED_SECRET_LEN
Definition: ssh.h:881
const char_t * privateKey
RSA private key (PEM or OpenSSH format)
Definition: ssh.h:1185
SSH channel buffer.
Definition: ssh.h:1408
error_t sshRegisterCaPublicKeyVerifyCallback(SshContext *context, SshCaPublicKeyVerifyCallback callback)
Register CA public key verification callback function.
Definition: ssh.c:338
error_t sshLoadDhGexGroup(SshContext *context, uint_t index, const char_t *dhParams, size_t dhParamsLen)
Load Diffie-Hellman group.
Definition: ssh.c:1234
SshCaPublicKeyVerifyCallback caPublicKeyVerifyCallback
CA public key verification callback.
Definition: ssh.h:1574
SshMessageType
SSH message types.
Definition: ssh.h:994
SshConnection * connection
SSH connection.
Definition: ssh.h:1426
error_t sshRegisterPasswordChangeCallback(SshContext *context, SshPasswordChangeCallback callback)
Register password change callback function.
Definition: ssh.c:462
@ SSH_MSG_KEX_KEM_INIT
Definition: ssh.h:1020
@ SSH_CONN_STATE_KEX_DH_GEX_GROUP
Definition: ssh.h:1107
@ SSH_MSG_NEWCOMPRESS
Definition: ssh.h:1003
@ SSH_CONN_STATE_KEX_HYBRID_REPLY
Definition: ssh.h:1115
@ SSH_CONN_STATE_SERVER_EXT_INFO_1
Definition: ssh.h:1119
Structure describing socket events.
Definition: socket.h:433
char_t username[SSH_MAX_USERNAME_LEN+1]
User name.
Definition: ssh.h:1560
uint_t eventFlags
Definition: ssh.h:1429
uint_t numChannels
Maximum number of SSH channels.
Definition: ssh.h:1553
char_t remoteId[SSH_MAX_ID_LEN+1]
Peer's identification string.
Definition: ssh.h:1465
SshCertVerifyCallback certVerifyCallback
Certificate verification callback.
Definition: ssh.h:1573
Encryption engine.
Definition: ssh.h:1381
#define SSH_MAX_CIPHER_BLOCK_SIZE
Definition: ssh.h:783
@ SSH_OPEN_ADMINISTRATIVELY_PROHIBITED
Definition: ssh.h:1083
@ SSH_CHANNEL_EVENT_CLOSED
Definition: ssh.h:1166
@ SSH_CONN_STATE_DISCONNECT
Definition: ssh.h:1128
error_t sshRegisterPasswordAuthCallback(SshContext *context, SshPasswordAuthCallback callback)
Register password authentication callback function.
Definition: ssh.c:431
@ SSH_MSG_KEX_DH_GEX_REPLY
Definition: ssh.h:1017
@ SSH_REQUEST_STATE_PENDING
Definition: ssh.h:1152
uint32_t remoteChannelNum
Remote channel number.
Definition: ssh.h:1433
error_t sshUnregisterGlobalRequestCallback(SshContext *context, SshGlobalReqCallback callback)
Unregister global request callback function.
Definition: ssh.c:665
@ SSH_CHANNEL_EVENT_TX_READY
Definition: ssh.h:1167
uint_t numConnections
Maximum number of SSH connections.
Definition: ssh.h:1551
int_t dhGexGroupIndex
Index of the selected Diffie-Hellman group.
Definition: ssh.h:1488
SshAuthStatus
Authentication status.
Definition: ssh.h:963
bool_t eofReceived
An SSH_MSG_CHANNEL_EOF message has been received.
Definition: ssh.h:1443
@ SSH_DISCONNECT_BY_APPLICATION
Definition: ssh.h:1069
error_t sshUnloadRsaKey(SshContext *context, uint_t index)
Unload transient RSA key (for RSA key exchange)
Definition: ssh.c:1197
@ SSH_MSG_CHANNEL_DATA
Definition: ssh.h:1041
@ SSH_CHANNEL_EVENT_TX_SHUTDOWN
Definition: ssh.h:1170
Diffie-Hellman context.
Definition: dh.h:60
error_t sshReadChannel(SshChannel *channel, void *data, size_t size, size_t *received, uint_t flags)
Receive data from the specified channel.
Definition: ssh.c:2206
void * channelOpenParam[SSH_MAX_CHANNEL_OPEN_CALLBACKS]
Opaque pointer passed to the channel open callback.
Definition: ssh.h:1599
@ SSH_MSG_KEX_DH_INIT
Definition: ssh.h:1011
@ SSH_MSG_GLOBAL_REQUEST
Definition: ssh.h:1034
@ SSH_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT
Definition: ssh.h:1059
#define SshContext
Definition: ssh.h:931
error_t sshUnloadHostKey(SshContext *context, uint_t index)
Unload entity's host key.
Definition: ssh.c:1615
const char_t * keyFormatId
Key format identifier.
Definition: ssh.h:1209
@ SSH_MSG_NEWKEYS
Definition: ssh.h:1005
int32_t exitStatus
Exit status of the command.
Definition: ssh.h:1447
@ SSH_MSG_INVALID
Definition: ssh.h:995
size_t kLen
Length of the shared secret, in bytes.
Definition: ssh.h:1496
size_t hLen
Length of the exchange hash, in bytes.
Definition: ssh.h:1494
error_t sshCloseChannel(SshChannel *channel)
Close channel.
Definition: ssh.c:2558
error_t
Error codes.
Definition: error.h:43
uint32_t seqNum
Definition: tcp.h:348
error_t sshLoadRsaKey(SshContext *context, uint_t index, const char_t *publicKey, size_t publicKeyLen, const char_t *privateKey, size_t privateKeyLen, const char_t *password)
Load transient RSA key (for RSA key exchange)
Definition: ssh.c:1087
@ SSH_MSG_KEX_HYBRID_REPLY
Definition: ssh.h:1023
SSH connection.
Definition: ssh.h:1458
CipherMode cipherMode
Cipher mode of operation.
Definition: ssh.h:1382
uint8_t cookie[SSH_COOKIE_SIZE]
Random value generated by the sender.
Definition: ssh.h:1466
bool_t closeRequest
Channel close request.
Definition: ssh.h:1444
error_t(* SshGlobalReqCallback)(SshConnection *connection, const SshString *name, const uint8_t *data, size_t length, void *param)
Global request callback function.
Definition: ssh.h:1331
KEM context.
Definition: kem.h:68
@ SSH_MSG_USERAUTH_INFO_RESPONSE
Definition: ssh.h:1033
bool_t disconnectRequest
Request for disconnection.
Definition: ssh.h:1520
@ SSH_MSG_CHANNEL_CLOSE
Definition: ssh.h:1044
SshRsaKey rsaKeys[SSH_MAX_RSA_KEYS]
Transient RSA keys (for RSA key exchange)
Definition: ssh.h:1565
#define SSH_MAX_ID_LEN
Definition: ssh.h:251
@ SSH_MSG_USERAUTH_PK_OK
Definition: ssh.h:1030
error_t sshRegisterSignGenCallback(SshContext *context, SshSignGenCallback callback)
Register signature generation callback function.
Definition: ssh.c:493
uint32_t localChannelNum
Current channel number.
Definition: ssh.h:1526
@ SSH_OPERATION_MODE_SERVER
Definition: ssh.h:954
@ SSH_CONN_STATE_KEX_KEM_INIT
Definition: ssh.h:1112
error_t(* SshChannelOpenCallback)(SshConnection *connection, const SshString *type, uint32_t senderChannel, uint32_t initialWindowSize, uint32_t maxPacketSize, const uint8_t *data, size_t length, void *param)
Channel open callback function.
Definition: ssh.h:1347
uint_t authAttempts
Number of authentication attempts.
Definition: ssh.h:1524
bool_t kexInitReceived
An SSH_MSG_KEXINIT message has been received.
Definition: ssh.h:1517
#define SSH_MAX_RSA_KEYS
Definition: ssh.h:692
@ SSH_OPERATION_MODE_CLIENT
Definition: ssh.h:953
@ SSH_MSG_KEXRSA_DONE
Definition: ssh.h:1010
size_t publicKeyLen
Length of the RSA public key.
Definition: ssh.h:1184
@ SSH_MSG_KEX_DH_GEX_REQUEST_OLD
Definition: ssh.h:1013
const char_t * publicKey
Public key (PEM, SSH2 or OpenSSH format)
Definition: ssh.h:1210
@ SSH_CONN_STATE_KEX_ECDH_INIT
Definition: ssh.h:1110
Diffie-Hellman group.
Definition: ssh.h:1196
const CipherAlgo * cipherAlgo
Cipher algorithm.
Definition: ssh.h:1383
bool_t publicKeyOk
The provided host key is acceptable.
Definition: ssh.h:1525
@ SSH_FLAG_NO_DELAY
Definition: ssh.h:980
size_t writePos
Definition: ssh.h:1412
EcdhContext ecdhContext
ECDH context.
Definition: ssh.h:1507
@ SSH_FLAG_DELAY
Definition: ssh.h:981
char_t passwordChangePrompt[SSH_MAX_PASSWORD_CHANGE_PROMPT_LEN+1]
Password change prompt string.
Definition: ssh.h:1470
@ SSH_MSG_SERVICE_REQUEST
Definition: ssh.h:1000
bool_t kexStrictReceived
"strict KEX" pseudo-algorithm received
Definition: ssh.h:1532
const char_t * kexAlgo
Selected key exchange algorithm name.
Definition: ssh.h:1473
error_t(* SshCertVerifyCallback)(SshConnection *connection, const SshCertificate *cert)
Certificate verification callback function.
Definition: ssh.h:1245
SshChannelBuffer rxBuffer
RX buffer.
Definition: ssh.h:1436
Host key.
Definition: ssh.h:1208
uint_t eventMask
Definition: ssh.h:1428
const char_t * dhParams
Diffie-Hellman parameters (PEM format)
Definition: ssh.h:1198
error_t sshPollChannels(SshChannelEventDesc *eventDesc, uint_t size, OsEvent *extEvent, systime_t timeout)
Wait for one of a set of channels to become ready to perform I/O.
Definition: ssh.c:2402
error_t sshRegisterKeyLogCallback(SshContext *context, SshKeyLogCallback callback)
Register key logging callback function (for debugging purpose only)
Definition: ssh.c:1052
bool_t etm
Encrypt-then-MAC.
Definition: ssh.h:1388
@ SSH_MSG_USERAUTH_REQUEST
Definition: ssh.h:1024
bool_t eofSent
An SSH_MSG_CHANNEL_EOF message has been sent.
Definition: ssh.h:1442
General definitions for cryptographic algorithms.
SshAuthStatus(* SshPasswordChangeCallback)(SshConnection *connection, const char_t *user, const char_t *oldPassword, size_t oldPasswordLen, const char_t *newPassword, size_t newPasswordLen)
Password change callback function.
Definition: ssh.h:1285
CipherContext cipherContext
Cipher context.
Definition: ssh.h:1384
error_t(* SshEcdhKeyPairGenCallback)(SshConnection *connection, const char_t *kexAlgo, EcPublicKey *publicKey)
ECDH key pair generation callback.
Definition: ssh.h:1314
@ SSH_CHANNEL_STATE_OPEN
Definition: ssh.h:1140
SSH certificate parsing.
@ SSH_CONN_STATE_KEX_ECDH_REPLY
Definition: ssh.h:1111
@ SSH_MSG_USERAUTH_FAILURE
Definition: ssh.h:1025
const char_t * serverEncAlgo
Selected server's encryption algorithm name.
Definition: ssh.h:1476
@ SSH_MSG_DEBUG
Definition: ssh.h:999
SshEncryptionEngine encryptionEngine
Encryption engine.
Definition: ssh.h:1513
SshHostKey hostKeys[SSH_MAX_HOST_KEYS]
List of host keys.
Definition: ssh.h:1557
@ SSH_MSG_PING
Definition: ssh.h:1048
uint8_t iv[]
Definition: ike.h:1695
@ SSH_CONN_STATE_KEX_RSA_PUB_KEY
Definition: ssh.h:1101
error_t sshRegisterChannelOpenCallback(SshContext *context, SshChannelOpenCallback callback, void *param)
Register channel open callback function.
Definition: ssh.c:792
error_t sshRegisterHostKeyVerifyCallback(SshContext *context, SshHostKeyVerifyCallback callback)
Register host key verification callback function.
Definition: ssh.c:281
SshDisconnectReasonCode
Disconnection messages reason codes.
Definition: ssh.h:1058
Block cipher modes of operation.
@ SSH_CONN_STATE_CLIENT_ID
Definition: ssh.h:1097
@ SSH_MSG_CHANNEL_OPEN_FAILURE
Definition: ssh.h:1039
size_t publicKeyLen
Length of the public key.
Definition: ssh.h:1211
error_t sshSetPassword(SshContext *context, const char_t *password)
Set the password to be used for authentication.
Definition: ssh.c:251
HashContext hashContext
Exchange hash context.
Definition: ssh.h:1499
error_t sshUnregisterChannelOpenCallback(SshContext *context, SshChannelOpenCallback callback)
Unregister channel open callback function.
Definition: ssh.c:839
error_t sshUnregisterChannelRequestCallback(SshContext *context, SshChannelReqCallback callback)
Unregister channel request callback function.
Definition: ssh.c:752
#define SSH_CHANNEL_BUFFER_SIZE
Definition: ssh.h:244
@ SSH_MSG_USERAUTH_BANNER
Definition: ssh.h:1027
@ SSH_DISCONNECT_CONNECTION_LOST
Definition: ssh.h:1068
Host key algorithm.
Definition: ssh.h:1226
@ SSH_REQUEST_STATE_IDLE
Definition: ssh.h:1151
error_t(* SshEcdhSharedSecretCalcCallback)(SshConnection *connection, const char_t *kexAlgo, const EcPublicKey *publicKey, uint8_t *output, size_t *outputLen)
ECDH shared secret calculation callback.
Definition: ssh.h:1322
@ SSH_MSG_DISCONNECT
Definition: ssh.h:996
SshPasswordChangeCallback passwordChangeCallback
Password change callback.
Definition: ssh.h:1584
bool_t newKeysReceived
An SSH_MSG_NEWKEYS message has been received.
Definition: ssh.h:1519
error_t sshWriteChannel(SshChannel *channel, const void *data, size_t length, size_t *written, uint_t flags)
Write data to the specified channel.
Definition: ssh.c:2077
uint8_t length
Definition: tcp.h:375
#define SSH_MAX_HOST_KEYS
Definition: ssh.h:181
@ SSH_CHANNEL_EVENT_TIMEOUT
Definition: ssh.h:1164
error_t sshRegisterConnectionCloseCallback(SshContext *context, SshConnectionCloseCallback callback, void *param)
Register connection close callback function.
Definition: ssh.c:966
error_t sshRegisterConnectionOpenCallback(SshContext *context, SshConnectionOpenCallback callback, void *param)
Register connection open callback function.
Definition: ssh.c:879
@ SSH_CONN_STATE_SERVER_NEW_KEYS
Definition: ssh.h:1117
@ SSH_AUTH_STATUS_PASSWORD_EXPIRED
Definition: ssh.h:966
SshChannelOpenCallback channelOpenCallback[SSH_MAX_CHANNEL_OPEN_CALLBACKS]
Channel open callbacks.
Definition: ssh.h:1598
#define SSH_CONNECTION_PRIVATE
Definition: ssh.h:908
uint8_t buffer[SSH_BUFFER_SIZE]
Internal buffer.
Definition: ssh.h:1535
bool_t kexInitSent
An SSH_MSG_KEXINIT message has been sent.
Definition: ssh.h:1516
String.
Definition: ssh_types.h:56
@ SSH_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED
Definition: ssh.h:1066
@ SSH_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE
Definition: ssh.h:1072
error_t(* SshConnectionOpenCallback)(SshConnection *connection, void *param)
Connection open callback function.
Definition: ssh.h:1356
error_t(* SshSignVerifyCallback)(SshConnection *connection, const SshString *publicKeyAlgo, const SshBinaryString *publicKeyBlob, const SshBinaryString *sessionId, const SshBinaryString *message, const SshBinaryString *signatureBlob)
Signature verification callback function.
Definition: ssh.h:1304
@ SSH_MSG_USERAUTH_SUCCESS
Definition: ssh.h:1026
size_t rxBufferPos
Current position in RX buffer.
Definition: ssh.h:1539
@ SSH_CONN_STATE_CLOSED
Definition: ssh.h:1096
@ SSH_CHANNEL_EVENT_TX_DONE
Definition: ssh.h:1168
bool_t extInfoReceived
"ext-info-c" or "ext-info-s" indicator has been received
Definition: ssh.h:1529
const char_t * clientCompressAlgo
Selected client's encryption algorithm name.
Definition: ssh.h:1479
#define SSH_MAX_PASSWORD_CHANGE_PROMPT_LEN
Definition: ssh.h:272
@ SSH_DISCONNECT_SERVICE_NOT_AVAILABLE
Definition: ssh.h:1065
#define SSH_MAX_HASH_DIGEST_SIZE
Definition: ssh.h:820
error_t sshSetPasswordChangePrompt(SshConnection *connection, const char_t *prompt)
Set password change prompt message.
Definition: ssh.c:1959
uint8_t * serverHostKey
Server's host key.
Definition: ssh.h:1484
uint8_t k[SSH_MAX_SHARED_SECRET_LEN]
Shared secret K.
Definition: ssh.h:1495
Collection of hash algorithms.
@ SSH_CONN_STATE_USER_AUTH_SUCCESS
Definition: ssh.h:1126
Mutex object.
@ SSH_REQUEST_STATE_FAILURE
Definition: ssh.h:1154
const char_t * keyFormatId
Key format identifier.
Definition: ssh.h:1228
@ SSH_CONN_STATE_CLIENT_NEW_KEYS
Definition: ssh.h:1116
error_t sshSetUsername(SshContext *context, const char_t *username)
Set the user name to be used for authentication.
Definition: ssh.c:221
uint32_t systime_t
System time.
#define SSH_MAX_CONNECTIONS
Definition: ssh.h:188
@ SSH_DISCONNECT_PROTOCOL_ERROR
Definition: ssh.h:1060
bool_t channelSuccessSent
An SSH_MSG_CHANNEL_SUCCESS message has been sent.
Definition: ssh.h:1440
Collection of AEAD algorithms.
EC public key.
Definition: ec.h:421
int_t hostKeyIndex
Index of the selected host key.
Definition: ssh.h:1481
void * connectionCloseParam[SSH_MAX_CONN_CLOSE_CALLBACKS]
Opaque pointer passed to the connection close callback.
Definition: ssh.h:1603
#define SSH_MAX_PASSWORD_LEN
Definition: ssh.h:265
SshKeyLogCallback keyLogCallback
Key logging callback (for debugging purpose only)
Definition: ssh.h:1605
char char_t
Definition: compiler_port.h:55
GCM context.
Definition: gcm.h:64
#define SSH_MAX_GLOBAL_REQ_CALLBACKS
Definition: ssh.h:195
SshConnection * connections
SSH connections.
Definition: ssh.h:1552
const char_t * publicKeyAlgo
Public key algorithm to use during user authentication.
Definition: ssh.h:1216
@ SSH_MSG_CHANNEL_OPEN
Definition: ssh.h:1037
@ SSH_OPEN_CONNECT_FAILED
Definition: ssh.h:1084
#define SSH_MAX_ENC_KEY_SIZE
Definition: ssh.h:776
SshRequestState
SSH request states.
Definition: ssh.h:1150
KemContext kemContext
KEM context.
Definition: ssh.h:1510
@ SSH_DISCONNECT_AUTH_CANCELLED_BY_USER
Definition: ssh.h:1071
size_t readPos
Definition: ssh.h:1413
@ SSH_REQUEST_STATE_SUCCESS
Definition: ssh.h:1153
@ SSH_CHANNEL_EVENT_RX_SHUTDOWN
Definition: ssh.h:1172
@ SSH_CONN_STATE_SERVER_KEX_INIT
Definition: ssh.h:1100
SshChannelFlags
Flags used by read and write functions.
Definition: ssh.h:975
error_t(* SshPublicKeyAuthCallback)(SshConnection *connection, const char_t *user, const uint8_t *publicKey, size_t publicKeyLen)
Public key authentication callback function.
Definition: ssh.h:1261
@ SSH_CONN_STATE_SERVER_ID
Definition: ssh.h:1098
@ SSH_CONN_STATE_KEX_DH_INIT
Definition: ssh.h:1104
error_t sshRegisterCertAuthCallback(SshContext *context, SshCertAuthCallback callback)
Register certificate authentication callback function.
Definition: ssh.c:400
@ SSH_MSG_CHANNEL_REQUEST
Definition: ssh.h:1045
const HashAlgo * hashAlgo
Exchange hash algorithm.
Definition: ssh.h:1498
@ SSH_CONN_STATE_CLIENT_EXT_INFO
Definition: ssh.h:1118
SSH data type representations.
Structure describing channel events.
Definition: ssh.h:1620
@ SSH_DISCONNECT_KEY_EXCHANGE_FAILED
Definition: ssh.h:1061
@ SSH_CHANNEL_EVENT_RX_READY
Definition: ssh.h:1171
@ SSH_CONN_STATE_KEX_RSA_DONE
Definition: ssh.h:1103
const char_t * serverHostKeyAlgo
Selected server's host key algorithm name.
Definition: ssh.h:1474
HmacContext hmacContext
HMAC context.
Definition: ssh.h:1501
@ SSH_CONN_STATE_SERVICE_REQUEST
Definition: ssh.h:1121
#define SshConnection
Definition: ssh.h:935
@ SSH_FLAG_EOF
Definition: ssh.h:976
Legacy definitions.
@ SSH_MSG_CHANNEL_EOF
Definition: ssh.h:1043
SshOpenFailureReasonCode
Channel connection failure reason codes.
Definition: ssh.h:1082
#define SSH_MAX_CONN_OPEN_CALLBACKS
Definition: ssh.h:216
@ SSH_CONN_STATE_USER_AUTH_REQUEST
Definition: ssh.h:1124
SshRequestState requestState
Channel request state.
Definition: ssh.h:1424
error_t sshUnregisterConnectionCloseCallback(SshContext *context, SshConnectionCloseCallback callback)
Unregister connection close callback function.
Definition: ssh.c:1013
@ SSH_MSG_CHANNEL_WINDOW_ADJUST
Definition: ssh.h:1040
@ SSH_MSG_KEX_DH_GEX_INIT
Definition: ssh.h:1016
@ SSH_CHANNEL_STATE_RESERVED
Definition: ssh.h:1139
@ SSH_MSG_KEXRSA_PUBKEY
Definition: ssh.h:1008
error_t sshRegisterChannelRequestCallback(SshContext *context, SshChannelReqCallback callback, void *param)
Register channel request callback function.
Definition: ssh.c:705
bool_t exitStatusSent
An SSH_MSG_CHANNEL_REQUEST with the exit status has been sent.
Definition: ssh.h:1448
#define Socket
Definition: socket.h:36
systime_t timestamp
Time stamp to manage connection timeout.
Definition: ssh.h:1463
@ SSH_CONN_STATE_CLIENT_KEX_INIT
Definition: ssh.h:1099
#define SSH_MAX_DH_GEX_GROUPS
Definition: ssh.h:699
@ SSH_MSG_KEX_ECDH_INIT
Definition: ssh.h:1018
@ SSH_MSG_PONG
Definition: ssh.h:1049
error_t sshSetOperationMode(SshContext *context, SshOperationMode mode)
Set operation mode (client or server)
Definition: ssh.c:167
size_t sessionIdLen
Length of the session identifier, in bytes.
Definition: ssh.h:1492
@ SSH_FLAG_BREAK_CRLF
Definition: ssh.h:979
@ SSH_CONN_STATE_KEX_DH_GEX_REPLY
Definition: ssh.h:1109
OsEvent * userEvent
Definition: ssh.h:1430
@ SSH_MSG_USERAUTH_INFO_REQUEST
Definition: ssh.h:1032
uint8_t sessionId[SSH_MAX_HASH_DIGEST_SIZE]
Session identifier.
Definition: ssh.h:1491
uint32_t localChannelNum
Local channel number.
Definition: ssh.h:1432
Common interface for encryption algorithms.
Definition: crypto.h:1285
error_t sshRegisterCertVerifyCallback(SshContext *context, SshCertVerifyCallback callback)
Register certificate verification callback function.
Definition: ssh.c:307
#define SSH_MAX_CHANNEL_REQ_CALLBACKS
Definition: ssh.h:202
#define SSH_CHANNEL_PRIVATE
Definition: ssh.h:913
SshAuthStatus(* SshPasswordAuthCallback)(SshConnection *connection, const char_t *user, const char_t *password, size_t passwordLen)
Password authentication callback function.
Definition: ssh.h:1277
@ SSH_MSG_KEX_DH_GEX_REQUEST
Definition: ssh.h:1014
SshCertAuthCallback certAuthCallback
Certificate authentication callback.
Definition: ssh.h:1580
@ SSH_MSG_REQUEST_SUCCESS
Definition: ssh.h:1035
@ SSH_MSG_IGNORE
Definition: ssh.h:997
char_t password[SSH_MAX_PASSWORD_LEN+1]
Password.
Definition: ssh.h:1561
const char_t * serverCompressAlgo
Selected server's encryption algorithm name.
Definition: ssh.h:1480
Collection of MAC algorithms.
void sshDeleteChannel(SshChannel *channel)
Release channel.
Definition: ssh.c:2629
bool_t disconnectSent
An SSH_MSG_DISCONNECT message has been sent.
Definition: ssh.h:1521
SshChannelReqCallback channelReqCallback[SSH_MAX_CHANNEL_REQ_CALLBACKS]
Channel request callbacks.
Definition: ssh.h:1596
@ SSH_CONN_STATE_KEX_DH_REPLY
Definition: ssh.h:1105
size_t privateKeyLen
Length of the private key.
Definition: ssh.h:1213
@ SSH_MSG_KEX_MAX
Definition: ssh.h:1007
SshConnectionOpenCallback connectionOpenCallback[SSH_MAX_CONN_OPEN_CALLBACKS]
Connection open callback function.
Definition: ssh.h:1600
uint_t dhModulusSize
Length of the prime modulus, in bits.
Definition: ssh.h:1197
@ SSH_DISCONNECT_RESERVED
Definition: ssh.h:1062
@ SSH_MSG_SERVICE_ACCEPT
Definition: ssh.h:1001
HmacContext * hmacContext
HMAC context.
Definition: ssh.h:1386
Common interface for hash algorithms.
Definition: crypto.h:1243
@ SSH_MSG_KEXRSA_SECRET
Definition: ssh.h:1009
SshChannelState state
Channel state.
Definition: ssh.h:1423
error_t sshRegisterEcdhKeyPairGenCallback(SshContext *context, SshEcdhKeyPairGenCallback callback)
Register ECDH key pair generation callback function.
Definition: ssh.c:555
@ SSH_CONN_STATE_KEX_DH_GEX_INIT
Definition: ssh.h:1108
bool_t newKeysSent
An SSH_MSG_NEWKEYS message has been sent.
Definition: ssh.h:1518
@ SSH_MSG_UNIMPLEMENTED
Definition: ssh.h:998
@ SSH_OPEN_UNKNOWN_CHANNEL_TYPE
Definition: ssh.h:1085
void * prngContext
Pseudo-random number generator context.
Definition: ssh.h:1556
OsMutex mutex
Mutex preventing simultaneous access to the context.
Definition: ssh.h:1608
@ SSH_MSG_KEX_KEM_REPLY
Definition: ssh.h:1021
@ SSH_MSG_USERAUTH_MAX
Definition: ssh.h:1029
SshRequestState requestState
Global request state.
Definition: ssh.h:1460
uint8_t flags
Definition: tcp.h:358
const char_t * serverMacAlgo
Selected server's MAC algorithm name.
Definition: ssh.h:1478
#define SSH_COOKIE_SIZE
Definition: ssh.h:920
SshPasswordAuthCallback passwordAuthCallback
Password authentication callback.
Definition: ssh.h:1583
error_t sshRegisterSignVerifyCallback(SshContext *context, SshSignVerifyCallback callback)
Register signature verification callback function.
Definition: ssh.c:524
int_t rsaKeyIndex
Index of the transient RSA key to use.
Definition: ssh.h:1483
#define SSH_CONTEXT_PRIVATE
Definition: ssh.h:903
SshSignGenCallback signGenCallback
Signature generation callback.
Definition: ssh.h:1587
SshDhGexGroup dhGexGroups[SSH_MAX_DH_GEX_GROUPS]
Diffie-Hellman groups.
Definition: ssh.h:1568
unsigned int uint_t
Definition: compiler_port.h:57
@ SSH_MSG_EXT_INFO
Definition: ssh.h:1002
@ SSH_CHANNEL_STATE_CLOSED
Definition: ssh.h:1141
bool_t disconnectReceived
An SSH_MSG_DISCONNECT message has been received.
Definition: ssh.h:1522
TCP/IP stack core.
SshContext * context
SSH context.
Definition: ssh.h:1461
SshChannel * sshCreateChannel(SshConnection *connection)
Create a new SSH channel.
Definition: ssh.c:1989
char_t user[SSH_MAX_USERNAME_LEN+1]
User name.
Definition: ssh.h:1467
@ SSH_MSG_KEX_ECDH_REPLY
Definition: ssh.h:1019
size_t length
Definition: ssh.h:1410
@ SSH_MSG_USERAUTH_MIN
Definition: ssh.h:1028
error_t(* SshSignGenCallback)(SshConnection *connection, const char_t *publicKeyAlgo, const SshHostKey *hostKey, const SshBinaryString *sessionId, const SshBinaryString *message, uint8_t *p, size_t *written)
Signature generation callback function.
Definition: ssh.h:1294
@ SSH_MSG_KEX_DH_GEX_GROUP
Definition: ssh.h:1015
SshEncryptionEngine decryptionEngine
Decryption engine.
Definition: ssh.h:1514
SshPublicKeyAuthCallback publicKeyAuthCallback
Public key authentication callback.
Definition: ssh.h:1577
OsEvent event
Definition: ssh.h:1427
error_t(* SshHostKeyVerifyCallback)(SshConnection *connection, const uint8_t *hostKey, size_t hostKeyLen)
Host key verification callback function.
Definition: ssh.h:1237
ECC (Elliptic Curve Cryptography)
#define SSH_MAX_USERNAME_LEN
Definition: ssh.h:258
@ SSH_CHANNEL_STATE_UNUSED
Definition: ssh.h:1138
SshChannel * channels
SSH channels.
Definition: ssh.h:1554
error_t sshRegisterGlobalRequestCallback(SshContext *context, SshGlobalReqCallback callback, void *param)
Register global request callback function.
Definition: ssh.c:618
SshConnectionState state
Connection state.
Definition: ssh.h:1459
uint_t modulusSize
Length of the modulus, in bits.
Definition: ssh.h:1182
DhContext dhContext
Diffie-Hellman context.
Definition: ssh.h:1504
#define SSH_BUFFER_SIZE
Definition: ssh.h:927
error_t sshSetChannelTimeout(SshChannel *channel, systime_t timeout)
Set timeout for read/write operations.
Definition: ssh.c:2053
error_t sshRegisterPublicKeyAuthCallback(SshContext *context, SshPublicKeyAuthCallback callback)
Register public key authentication callback function.
Definition: ssh.c:369
@ SSH_DISCONNECT_TOO_MANY_CONNECTIONS
Definition: ssh.h:1070
SshHostKeyVerifyCallback hostKeyVerifyCallback
Host key verification callback.
Definition: ssh.h:1571
SSH context.
Definition: ssh.h:1549
ECDH context.
Definition: ecdh.h:60
@ SSH_CONN_STATE_USER_AUTH_BANNER
Definition: ssh.h:1123
const char_t * signFormatId
Signature format identifier.
Definition: ssh.h:1229
SSH certificate (OpenSSH format)
size_t encKeyLen
Length of the encryption key, in bytes.
Definition: ssh.h:1391
SshOperationMode mode
Mode of operation (client or server)
Definition: ssh.h:1550
@ SSH_MSG_KEX_MIN
Definition: ssh.h:1006
#define SshChannel
Definition: ssh.h:939
SshEcdhSharedSecretCalcCallback ecdhSharedSecretCalcCallback
ECDH shared secret calculation callback.
Definition: ssh.h:1592
Socket * socket
Underlying socket.
Definition: ssh.h:1462
uint32_t maxPacketSize
Maximum packet size.
Definition: ssh.h:1434
@ SSH_CHANNEL_EVENT_TX_ACKED
Definition: ssh.h:1169
error_t sshAbortChannel(SshChannel *channel)
Abort channel.
Definition: ssh.c:2511
void sshDeinit(SshContext *context)
Release SSH context.
Definition: ssh.c:2649
@ SSH_MSG_CHANNEL_EXTENDED_DATA
Definition: ssh.h:1042
bool_t wrongGuess
A wrong guessed key exchange packet follows.
Definition: ssh.h:1523
SSH channel.
Definition: ssh.h:1422
size_t dhParamsLen
Length of the Diffie-Hellman parameters.
Definition: ssh.h:1199
CipherMode
Cipher operation modes.
Definition: cipher_modes.h:78
@ SSH_DISCONNECT_ILLEGAL_USER_NAME
Definition: ssh.h:1073
@ SSH_MSG_KEXINIT
Definition: ssh.h:1004