goolm/crypto: add test to ensure shared secrets can't be zero
Some checks are pending
Go / Lint (latest) (push) Waiting to run
Go / Build (old, libolm) (push) Waiting to run
Go / Build (latest, libolm) (push) Waiting to run
Go / Build (old, goolm) (push) Waiting to run
Go / Build (latest, goolm) (push) Waiting to run

This commit is contained in:
Tulir Asokan 2026-02-18 12:41:16 +02:00
commit de0d12e26a
2 changed files with 3 additions and 0 deletions

View file

@ -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)
}

View file

@ -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) {