Skip to content

Commit

Permalink
Merge pull request #1701 from GaloisInc/issue#1675
Browse files Browse the repository at this point in the history
Close Issue #1675
  • Loading branch information
mccleeary-galois authored Jul 10, 2024
2 parents e549792 + dd11250 commit f5fa503
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Cryptol/PrimeEC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tests/issues/issue1675/issue1675.icry
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions tests/issues/issue1675/issue1675.icry.stdout
Original file line number Diff line number Diff line change
@@ -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}

0 comments on commit f5fa503

Please sign in to comment.