X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=sshecc.c;h=3ce6c7fe6ae07e19e3b0b35dfdba92398e1cf999;hb=700908ef6e9c66886af6c73f86287a84dc4731f2;hp=5f170215dbc2dd9764158b5334254943ae40709c;hpb=0bd014e456a0e5f755c45a8a5a420d6fad85c1d8;p=PuTTY.git diff --git a/sshecc.c b/sshecc.c index 5f170215..3ce6c7fe 100644 --- a/sshecc.c +++ b/sshecc.c @@ -1648,6 +1648,7 @@ static int decodepoint_ed(const char *p, int length, struct ec_point *point) /* Read x bit and then reset it */ negative = bignum_bit(point->y, point->curve->fieldBits - 1); bignum_set_bit(point->y, point->curve->fieldBits - 1, 0); + bn_restore_invariant(point->y); /* Get the x from the y */ point->x = ecp_edx(point->curve, point->y); @@ -1770,6 +1771,7 @@ static void *ecdsa_newkey(const struct ssh_signkey *self, /* Curve name is duplicated for Weierstrass form */ if (curve->type == EC_WEIERSTRASS) { getstring(&data, &len, &p, &slen); + if (!p) return NULL; if (!match_ssh_id(slen, p, curve->name)) return NULL; } @@ -1781,11 +1783,11 @@ static void *ecdsa_newkey(const struct ssh_signkey *self, ec->publicKey.x = NULL; ec->publicKey.y = NULL; ec->publicKey.z = NULL; + ec->privateKey = NULL; if (!getmppoint(&data, &len, &ec->publicKey)) { ecdsa_freekey(ec); return NULL; } - ec->privateKey = NULL; if (!ec->publicKey.x || !ec->publicKey.y || bignum_cmp(ec->publicKey.x, curve->p) >= 0 || @@ -2027,10 +2029,10 @@ static void *ed25519_openssh_createkey(const struct ssh_signkey *self, } getstring((const char**)blob, len, &q, &qlen); - if (!q) - return NULL; - if (qlen != 64) + if (!q || qlen != 64) { + ecdsa_freekey(ec); return NULL; + } ec->privateKey = bignum_from_bytes_le((const unsigned char *)q, 32); @@ -2266,6 +2268,7 @@ static int ecdsa_verifysig(void *key, const char *sig, int siglen, } getstring(&sig, &siglen, &p, &slen); + if (!p) return 0; if (ec->publicKey.curve->type == EC_EDWARDS) { struct ec_point *r; Bignum s, h; @@ -2757,11 +2760,8 @@ void *ssh_ecdhkex_newkey(const struct ssh_kex *kex) bytes[0] &= 248; bytes[31] &= 127; bytes[31] |= 64; - key->privateKey = bignum_from_bytes(bytes, sizeof(bytes)); - for (i = 0; i < sizeof(bytes); ++i) - { - ((volatile char*)bytes)[i] = 0; - } + key->privateKey = bignum_from_bytes_le(bytes, sizeof(bytes)); + smemclr(bytes, sizeof(bytes)); if (!key->privateKey) { sfree(key); return NULL; @@ -2937,6 +2937,9 @@ const unsigned char *ec_alg_oid(const struct ssh_signkey *alg, return extra->oid; } +const int ec_nist_curve_lengths[] = { 256, 384, 521 }; +const int n_ec_nist_curve_lengths = lenof(ec_nist_curve_lengths); + const int ec_nist_alg_and_curve_by_bits(int bits, const struct ec_curve **curve, const struct ssh_signkey **alg)