Remove powF2m'

We keep only the function providing the base service, negative
exponents can be still computed with invF2m.
This commit is contained in:
Olivier Chéron 2020-06-12 18:54:37 +02:00
parent f64efafbad
commit 5f657fda2e

View File

@ -17,7 +17,6 @@ module Crypto.Number.F2m
, squareF2m' , squareF2m'
, squareF2m , squareF2m
, powF2m , powF2m
, powF2m'
, modF2m , modF2m
, sqrtF2m , sqrtF2m
, invF2m , invF2m
@ -106,8 +105,7 @@ squareF2m' n
-- | Exponentiation in F₂m by computing @a^b mod fx@. -- | Exponentiation in F₂m by computing @a^b mod fx@.
-- --
-- This implements an exponentiation by squaring based solution. It inherits the -- This implements an exponentiation by squaring based solution. It inherits the
-- same restrictions as 'squareF2m'. Negative exponents are disallowed. See -- same restrictions as 'squareF2m'. Negative exponents are disallowed.
-- 'powF2m'' for one that handles this case
powF2m :: BinaryPolynomial -- ^Modulus powF2m :: BinaryPolynomial -- ^Modulus
-> Integer -- ^a -> Integer -- ^a
-> Integer -- ^b -> Integer -- ^b
@ -119,23 +117,6 @@ powF2m fx a b
| otherwise = error "powF2m: impossible" | otherwise = error "powF2m: impossible"
where x = powF2m fx a (b `div` 2) where x = powF2m fx a (b `div` 2)
-- | Exponentiation in F₂m by computing @a^b mod fx@.
--
-- This implements an exponentiation by squaring based solution. It inherits the
-- same restrictions as 'squareF2m'. 'Nothing' is returned when a negative
-- exponent is given and @a@ is not invertible.
powF2m' :: BinaryPolynomial -- ^Modulus
-> Integer -- ^a
-> Integer -- ^b
-> Maybe Integer
powF2m' fx a b
| b == 0 = Just 1
| b > 0 = Just $ powF2m fx a b
| b < 0 = case invF2m fx a of
Just inv -> Just $ powF2m fx inv (-b)
Nothing -> Nothing
| otherwise = error "impossible"
-- | Square rooot in F₂m. -- | Square rooot in F₂m.
-- --
-- We exploit the fact that @a^(2^m) = a@, or in particular, @a^(2^m - 1) = 1@ -- We exploit the fact that @a^(2^m) = a@, or in particular, @a^(2^m - 1) = 1@