Skip to content

Commit

Permalink
Length check for scalarFromBS
Browse files Browse the repository at this point in the history
  • Loading branch information
iquerejeta committed Nov 29, 2022
1 parent 7db675f commit 43cba76
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,10 @@ scalarFromBS bs =
(success, scalar) = unsafePerformIO $
withNewScalar $ \scalarPtr ->
BS.useAsCStringLen bs $ \(cstr, l) ->
c_blst_scalar_from_be_bytes scalarPtr cstr (fromIntegral l)
if l == 32 then
c_blst_scalar_from_be_bytes scalarPtr cstr (fromIntegral l)
else
return False

scalarToBS :: Scalar -> ByteString
scalarToBS scalar = unsafePerformIO $ do
Expand Down
2 changes: 1 addition & 1 deletion cardano-crypto-tests/src/Test/Crypto/EllipticCurve.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ testScalar name =
, testProperty "to/from Integer round-trip" $
\s -> s === ((unsafePerformIO . BLS.scalarFromInteger) . (unsafePerformIO . BLS.scalarToInteger) $ s)
, testCase "integer from scalar" $ do
s <- case BLS.scalarFromBS (BS.pack [0x12, 0x34]) of
s <- case BLS.scalarFromBS (BLS.padBS 32 (BS.pack [0x12, 0x34])) of
Left err -> error (show err)
Right x -> return x
let expected = 0x1234
Expand Down
3 changes: 0 additions & 3 deletions cardano-crypto-tests/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ tests =
, Test.Crypto.KES.tests
, Test.Crypto.VRF.tests
, Test.Crypto.Regressions.tests
<<<<<<< HEAD
, Test.Crypto.Vector.Secp256k1DSIGN.tests
=======
, Test.Crypto.EllipticCurve.tests
>>>>>>> 8c57190 (BLS12-381 bindings)
]

0 comments on commit 43cba76

Please sign in to comment.