[tests] add first P256 test
This commit is contained in:
parent
b9e6bff690
commit
e2c1b82234
@ -254,6 +254,7 @@ Test-Suite test-cryptonite
|
|||||||
KAT_PubKey.ECDSA
|
KAT_PubKey.ECDSA
|
||||||
KAT_PubKey.OAEP
|
KAT_PubKey.OAEP
|
||||||
KAT_PubKey.PSS
|
KAT_PubKey.PSS
|
||||||
|
KAT_PubKey.P256
|
||||||
KAT_PubKey
|
KAT_PubKey
|
||||||
KAT_RC4
|
KAT_RC4
|
||||||
KAT_Scrypt
|
KAT_Scrypt
|
||||||
|
|||||||
@ -17,6 +17,7 @@ import KAT_PubKey.DSA
|
|||||||
import KAT_PubKey.ECC
|
import KAT_PubKey.ECC
|
||||||
import KAT_PubKey.ECDSA
|
import KAT_PubKey.ECDSA
|
||||||
import Utils
|
import Utils
|
||||||
|
import qualified KAT_PubKey.P256 as P256
|
||||||
|
|
||||||
data VectorMgf = VectorMgf { seed :: ByteString
|
data VectorMgf = VectorMgf { seed :: ByteString
|
||||||
, dbMask :: ByteString
|
, dbMask :: ByteString
|
||||||
@ -39,6 +40,7 @@ tests = testGroup "PubKey"
|
|||||||
, dsaTests
|
, dsaTests
|
||||||
, eccTests
|
, eccTests
|
||||||
, ecdsaTests
|
, ecdsaTests
|
||||||
|
, P256.tests
|
||||||
]
|
]
|
||||||
|
|
||||||
--newKats = [ eccKatTests ]
|
--newKats = [ eccKatTests ]
|
||||||
|
|||||||
36
tests/KAT_PubKey/P256.hs
Normal file
36
tests/KAT_PubKey/P256.hs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
module KAT_PubKey.P256 (tests) where
|
||||||
|
|
||||||
|
import Control.Arrow (second)
|
||||||
|
|
||||||
|
import qualified Crypto.PubKey.ECC.Types as ECC
|
||||||
|
import qualified Crypto.PubKey.ECC.Prim as ECC
|
||||||
|
import qualified Crypto.PubKey.ECC.P256 as P256
|
||||||
|
|
||||||
|
import Test.Tasty.KAT
|
||||||
|
import Test.Tasty.KAT.FileLoader
|
||||||
|
import Data.ByteArray (Bytes)
|
||||||
|
import Crypto.Number.Serialize (i2ospOf)
|
||||||
|
import Crypto.Error
|
||||||
|
|
||||||
|
import Imports
|
||||||
|
|
||||||
|
tests = testGroup "P256"
|
||||||
|
[ testGroup "scalar"
|
||||||
|
[ testProperty "marshalling" $ \(Positive r') ->
|
||||||
|
let r = r' `mod` curveN
|
||||||
|
rBytes = i2ospScalar r
|
||||||
|
in case P256.scalarFromBinary rBytes of
|
||||||
|
CryptoFailed err -> error (show err)
|
||||||
|
CryptoPassed scalar -> rBytes `propertyEq` P256.scalarToBinary scalar
|
||||||
|
]
|
||||||
|
]
|
||||||
|
where
|
||||||
|
curve = ECC.getCurveByName ECC.SEC_p256r1
|
||||||
|
curveN = ECC.ecc_n . ECC.common_curve $ curve
|
||||||
|
|
||||||
|
i2ospScalar :: Integer -> Bytes
|
||||||
|
i2ospScalar i =
|
||||||
|
case i2ospOf 32 i of
|
||||||
|
Nothing -> error "invalid size of P256 scalar"
|
||||||
|
Just b -> b
|
||||||
Loading…
Reference in New Issue
Block a user