mirror of
https://github.com/status-im/constantine.git
synced 2025-02-23 09:28:07 +00:00
Add cmov according to Milagro / hash_to_curve spec
This commit is contained in:
parent
6694023f16
commit
285b6aad1a
@ -217,6 +217,16 @@ func setZero*(a: BigIntViewMut) =
|
||||
## It's bit size is unchanged
|
||||
zeroMem(a[0].unsafeAddr, a.numLimbs() * sizeof(Word))
|
||||
|
||||
|
||||
func cmov*(a: BigIntViewMut, b: BigIntViewAny, ctl: CTBool[Word]) =
|
||||
## Constant-time conditional copy
|
||||
## If ctl is true: b is copied into a
|
||||
## if ctl is false: b is not copied and a is untouched
|
||||
## Time and memory accesses are the same whether a copy occurs or not
|
||||
checkMatchingBitlengths(a, b)
|
||||
for i in 0 ..< a.numLimbs():
|
||||
a[i] = ctl.mux(b[i], a[i])
|
||||
|
||||
# The arithmetic primitives all accept a control input that indicates
|
||||
# if it is a placebo operation. It stills performs the
|
||||
# same memory accesses to be side-channel attack resistant.
|
||||
|
Loading…
x
Reference in New Issue
Block a user