Skip to content

Commit

Permalink
secp256k1: Make field value mul int take uint8.
Browse files Browse the repository at this point in the history
This modifies the MulInt method on a field value to take a uint8 instead
of a uint in order to make it harder to misuse it since it has a
precondition which requires to the caller to ensure internal overflows
are avoided.   In practice, the code currently only ever calls it with a
max value of 8, but in order to prepare for exporting the type, it's
nicer to make it harder to misuse.
  • Loading branch information
davecgh committed Mar 24, 2020
1 parent ebb25a7 commit e80c805
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dcrec/secp256k1/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ func (f *fieldVal) Add2(val *fieldVal, val2 *fieldVal) *fieldVal {
//
// The field value is returned to support chaining. This enables syntax like:
// f.MulInt(2).Add(f2) so that f = 2 * f + f2.
func (f *fieldVal) MulInt(val uint) *fieldVal {
func (f *fieldVal) MulInt(val uint8) *fieldVal {
// Since each word of the field representation can hold up to
// 32 - fieldBase extra bits which will be normalized out, it's safe
// to multiply each word without using a larger type or carry
Expand Down
2 changes: 1 addition & 1 deletion dcrec/secp256k1/field_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ func TestFieldMulInt(t *testing.T) {
tests := []struct {
name string // test description
in1 string // hex encoded value
in2 uint // unsigned integer to multiply with value above
in2 uint8 // unsigned integer to multiply with value above
expected string // expected hex encoded value
}{{
name: "zero * zero",
Expand Down

0 comments on commit e80c805

Please sign in to comment.