From 12c3b1ccf6a4014da077a9c1427faec588af0be1 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Mon, 31 Aug 2015 21:11:24 +0300 Subject: [PATCH] bignum: add specific tests for bn_mod() edge cases --- test_curves.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test_curves.py b/test_curves.py index 67d1808093..c511bbc97f 100755 --- a/test_curves.py +++ b/test_curves.py @@ -261,6 +261,13 @@ def test_mod(curve, r): lib.bn_mod(y, int2bn(curve.p)) assert bn2int(y) == x % curve.p +def test_mod_specific(curve): + p = curve.p + for x in [0, 1, 2, p - 2, p - 1, p, p + 1, p + 2, 2*p - 2, 2*p - 1]: + y = int2bn(x) + lib.bn_mod(y, int2bn(curve.p)) + assert bn2int(y) == x % p + POINT = BIGNUM * 2 to_POINT = lambda p: POINT(int2bn(p.x()), int2bn(p.y())) from_POINT = lambda p: (bn2int(p[0]), bn2int(p[1]))