refactor(crypto): simplify elliptic curve implementation

This commit is contained in:
2025-10-09 15:11:59 -04:00
parent a934caa7d3
commit 7d339ae522
205 changed files with 380 additions and 380 deletions

View File

@@ -19,7 +19,7 @@ import (
bls12377 "github.com/consensys/gnark-crypto/ecc/bls12-377"
"golang.org/x/crypto/sha3"
"github.com/sonr-io/sonr/crypto/core"
"github.com/sonr-io/crypto/core"
)
// See 'r' = https://eprint.iacr.org/2018/962.pdf Figure 16

View File

@@ -13,9 +13,9 @@ import (
"golang.org/x/crypto/sha3"
"github.com/sonr-io/sonr/crypto/core/curves/native"
"github.com/sonr-io/sonr/crypto/core/curves/native/bls12381"
"github.com/sonr-io/sonr/crypto/internal"
"github.com/sonr-io/crypto/core/curves/native"
"github.com/sonr-io/crypto/core/curves/native/bls12381"
"github.com/sonr-io/crypto/internal"
)
var bls12381modulus = bhex(

View File

@@ -16,7 +16,7 @@ import (
"math/big"
"sync"
"github.com/sonr-io/sonr/crypto/core/curves/native/bls12381"
"github.com/sonr-io/crypto/core/curves/native/bls12381"
)
var (

View File

@@ -7,7 +7,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/sonr-io/sonr/crypto/core"
"github.com/sonr-io/crypto/core"
)
// TestAdditionalCurveSupport tests the new curve support in hash.go

View File

@@ -12,10 +12,10 @@ import (
"fmt"
"math/big"
"github.com/sonr-io/sonr/crypto/core"
"github.com/sonr-io/crypto/core"
"github.com/dustinxie/ecc"
"github.com/sonr-io/sonr/crypto/internal"
"github.com/sonr-io/crypto/internal"
)
var curveNameToID = map[string]byte{

View File

@@ -15,8 +15,8 @@ import (
"github.com/btcsuite/btcd/btcec/v2"
"github.com/stretchr/testify/require"
"github.com/sonr-io/sonr/crypto/core"
tt "github.com/sonr-io/sonr/crypto/internal"
"github.com/sonr-io/crypto/core"
tt "github.com/sonr-io/crypto/internal"
)
func TestIsIdentity(t *testing.T) {

View File

@@ -18,9 +18,9 @@ import (
"github.com/btcsuite/btcd/btcec/v2"
"github.com/bwesterb/go-ristretto"
"github.com/sonr-io/sonr/crypto/core"
"github.com/sonr-io/sonr/crypto/core/curves/native/bls12381"
"github.com/sonr-io/sonr/crypto/internal"
"github.com/sonr-io/crypto/core"
"github.com/sonr-io/crypto/core/curves/native/bls12381"
"github.com/sonr-io/crypto/internal"
)
type EcScalar interface {

View File

@@ -19,7 +19,7 @@ import (
"github.com/bwesterb/go-ristretto"
ed "github.com/bwesterb/go-ristretto/edwards25519"
"github.com/sonr-io/sonr/crypto/internal"
"github.com/sonr-io/crypto/internal"
)
type ScalarEd25519 struct {

View File

@@ -15,7 +15,7 @@ import (
ed "filippo.io/edwards25519"
"github.com/stretchr/testify/require"
"github.com/sonr-io/sonr/crypto/internal"
"github.com/sonr-io/crypto/internal"
)
func TestScalarEd25519Random(t *testing.T) {

View File

@@ -9,8 +9,8 @@ import (
"github.com/btcsuite/btcd/btcec/v2"
mod "github.com/sonr-io/sonr/crypto/core"
"github.com/sonr-io/sonr/crypto/internal"
mod "github.com/sonr-io/crypto/core"
"github.com/sonr-io/crypto/internal"
)
func BenchmarkK256(b *testing.B) {

View File

@@ -15,11 +15,11 @@ import (
"github.com/btcsuite/btcd/btcec/v2"
"github.com/sonr-io/sonr/crypto/core/curves/native"
secp256k1 "github.com/sonr-io/sonr/crypto/core/curves/native/k256"
"github.com/sonr-io/sonr/crypto/core/curves/native/k256/fp"
"github.com/sonr-io/sonr/crypto/core/curves/native/k256/fq"
"github.com/sonr-io/sonr/crypto/internal"
"github.com/sonr-io/crypto/core/curves/native"
secp256k1 "github.com/sonr-io/crypto/core/curves/native/k256"
"github.com/sonr-io/crypto/core/curves/native/k256/fp"
"github.com/sonr-io/crypto/core/curves/native/k256/fq"
"github.com/sonr-io/crypto/internal"
)
var (

View File

@@ -3,7 +3,7 @@ package bls12381
import (
"math/bits"
"github.com/sonr-io/sonr/crypto/core/curves/native"
"github.com/sonr-io/crypto/core/curves/native"
)
var fqModulusBytes = [native.FieldBytes]byte{

View File

@@ -6,8 +6,8 @@ import (
"io"
"math/big"
"github.com/sonr-io/sonr/crypto/core/curves/native"
"github.com/sonr-io/sonr/crypto/internal"
"github.com/sonr-io/crypto/core/curves/native"
"github.com/sonr-io/crypto/internal"
)
// fp field element mod p

View File

@@ -14,7 +14,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/sonr-io/sonr/crypto/internal"
"github.com/sonr-io/crypto/internal"
)
func TestFpSetOne(t *testing.T) {

View File

@@ -5,7 +5,7 @@ import (
"math/big"
"sync"
"github.com/sonr-io/sonr/crypto/core/curves/native"
"github.com/sonr-io/crypto/core/curves/native"
)
type Fq [native.FieldLimbs]uint64

View File

@@ -14,8 +14,8 @@ import (
"github.com/stretchr/testify/require"
"github.com/sonr-io/sonr/crypto/core/curves/native"
"github.com/sonr-io/sonr/crypto/internal"
"github.com/sonr-io/crypto/core/curves/native"
"github.com/sonr-io/crypto/internal"
)
func TestFqSetOne(t *testing.T) {

View File

@@ -7,8 +7,8 @@ import (
"github.com/pkg/errors"
"github.com/sonr-io/sonr/crypto/core/curves/native"
"github.com/sonr-io/sonr/crypto/internal"
"github.com/sonr-io/crypto/core/curves/native"
"github.com/sonr-io/crypto/internal"
)
var (

View File

@@ -7,7 +7,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/sonr-io/sonr/crypto/core/curves/native"
"github.com/sonr-io/crypto/core/curves/native"
)
func TestG1IsOnCurve(t *testing.T) {

View File

@@ -7,8 +7,8 @@ import (
"github.com/pkg/errors"
"github.com/sonr-io/sonr/crypto/core/curves/native"
"github.com/sonr-io/sonr/crypto/internal"
"github.com/sonr-io/crypto/core/curves/native"
"github.com/sonr-io/crypto/internal"
)
var (

View File

@@ -7,7 +7,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/sonr-io/sonr/crypto/core/curves/native"
"github.com/sonr-io/crypto/core/curves/native"
)
func TestG2IsOnCurve(t *testing.T) {

View File

@@ -3,8 +3,8 @@ package bls12381
import (
"io"
"github.com/sonr-io/sonr/crypto/core/curves/native"
"github.com/sonr-io/sonr/crypto/internal"
"github.com/sonr-io/crypto/core/curves/native"
"github.com/sonr-io/crypto/internal"
)
// GtFieldBytes is the number of bytes needed to represent this field

View File

@@ -6,7 +6,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/sonr-io/sonr/crypto/core/curves/native"
"github.com/sonr-io/crypto/core/curves/native"
)
func TestSinglePairing(t *testing.T) {

View File

@@ -5,7 +5,7 @@ import (
"fmt"
"math/big"
"github.com/sonr-io/sonr/crypto/internal"
"github.com/sonr-io/crypto/internal"
)
// FieldLimbs is the number of limbs needed to represent this field

View File

@@ -10,7 +10,7 @@ import (
"math/big"
"sync"
"github.com/sonr-io/sonr/crypto/core/curves/native"
"github.com/sonr-io/crypto/core/curves/native"
)
var (

View File

@@ -14,8 +14,8 @@ import (
"github.com/stretchr/testify/require"
"github.com/sonr-io/sonr/crypto/core/curves/native"
"github.com/sonr-io/sonr/crypto/internal"
"github.com/sonr-io/crypto/core/curves/native"
"github.com/sonr-io/crypto/internal"
)
func TestFpSetOne(t *testing.T) {

View File

@@ -10,7 +10,7 @@ import (
"math/big"
"sync"
"github.com/sonr-io/sonr/crypto/core/curves/native"
"github.com/sonr-io/crypto/core/curves/native"
)
var (

View File

@@ -14,8 +14,8 @@ import (
"github.com/stretchr/testify/require"
"github.com/sonr-io/sonr/crypto/core/curves/native"
"github.com/sonr-io/sonr/crypto/internal"
"github.com/sonr-io/crypto/core/curves/native"
"github.com/sonr-io/crypto/internal"
)
func TestFqSetOne(t *testing.T) {

View File

@@ -3,9 +3,9 @@ package k256
import (
"sync"
"github.com/sonr-io/sonr/crypto/core/curves/native"
"github.com/sonr-io/sonr/crypto/core/curves/native/k256/fp"
"github.com/sonr-io/sonr/crypto/internal"
"github.com/sonr-io/crypto/core/curves/native"
"github.com/sonr-io/crypto/core/curves/native/k256/fp"
"github.com/sonr-io/crypto/internal"
)
var (

View File

@@ -5,8 +5,8 @@ import (
"github.com/stretchr/testify/require"
"github.com/sonr-io/sonr/crypto/core/curves/native"
"github.com/sonr-io/sonr/crypto/core/curves/native/k256"
"github.com/sonr-io/crypto/core/curves/native"
"github.com/sonr-io/crypto/core/curves/native/k256"
)
func TestK256PointArithmetic_Hash(t *testing.T) {

View File

@@ -10,7 +10,7 @@ import (
"math/big"
"sync"
"github.com/sonr-io/sonr/crypto/core/curves/native"
"github.com/sonr-io/crypto/core/curves/native"
)
var (

View File

@@ -14,8 +14,8 @@ import (
"github.com/stretchr/testify/require"
"github.com/sonr-io/sonr/crypto/core/curves/native"
"github.com/sonr-io/sonr/crypto/internal"
"github.com/sonr-io/crypto/core/curves/native"
"github.com/sonr-io/crypto/internal"
)
func TestFpSetOne(t *testing.T) {

View File

@@ -10,7 +10,7 @@ import (
"math/big"
"sync"
"github.com/sonr-io/sonr/crypto/core/curves/native"
"github.com/sonr-io/crypto/core/curves/native"
)
var (

View File

@@ -14,8 +14,8 @@ import (
"github.com/stretchr/testify/require"
"github.com/sonr-io/sonr/crypto/core/curves/native"
"github.com/sonr-io/sonr/crypto/internal"
"github.com/sonr-io/crypto/core/curves/native"
"github.com/sonr-io/crypto/internal"
)
func TestFqSetOne(t *testing.T) {

View File

@@ -3,9 +3,9 @@ package p256
import (
"sync"
"github.com/sonr-io/sonr/crypto/core/curves/native"
"github.com/sonr-io/sonr/crypto/core/curves/native/p256/fp"
"github.com/sonr-io/sonr/crypto/internal"
"github.com/sonr-io/crypto/core/curves/native"
"github.com/sonr-io/crypto/core/curves/native/p256/fp"
"github.com/sonr-io/crypto/internal"
)
var (

View File

@@ -6,10 +6,10 @@ import (
"github.com/stretchr/testify/require"
"github.com/sonr-io/sonr/crypto/core/curves"
"github.com/sonr-io/sonr/crypto/core/curves/native"
"github.com/sonr-io/sonr/crypto/core/curves/native/p256"
"github.com/sonr-io/sonr/crypto/core/curves/native/p256/fp"
"github.com/sonr-io/crypto/core/curves"
"github.com/sonr-io/crypto/core/curves/native"
"github.com/sonr-io/crypto/core/curves/native/p256"
"github.com/sonr-io/crypto/core/curves/native/p256/fp"
)
func TestP256PointArithmetic_Double(t *testing.T) {

View File

@@ -11,7 +11,7 @@ import (
"fmt"
"math/big"
"github.com/sonr-io/sonr/crypto/internal"
"github.com/sonr-io/crypto/internal"
)
type Fp fiat_pasta_fp_montgomery_domain_field_element

View File

@@ -11,7 +11,7 @@ import (
"fmt"
"math/big"
"github.com/sonr-io/sonr/crypto/internal"
"github.com/sonr-io/crypto/internal"
)
type Fq fiat_pasta_fq_montgomery_domain_field_element

View File

@@ -16,7 +16,7 @@ import (
"math/big"
"testing"
"github.com/sonr-io/sonr/crypto/core"
"github.com/sonr-io/crypto/core"
)
func BenchmarkP256(b *testing.B) {

View File

@@ -13,11 +13,11 @@ import (
"math/big"
"sync"
"github.com/sonr-io/sonr/crypto/core/curves/native"
p256n "github.com/sonr-io/sonr/crypto/core/curves/native/p256"
"github.com/sonr-io/sonr/crypto/core/curves/native/p256/fp"
"github.com/sonr-io/sonr/crypto/core/curves/native/p256/fq"
"github.com/sonr-io/sonr/crypto/internal"
"github.com/sonr-io/crypto/core/curves/native"
p256n "github.com/sonr-io/crypto/core/curves/native/p256"
"github.com/sonr-io/crypto/core/curves/native/p256/fp"
"github.com/sonr-io/crypto/core/curves/native/p256/fq"
"github.com/sonr-io/crypto/internal"
)
var (

View File

@@ -18,8 +18,8 @@ import (
"golang.org/x/crypto/blake2b"
"github.com/sonr-io/sonr/crypto/core/curves/native/pasta/fp"
"github.com/sonr-io/sonr/crypto/core/curves/native/pasta/fq"
"github.com/sonr-io/crypto/core/curves/native/pasta/fp"
"github.com/sonr-io/crypto/core/curves/native/pasta/fq"
)
var (

View File

@@ -12,8 +12,8 @@ import (
"github.com/stretchr/testify/require"
"github.com/sonr-io/sonr/crypto/core/curves/native/pasta/fp"
"github.com/sonr-io/sonr/crypto/core/curves/native/pasta/fq"
"github.com/sonr-io/crypto/core/curves/native/pasta/fp"
"github.com/sonr-io/crypto/core/curves/native/pasta/fq"
)
func TestPointPallasAddDoubleMul(t *testing.T) {

View File

@@ -20,7 +20,7 @@ import (
"golang.org/x/crypto/hkdf"
"golang.org/x/crypto/sha3"
"github.com/sonr-io/sonr/crypto/internal"
"github.com/sonr-io/crypto/internal"
)
type HashField struct {

View File

@@ -16,7 +16,7 @@ import (
"fmt"
"math/big"
"github.com/sonr-io/sonr/crypto/internal"
"github.com/sonr-io/crypto/internal"
)
var (

View File

@@ -12,7 +12,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/sonr-io/sonr/crypto/internal"
"github.com/sonr-io/crypto/internal"
)
var (