mirror of
https://github.com/emmansun/gmsm.git
synced 2025-04-26 12:16:20 +08:00
supplement tesst cases
This commit is contained in:
parent
0342ada322
commit
ecdf5fca82
@ -69,3 +69,14 @@ func TestNistHashDrbgPrng(t *testing.T) {
|
||||
t.Errorf("not got enough random bytes")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGMSecurityStrengthValidation(t *testing.T) {
|
||||
_, err := NewGmHashDrbgPrng(nil, 24, SECURITY_LEVEL_TEST, nil)
|
||||
if err == nil {
|
||||
t.Fatalf("expected error here")
|
||||
}
|
||||
_, err = NewGmCtrDrbgPrng(nil, 24, SECURITY_LEVEL_TEST, nil)
|
||||
if err == nil {
|
||||
t.Fatalf("expected error here")
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ func NewCtrDrbg(cipherProvider func(key []byte) (cipher.Block, error), keyLen in
|
||||
}
|
||||
|
||||
// here for the min length, we just check <=0 now
|
||||
if len(nonce) == 0 || (hd.gm && len(entropy) < 16) || len(nonce) >= MAX_BYTES>>1 {
|
||||
if len(nonce) == 0 || (hd.gm && len(nonce) < 16) || len(nonce) >= MAX_BYTES>>1 {
|
||||
return nil, errors.New("invalid nonce length")
|
||||
}
|
||||
|
||||
|
@ -283,3 +283,23 @@ func TestCtrDRBG(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGmCtrDRBG_Validation(t *testing.T) {
|
||||
entropyInput := make([]byte, 64)
|
||||
_, err := NewCtrDrbg(sm4.NewCipher, 16, SECURITY_LEVEL_ONE, true, entropyInput[:16], entropyInput[16:24], nil)
|
||||
if err == nil {
|
||||
t.Fatalf("expected error here")
|
||||
}
|
||||
_, err = NewCtrDrbg(sm4.NewCipher, 16, SECURITY_LEVEL_ONE, true, entropyInput[:32], entropyInput[32:40], nil)
|
||||
if err == nil {
|
||||
t.Fatalf("expected error here")
|
||||
}
|
||||
hd, err := NewCtrDrbg(sm4.NewCipher, 16, SECURITY_LEVEL_ONE, true, entropyInput[:32], entropyInput[32:48], nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = hd.Reseed(entropyInput[:16], nil)
|
||||
if err == nil {
|
||||
t.Fatalf("expected error here")
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ func NewHashDrbg(md hash.Hash, securityLevel SecurityLevel, gm bool, entropy, no
|
||||
}
|
||||
|
||||
// here for the min length, we just check <=0 now
|
||||
if len(nonce) == 0 || (hd.gm && len(entropy) < hd.md.Size()/2) || len(nonce) >= MAX_BYTES>>1 {
|
||||
if len(nonce) == 0 || (hd.gm && len(nonce) < hd.md.Size()/2) || len(nonce) >= MAX_BYTES>>1 {
|
||||
return nil, errors.New("invalid nonce length")
|
||||
}
|
||||
|
||||
|
@ -229,3 +229,23 @@ func TestHashDRBG(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGmHashDRBG_Validation(t *testing.T) {
|
||||
entropyInput := make([]byte, 64)
|
||||
_, err := NewHashDrbg(sm3.New(), SECURITY_LEVEL_ONE, true, entropyInput[:16], entropyInput[16:24], nil)
|
||||
if err == nil {
|
||||
t.Fatalf("expected error here")
|
||||
}
|
||||
_, err = NewHashDrbg(sm3.New(), SECURITY_LEVEL_ONE, true, entropyInput[:32], entropyInput[32:40], nil)
|
||||
if err == nil {
|
||||
t.Fatalf("expected error here")
|
||||
}
|
||||
hd, err := NewHashDrbg(sm3.New(), SECURITY_LEVEL_ONE, true, entropyInput[:32], entropyInput[32:48], nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = hd.Reseed(entropyInput[:16], nil)
|
||||
if err == nil {
|
||||
t.Fatalf("expected error here")
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user