mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-10 01:48:00 +00:00
New BinarySink function 'put_padding'.
It is to put_data what memset is to memcpy. Several places in the code wanted it already, but not _quite_ enough for me to have written it with the rest of the BinarySink infrastructure originally.
This commit is contained in:
parent
72c2b70736
commit
8b98fea4ae
3
import.c
3
import.c
@ -1010,8 +1010,7 @@ int openssh_pem_write(const Filename *filename, struct ssh2_userkey *key,
|
|||||||
origlen = outblob->len;
|
origlen = outblob->len;
|
||||||
outlen = (origlen + 8) &~ 7;
|
outlen = (origlen + 8) &~ 7;
|
||||||
pad = outlen - origlen;
|
pad = outlen - origlen;
|
||||||
for (i = 0; i < pad; i++)
|
put_padding(outblob, pad, pad);
|
||||||
put_byte(outblob, pad);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Invent an iv. Then derive encryption key from passphrase
|
* Invent an iv. Then derive encryption key from passphrase
|
||||||
|
11
marshal.c
11
marshal.c
@ -11,6 +11,17 @@ void BinarySink_put_data(BinarySink *bs, const void *data, size_t len)
|
|||||||
bs->write(bs, data, len);
|
bs->write(bs, data, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BinarySink_put_padding(BinarySink *bs, unsigned char padbyte, size_t len)
|
||||||
|
{
|
||||||
|
char buf[16];
|
||||||
|
memset(buf, padbyte, sizeof(buf));
|
||||||
|
while (len > 0) {
|
||||||
|
size_t thislen = len < sizeof(buf) ? len : sizeof(buf);
|
||||||
|
bs->write(bs, buf, thislen);
|
||||||
|
len -= thislen;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void BinarySink_put_byte(BinarySink *bs, unsigned char val)
|
void BinarySink_put_byte(BinarySink *bs, unsigned char val)
|
||||||
{
|
{
|
||||||
bs->write(bs, &val, 1);
|
bs->write(bs, &val, 1);
|
||||||
|
@ -110,6 +110,10 @@ struct BinarySink {
|
|||||||
#define put_mp_ssh2(bs, val) \
|
#define put_mp_ssh2(bs, val) \
|
||||||
BinarySink_put_mp_ssh2(BinarySink_UPCAST(bs), val)
|
BinarySink_put_mp_ssh2(BinarySink_UPCAST(bs), val)
|
||||||
|
|
||||||
|
/* Padding with a specified byte. */
|
||||||
|
#define put_padding(bs, padbyte, len) \
|
||||||
|
BinarySink_put_padding(BinarySink_UPCAST(bs), padbyte, len)
|
||||||
|
|
||||||
/* Fallback: just emit raw data bytes, using a syntax that matches the
|
/* Fallback: just emit raw data bytes, using a syntax that matches the
|
||||||
* rest of these macros. */
|
* rest of these macros. */
|
||||||
#define put_data(bs, val, len) \
|
#define put_data(bs, val, len) \
|
||||||
@ -126,6 +130,7 @@ struct BinarySink {
|
|||||||
* declaration(s) of their other parameter type(s) are in scope.
|
* declaration(s) of their other parameter type(s) are in scope.
|
||||||
*/
|
*/
|
||||||
void BinarySink_put_data(BinarySink *, const void *data, size_t len);
|
void BinarySink_put_data(BinarySink *, const void *data, size_t len);
|
||||||
|
void BinarySink_put_padding(BinarySink *, unsigned char padbyte, size_t len);
|
||||||
void BinarySink_put_byte(BinarySink *, unsigned char);
|
void BinarySink_put_byte(BinarySink *, unsigned char);
|
||||||
void BinarySink_put_bool(BinarySink *, int);
|
void BinarySink_put_bool(BinarySink *, int);
|
||||||
void BinarySink_put_uint16(BinarySink *, unsigned long);
|
void BinarySink_put_uint16(BinarySink *, unsigned long);
|
||||||
|
3
ssh.c
3
ssh.c
@ -2803,8 +2803,7 @@ static void ssh2_add_sigblob(Ssh ssh, PktOut *pkt,
|
|||||||
strbuf *substr = strbuf_new();
|
strbuf *substr = strbuf_new();
|
||||||
put_data(substr, sigblob, sig_prefix_len);
|
put_data(substr, sigblob, sig_prefix_len);
|
||||||
put_uint32(substr, mod_mp.len);
|
put_uint32(substr, mod_mp.len);
|
||||||
while (mod_mp.len-- > sig_mp.len)
|
put_padding(substr, mod_mp.len - sig_mp.len, 0);
|
||||||
put_byte(substr, 0);
|
|
||||||
put_data(substr, sig_mp.ptr, sig_mp.len);
|
put_data(substr, sig_mp.ptr, sig_mp.len);
|
||||||
put_stringsb(pkt, substr);
|
put_stringsb(pkt, substr);
|
||||||
return;
|
return;
|
||||||
|
@ -356,8 +356,7 @@ int rsa_ssh1_savekey(const Filename *filename, struct RSAKey *key,
|
|||||||
* Now write zeros until the encrypted portion is a multiple of
|
* Now write zeros until the encrypted portion is a multiple of
|
||||||
* 8 bytes.
|
* 8 bytes.
|
||||||
*/
|
*/
|
||||||
while ((buf->len - estart) % 8)
|
put_padding(buf, (estart - buf->len) & 7, 0);
|
||||||
put_byte(buf, 0);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Now encrypt the encrypted portion.
|
* Now encrypt the encrypted portion.
|
||||||
|
Loading…
Reference in New Issue
Block a user