Safe Haskell | None |
---|---|
Language | Haskell98 |
Finite field of order p, where p is the prime parameter of the secp256k1 elliptic curve. Relatively fast arithmetic (written in C)
Should work on both little-endian and big-endian architectures, but only tested on little-endian.
- newtype Fp = Fp {}
- fpDecimal :: Fp -> String
- fpHex :: Fp -> String
- toFp :: Integer -> Fp
- fromFp :: Fp -> Integer
- fpToByteStringLE :: Fp -> ByteString
- fpToByteStringBE :: Fp -> ByteString
- fpToWord8ListLE :: Fp -> [Word8]
- c_neg_modp :: Ptr Word32 -> Ptr Word32 -> IO ()
- c_inv_modp_power :: Ptr Word32 -> Ptr Word32 -> IO ()
- c_inv_modp_pow_spec :: Ptr Word32 -> Ptr Word32 -> IO ()
- c_inv_modp_euclid :: Ptr Word32 -> Ptr Word32 -> IO ()
- c_add_modp :: Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> IO ()
- c_sub_modp :: Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> IO ()
- c_mul_modp :: Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> IO ()
- c_div_modp :: Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> IO ()
- c_pow_modp :: Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> IO ()
- neg_modp :: Word256 -> Word256
- inv_modp_power :: Word256 -> Word256
- inv_modp_pow_spec :: Word256 -> Word256
- inv_modp_euclid :: Word256 -> Word256
- add_modp :: Word256 -> Word256 -> Word256
- sub_modp :: Word256 -> Word256 -> Word256
- mul_modp :: Word256 -> Word256 -> Word256
- div_modp :: Word256 -> Word256 -> Word256
- pow_modp :: Word256 -> Word256 -> Word256
- pow_p :: Fp -> Word256 -> Fp
- sqrt_p :: Fp -> Maybe Fp
- secp256k1_ndiv4 :: Word256
- secp256k1_ndiv4p1 :: Word256
- unsafeSqrtFp :: Word256 -> Word256
- sqrtFp :: Word256 -> Maybe Word256
- secp256k1_p :: Integer
- modp :: Integer -> Integer
Documentation
fpToByteStringLE :: Fp -> ByteString Source #
Converts to a little-endian bytestring
fpToByteStringBE :: Fp -> ByteString Source #
Converts to a big-endian bytestring
fpToWord8ListLE :: Fp -> [Word8] Source #
Converts to a little-endian sequence of bytes
inv_modp_power :: Word256 -> Word256 Source #
inv_modp_pow_spec :: Word256 -> Word256 Source #
inv_modp_euclid :: Word256 -> Word256 Source #
square root in Fp
unsafeSqrtFp :: Word256 -> Word256 Source #
(One of the) square roots mod p (if any exists). Since p is a prime and p = 4k+3
,
we have a fortunately a very easy solution by some quadratic reciprocity stuff I don't
remember how exactly works
(but it's elementary number theory)
sqrtFp :: Word256 -> Maybe Word256 Source #
Note that square roots do not always exist in Fp: consider for example p=7, then 3, 5 and 6 do not have square roots, while the rest has two (except 0).
In general, if x is a square root then so is (p-x), since
(p-x)*(p-x) = p*p - p*(2*x) + x*x = x*x (mod p)
And that should be all solutions, since it's a quadratic equation.