Improve Ed25519c masking
This commit is contained in:
parent
3c2a5ad4ee
commit
4c52aa8774
|
@ -40,11 +40,11 @@ function mod.sign(sks, pk, msg)
|
|||
-- Challenge.
|
||||
local e = fq.decodeWide(sha512.digest(rStr .. pk .. msg))
|
||||
|
||||
-- Reduce secret key using the challenge.
|
||||
local xe = maddq.reduce(sks, e)
|
||||
|
||||
-- Response.
|
||||
local s = fq.add(k, fq.neg(xe))
|
||||
-- Reduce secret key using the challenge and an extra mask.
|
||||
local m = fq.decodeWide(random.random(64))
|
||||
local xme = maddq.reduce(maddq.add(sks, m), e)
|
||||
local s = fq.add(fq.add(k, fq.neg(xme)), fq.mul(m, e))
|
||||
local sStr = fq.encode(s)
|
||||
|
||||
return rStr .. sStr
|
||||
|
|
|
@ -280,6 +280,10 @@ local function bits(a)
|
|||
return util.rebaseLE(demontgomery(a), 2 ^ 24, 2)
|
||||
end
|
||||
|
||||
local function clone(a)
|
||||
return {unpack(a)}
|
||||
end
|
||||
|
||||
return {
|
||||
num = num,
|
||||
add = add,
|
||||
|
@ -292,4 +296,5 @@ return {
|
|||
decodeWide = decodeWide,
|
||||
decodeClamped = decodeClamped,
|
||||
bits = bits,
|
||||
clone = clone,
|
||||
}
|
||||
|
|
|
@ -38,10 +38,18 @@ local function reduce(arr, k)
|
|||
return out
|
||||
end
|
||||
|
||||
local function add(arr, v)
|
||||
local out = {}
|
||||
for i = 1, #arr do out[i] = fq.clone(arr[i]) end
|
||||
out[#arr] = fq.add(out[#arr], v)
|
||||
return out
|
||||
end
|
||||
|
||||
return {
|
||||
new = new,
|
||||
encode = encode,
|
||||
decode = decode,
|
||||
remask = remask,
|
||||
reduce = reduce,
|
||||
add = add,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue