Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

secp256k1: Tighten max magnitudes in comments. #3442

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions dcrec/secp256k1/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ const (
// and the caller MUST normalize the field value if a given operation would
// cause the magnitude of the result to exceed the max allowed value.
//
// IMPORTANT: The max allowed magnitude of a field value is 64.
// IMPORTANT: The max allowed magnitude of a field value is 32.
type FieldVal struct {
// Each 256-bit value is represented as 10 32-bit integers in base 2^26.
// This provides 6 bits of overflow in each word (10 bits in the most
Expand Down Expand Up @@ -628,14 +628,14 @@ func (f *FieldVal) Equals(val *FieldVal) bool {
}

// NegateVal negates the passed value and stores the result in f in constant
// time. The caller must provide the magnitude of the passed value for a
// correct result.
// time. The caller must provide the maximum magnitude of the passed value for
// a correct result.
//
// The field value is returned to support chaining. This enables syntax like:
// f.NegateVal(f2).AddInt(1) so that f = -f2 + 1.
//
// Preconditions:
// - The max magnitude MUST be 63
// - The max magnitude MUST be 31
// Output Normalized: No
// Output Max Magnitude: Input magnitude + 1
func (f *FieldVal) NegateVal(val *FieldVal, magnitude uint32) *FieldVal {
Expand Down Expand Up @@ -672,14 +672,14 @@ func (f *FieldVal) NegateVal(val *FieldVal, magnitude uint32) *FieldVal {
}

// Negate negates the field value in constant time. The existing field value is
// modified. The caller must provide the magnitude of the field value for a
// correct result.
// modified. The caller must provide the maximum magnitude of the field value
// for a correct result.
//
// The field value is returned to support chaining. This enables syntax like:
// f.Negate().AddInt(1) so that f = -f + 1.
//
// Preconditions:
// - The max magnitude MUST be 63
// - The max magnitude MUST be 31
// Output Normalized: No
// Output Max Magnitude: Input magnitude + 1
func (f *FieldVal) Negate(magnitude uint32) *FieldVal {
Expand All @@ -694,7 +694,8 @@ func (f *FieldVal) Negate(magnitude uint32) *FieldVal {
// f.AddInt(1).Add(f2) so that f = f + 1 + f2.
//
// Preconditions:
// - The field value MUST have a max magnitude of 63
// - The field value MUST have a max magnitude of 31
// - The integer MUST be a max of 32767
// Output Normalized: No
// Output Max Magnitude: Existing field magnitude + 1
func (f *FieldVal) AddInt(ui uint16) *FieldVal {
Expand All @@ -713,7 +714,7 @@ func (f *FieldVal) AddInt(ui uint16) *FieldVal {
// f.Add(f2).AddInt(1) so that f = f + f2 + 1.
//
// Preconditions:
// - The sum of the magnitudes of the two field values MUST be a max of 64
// - The sum of the magnitudes of the two field values MUST be a max of 32
// Output Normalized: No
// Output Max Magnitude: Sum of the magnitude of the two individual field values
func (f *FieldVal) Add(val *FieldVal) *FieldVal {
Expand Down Expand Up @@ -742,7 +743,7 @@ func (f *FieldVal) Add(val *FieldVal) *FieldVal {
// f3.Add2(f, f2).AddInt(1) so that f3 = f + f2 + 1.
//
// Preconditions:
// - The sum of the magnitudes of the two field values MUST be a max of 64
// - The sum of the magnitudes of the two field values MUST be a max of 32
// Output Normalized: No
// Output Max Magnitude: Sum of the magnitude of the two field values
func (f *FieldVal) Add2(val *FieldVal, val2 *FieldVal) *FieldVal {
Expand Down Expand Up @@ -774,7 +775,7 @@ func (f *FieldVal) Add2(val *FieldVal, val2 *FieldVal) *FieldVal {
// f.MulInt(2).Add(f2) so that f = 2 * f + f2.
//
// Preconditions:
// - The field value magnitude multiplied by given val MUST be a max of 64
// - The field value magnitude multiplied by given val MUST be a max of 32
// Output Normalized: No
// Output Max Magnitude: Existing field magnitude times the provided integer val
func (f *FieldVal) MulInt(val uint8) *FieldVal {
Expand Down