Copyright | Dong Han 2021 |
---|---|
License | BSD |
Maintainer | winterland1989@gmail.com |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
This module provide Botan's Multiple Precision Integer, featuring constant-time operations, which is suit for cryptograph usage.
Synopsis
- data MPI
- fromCInt :: CInt -> MPI
- toWord32 :: HasCallStack => MPI -> Word32
- byteSize :: MPI -> Int
- bitSize :: MPI -> Int
- toHex :: MPI -> Builder ()
- toDecimal :: MPI -> Builder ()
- fromHex :: Parser MPI
- fromDecimal :: Parser MPI
- isNegative :: MPI -> Bool
- isZero :: MPI -> Bool
- isOdd :: MPI -> Bool
- isEven :: MPI -> Bool
- isPrim :: RNG -> MPI -> Int -> IO Bool
- mulMod :: MPI -> MPI -> MPI -> MPI
- powMod :: MPI -> MPI -> MPI -> MPI
- modInverse :: MPI -> MPI -> MPI
- gcd :: MPI -> MPI -> MPI
- randBits :: RNG -> Int -> IO MPI
- randRange :: RNG -> MPI -> MPI -> IO MPI
- copyMPI :: MPI -> IO MPI
- newMPI :: (BotanStructT -> IO a) -> IO MPI
- unsafeNewMPI :: (BotanStructT -> IO a) -> MPI
- newMPI' :: (BotanStructT -> IO a) -> IO (MPI, a)
- unsafeNewMPI' :: (BotanStructT -> IO a) -> (MPI, a)
- withMPI :: MPI -> (BotanStructT -> IO a) -> IO a
- unsafeWithMPI :: MPI -> (BotanStructT -> IO a) -> a
RNG
Opaque Botan Multiple Precision Integers.
Instances
Enum MPI Source # | |
Eq MPI Source # | |
Integral MPI Source # | |
Num MPI Source # | |
Ord MPI Source # | |
Real MPI Source # | |
Defined in Z.Crypto.MPI toRational :: MPI -> Rational # | |
Show MPI Source # | |
JSON MPI Source # | |
Print MPI Source # | |
Defined in Z.Crypto.MPI toUTF8BuilderP :: Int -> MPI -> Builder () # | |
Bits MPI Source # | The |
Defined in Z.Crypto.MPI |
Builder & Parser
toHex :: MPI -> Builder () Source #
Write a MPI
in hexadecimal format(without '0x' prefix), the sign is ignored.
fromHex :: Parser MPI Source #
Parse a MPI
in hexadecimal format(without '0x' prefix), no sign is allowed.
Predicator
isNegative :: MPI -> Bool Source #
isPrim :: RNG -> MPI -> Int -> IO Bool Source #
Test if n is prime.
The algorithm used (Miller-Rabin) is probabilistic, set test_prob to the desired assurance level. For example if test_prob is 64, then sufficient Miller-Rabin iterations will run to assure there is at most a 1/2**64 chance that n is composite.
MPI specific
powMod :: MPI -> MPI -> MPI -> MPI Source #
Modular exponentiation. powMod base exp mod = base power exp module mod
modInverse :: MPI -> MPI -> MPI Source #
Modular inverse, find an integer x so that a⋅x ≡ 1 mod m
If no modular inverse exists (for instance because in and modulus are not relatively prime), return 0.
Random MPI
Create a random MPI
within the provided range.
Internal
unsafeNewMPI :: (BotanStructT -> IO a) -> MPI Source #
unsafeNewMPI' :: (BotanStructT -> IO a) -> (MPI, a) Source #
unsafeWithMPI :: MPI -> (BotanStructT -> IO a) -> a Source #