mirror of
https://github.com/sonr-io/crypto.git
synced 2026-01-12 04:09:13 +00:00
refactor(crypto): simplify elliptic curve implementation
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
||||
"github.com/sonr-io/sonr/crypto/internal"
|
||||
"github.com/sonr-io/crypto/internal"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/sonr-io/sonr/crypto/internal"
|
||||
"github.com/sonr-io/crypto/internal"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
Reference in New Issue
Block a user