2024-02-13 07:04:56 +00:00
|
|
|
package channel_test
|
2023-08-21 03:50:38 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/rand"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"source.quilibrium.com/quilibrium/monorepo/nekryptology/pkg/core/curves"
|
2024-02-13 07:04:56 +00:00
|
|
|
"source.quilibrium.com/quilibrium/monorepo/node/crypto/channel"
|
2023-08-21 03:50:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestX3DHMatches(t *testing.T) {
|
|
|
|
x448SendingIdentityPrivateKey := curves.ED448().Scalar.Random(rand.Reader)
|
|
|
|
x448SendingEphemeralPrivateKey := curves.ED448().Scalar.Random(rand.Reader)
|
|
|
|
x448ReceivingIdentityPrivateKey := curves.ED448().Scalar.Random(rand.Reader)
|
|
|
|
x448ReceivingSignedPrePrivateKey := curves.ED448().Scalar.Random(rand.Reader)
|
|
|
|
x448SendingIdentityKey := curves.ED448().NewGeneratorPoint().Mul(x448SendingIdentityPrivateKey)
|
|
|
|
x448SendingEphemeralKey := curves.ED448().NewGeneratorPoint().Mul(x448SendingEphemeralPrivateKey)
|
|
|
|
x448ReceivingIdentityKey := curves.ED448().NewGeneratorPoint().Mul(x448ReceivingIdentityPrivateKey)
|
|
|
|
x448ReceivingSignedPreKey := curves.ED448().NewGeneratorPoint().Mul(x448ReceivingSignedPrePrivateKey)
|
|
|
|
|
2024-02-13 07:04:56 +00:00
|
|
|
result := channel.SenderX3DH(
|
2023-08-21 03:50:38 +00:00
|
|
|
x448SendingIdentityPrivateKey,
|
|
|
|
x448SendingEphemeralPrivateKey,
|
|
|
|
x448ReceivingIdentityKey,
|
|
|
|
x448ReceivingSignedPreKey,
|
|
|
|
32,
|
|
|
|
)
|
|
|
|
|
2024-02-13 07:04:56 +00:00
|
|
|
compare := channel.ReceiverX3DH(
|
2023-08-21 03:50:38 +00:00
|
|
|
x448ReceivingIdentityPrivateKey,
|
|
|
|
x448ReceivingSignedPrePrivateKey,
|
|
|
|
x448SendingIdentityKey,
|
|
|
|
x448SendingEphemeralKey,
|
|
|
|
32,
|
|
|
|
)
|
|
|
|
|
|
|
|
require.Equal(t, result, compare)
|
|
|
|
}
|