Improve Ed25519c masking
This commit is contained in:
parent
3c2a5ad4ee
commit
4c52aa8774
|
@ -40,11 +40,11 @@ function mod.sign(sks, pk, msg)
|
||||||
-- Challenge.
|
-- Challenge.
|
||||||
local e = fq.decodeWide(sha512.digest(rStr .. pk .. msg))
|
local e = fq.decodeWide(sha512.digest(rStr .. pk .. msg))
|
||||||
|
|
||||||
-- Reduce secret key using the challenge.
|
|
||||||
local xe = maddq.reduce(sks, e)
|
|
||||||
|
|
||||||
-- Response.
|
-- 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)
|
local sStr = fq.encode(s)
|
||||||
|
|
||||||
return rStr .. sStr
|
return rStr .. sStr
|
||||||
|
|
|
@ -280,6 +280,10 @@ local function bits(a)
|
||||||
return util.rebaseLE(demontgomery(a), 2 ^ 24, 2)
|
return util.rebaseLE(demontgomery(a), 2 ^ 24, 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function clone(a)
|
||||||
|
return {unpack(a)}
|
||||||
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
num = num,
|
num = num,
|
||||||
add = add,
|
add = add,
|
||||||
|
@ -292,4 +296,5 @@ return {
|
||||||
decodeWide = decodeWide,
|
decodeWide = decodeWide,
|
||||||
decodeClamped = decodeClamped,
|
decodeClamped = decodeClamped,
|
||||||
bits = bits,
|
bits = bits,
|
||||||
|
clone = clone,
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,10 +38,18 @@ local function reduce(arr, k)
|
||||||
return out
|
return out
|
||||||
end
|
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 {
|
return {
|
||||||
new = new,
|
new = new,
|
||||||
encode = encode,
|
encode = encode,
|
||||||
decode = decode,
|
decode = decode,
|
||||||
remask = remask,
|
remask = remask,
|
||||||
reduce = reduce,
|
reduce = reduce,
|
||||||
|
add = add,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue