Skip to content

Commit

Permalink
crypto/internal/edwards25519: reduce Point size by reordering fields
Browse files Browse the repository at this point in the history
Updates #58483

Tested on Linux amd64:
  type Element struct {
    l0, l1, l2, l3, l4 uint64
  }

  type PointAfter struct {
    x, y, z, t Element
    _          incomparable
  }

  type PointBefore struct {
    _          incomparable
    x, y, z, t Element
  }

  type incomparable [0]func()

  func main() {
    fmt.Println(unsafe.Sizeof(PointAfter{})) // 168
    fmt.Println(unsafe.Sizeof(PointBefore{})) // 160
  }

Change-Id: I6c4fcb586bbf3febf62b6e54608496ff81685e43
Reviewed-on: https://go-review.googlesource.com/c/go/+/467616
Reviewed-by: Roland Shoemaker <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Filippo Valsorda <[email protected]>
Reviewed-by: Damien Neil <[email protected]>
Run-TryBot: Filippo Valsorda <[email protected]>
  • Loading branch information
Jorropo authored and FiloSottile committed Dec 10, 2023
1 parent daffb31 commit c901e5e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions edwards25519.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ type projP2 struct {
//
// The zero value is NOT valid, and it may be used only as a receiver.
type Point struct {
// The point is internally represented in extended coordinates (X, Y, Z, T)
// where x = X/Z, y = Y/Z, and xy = T/Z per https://eprint.iacr.org/2008/522.
x, y, z, t field.Element

// Make the type not comparable (i.e. used with == or as a map key), as
// equivalent points can be represented by different Go values.
_ incomparable

// The point is internally represented in extended coordinates (X, Y, Z, T)
// where x = X/Z, y = Y/Z, and xy = T/Z per https://eprint.iacr.org/2008/522.
x, y, z, t field.Element
}

type incomparable [0]func()
Expand Down

0 comments on commit c901e5e

Please sign in to comment.