1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
/*
20140207
20241211 - reformated using clang-format
Jan Mojzis
Public domain.
*/
#include "crypto_uint32.h"
#include "buf.h"
#include "bug.h"
#include "sshcrypto.h"
#include "ssh.h"
#include "log.h"
#include "packet.h"
static void packet_put_plain_(struct buf *b) {
long long pos;
crypto_uint8 paddinglen;
struct buf *sendbuf = &packet.sendbuf;
pos = sendbuf->len; /* get position */
buf_putnum32(sendbuf, 0); /* length */
buf_putnum8(sendbuf, 0); /* padding length */
buf_put(sendbuf, b->buf, b->len); /* add data */
packet.sendpacketid++; /* increment id */
/* padding */
paddinglen = 2 * 8 - ((sendbuf->len - pos) % 8);
buf_putzerobytes(sendbuf, paddinglen);
sendbuf->buf[pos + 4] = paddinglen;
/* add packet length */
crypto_uint32_store_bigendian(sendbuf->buf + pos, sendbuf->len - pos - 4);
}
int packet_putisready(void) {
return buf_ready(&packet.sendbuf, PACKET_FULLLIMIT);
}
void packet_put(struct buf *b) {
if (packet.flagkeys) { sshcrypto_packet_put(b); }
else { packet_put_plain_(b); }
/* overflow check */
if (!packet.sendpacketid) {
log_f1("sendpacketid overflow");
global_die(111);
}
/* strict kex - reset sendpacketid */
if (b->buf[0] == SSH_MSG_NEWKEYS &&
sshcrypto_kex_flags & sshcrypto_FLAGSTRICTKEX) {
packet.sendpacketid = 0;
}
}
|