diff --git a/src/Cryptol/PrimeEC.hs b/src/Cryptol/PrimeEC.hs index e86771ba3..f230a1db8 100644 --- a/src/Cryptol/PrimeEC.hs +++ b/src/Cryptol/PrimeEC.hs @@ -202,13 +202,13 @@ ec_add p s t ec_sub :: PrimeModulus -> ProjectivePoint -> ProjectivePoint -> ProjectivePoint ec_sub p s t = ec_add p s u where u = case BN.bigNatSub (primeMod p) (py t) of - (# | y' #) -> t{ py = y' } + (# | y' #) -> t{ py = y' `BN.bigNatRem` (primeMod p) } (# (# #) | #) -> panic "ec_sub" ["cooridnate not in reduced form!", show (BN.bigNatToInteger (py t))] {-# INLINE ec_sub #-} ec_negate :: PrimeModulus -> ProjectivePoint -> ProjectivePoint -ec_negate p s = s{ py = BN.bigNatSubUnsafe (primeMod p) (py s) } +ec_negate p s = s{ py = (BN.bigNatSubUnsafe (primeMod p) (py s)) `BN.bigNatRem` (primeMod p) } {-# INLINE ec_negate #-} -- | Compute the elliptic curve group addition operation @@ -294,7 +294,7 @@ ec_mult p d s | BN.bigNatIsZero (pz s) = zro | otherwise = case m of - 0# -> panic "ec_mult" ["modulus too large", show (BN.bigNatToInteger (primeMod p))] + 0# -> panic "ec_mult" ["integer with 0 width", show h] _ -> go m zro where diff --git a/tests/issues/issue1675/issue1675.icry b/tests/issues/issue1675/issue1675.icry new file mode 100644 index 000000000..716382ca5 --- /dev/null +++ b/tests/issues/issue1675/issue1675.icry @@ -0,0 +1,4 @@ +:m PrimeEC +ec_mult`{13} 3 {x = 0, y = 0, z = 1} +:t ec_mult`{13} +ec_mult`{13} 3 {x = 0, y = 0, z = 1} : ProjectivePoint 13 \ No newline at end of file diff --git a/tests/issues/issue1675/issue1675.icry.stdout b/tests/issues/issue1675/issue1675.icry.stdout new file mode 100644 index 000000000..753daaa13 --- /dev/null +++ b/tests/issues/issue1675/issue1675.icry.stdout @@ -0,0 +1,6 @@ +Loading module Cryptol +Loading module Cryptol +Loading module PrimeEC +{x = 0, y = 0, z = 1} +ec_mult`{13} : Z 13 -> ProjectivePoint 13 -> ProjectivePoint 13 +{x = 0, y = 0, z = 1}