ssh_packet.h
Go to the documentation of this file.
1 /**
2  * @file ssh_packet.h
3  * @brief SSH packet encryption/decryption
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_PACKET_H
32 #define _SSH_PACKET_H
33 
34 //Dependencies
35 #include "ssh/ssh.h"
36 
37 //SSH packet header size
38 #define SSH_PACKET_HEADER_SIZE 5
39 //Minimum SSH packet size
40 #define SSH_MIN_PACKET_SIZE 8
41 //Default maximum packet size
42 #define SSH_DEFAULT_MAX_PACKET_SIZE 32768
43 //Size of SSH_MSG_CHANNEL_DATA message header
44 #define SSH_CHANNEL_DATA_MSG_HEADER_SIZE 9
45 
46 //C++ guard
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 //SSH related functions
52 error_t sshSendPacket(SshConnection *connection, uint8_t *payload,
53  size_t payloadLen);
54 
56 
57 error_t sshParsePacket(SshConnection *connection, uint8_t *packet,
58  size_t length);
59 
60 error_t sshEncryptPacket(SshConnection *connection, uint8_t *packet,
61  size_t *length);
62 
63 error_t sshDecryptPacket(SshConnection *connection, uint8_t *packet,
64  size_t *length);
65 
66 error_t sshParsePacketLength(SshConnection *connection, uint8_t *packet);
67 error_t sshDecryptPacketLength(SshConnection *connection, uint8_t *packet);
68 
69 error_t sshParseMessage(SshConnection *connection, const uint8_t *message,
70  size_t length);
71 
72 void sshAppendMessageAuthCode(SshEncryptionEngine *encryptionEngine,
73  uint8_t *packet, size_t length);
74 
76  const uint8_t *packet, size_t length);
77 
78 void sshIncSequenceNumber(uint8_t *seqNum);
79 void sshIncInvocationCounter(uint8_t *iv);
80 
81 //C++ guard
82 #ifdef __cplusplus
83 }
84 #endif
85 
86 #endif
uint8_t message[]
Definition: chap.h:154
error_t
Error codes.
Definition: error.h:43
uint8_t iv[]
Definition: ike.h:1502
uint8_t payload[]
Definition: ipv6.h:277
uint16_t payloadLen
Definition: ipv6.h:272
Secure Shell (SSH)
#define SshConnection
Definition: ssh.h:883
error_t sshDecryptPacketLength(SshConnection *connection, uint8_t *packet)
Decrypt the length field of an incoming SSH packet.
Definition: ssh_packet.c:950
void sshIncSequenceNumber(uint8_t *seqNum)
Increment sequence number.
Definition: ssh_packet.c:1412
error_t sshEncryptPacket(SshConnection *connection, uint8_t *packet, size_t *length)
Encrypt an outgoing SSH packet.
Definition: ssh_packet.c:467
error_t sshParsePacket(SshConnection *connection, uint8_t *packet, size_t length)
Parse SSH packet.
Definition: ssh_packet.c:332
error_t sshVerifyMessageAuthCode(SshEncryptionEngine *decryptionEngine, const uint8_t *packet, size_t length)
Verify message authentication code.
Definition: ssh_packet.c:1368
error_t sshSendPacket(SshConnection *connection, uint8_t *payload, size_t payloadLen)
Send SSH packet.
Definition: ssh_packet.c:57
error_t sshReceivePacket(SshConnection *connection)
Receive SSH packet.
Definition: ssh_packet.c:178
void sshIncInvocationCounter(uint8_t *iv)
Increment invocation counter.
Definition: ssh_packet.c:1433
error_t sshParsePacketLength(SshConnection *connection, uint8_t *packet)
Retrieve the length of an incoming SSH packet.
Definition: ssh_packet.c:913
error_t sshParseMessage(SshConnection *connection, const uint8_t *message, size_t length)
Parse SSH message.
Definition: ssh_packet.c:1129
void sshAppendMessageAuthCode(SshEncryptionEngine *encryptionEngine, uint8_t *packet, size_t length)
Compute message authentication code.
Definition: ssh_packet.c:1338
error_t sshDecryptPacket(SshConnection *connection, uint8_t *packet, size_t *length)
Decrypt an incoming SSH packet.
Definition: ssh_packet.c:677
Encryption engine.
Definition: ssh.h:1325
uint8_t length
Definition: tcp.h:368
uint32_t seqNum
Definition: tcp.h:341