package hashrng

import (
	"bytes"
	"encoding/hex"

	"xdx.jelly/xgcl/grand/drng/internal"
	"xdx.jelly/xgcl/sm"
)

// 随机数发生器的已知答案检测
func KAT() bool {
	raw, _ := NewHashDrng(sm.SM3, Config(internal.SecureLevel2))
	nonce, _ := hex.DecodeString("0001020304050607")
	entropy, _ := hex.DecodeString("C4F7D581BEFEF25C8BBB6DAD52A6AB8234FA7DB7A988592BC592DAF2BE630647")
	rng, _ := raw.Instantiate(nil, nonce, bytes.NewReader(entropy))
	additionalInput, _ := hex.DecodeString("00010203040506")

	rand := make([]byte, 32)
	rng.Generate(rand, additionalInput)

	wanted, _ := hex.DecodeString("a6e3c0ad539fa0c211b23e3aa7c3b92482bfc77fcb9864690e832bcda4357046")
	return bytes.Compare(rand, wanted) == 0
}
