diff --git a/sshdss.c b/sshdss.c index df9263fe..262d3e39 100644 --- a/sshdss.c +++ b/sshdss.c @@ -295,6 +295,7 @@ static ssh_key *dss_createkey(const ssh_keyalg *self, const void *pub_blob, int pub_len, const void *priv_blob, int priv_len) { + ssh_key *sshk; struct dss_key *dss; const char *pb = (const char *) priv_blob; const char *hash; @@ -303,10 +304,11 @@ static ssh_key *dss_createkey(const ssh_keyalg *self, unsigned char digest[20]; Bignum ytest; - dss = FROMFIELD(dss_newkey(self, pub_blob, pub_len), - struct dss_key, sshk); - if (!dss) + sshk = dss_newkey(self, pub_blob, pub_len); + if (!sshk) return NULL; + + dss = FROMFIELD(sshk, struct dss_key, sshk); dss->x = getmp(&pb, &priv_len); if (!dss->x) { dss_freekey(&dss->sshk); @@ -382,13 +384,15 @@ static void dss_openssh_fmtkey(ssh_key *key, BinarySink *bs) static int dss_pubkey_bits(const ssh_keyalg *self, const void *blob, int len) { + ssh_key *sshk; struct dss_key *dss; int ret; - dss = FROMFIELD(dss_newkey(self, blob, len), - struct dss_key, sshk); - if (!dss) + sshk = dss_newkey(self, blob, len); + if (!sshk) return -1; + + dss = FROMFIELD(sshk, struct dss_key, sshk); ret = bignum_bitcount(dss->p); dss_freekey(&dss->sshk); diff --git a/sshecc.c b/sshecc.c index 769da581..9ce2784b 100644 --- a/sshecc.c +++ b/sshecc.c @@ -1734,8 +1734,10 @@ struct ecsign_extra { static void ecdsa_freekey(ssh_key *key) { - struct ec_key *ec = FROMFIELD(key, struct ec_key, sshk); - if (!ec) return; + struct ec_key *ec; + + if (!key) return; + ec = FROMFIELD(key, struct ec_key, sshk); if (ec->publicKey.x) freebn(ec->publicKey.x); @@ -1909,15 +1911,16 @@ static ssh_key *ecdsa_createkey(const ssh_keyalg *self, const void *pub_blob, int pub_len, const void *priv_blob, int priv_len) { + ssh_key *sshk; struct ec_key *ec; struct ec_point *publicKey; const char *pb = (const char *) priv_blob; - ec = FROMFIELD(ecdsa_newkey(self, pub_blob, pub_len), - struct ec_key, sshk); - if (!ec) { + sshk = ecdsa_newkey(self, pub_blob, pub_len); + if (!sshk) return NULL; - } + + ec = FROMFIELD(sshk, struct ec_key, sshk); if (ec->publicKey.curve->type != EC_WEIERSTRASS && ec->publicKey.curve->type != EC_EDWARDS) { @@ -2147,13 +2150,15 @@ static void ecdsa_openssh_fmtkey(ssh_key *key, BinarySink *bs) static int ecdsa_pubkey_bits(const ssh_keyalg *self, const void *blob, int len) { + ssh_key *sshk; struct ec_key *ec; int ret; - ec = FROMFIELD(ecdsa_newkey(self, blob, len), - struct ec_key, sshk); - if (!ec) + sshk = ecdsa_newkey(self, blob, len); + if (!sshk) return -1; + + ec = FROMFIELD(sshk, struct ec_key, sshk); ret = ec->publicKey.curve->fieldBits; ecdsa_freekey(&ec->sshk); diff --git a/sshrsa.c b/sshrsa.c index ee5942e4..2fcf5e6b 100644 --- a/sshrsa.c +++ b/sshrsa.c @@ -601,11 +601,15 @@ static ssh_key *rsa2_createkey(const ssh_keyalg *self, const void *pub_blob, int pub_len, const void *priv_blob, int priv_len) { + ssh_key *sshk; struct RSAKey *rsa; const char *pb = (const char *) priv_blob; - rsa = FROMFIELD(rsa2_newkey(self, pub_blob, pub_len), - struct RSAKey, sshk); + sshk = rsa2_newkey(self, pub_blob, pub_len); + if (!sshk) + return NULL; + + rsa = FROMFIELD(sshk, struct RSAKey, sshk); rsa->private_exponent = getmp(&pb, &priv_len); rsa->p = getmp(&pb, &priv_len); rsa->q = getmp(&pb, &priv_len); @@ -664,13 +668,15 @@ static void rsa2_openssh_fmtkey(ssh_key *key, BinarySink *bs) static int rsa2_pubkey_bits(const ssh_keyalg *self, const void *blob, int len) { + ssh_key *sshk; struct RSAKey *rsa; int ret; - rsa = FROMFIELD(rsa2_newkey(self, blob, len), - struct RSAKey, sshk); - if (!rsa) - return -1; + sshk = rsa2_newkey(self, blob, len); + if (!sshk) + return -1; + + rsa = FROMFIELD(sshk, struct RSAKey, sshk); ret = bignum_bitcount(rsa->modulus); rsa2_freekey(&rsa->sshk); @@ -818,8 +824,10 @@ const ssh_keyalg ssh_rsa = { struct RSAKey *ssh_rsakex_newkey(const void *data, int len) { - return FROMFIELD(rsa2_newkey(&ssh_rsa, data, len), - struct RSAKey, sshk); + ssh_key *sshk = rsa2_newkey(&ssh_rsa, data, len); + if (!sshk) + return NULL; + return FROMFIELD(sshk, struct RSAKey, sshk); } void ssh_rsakex_freekey(struct RSAKey *key)