mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
goolm/crypto: add test to ensure shared secrets can't be zero
This commit is contained in:
parent
9cd7258764
commit
de0d12e26a
2 changed files with 3 additions and 0 deletions
|
|
@ -53,6 +53,7 @@ func (c Curve25519KeyPair) B64Encoded() id.Curve25519 {
|
|||
|
||||
// SharedSecret returns the shared secret between the key pair and the given public key.
|
||||
func (c Curve25519KeyPair) SharedSecret(pubKey Curve25519PublicKey) ([]byte, error) {
|
||||
// Note: the standard library checks that the output is non-zero
|
||||
return c.PrivateKey.SharedSecret(pubKey)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ func TestCurve25519(t *testing.T) {
|
|||
fromPrivate, err := crypto.Curve25519GenerateFromPrivate(firstKeypair.PrivateKey)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, fromPrivate, firstKeypair)
|
||||
_, err = secondKeypair.SharedSecret(make([]byte, crypto.Curve25519PublicKeyLength))
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestCurve25519Case1(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue