From 3d9cda1d253973d300991bd82d9705f7b9b8cd14 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Sat, 21 Mar 2020 03:09:44 -0500 Subject: [PATCH] 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. --- dcrec/secp256k1/field.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dcrec/secp256k1/field.go b/dcrec/secp256k1/field.go index bff0056a75..fba16fcf3d 100644 --- a/dcrec/secp256k1/field.go +++ b/dcrec/secp256k1/field.go @@ -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