crypto: validate BBS proof parameters (#1810)

This commit is contained in:
Samy
2026-06-21 13:06:30 +01:00
committed by GitHub
parent 91cb297e9e
commit 84724bc03e
2 changed files with 24 additions and 0 deletions
+2
View File
@@ -287,8 +287,10 @@ bbsProofVerify ::
[ByteString] ->
IO Bool
bbsProofVerify (BBSPublicKey pk) (BBSProof proof) (BBSHeader header) (BBSPresHeader ph) disclosedIdxs numMessages disclosedMsgs
| numMessages < 0 = pure False
| length disclosedIdxs /= length disclosedMsgs = pure False
| not (ascendingInRange disclosedIdxs numMessages) = pure False
| B.length proof /= bbsProofLen (numMessages - length disclosedIdxs) = pure False
| otherwise =
withBS pk $ \pkPtr _ ->
withBS proof $ \proofPtr proofLen ->
+22
View File
@@ -110,6 +110,7 @@ cryptoTests = do
it "should reject tampered proof" testBBSTamperedProof
it "should reject wrong disclosed message" testBBSWrongMessage
it "should reject wrong public key" testBBSWrongKey
it "should reject invalid proof parameters" testBBSInvalidProofParams
it "should produce unlinkable proofs" testBBSUnlinkable
it "should produce proof of expected size" testBBSProofSize
it "should roundtrip JSON and reject wrong-length input" testBBSJSON
@@ -355,6 +356,27 @@ testBBSWrongKey = do
result <- bbsProofVerify pk2 proof bbsHeader ph bbsDisclosedIdxs 3 bbsDisclosedMsgs
result `shouldBe` False
testBBSInvalidProofParams :: IO ()
testBBSInvalidProofParams = do
Right (pk, sk) <- bbsKeyGen
Right sig <- bbsSign sk bbsHeader bbsMessages
let ph = BBSPresHeader "test-nonce-invalid"
Right proof <- bbsProofGen pk sig bbsHeader ph bbsDisclosedIdxs bbsMessages
bbsProofGen pk sig bbsHeader ph [2, 1] bbsMessages
`shouldReturn` Left "bbsProofGen: invalid disclosed indexes"
bbsProofGen pk sig bbsHeader ph [1, 1] bbsMessages
`shouldReturn` Left "bbsProofGen: invalid disclosed indexes"
bbsProofGen pk sig bbsHeader ph [3] bbsMessages
`shouldReturn` Left "bbsProofGen: invalid disclosed indexes"
bbsProofVerify pk proof bbsHeader ph bbsDisclosedIdxs 3 ["2026-07-31"]
>>= (`shouldBe` False)
bbsProofVerify pk proof bbsHeader ph [2, 1] 3 bbsDisclosedMsgs
>>= (`shouldBe` False)
bbsProofVerify pk proof bbsHeader ph bbsDisclosedIdxs 4 bbsDisclosedMsgs
>>= (`shouldBe` False)
bbsProofVerify pk proof bbsHeader ph [] (-1) []
>>= (`shouldBe` False)
testBBSUnlinkable :: IO ()
testBBSUnlinkable = do
Right (pk, sk) <- bbsKeyGen