Safe Haskell | None |
---|---|
Language | Haskell98 |
Using (weighted) projective coordinates on the curve we can maybe avoid the division bottleneck.
Based on: Chae Hoon Lim, Hyo Sun Hwang: Fast implementation of Elliptic Curve arithmetic in GF(p^n).
We will use (2,3,1) weighting, and a constant factor of 2 in Y:
x = X/Z^2 y = Y/(2*Z^3) z = 1
Thus the curve equation y^2 = x^3 + 7
becomes
Y^2/4 = X^3 + 7*Z^6
and then the infinity point on the curve is (1,2,0)
.
- data ECProj = ECProj !Fp !Fp !Fp
- toECProj :: ECPoint -> ECProj
- fromECProj :: ECProj -> ECPoint
- c_addECP_ :: Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> IO ()
- c_dblECP_ :: Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> IO ()
- c_mulECP_ :: Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> IO ()
- withECProj :: ECProj -> (Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> IO a) -> IO a
- withNewECProj :: (Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> IO ()) -> IO ECProj
- c_dblECP :: ECProj -> ECProj
- c_addECP :: ECProj -> ECProj -> ECProj
- c_mulECP :: ECProj -> Integer -> ECProj
- dblECP :: ECProj -> ECProj
- addECP :: ECProj -> ECProj -> ECProj
- mulECP :: ECProj -> Integer -> ECProj
- (=~=) :: ECProj -> ECProj -> Bool
- ecpInfinity :: ECProj
- isECPInfinity :: ECProj -> Bool
- isECPOnCurve :: ECProj -> Bool
- secp256k1_G_proj :: ECProj
- hs_addECP :: ECProj -> ECProj -> ECProj
- hs_dblECP :: ECProj -> ECProj
- invECP :: ECProj -> ECProj
- subECP :: ECProj -> ECProj -> ECProj
- hs_mulECP :: ECProj -> Integer -> ECProj
Documentation
Note: the Eq instance is equality of all coordinates, not equality on the projective plane (for that, use "(=~=)" instead)
fromECProj :: ECProj -> ECPoint Source #
c_addECP_ :: Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> IO () Source #
c_dblECP_ :: Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> IO () Source #
c_mulECP_ :: Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> IO () Source #
Num/Eq instances
ecpInfinity :: ECProj Source #
isECPInfinity :: ECProj -> Bool Source #
isECPOnCurve :: ECProj -> Bool Source #
hs_addECP :: ECProj -> ECProj -> ECProj Source #
Addition in the elliptic curve (or multiplication if you prefer to think it as a multiplicative group)