Skip to content

Commit

Permalink
secp256k1: Make field set byte slice const time.
Browse files Browse the repository at this point in the history
This makes the SetByteSlice method on the field value type constant time
in preparation for exporting the type.
  • Loading branch information
davecgh committed Mar 24, 2020
1 parent e80c805 commit 3d9cda1
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions dcrec/secp256k1/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,12 @@ func (f *fieldVal) SetBytes(b *[32]byte) *fieldVal {
// f := new(fieldVal).SetByteSlice(byteSlice)
func (f *fieldVal) SetByteSlice(b []byte) *fieldVal {
var b32 [32]byte
for i := 0; i < len(b); i++ {
if i < 32 {
b32[i+(32-len(b))] = b[i]
}
}
return f.SetBytes(&b32)
b = b[:constantTimeMin(uint32(len(b)), 32)]
copy(b32[:], b32[:32-len(b)])
copy(b32[32-len(b):], b)
f.SetBytes(&b32)
zeroArray32(&b32)
return f
}

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

0 comments on commit 3d9cda1

Please sign in to comment.