mirror of
https://github.com/sonr-io/crypto.git
synced 2026-08-02 15:31:38 +00:00
No commit suggestions generated
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package dealer_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"golang.org/x/crypto/sha3"
|
||||
|
||||
"github.com/sonr-io/sonr/crypto/core/curves"
|
||||
"github.com/sonr-io/sonr/crypto/tecdsa/dklsv1/dealer"
|
||||
"github.com/sonr-io/sonr/crypto/tecdsa/dklsv1/sign"
|
||||
)
|
||||
|
||||
func Test_DealerCanGenerateKeysThatSign(t *testing.T) {
|
||||
curveInstances := []*curves.Curve{
|
||||
curves.K256(),
|
||||
curves.P256(),
|
||||
}
|
||||
for _, curve := range curveInstances {
|
||||
aliceOutput, bobOutput, err := dealer.GenerateAndDeal(curve)
|
||||
require.NoError(t, err)
|
||||
|
||||
alice := sign.NewAlice(curve, sha3.New256(), aliceOutput)
|
||||
bob := sign.NewBob(curve, sha3.New256(), bobOutput)
|
||||
|
||||
message := []byte("A message.")
|
||||
seed, err := alice.Round1GenerateRandomSeed()
|
||||
require.NoError(t, err)
|
||||
round3Output, err := bob.Round2Initialize(seed)
|
||||
require.NoError(t, err)
|
||||
round4Output, err := alice.Round3Sign(message, round3Output)
|
||||
require.NoError(t, err)
|
||||
err = bob.Round4Final(message, round4Output)
|
||||
require.NoError(t, err, "curve: %s", curve.Name)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_DealerGeneratesDifferentResultsEachTime(t *testing.T) {
|
||||
curve := curves.K256()
|
||||
aliceOutput1, bobOutput1, err := dealer.GenerateAndDeal(curve)
|
||||
require.NoError(t, err)
|
||||
aliceOutput2, bobOutput2, err := dealer.GenerateAndDeal(curve)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NotEqual(t, aliceOutput1.SecretKeyShare, aliceOutput2.SecretKeyShare)
|
||||
require.NotEqual(t, bobOutput1.SecretKeyShare, bobOutput2.SecretKeyShare)
|
||||
require.NotEqualValues(
|
||||
t,
|
||||
aliceOutput1.SeedOtResult.RandomChoiceBits,
|
||||
aliceOutput2.SeedOtResult.RandomChoiceBits,
|
||||
)
|
||||
require.NotEqualValues(
|
||||
t,
|
||||
bobOutput1.SeedOtResult.OneTimePadEncryptionKeys,
|
||||
bobOutput2.SeedOtResult.OneTimePadEncryptionKeys,
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user