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