Skip to content

Commit 3d9cda1

Browse files
committed
secp256k1: Make field set byte slice const time.
This makes the SetByteSlice method on the field value type constant time in preparation for exporting the type.
1 parent e80c805 commit 3d9cda1

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

dcrec/secp256k1/field.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,12 @@ func (f *fieldVal) SetBytes(b *[32]byte) *fieldVal {
218218
// f := new(fieldVal).SetByteSlice(byteSlice)
219219
func (f *fieldVal) SetByteSlice(b []byte) *fieldVal {
220220
var b32 [32]byte
221-
for i := 0; i < len(b); i++ {
222-
if i < 32 {
223-
b32[i+(32-len(b))] = b[i]
224-
}
225-
}
226-
return f.SetBytes(&b32)
221+
b = b[:constantTimeMin(uint32(len(b)), 32)]
222+
copy(b32[:], b32[:32-len(b)])
223+
copy(b32[32-len(b):], b)
224+
f.SetBytes(&b32)
225+
zeroArray32(&b32)
226+
return f
227227
}
228228

229229
// SetHex decodes the passed big-endian hex string into the internal field value

0 commit comments

Comments
 (0)