gpt4 book ai didi

go - 如何检查随机性?

转载 作者:IT王子 更新时间:2023-10-29 01:53:52 24 4
gpt4 key购买 nike

<分区>

我正在使用 BIP39 规范生成 12 个单词的助记符,稍后将用于生成主公钥/私钥及其 2^32-1 子 key 。然后,这些子 key 将用于非对称加密。

 import (
"github.com/tyler-smith/go-bip39"
"github.com/tyler-smith/go-bip32"
b64 "encoding/base64"
)
type BipKeys struct {
Entropy []byte
Mnemonic string
Passphrase []byte
Seed []byte
MnemonicShares []string
RootPublicExtendedKey *bip32.Key
RootPrivateExtendedKey *bip32.Key
RootPrivateHexKey string
}

func(instance *BipKeys) GenerateEntropy(numberOfBytes int)([]byte, error){
entropy, err := bip39.NewEntropy(numberOfBytes)
if err != nil {
log.Printf("There is some error generating entropy %s", err)
}
return entropy, err
}

func (instance *BipKeys) GenerateMnemonic(entropy []byte) (string, error){
mnemonic, err := bip39.NewMnemonic(entropy)
if err != nil {
log.Printf("Some error in generating Mnemonic %s", err)

}
return mnemonic, err
}

func (instance *BipKeys) GeneratePassphrase(saltBytes int, passphraseBytes int) ([]byte, error){
salt := GenerateRandomSalt(8)
passphrase := GenerateRandomString(8)
password, err := GenerateScryptKey(salt, []byte(passphrase))
return password, err
}

GenerateRandomString 和 GenerateRandomSalt 只是根据 crypto/rand 包生成随机字符串和字节。

我的问题是,当人们说没有从随机函数正确生成的 key 容易被破解时,他们到底是什么意思?我如何检查 bip39.NewEntropy(numberOfBytes) 是否实际生成了助记符所需的完美熵?有什么方法可以检查仅通过公开前 5 个单词是否可以生成 12 个单词的助记符(这意味着熵函数实现不正确并且容易受到攻击)?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com