From 7688e341c5cfe42ee9d22abe73bbaf38fe0b70df Mon Sep 17 00:00:00 2001 From: Gregory Maxwell Date: Fri, 2 Jan 2015 07:52:27 -0800 Subject: [PATCH] Add magnitude limits to secp256k1_fe_verify to ensure that it's own tests function correctly. --- src/field_10x26_impl.h | 1 + src/field_5x52_impl.h | 1 + 2 files changed, 2 insertions(+) diff --git a/src/field_10x26_impl.h b/src/field_10x26_impl.h index 8f5d15c729e..9ef60a807ac 100644 --- a/src/field_10x26_impl.h +++ b/src/field_10x26_impl.h @@ -31,6 +31,7 @@ static void secp256k1_fe_verify(const secp256k1_fe_t *a) { r &= (d[8] <= 0x3FFFFFFUL * m); r &= (d[9] <= 0x03FFFFFUL * m); r &= (a->magnitude >= 0); + r &= (a->magnitude <= 32); if (a->normalized) { r &= (a->magnitude <= 1); if (r && (d[9] == 0x03FFFFFUL)) { diff --git a/src/field_5x52_impl.h b/src/field_5x52_impl.h index 33597c446f2..4db9e6f5ff5 100644 --- a/src/field_5x52_impl.h +++ b/src/field_5x52_impl.h @@ -43,6 +43,7 @@ static void secp256k1_fe_verify(const secp256k1_fe_t *a) { r &= (d[3] <= 0xFFFFFFFFFFFFFULL * m); r &= (d[4] <= 0x0FFFFFFFFFFFFULL * m); r &= (a->magnitude >= 0); + r &= (a->magnitude <= 2048); if (a->normalized) { r &= (a->magnitude <= 1); if (r && (d[4] == 0x0FFFFFFFFFFFFULL) && ((d[3] & d[2] & d[1]) == 0xFFFFFFFFFFFFFULL)) {