summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@redhat.com>2016-04-18 11:18:04 +0200
committerNikos Mavrogiannopoulos <nmav@redhat.com>2016-04-18 14:35:04 +0200
commit0f65c523d48f12bf67e3ba4cee13ef009455f5d3 (patch)
treeeec5937cd6c29f45307b5ddaaa09300becf4a253
parenta64707030ea0b054ff1b6a09068ee17de1ca4652 (diff)
downloadgnutls-0f65c523d48f12bf67e3ba4cee13ef009455f5d3.tar.gz
_wrap_nettle_pk_derive: reject values of public key that are over the prime
That is do not canonicalise the value we get from the network, but rather check it for validity. This saves a modular reduction on handshake and performs a sanity check on the peer's (client) parameters. Reported by Hubert Kario. Resolves #84
-rw-r--r--lib/nettle/pk.c14
1 files changed, 4 insertions, 10 deletions
diff --git a/lib/nettle/pk.c b/lib/nettle/pk.c
index 2fba4de3a7..533a174ef9 100644
--- a/lib/nettle/pk.c
+++ b/lib/nettle/pk.c
@@ -193,23 +193,17 @@ static int _wrap_nettle_pk_derive(gnutls_pk_algorithm_t algo,
if (ret < 0)
return gnutls_assert_val(ret);
- ret = _gnutls_mpi_modm(ff, f, prime);
+ ret = _gnutls_mpi_add_ui(ff, f, 1);
if (ret < 0) {
gnutls_assert();
goto dh_cleanup;
}
- ret = _gnutls_mpi_add_ui(ff, ff, 1);
- if (ret < 0) {
- gnutls_assert();
- goto dh_cleanup;
- }
-
- /* check if f==0,1,p-1.
- * or (ff=f+1) equivalently ff==1,2,p */
+ /* check if f==0,1, or f >= p-1.
+ * or (ff=f+1) equivalently ff==1,2, ff >= p */
if ((_gnutls_mpi_cmp_ui(ff, 2) == 0)
|| (_gnutls_mpi_cmp_ui(ff, 1) == 0)
- || (_gnutls_mpi_cmp(ff, prime) == 0)) {
+ || (_gnutls_mpi_cmp(ff, prime) >= 0)) {
gnutls_assert();
ret = GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER;
goto dh_cleanup;