mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-10 08:29:58 +08:00
fix: critical security fixes in core/codec (S0) (#5479)
This commit is contained in:
@@ -94,3 +94,32 @@ func TestDHOnErrors(t *testing.T) {
|
||||
|
||||
assert.NotNil(t, NewPublicKey([]byte("")))
|
||||
}
|
||||
|
||||
func TestDHPubKeyBoundary(t *testing.T) {
|
||||
key, err := GenerateKey()
|
||||
assert.Nil(t, err)
|
||||
|
||||
// pubKey = 0 should be rejected
|
||||
_, err = ComputeKey(big.NewInt(0), key.PriKey)
|
||||
assert.ErrorIs(t, err, ErrPubKeyOutOfBound)
|
||||
|
||||
// pubKey = -1 should be rejected
|
||||
_, err = ComputeKey(big.NewInt(-1), key.PriKey)
|
||||
assert.ErrorIs(t, err, ErrPubKeyOutOfBound)
|
||||
|
||||
// pubKey = p should be rejected
|
||||
_, err = ComputeKey(new(big.Int).Set(p), key.PriKey)
|
||||
assert.ErrorIs(t, err, ErrPubKeyOutOfBound)
|
||||
|
||||
// pubKey = p+1 should be rejected
|
||||
_, err = ComputeKey(new(big.Int).Add(p, big.NewInt(1)), key.PriKey)
|
||||
assert.ErrorIs(t, err, ErrPubKeyOutOfBound)
|
||||
|
||||
// pubKey = 1 should be accepted
|
||||
_, err = ComputeKey(big.NewInt(1), key.PriKey)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// pubKey = p-1 should be accepted
|
||||
_, err = ComputeKey(new(big.Int).Sub(p, big.NewInt(1)), key.PriKey)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user