]> Cypherpunks repositories - gostls13.git/commitdiff
crypto/internal/nistec: move to crypto/internal/fips/nistec
authorFilippo Valsorda <filippo@golang.org>
Thu, 14 Nov 2024 14:27:28 +0000 (15:27 +0100)
committerGopher Robot <gobot@golang.org>
Tue, 19 Nov 2024 23:01:35 +0000 (23:01 +0000)
For #69536

Change-Id: Id9d76aefbbe1f7c957973380c6eaeb5bfb9de967
Reviewed-on: https://go-review.googlesource.com/c/go/+/627957
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Daniel McCarney <daniel@binaryparadox.net>
Auto-Submit: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
TryBot-Bypass: Filippo Valsorda <filippo@golang.org>
Commit-Queue: Filippo Valsorda <filippo@golang.org>

45 files changed:
src/cmd/compile/internal/ssa/stmtlines_test.go
src/crypto/ecdh/nist.go
src/crypto/ecdsa/ecdsa.go
src/crypto/elliptic/nistec.go
src/crypto/elliptic/nistec_p256.go
src/crypto/internal/fips/nistec/_asm/go.mod [moved from src/crypto/internal/nistec/_asm/go.mod with 80% similarity]
src/crypto/internal/fips/nistec/_asm/go.sum [moved from src/crypto/internal/nistec/_asm/go.sum with 100% similarity]
src/crypto/internal/fips/nistec/_asm/p256_asm.go [moved from src/crypto/internal/nistec/_asm/p256_asm.go with 99% similarity]
src/crypto/internal/fips/nistec/benchmark_test.go [new file with mode: 0644]
src/crypto/internal/fips/nistec/fiat/Dockerfile [moved from src/crypto/internal/nistec/fiat/Dockerfile with 100% similarity]
src/crypto/internal/fips/nistec/fiat/README [moved from src/crypto/internal/nistec/fiat/README with 100% similarity]
src/crypto/internal/fips/nistec/fiat/benchmark_test.go [moved from src/crypto/internal/nistec/fiat/fiat_test.go with 97% similarity]
src/crypto/internal/fips/nistec/fiat/generate.go [moved from src/crypto/internal/nistec/fiat/generate.go with 99% similarity]
src/crypto/internal/fips/nistec/fiat/p224.go [moved from src/crypto/internal/nistec/fiat/p224.go with 99% similarity]
src/crypto/internal/fips/nistec/fiat/p224_fiat64.go [moved from src/crypto/internal/nistec/fiat/p224_fiat64.go with 100% similarity]
src/crypto/internal/fips/nistec/fiat/p224_invert.go [moved from src/crypto/internal/nistec/fiat/p224_invert.go with 100% similarity]
src/crypto/internal/fips/nistec/fiat/p256.go [moved from src/crypto/internal/nistec/fiat/p256.go with 99% similarity]
src/crypto/internal/fips/nistec/fiat/p256_fiat64.go [moved from src/crypto/internal/nistec/fiat/p256_fiat64.go with 100% similarity]
src/crypto/internal/fips/nistec/fiat/p256_invert.go [moved from src/crypto/internal/nistec/fiat/p256_invert.go with 100% similarity]
src/crypto/internal/fips/nistec/fiat/p384.go [moved from src/crypto/internal/nistec/fiat/p384.go with 99% similarity]
src/crypto/internal/fips/nistec/fiat/p384_fiat64.go [moved from src/crypto/internal/nistec/fiat/p384_fiat64.go with 100% similarity]
src/crypto/internal/fips/nistec/fiat/p384_invert.go [moved from src/crypto/internal/nistec/fiat/p384_invert.go with 100% similarity]
src/crypto/internal/fips/nistec/fiat/p521.go [moved from src/crypto/internal/nistec/fiat/p521.go with 99% similarity]
src/crypto/internal/fips/nistec/fiat/p521_fiat64.go [moved from src/crypto/internal/nistec/fiat/p521_fiat64.go with 100% similarity]
src/crypto/internal/fips/nistec/fiat/p521_invert.go [moved from src/crypto/internal/nistec/fiat/p521_invert.go with 100% similarity]
src/crypto/internal/fips/nistec/generate.go [moved from src/crypto/internal/nistec/generate.go with 99% similarity]
src/crypto/internal/fips/nistec/nistec.go [moved from src/crypto/internal/nistec/nistec.go with 89% similarity]
src/crypto/internal/fips/nistec/p224.go [moved from src/crypto/internal/nistec/p224.go with 99% similarity]
src/crypto/internal/fips/nistec/p224_sqrt.go [moved from src/crypto/internal/nistec/p224_sqrt.go with 98% similarity]
src/crypto/internal/fips/nistec/p256.go [moved from src/crypto/internal/nistec/p256.go with 98% similarity]
src/crypto/internal/fips/nistec/p256_asm.go [moved from src/crypto/internal/nistec/p256_asm.go with 98% similarity]
src/crypto/internal/fips/nistec/p256_asm_amd64.s [moved from src/crypto/internal/nistec/p256_asm_amd64.s with 100% similarity]
src/crypto/internal/fips/nistec/p256_asm_arm64.s [moved from src/crypto/internal/nistec/p256_asm_arm64.s with 100% similarity]
src/crypto/internal/fips/nistec/p256_asm_ppc64le.s [moved from src/crypto/internal/nistec/p256_asm_ppc64le.s with 100% similarity]
src/crypto/internal/fips/nistec/p256_asm_s390x.s [moved from src/crypto/internal/nistec/p256_asm_s390x.s with 100% similarity]
src/crypto/internal/fips/nistec/p256_asm_test.go [moved from src/crypto/internal/nistec/p256_asm_test.go with 100% similarity]
src/crypto/internal/fips/nistec/p256_ordinv.go [moved from src/crypto/internal/nistec/p256_ordinv.go with 100% similarity]
src/crypto/internal/fips/nistec/p256_ordinv_noasm.go [moved from src/crypto/internal/nistec/p256_ordinv_noasm.go with 100% similarity]
src/crypto/internal/fips/nistec/p256_table.go [moved from src/crypto/internal/nistec/p256_table.go with 100% similarity]
src/crypto/internal/fips/nistec/p256_table_test.go [moved from src/crypto/internal/nistec/p256_test.go with 96% similarity]
src/crypto/internal/fips/nistec/p384.go [moved from src/crypto/internal/nistec/p384.go with 99% similarity]
src/crypto/internal/fips/nistec/p521.go [moved from src/crypto/internal/nistec/p521.go with 99% similarity]
src/crypto/internal/fipstest/nistec_ordinv_test.go [moved from src/crypto/internal/nistec/p256_ordinv_test.go with 97% similarity]
src/crypto/internal/fipstest/nistec_test.go [moved from src/crypto/internal/nistec/nistec_test.go with 82% similarity]
src/go/build/deps_test.go

index 8a8f18c811108d5be5fe8eefc62f431a5613c94a..f04ca706b65e432a90648fa23340703299aca703 100644 (file)
@@ -103,7 +103,7 @@ func TestStmtLines(t *testing.T) {
                if pkgname == "runtime" {
                        continue
                }
-               if pkgname == "crypto/internal/nistec/fiat" {
+               if pkgname == "crypto/internal/fips/nistec/fiat" {
                        continue // golang.org/issue/49372
                }
                if e.Val(dwarf.AttrStmtList) == nil {
index b91e8f38a5a78e249e9a51ed8fcefd5f6184be7d..85b53b4c1afa27d153f0a881e13cb05c4e80098c 100644 (file)
@@ -6,7 +6,7 @@ package ecdh
 
 import (
        "crypto/internal/boring"
-       "crypto/internal/nistec"
+       "crypto/internal/fips/nistec"
        "crypto/internal/randutil"
        "errors"
        "internal/byteorder"
index 2179b01e8e3db57e9b7686c15a777ec75e4c206d..95a4b4be69f32e7fd07376ba316abdde96496b9d 100644 (file)
@@ -33,7 +33,7 @@ import (
        "crypto/internal/bigmod"
        "crypto/internal/boring"
        "crypto/internal/boring/bbig"
-       "crypto/internal/nistec"
+       "crypto/internal/fips/nistec"
        "crypto/internal/randutil"
        "crypto/sha512"
        "crypto/subtle"
index d906c570745e9eff7a79a227e39034de735482ab..b785b2cca697405971cea5282c964dd536556bd4 100644 (file)
@@ -5,7 +5,7 @@
 package elliptic
 
 import (
-       "crypto/internal/nistec"
+       "crypto/internal/fips/nistec"
        "errors"
        "math/big"
 )
@@ -18,7 +18,7 @@ func initP224() {
        p224.params = &CurveParams{
                Name:    "P-224",
                BitSize: 224,
-               // FIPS 186-4, section D.1.2.2
+               // SP 800-186, Section 3.2.1.2
                P:  bigFromDecimal("26959946667150639794667015087019630673557916260026308143510066298881"),
                N:  bigFromDecimal("26959946667150639794667015087019625940457807714424391721682722368061"),
                B:  bigFromHex("b4050a850c04b3abf54132565044b0b7d7bfd8ba270b39432355ffb4"),
@@ -39,7 +39,7 @@ func initP256() {
        p256.params = &CurveParams{
                Name:    "P-256",
                BitSize: 256,
-               // FIPS 186-4, section D.1.2.3
+               // SP 800-186, Section 3.2.1.3
                P:  bigFromDecimal("115792089210356248762697446949407573530086143415290314195533631308867097853951"),
                N:  bigFromDecimal("115792089210356248762697446949407573529996955224135760342422259061068512044369"),
                B:  bigFromHex("5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),
@@ -56,7 +56,7 @@ func initP384() {
        p384.params = &CurveParams{
                Name:    "P-384",
                BitSize: 384,
-               // FIPS 186-4, section D.1.2.4
+               // SP 800-186, Section 3.2.1.4
                P: bigFromDecimal("394020061963944792122790401001436138050797392704654" +
                        "46667948293404245721771496870329047266088258938001861606973112319"),
                N: bigFromDecimal("394020061963944792122790401001436138050797392704654" +
@@ -78,7 +78,7 @@ func initP521() {
        p521.params = &CurveParams{
                Name:    "P-521",
                BitSize: 521,
-               // FIPS 186-4, section D.1.2.5
+               // SP 800-186, Section 3.2.1.5
                P: bigFromDecimal("68647976601306097149819007990813932172694353001433" +
                        "0540939446345918554318339765605212255964066145455497729631139148" +
                        "0858037121987999716643812574028291115057151"),
index 304f8f2659c0006ba8b4bde11e43da2120f528df..14bf167774f13f1c96829760ec4dfcaf9a820aa2 100644 (file)
@@ -7,7 +7,7 @@
 package elliptic
 
 import (
-       "crypto/internal/nistec"
+       "crypto/internal/fips/nistec"
        "math/big"
 )
 
similarity index 80%
rename from src/crypto/internal/nistec/_asm/go.mod
rename to src/crypto/internal/fips/nistec/_asm/go.mod
index 116284483d2b6c5acbda42a934abb08f99c66eea..d631322e10243d27991ad4b8182902a6ad9e0e85 100644 (file)
@@ -1,4 +1,4 @@
-module std/crypto/internal/nistec/_asm
+module std/crypto/internal/fips/nistec/_asm
 
 go 1.24
 
similarity index 99%
rename from src/crypto/internal/nistec/_asm/p256_asm.go
rename to src/crypto/internal/fips/nistec/_asm/p256_asm.go
index 0591b25a9331ac46d6505918590ff97ae38fb610..5616513a2429440abbc1425dd18116352504eeda 100644 (file)
@@ -43,7 +43,7 @@ var (
 )
 
 func main() {
-       Package("crypto/internal/nistec")
+       Package("crypto/internal/fips/nistec")
        ConstraintExpr("!purego")
        p256MovCond()
        p256NegCond()
diff --git a/src/crypto/internal/fips/nistec/benchmark_test.go b/src/crypto/internal/fips/nistec/benchmark_test.go
new file mode 100644 (file)
index 0000000..17d131e
--- /dev/null
@@ -0,0 +1,71 @@
+// Copyright 2024 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package nistec_test
+
+import (
+       "crypto/internal/fips/nistec"
+       "crypto/rand"
+       "testing"
+)
+
+type nistPoint[T any] interface {
+       Bytes() []byte
+       SetGenerator() T
+       SetBytes([]byte) (T, error)
+       Add(T, T) T
+       Double(T) T
+       ScalarMult(T, []byte) (T, error)
+       ScalarBaseMult([]byte) (T, error)
+}
+
+func BenchmarkScalarMult(b *testing.B) {
+       b.Run("P224", func(b *testing.B) {
+               benchmarkScalarMult(b, nistec.NewP224Point().SetGenerator(), 28)
+       })
+       b.Run("P256", func(b *testing.B) {
+               benchmarkScalarMult(b, nistec.NewP256Point().SetGenerator(), 32)
+       })
+       b.Run("P384", func(b *testing.B) {
+               benchmarkScalarMult(b, nistec.NewP384Point().SetGenerator(), 48)
+       })
+       b.Run("P521", func(b *testing.B) {
+               benchmarkScalarMult(b, nistec.NewP521Point().SetGenerator(), 66)
+       })
+}
+
+func benchmarkScalarMult[P nistPoint[P]](b *testing.B, p P, scalarSize int) {
+       scalar := make([]byte, scalarSize)
+       rand.Read(scalar)
+       b.ReportAllocs()
+       b.ResetTimer()
+       for i := 0; i < b.N; i++ {
+               p.ScalarMult(p, scalar)
+       }
+}
+
+func BenchmarkScalarBaseMult(b *testing.B) {
+       b.Run("P224", func(b *testing.B) {
+               benchmarkScalarBaseMult(b, nistec.NewP224Point().SetGenerator(), 28)
+       })
+       b.Run("P256", func(b *testing.B) {
+               benchmarkScalarBaseMult(b, nistec.NewP256Point().SetGenerator(), 32)
+       })
+       b.Run("P384", func(b *testing.B) {
+               benchmarkScalarBaseMult(b, nistec.NewP384Point().SetGenerator(), 48)
+       })
+       b.Run("P521", func(b *testing.B) {
+               benchmarkScalarBaseMult(b, nistec.NewP521Point().SetGenerator(), 66)
+       })
+}
+
+func benchmarkScalarBaseMult[P nistPoint[P]](b *testing.B, p P, scalarSize int) {
+       scalar := make([]byte, scalarSize)
+       rand.Read(scalar)
+       b.ReportAllocs()
+       b.ResetTimer()
+       for i := 0; i < b.N; i++ {
+               p.ScalarBaseMult(scalar)
+       }
+}
similarity index 97%
rename from src/crypto/internal/nistec/fiat/fiat_test.go
rename to src/crypto/internal/fips/nistec/fiat/benchmark_test.go
index dee9f68222989100f98c208b87bbeda28453b911..013d76f7ba86858246551deba885a341c680b0a1 100644 (file)
@@ -5,7 +5,7 @@
 package fiat_test
 
 import (
-       "crypto/internal/nistec/fiat"
+       "crypto/internal/fips/nistec/fiat"
        "testing"
 )
 
similarity index 99%
rename from src/crypto/internal/nistec/fiat/generate.go
rename to src/crypto/internal/fips/nistec/fiat/generate.go
index db57021531b3a9a4695fd0e1b14d17a3ef473efb..831524970b9ec645839ef2dd5ba7654ab28caf78 100644 (file)
@@ -152,7 +152,7 @@ const tmplWrapper = `// Copyright 2021 The Go Authors. All rights reserved.
 package fiat
 
 import (
-       "crypto/subtle"
+       "crypto/internal/fips/subtle"
        "errors"
 )
 
similarity index 99%
rename from src/crypto/internal/nistec/fiat/p224.go
rename to src/crypto/internal/fips/nistec/fiat/p224.go
index e1a78db33e2cb29af17ba7b268136ef586f407f2..0973f173c1f2c74932f36317235e6d779aa3122e 100644 (file)
@@ -7,7 +7,7 @@
 package fiat
 
 import (
-       "crypto/subtle"
+       "crypto/internal/fips/subtle"
        "errors"
 )
 
similarity index 99%
rename from src/crypto/internal/nistec/fiat/p256.go
rename to src/crypto/internal/fips/nistec/fiat/p256.go
index 7705904ca1a9b26214d51c2c9596067e07d4e361..7933e05bcf06af1c12b45851b9e4fea1c50b9190 100644 (file)
@@ -7,7 +7,7 @@
 package fiat
 
 import (
-       "crypto/subtle"
+       "crypto/internal/fips/subtle"
        "errors"
 )
 
similarity index 99%
rename from src/crypto/internal/nistec/fiat/p384.go
rename to src/crypto/internal/fips/nistec/fiat/p384.go
index aed0c013c87e1e5bb81ae7a66999207907f5e26b..667c62b01c1e2f00165c7babe704ae72cafb4137 100644 (file)
@@ -7,7 +7,7 @@
 package fiat
 
 import (
-       "crypto/subtle"
+       "crypto/internal/fips/subtle"
        "errors"
 )
 
similarity index 99%
rename from src/crypto/internal/nistec/fiat/p521.go
rename to src/crypto/internal/fips/nistec/fiat/p521.go
index 43ac7d06a0cb1cf30a34b8b610383ebd4fc7cd42..7106470572b371f0ce104d52747489a11f39ad82 100644 (file)
@@ -7,7 +7,7 @@
 package fiat
 
 import (
-       "crypto/subtle"
+       "crypto/internal/fips/subtle"
        "errors"
 )
 
similarity index 99%
rename from src/crypto/internal/nistec/generate.go
rename to src/crypto/internal/fips/nistec/generate.go
index 27e8d13943b2430f19135937a82b908c4bdad91b..5f52edda6e099009f61ce1644cf9ab918145e6c4 100644 (file)
@@ -152,8 +152,8 @@ const tmplNISTEC = `// Copyright 2022 The Go Authors. All rights reserved.
 package nistec
 
 import (
-       "crypto/internal/nistec/fiat"
-       "crypto/subtle"
+       "crypto/internal/fips/nistec/fiat"
+       "crypto/internal/fips/subtle"
        "errors"
        "sync"
 )
similarity index 89%
rename from src/crypto/internal/nistec/nistec.go
rename to src/crypto/internal/fips/nistec/nistec.go
index d898d409ca782c8fc5083765f1139ec93c4815ef..d1c63dacd59573ef562f33b9b7e772e8ffdbf2eb 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// Package nistec implements the NIST P elliptic curves from FIPS 186-4.
+// Package nistec implements the elliptic curves from NIST SP 800-186.
 //
 // This package uses fiat-crypto or specialized assembly and Go code for its
 // backend field arithmetic (not math/big) and exposes constant-time, heap
similarity index 99%
rename from src/crypto/internal/nistec/p224.go
rename to src/crypto/internal/fips/nistec/p224.go
index faa971d7ed268184b7ac165dec282a8436e407b0..ef6e7e6bafd62341b2950103d138d209ca284892 100644 (file)
@@ -7,8 +7,8 @@
 package nistec
 
 import (
-       "crypto/internal/nistec/fiat"
-       "crypto/subtle"
+       "crypto/internal/fips/nistec/fiat"
+       "crypto/internal/fips/subtle"
        "errors"
        "sync"
 )
similarity index 98%
rename from src/crypto/internal/nistec/p224_sqrt.go
rename to src/crypto/internal/fips/nistec/p224_sqrt.go
index 0c775790dadd2260571bb56380a4dc375ad3edf4..c83e965bb4df682d191560c115bbaffcdee41675 100644 (file)
@@ -5,7 +5,7 @@
 package nistec
 
 import (
-       "crypto/internal/nistec/fiat"
+       "crypto/internal/fips/nistec/fiat"
        "sync"
 )
 
similarity index 98%
rename from src/crypto/internal/nistec/p256.go
rename to src/crypto/internal/fips/nistec/p256.go
index d0a0d60fe4cbe513c14fbf7dbcb67b8a95129501..e83fc034bd8f112f2526b262a72d947053db81c9 100644 (file)
@@ -7,11 +7,11 @@
 package nistec
 
 import (
-       "crypto/internal/nistec/fiat"
-       "crypto/subtle"
+       "crypto/internal/fips/nistec/fiat"
+       "crypto/internal/fips/subtle"
+       "crypto/internal/fipsdeps/byteorder"
+       "crypto/internal/fipsdeps/cpu"
        "errors"
-       "internal/byteorder"
-       "internal/goarch"
        "math/bits"
        "sync"
        "unsafe"
@@ -402,10 +402,10 @@ func (s *p256OrdElement) SetBytes(x []byte) (*p256OrdElement, error) {
                return nil, errors.New("invalid scalar length")
        }
 
-       s[0] = byteorder.BeUint64(x[24:])
-       s[1] = byteorder.BeUint64(x[16:])
-       s[2] = byteorder.BeUint64(x[8:])
-       s[3] = byteorder.BeUint64(x[:])
+       s[0] = byteorder.BEUint64(x[24:])
+       s[1] = byteorder.BEUint64(x[16:])
+       s[2] = byteorder.BEUint64(x[8:])
+       s[3] = byteorder.BEUint64(x[:])
 
        // Ensure s is in the range [0, ord(G)-1]. Since 2 * ord(G) > 2²⁵⁶, we can
        // just conditionally subtract ord(G), keeping the result if it doesn't
@@ -425,10 +425,10 @@ func (s *p256OrdElement) SetBytes(x []byte) (*p256OrdElement, error) {
 
 func (s *p256OrdElement) Bytes() []byte {
        var out [32]byte
-       byteorder.BePutUint64(out[24:], s[0])
-       byteorder.BePutUint64(out[16:], s[1])
-       byteorder.BePutUint64(out[8:], s[2])
-       byteorder.BePutUint64(out[:], s[3])
+       byteorder.BEPutUint64(out[24:], s[0])
+       byteorder.BEPutUint64(out[16:], s[1])
+       byteorder.BEPutUint64(out[8:], s[2])
+       byteorder.BEPutUint64(out[:], s[3])
        return out[:]
 }
 
@@ -570,10 +570,10 @@ var p256GeneratorTables *[43]p256AffineTable
 
 func init() {
        p256GeneratorTablesPtr := unsafe.Pointer(&p256PrecomputedEmbed)
-       if goarch.BigEndian {
+       if cpu.BigEndian {
                var newTable [43 * 32 * 2 * 4]uint64
                for i, x := range (*[43 * 32 * 2 * 4][8]byte)(p256GeneratorTablesPtr) {
-                       newTable[i] = byteorder.LeUint64(x[:])
+                       newTable[i] = byteorder.LEUint64(x[:])
                }
                p256GeneratorTablesPtr = unsafe.Pointer(&newTable)
        }
similarity index 98%
rename from src/crypto/internal/nistec/p256_asm.go
rename to src/crypto/internal/fips/nistec/p256_asm.go
index ca164419206e2565dc352cf4af240a1e086c4602..08e771cc10015114e8fbe6e09e7935fd40a0785c 100644 (file)
@@ -15,8 +15,8 @@
 package nistec
 
 import (
+       "crypto/internal/fipsdeps/byteorder"
        "errors"
-       "internal/byteorder"
        "math/bits"
        "runtime"
        "unsafe"
@@ -182,10 +182,10 @@ func p256BigToLittle(l *p256Element, b *[32]byte) {
 }
 
 func bytesToLimbs(l *[4]uint64, b *[32]byte) {
-       l[0] = byteorder.BeUint64(b[24:])
-       l[1] = byteorder.BeUint64(b[16:])
-       l[2] = byteorder.BeUint64(b[8:])
-       l[3] = byteorder.BeUint64(b[:])
+       l[0] = byteorder.BEUint64(b[24:])
+       l[1] = byteorder.BEUint64(b[16:])
+       l[2] = byteorder.BEUint64(b[8:])
+       l[3] = byteorder.BEUint64(b[:])
 }
 
 func p256LittleToBig(b *[32]byte, l *p256Element) {
@@ -193,10 +193,10 @@ func p256LittleToBig(b *[32]byte, l *p256Element) {
 }
 
 func limbsToBytes(b *[32]byte, l *[4]uint64) {
-       byteorder.BePutUint64(b[24:], l[0])
-       byteorder.BePutUint64(b[16:], l[1])
-       byteorder.BePutUint64(b[8:], l[2])
-       byteorder.BePutUint64(b[:], l[3])
+       byteorder.BEPutUint64(b[24:], l[0])
+       byteorder.BEPutUint64(b[16:], l[1])
+       byteorder.BEPutUint64(b[8:], l[2])
+       byteorder.BEPutUint64(b[:], l[3])
 }
 
 // p256Add sets res = x + y.
@@ -333,7 +333,7 @@ func init() {
        if runtime.GOARCH == "s390x" {
                var newTable [43 * 32 * 2 * 4]uint64
                for i, x := range (*[43 * 32 * 2 * 4][8]byte)(p256PrecomputedPtr) {
-                       newTable[i] = byteorder.LeUint64(x[:])
+                       newTable[i] = byteorder.LEUint64(x[:])
                }
                p256PrecomputedPtr = unsafe.Pointer(&newTable)
        }
similarity index 96%
rename from src/crypto/internal/nistec/p256_test.go
rename to src/crypto/internal/fips/nistec/p256_table_test.go
index 7ebe7209dcc718da5ddf398beaeabb852fee4f62..0fb95ccf822bd19e23c79e292b9884e9a61d7e5c 100644 (file)
@@ -8,7 +8,7 @@ package nistec
 
 import (
        "bytes"
-       "crypto/internal/nistec/fiat"
+       "crypto/internal/fips/nistec/fiat"
        "fmt"
        "testing"
 )
similarity index 99%
rename from src/crypto/internal/nistec/p384.go
rename to src/crypto/internal/fips/nistec/p384.go
index b452ec9aea294ee5c3044c200ee9250388583e3c..49226d96dfedb2f2213b0c8bfd45c5ae2cafd1ce 100644 (file)
@@ -7,8 +7,8 @@
 package nistec
 
 import (
-       "crypto/internal/nistec/fiat"
-       "crypto/subtle"
+       "crypto/internal/fips/nistec/fiat"
+       "crypto/internal/fips/subtle"
        "errors"
        "sync"
 )
similarity index 99%
rename from src/crypto/internal/nistec/p521.go
rename to src/crypto/internal/fips/nistec/p521.go
index a57ad24c4d441b6b6b90530e8ca464c540e06429..f724d0233ad118886dff6a73b6de2c4dcfa8e687 100644 (file)
@@ -7,8 +7,8 @@
 package nistec
 
 import (
-       "crypto/internal/nistec/fiat"
-       "crypto/subtle"
+       "crypto/internal/fips/nistec/fiat"
+       "crypto/internal/fips/subtle"
        "errors"
        "sync"
 )
similarity index 97%
rename from src/crypto/internal/nistec/p256_ordinv_test.go
rename to src/crypto/internal/fipstest/nistec_ordinv_test.go
index ca323a3ae294f9d5f53a039292a2d03719958e32..60317e0e448047e780077ffabb628e37d12eb2b7 100644 (file)
@@ -4,12 +4,12 @@
 
 //go:build (amd64 || arm64) && !purego
 
-package nistec_test
+package fipstest
 
 import (
        "bytes"
        "crypto/elliptic"
-       "crypto/internal/nistec"
+       "crypto/internal/fips/nistec"
        "math/big"
        "testing"
 )
similarity index 82%
rename from src/crypto/internal/nistec/nistec_test.go
rename to src/crypto/internal/fipstest/nistec_test.go
index d608b4bd1708f7bd61216cd393664f6bc2151613..42c671c238b2a56c85947410d02b462b153b0060 100644 (file)
@@ -2,20 +2,20 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-package nistec_test
+package fipstest
 
 import (
        "bytes"
        "crypto/elliptic"
        "crypto/internal/cryptotest"
-       "crypto/internal/nistec"
+       "crypto/internal/fips/nistec"
        "fmt"
        "math/big"
        "math/rand"
        "testing"
 )
 
-func TestAllocations(t *testing.T) {
+func TestNISTECAllocations(t *testing.T) {
        cryptotest.SkipTestAllocations(t)
        t.Run("P224", func(t *testing.T) {
                if allocs := testing.AllocsPerRun(10, func() {
@@ -258,53 +258,3 @@ func fatalIfErr(t *testing.T, err error) {
                t.Fatal(err)
        }
 }
-
-func BenchmarkScalarMult(b *testing.B) {
-       b.Run("P224", func(b *testing.B) {
-               benchmarkScalarMult(b, nistec.NewP224Point().SetGenerator(), 28)
-       })
-       b.Run("P256", func(b *testing.B) {
-               benchmarkScalarMult(b, nistec.NewP256Point().SetGenerator(), 32)
-       })
-       b.Run("P384", func(b *testing.B) {
-               benchmarkScalarMult(b, nistec.NewP384Point().SetGenerator(), 48)
-       })
-       b.Run("P521", func(b *testing.B) {
-               benchmarkScalarMult(b, nistec.NewP521Point().SetGenerator(), 66)
-       })
-}
-
-func benchmarkScalarMult[P nistPoint[P]](b *testing.B, p P, scalarSize int) {
-       scalar := make([]byte, scalarSize)
-       rand.Read(scalar)
-       b.ReportAllocs()
-       b.ResetTimer()
-       for i := 0; i < b.N; i++ {
-               p.ScalarMult(p, scalar)
-       }
-}
-
-func BenchmarkScalarBaseMult(b *testing.B) {
-       b.Run("P224", func(b *testing.B) {
-               benchmarkScalarBaseMult(b, nistec.NewP224Point().SetGenerator(), 28)
-       })
-       b.Run("P256", func(b *testing.B) {
-               benchmarkScalarBaseMult(b, nistec.NewP256Point().SetGenerator(), 32)
-       })
-       b.Run("P384", func(b *testing.B) {
-               benchmarkScalarBaseMult(b, nistec.NewP384Point().SetGenerator(), 48)
-       })
-       b.Run("P521", func(b *testing.B) {
-               benchmarkScalarBaseMult(b, nistec.NewP521Point().SetGenerator(), 66)
-       })
-}
-
-func benchmarkScalarBaseMult[P nistPoint[P]](b *testing.B, p P, scalarSize int) {
-       scalar := make([]byte, scalarSize)
-       rand.Read(scalar)
-       b.ReportAllocs()
-       b.ResetTimer()
-       for i := 0; i < b.N; i++ {
-               p.ScalarBaseMult(scalar)
-       }
-}
index 8649f247a2e28d2ae6db3055432a443bc177908f..5aac83f95bb7b2116a8b943f57163e019c5238a1 100644 (file)
@@ -471,6 +471,8 @@ var depsRules = `
        < crypto/internal/fips/ssh
        < crypto/internal/fips/tls12
        < crypto/internal/fips/tls13
+       < crypto/internal/fips/nistec/fiat
+       < crypto/internal/fips/nistec
        < FIPS;
 
        FIPS < crypto/internal/fips/check/checktest;
@@ -497,8 +499,6 @@ var depsRules = `
        crypto/internal/fips/alias, math/rand/v2,
        crypto/subtle, embed
        < crypto/internal/randutil
-       < crypto/internal/nistec/fiat
-       < crypto/internal/nistec
        < crypto/internal/edwards25519/field
        < crypto/internal/edwards25519;