mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-08 08:58:00 +00:00
Add and use BinarySource_*INIT_PL.
A great many BinarySource_BARE_INIT calls are passing the two halves of a ptrlen as separate arguments. It saves a lot of call-site faff to have a variant of the init function that just takes the whole ptrlen in one go.
This commit is contained in:
parent
59f7b24b9d
commit
751a989091
14
import.c
14
import.c
@ -600,7 +600,7 @@ static ssh2_userkey *openssh_pem_read(
|
||||
|
||||
/* Reinitialise our BinarySource to parse just the inside of that
|
||||
* SEQUENCE. */
|
||||
BinarySource_BARE_INIT(src, seq.data.ptr, seq.data.len);
|
||||
BinarySource_BARE_INIT_PL(src, seq.data);
|
||||
}
|
||||
|
||||
/* Expect a load of INTEGERs. */
|
||||
@ -625,11 +625,11 @@ static ssh2_userkey *openssh_pem_read(
|
||||
sub1 = get_ber(src);
|
||||
|
||||
/* Now look inside sub0 for the curve OID */
|
||||
BinarySource_BARE_INIT(src, sub0.data.ptr, sub0.data.len);
|
||||
BinarySource_BARE_INIT_PL(src, sub0.data);
|
||||
oid = get_ber(src);
|
||||
|
||||
/* And inside sub1 for the public-key BIT STRING */
|
||||
BinarySource_BARE_INIT(src, sub1.data.ptr, sub1.data.len);
|
||||
BinarySource_BARE_INIT_PL(src, sub1.data);
|
||||
pubkey = get_ber(src);
|
||||
|
||||
if (get_err(src) ||
|
||||
@ -1229,7 +1229,7 @@ static struct openssh_new_key *load_openssh_new_key(const Filename *filename,
|
||||
{
|
||||
BinarySource opts[1];
|
||||
|
||||
BinarySource_BARE_INIT(opts, str.ptr, str.len);
|
||||
BinarySource_BARE_INIT_PL(opts, str);
|
||||
ret->kdfopts.bcrypt.salt = get_string(opts);
|
||||
ret->kdfopts.bcrypt.rounds = get_uint32(opts);
|
||||
|
||||
@ -1398,7 +1398,7 @@ static ssh2_userkey *openssh_new_read(
|
||||
* Now parse the entire encrypted section, and extract the key
|
||||
* identified by key_wanted.
|
||||
*/
|
||||
BinarySource_BARE_INIT(src, key->private.ptr, key->private.len);
|
||||
BinarySource_BARE_INIT_PL(src, key->private);
|
||||
|
||||
checkint = get_uint32(src);
|
||||
if (get_uint32(src) != checkint || get_err(src)) {
|
||||
@ -2077,13 +2077,13 @@ static ssh2_userkey *sshcom_read(
|
||||
* Expect the ciphertext to be formatted as a containing string,
|
||||
* and reinitialise src to start parsing the inside of that string.
|
||||
*/
|
||||
BinarySource_BARE_INIT(src, ciphertext.ptr, ciphertext.len);
|
||||
BinarySource_BARE_INIT_PL(src, ciphertext);
|
||||
str = get_string(src);
|
||||
if (get_err(src)) {
|
||||
errmsg = "containing string was ill-formed";
|
||||
goto error;
|
||||
}
|
||||
BinarySource_BARE_INIT(src, str.ptr, str.len);
|
||||
BinarySource_BARE_INIT_PL(src, str);
|
||||
|
||||
/*
|
||||
* Now we break down into RSA versus DSA. In either case we'll
|
||||
|
28
marshal.h
28
marshal.h
@ -227,19 +227,25 @@ struct BinarySource {
|
||||
* Implementation macros, similar to BinarySink.
|
||||
*/
|
||||
#define BinarySource_IMPLEMENTATION BinarySource binarysource_[1]
|
||||
#define BinarySource_INIT__(obj, data_, len_) \
|
||||
((obj)->data = (data_), \
|
||||
(obj)->len = (len_), \
|
||||
(obj)->pos = 0, \
|
||||
(obj)->err = BSE_NO_ERROR, \
|
||||
(obj)->binarysource_ = (obj))
|
||||
#define BinarySource_BARE_INIT(obj, data_, len_) \
|
||||
static inline void BinarySource_INIT__(BinarySource *src, ptrlen data)
|
||||
{
|
||||
src->data = data.ptr;
|
||||
src->len = data.len;
|
||||
src->pos = 0;
|
||||
src->err = BSE_NO_ERROR;
|
||||
src->binarysource_ = src;
|
||||
}
|
||||
#define BinarySource_BARE_INIT_PL(obj, pl) \
|
||||
TYPECHECK(&(obj)->binarysource_ == (BinarySource **)0, \
|
||||
BinarySource_INIT__(obj, data_, len_))
|
||||
#define BinarySource_INIT(obj, data_, len_) \
|
||||
BinarySource_INIT__(obj, pl))
|
||||
#define BinarySource_BARE_INIT(obj, data_, len_) \
|
||||
BinarySource_BARE_INIT_PL(obj, make_ptrlen(data_, len_))
|
||||
#define BinarySource_INIT_PL(obj, pl) \
|
||||
TYPECHECK(&(obj)->binarysource_ == (BinarySource (*)[1])0, \
|
||||
BinarySource_INIT__(BinarySource_UPCAST(obj), data_, len_))
|
||||
#define BinarySource_DOWNCAST(object, type) \
|
||||
BinarySource_INIT__(BinarySource_UPCAST(obj), pl))
|
||||
#define BinarySource_INIT(obj, data_, len_) \
|
||||
BinarySource_INIT_PL(obj, make_ptrlen(data_, len_))
|
||||
#define BinarySource_DOWNCAST(object, type) \
|
||||
TYPECHECK((object) == ((type *)0)->binarysource_, \
|
||||
((type *)(((char *)(object)) - offsetof(type, binarysource_))))
|
||||
#define BinarySource_UPCAST(object) \
|
||||
|
@ -17,7 +17,7 @@ int ssh1_censor_packet(
|
||||
ptrlen str;
|
||||
BinarySource src[1];
|
||||
|
||||
BinarySource_BARE_INIT(src, pkt.ptr, pkt.len);
|
||||
BinarySource_BARE_INIT_PL(src, pkt);
|
||||
|
||||
if (pls->omit_data &&
|
||||
(type == SSH1_SMSG_STDOUT_DATA ||
|
||||
|
@ -490,8 +490,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
|
||||
strbuf_free(request);
|
||||
crMaybeWaitUntilV(!s->auth_agent_query);
|
||||
}
|
||||
BinarySource_BARE_INIT(
|
||||
s->asrc, s->agent_response.ptr, s->agent_response.len);
|
||||
BinarySource_BARE_INIT_PL(s->asrc, s->agent_response);
|
||||
|
||||
get_uint32(s->asrc); /* skip length field */
|
||||
if (get_byte(s->asrc) == SSH1_AGENT_RSA_IDENTITIES_ANSWER) {
|
||||
|
@ -17,7 +17,7 @@ int ssh2_censor_packet(
|
||||
ptrlen str;
|
||||
BinarySource src[1];
|
||||
|
||||
BinarySource_BARE_INIT(src, pkt.ptr, pkt.len);
|
||||
BinarySource_BARE_INIT_PL(src, pkt);
|
||||
|
||||
if (pls->omit_data &&
|
||||
(type == SSH2_MSG_CHANNEL_DATA ||
|
||||
|
@ -681,8 +681,7 @@ static bool ssh2_connection_filter_queue(struct ssh2_connection_state *s)
|
||||
BinarySource bs_modes[1];
|
||||
struct ssh_ttymodes modes;
|
||||
|
||||
BinarySource_BARE_INIT(
|
||||
bs_modes, encoded_modes.ptr, encoded_modes.len);
|
||||
BinarySource_BARE_INIT_PL(bs_modes, encoded_modes);
|
||||
modes = read_ttymodes_from_packet(bs_modes, 2);
|
||||
if (get_err(bs_modes) || get_avail(bs_modes) > 0) {
|
||||
ppl_logevent("Unable to decode terminal mode string");
|
||||
|
@ -754,8 +754,8 @@ static bool ssh2_scan_kexinits(
|
||||
ptrlen clists[NKEXLIST], slists[NKEXLIST];
|
||||
const struct kexinit_algorithm *selected[NKEXLIST];
|
||||
|
||||
BinarySource_BARE_INIT(client, client_kexinit.ptr, client_kexinit.len);
|
||||
BinarySource_BARE_INIT(server, server_kexinit.ptr, server_kexinit.len);
|
||||
BinarySource_BARE_INIT_PL(client, client_kexinit);
|
||||
BinarySource_BARE_INIT_PL(server, server_kexinit);
|
||||
|
||||
/* Skip packet type bytes and random cookies. */
|
||||
get_data(client, 1 + 16);
|
||||
|
@ -276,8 +276,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
|
||||
strbuf_free(request);
|
||||
crWaitUntilV(!s->auth_agent_query);
|
||||
}
|
||||
BinarySource_BARE_INIT(
|
||||
s->asrc, s->agent_response.ptr, s->agent_response.len);
|
||||
BinarySource_BARE_INIT_PL(s->asrc, s->agent_response);
|
||||
|
||||
get_uint32(s->asrc); /* skip length field */
|
||||
if (get_byte(s->asrc) == SSH2_AGENT_IDENTITIES_ANSWER) {
|
||||
@ -645,7 +644,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
|
||||
s->comment = get_string(s->asrc);
|
||||
{
|
||||
BinarySource src[1];
|
||||
BinarySource_BARE_INIT(src, s->pk.ptr, s->pk.len);
|
||||
BinarySource_BARE_INIT_PL(src, s->pk);
|
||||
s->alg = get_string(src);
|
||||
}
|
||||
|
||||
@ -1598,8 +1597,8 @@ static void ssh2_userauth_add_sigblob(
|
||||
struct ssh2_userauth_state *s, PktOut *pkt, ptrlen pkblob, ptrlen sigblob)
|
||||
{
|
||||
BinarySource pk[1], sig[1];
|
||||
BinarySource_BARE_INIT(pk, pkblob.ptr, pkblob.len);
|
||||
BinarySource_BARE_INIT(sig, sigblob.ptr, sigblob.len);
|
||||
BinarySource_BARE_INIT_PL(pk, pkblob);
|
||||
BinarySource_BARE_INIT_PL(sig, sigblob);
|
||||
|
||||
/* dmemdump(pkblob, pkblob_len); */
|
||||
/* dmemdump(sigblob, sigblob_len); */
|
||||
|
6
sshdss.c
6
sshdss.c
@ -17,7 +17,7 @@ static ssh_key *dss_new_pub(const ssh_keyalg *self, ptrlen data)
|
||||
BinarySource src[1];
|
||||
struct dss_key *dss;
|
||||
|
||||
BinarySource_BARE_INIT(src, data.ptr, data.len);
|
||||
BinarySource_BARE_INIT_PL(src, data);
|
||||
if (!ptrlen_eq_string(get_string(src), "ssh-dss"))
|
||||
return NULL;
|
||||
|
||||
@ -93,7 +93,7 @@ static bool dss_verify(ssh_key *key, ptrlen sig, ptrlen data)
|
||||
if (!dss->p)
|
||||
return false;
|
||||
|
||||
BinarySource_BARE_INIT(src, sig.ptr, sig.len);
|
||||
BinarySource_BARE_INIT_PL(src, sig);
|
||||
|
||||
/*
|
||||
* Commercial SSH (2.0.13) and OpenSSH disagree over the format
|
||||
@ -214,7 +214,7 @@ static ssh_key *dss_new_priv(const ssh_keyalg *self, ptrlen pub, ptrlen priv)
|
||||
return NULL;
|
||||
|
||||
dss = container_of(sshk, struct dss_key, sshk);
|
||||
BinarySource_BARE_INIT(src, priv.ptr, priv.len);
|
||||
BinarySource_BARE_INIT_PL(src, priv);
|
||||
dss->x = get_mp_ssh2(src);
|
||||
if (get_err(src)) {
|
||||
dss_freekey(&dss->sshk);
|
||||
|
21
sshecc.c
21
sshecc.c
@ -350,7 +350,7 @@ static WeierstrassPoint *ecdsa_decode(
|
||||
assert(curve->type == EC_WEIERSTRASS);
|
||||
BinarySource src[1];
|
||||
|
||||
BinarySource_BARE_INIT(src, encoded.ptr, encoded.len);
|
||||
BinarySource_BARE_INIT_PL(src, encoded);
|
||||
unsigned char format_type = get_byte(src);
|
||||
|
||||
WeierstrassPoint *P;
|
||||
@ -557,7 +557,7 @@ static ssh_key *ecdsa_new_pub(const ssh_keyalg *alg, ptrlen data)
|
||||
assert(curve->type == EC_WEIERSTRASS);
|
||||
|
||||
BinarySource src[1];
|
||||
BinarySource_BARE_INIT(src, data.ptr, data.len);
|
||||
BinarySource_BARE_INIT_PL(src, data);
|
||||
get_string(src);
|
||||
|
||||
/* Curve name is duplicated for Weierstrass form */
|
||||
@ -586,7 +586,7 @@ static ssh_key *eddsa_new_pub(const ssh_keyalg *alg, ptrlen data)
|
||||
assert(curve->type == EC_EDWARDS);
|
||||
|
||||
BinarySource src[1];
|
||||
BinarySource_BARE_INIT(src, data.ptr, data.len);
|
||||
BinarySource_BARE_INIT_PL(src, data);
|
||||
get_string(src);
|
||||
|
||||
struct eddsa_key *ek = snew(struct eddsa_key);
|
||||
@ -687,7 +687,7 @@ static ssh_key *ecdsa_new_priv(const ssh_keyalg *alg, ptrlen pub, ptrlen priv)
|
||||
struct ecdsa_key *ek = container_of(sshk, struct ecdsa_key, sshk);
|
||||
|
||||
BinarySource src[1];
|
||||
BinarySource_BARE_INIT(src, priv.ptr, priv.len);
|
||||
BinarySource_BARE_INIT_PL(src, priv);
|
||||
ek->privateKey = get_mp_ssh2(src);
|
||||
|
||||
return &ek->sshk;
|
||||
@ -701,7 +701,7 @@ static ssh_key *eddsa_new_priv(const ssh_keyalg *alg, ptrlen pub, ptrlen priv)
|
||||
struct eddsa_key *ek = container_of(sshk, struct eddsa_key, sshk);
|
||||
|
||||
BinarySource src[1];
|
||||
BinarySource_BARE_INIT(src, priv.ptr, priv.len);
|
||||
BinarySource_BARE_INIT_PL(src, priv);
|
||||
ek->privateKey = get_mp_le(src);
|
||||
|
||||
return &ek->sshk;
|
||||
@ -729,8 +729,7 @@ static ssh_key *eddsa_new_priv_openssh(
|
||||
* it.
|
||||
*/
|
||||
BinarySource subsrc[1];
|
||||
BinarySource_BARE_INIT(
|
||||
subsrc, privkey_extended_pl.ptr, privkey_extended_pl.len);
|
||||
BinarySource_BARE_INIT_PL(subsrc, privkey_extended_pl);
|
||||
ptrlen privkey_pl = get_data(subsrc, curve->fieldBytes);
|
||||
ptrlen pubkey_copy_pl = get_data(subsrc, curve->fieldBytes);
|
||||
if (get_err(subsrc) || get_avail(subsrc))
|
||||
@ -856,7 +855,7 @@ static bool ecdsa_verify(ssh_key *key, ptrlen sig, ptrlen data)
|
||||
(const struct ecsign_extra *)ek->sshk.vt->extra;
|
||||
|
||||
BinarySource src[1];
|
||||
BinarySource_BARE_INIT(src, sig.ptr, sig.len);
|
||||
BinarySource_BARE_INIT_PL(src, sig);
|
||||
|
||||
/* Check the signature starts with the algorithm name */
|
||||
if (!ptrlen_eq_string(get_string(src), ek->sshk.vt->ssh_id))
|
||||
@ -866,7 +865,7 @@ static bool ecdsa_verify(ssh_key *key, ptrlen sig, ptrlen data)
|
||||
ptrlen sigstr = get_string(src);
|
||||
if (get_err(src))
|
||||
return false;
|
||||
BinarySource_BARE_INIT(src, sigstr.ptr, sigstr.len);
|
||||
BinarySource_BARE_INIT_PL(src, sigstr);
|
||||
|
||||
/* Extract the signature integers r,s */
|
||||
mp_int *r = get_mp_ssh2(src);
|
||||
@ -941,7 +940,7 @@ static bool eddsa_verify(ssh_key *key, ptrlen sig, ptrlen data)
|
||||
(const struct ecsign_extra *)ek->sshk.vt->extra;
|
||||
|
||||
BinarySource src[1];
|
||||
BinarySource_BARE_INIT(src, sig.ptr, sig.len);
|
||||
BinarySource_BARE_INIT_PL(src, sig);
|
||||
|
||||
/* Check the signature starts with the algorithm name */
|
||||
if (!ptrlen_eq_string(get_string(src), ek->sshk.vt->ssh_id))
|
||||
@ -952,7 +951,7 @@ static bool eddsa_verify(ssh_key *key, ptrlen sig, ptrlen data)
|
||||
ptrlen sigstr = get_string(src);
|
||||
if (get_err(src))
|
||||
return false;
|
||||
BinarySource_BARE_INIT(src, sigstr.ptr, sigstr.len);
|
||||
BinarySource_BARE_INIT_PL(src, sigstr);
|
||||
ptrlen rstr = get_data(src, ek->curve->fieldBytes);
|
||||
ptrlen sstr = get_data(src, ek->curve->fieldBytes);
|
||||
if (get_err(src) || get_avail(src))
|
||||
|
8
sshrsa.c
8
sshrsa.c
@ -357,7 +357,7 @@ int rsa_ssh1_public_blob_len(ptrlen data)
|
||||
{
|
||||
BinarySource src[1];
|
||||
|
||||
BinarySource_BARE_INIT(src, data.ptr, data.len);
|
||||
BinarySource_BARE_INIT_PL(src, data);
|
||||
|
||||
/* Expect a length word, then exponent and modulus. (It doesn't
|
||||
* even matter which order.) */
|
||||
@ -420,7 +420,7 @@ static ssh_key *rsa2_new_pub(const ssh_keyalg *self, ptrlen data)
|
||||
BinarySource src[1];
|
||||
RSAKey *rsa;
|
||||
|
||||
BinarySource_BARE_INIT(src, data.ptr, data.len);
|
||||
BinarySource_BARE_INIT_PL(src, data);
|
||||
if (!ptrlen_eq_string(get_string(src), "ssh-rsa"))
|
||||
return NULL;
|
||||
|
||||
@ -484,7 +484,7 @@ static ssh_key *rsa2_new_priv(const ssh_keyalg *self,
|
||||
return NULL;
|
||||
|
||||
rsa = container_of(sshk, RSAKey, sshk);
|
||||
BinarySource_BARE_INIT(src, priv.ptr, priv.len);
|
||||
BinarySource_BARE_INIT_PL(src, priv);
|
||||
rsa->private_exponent = get_mp_ssh2(src);
|
||||
rsa->p = get_mp_ssh2(src);
|
||||
rsa->q = get_mp_ssh2(src);
|
||||
@ -643,7 +643,7 @@ static bool rsa2_verify(ssh_key *key, ptrlen sig, ptrlen data)
|
||||
ptrlen type, in_pl;
|
||||
mp_int *in, *out;
|
||||
|
||||
BinarySource_BARE_INIT(src, sig.ptr, sig.len);
|
||||
BinarySource_BARE_INIT_PL(src, sig);
|
||||
type = get_string(src);
|
||||
/*
|
||||
* RFC 4253 section 6.6: the signature integer in an ssh-rsa
|
||||
|
Loading…
Reference in New Issue
Block a user