Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BBS+: add some checks on disclosed indexes array #949

Merged
merged 3 commits into from
Oct 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions src/lua/crypto_bbs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -644,16 +644,19 @@ local function core_proof_gen(ciphersuite, pk, signature, generators, header, ph
local signature_result = octets_to_signature(signature)
local AA, e = table.unpack(signature_result)
local undisclosed_indexes = {}
local disclosed_messages = {}
local undisclosed_messages = {}
for i, v in ipairs(disclosed_indexes) do
if i > 1 and disclosed_indexes[i] == disclosed_indexes[i - 1] then --Arrays are always sorted in proof_gen (line 684) before being passed as input to core_proof_gen
error('disclosed indexes contains duplicates', 3)
end
table.insert(disclosed_messages, messages[v])
end
for i = 1, L do
if not array_contains(disclosed_indexes, i) then
table.insert(undisclosed_indexes, i)
end
end
local disclosed_messages = {}
local undisclosed_messages = {}
for _,v in ipairs(disclosed_indexes) do
table.insert(disclosed_messages, messages[v])
end
for _,v in ipairs(undisclosed_indexes) do
table.insert(undisclosed_messages, messages[v])
end
Expand All @@ -679,6 +682,12 @@ function bbs.proof_gen(ciphersuite, pk, signature, header, ph, messages, disclos
header = header or O.empty()
ph = ph or O.empty()
table.sort(disclosed_indexes) -- make sure indexes are sorted
if disclosed_indexes[1] <= 0 then
error('Disclosed indexes contains an integer less than or equal to 0', 2)
end
if disclosed_indexes[#disclosed_indexes] > #messages then
error('Disclosed index contains an integer which exceeds the total number of messages', 2)
end
local messages = bbs.messages_to_scalars(ciphersuite,messages)
local generators = bbs.create_generators(ciphersuite, table_size(messages) + 1)
local proof = core_proof_gen(ciphersuite, pk, signature, generators, header, ph, messages, disclosed_indexes)
Expand Down Expand Up @@ -830,7 +839,17 @@ function bbs.proof_verify(ciphersuite, pk, proof, header, ph, disclosed_messages
disclosed_indexes = disclosed_indexes or {}
local len_U = math.floor((#proof-proof_len_floor)/OCTET_SCALAR_LENGTH)
local len_R = table_size(disclosed_indexes)

if disclosed_indexes[1] <= 0 then
error('Disclosed indexes contains an integer less than or equal to 0', 2)
end
if disclosed_indexes[#disclosed_indexes] > len_R+len_U then
error('Disclosed index contains an integer which exceeds the total number of messages', 2)
end
for i = 2, len_R, 1 do
if disclosed_indexes[i] == disclosed_indexes[i - 1] then
error('disclosed indexes contains duplicates', 2)
end
end
local message_scalars = bbs.messages_to_scalars(ciphersuite, disclosed_messages_octets)
local generators = bbs.create_generators(ciphersuite, len_U+len_R+1)

Expand Down
Loading