我正在使用BIP39规范来生成12个单词的助记符,这以后将用于生成主公钥/私钥及其2^32-1子密钥。然后,这些子密钥将用于非对称加密。
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只是基于密码/rand包生成随机字符串和字节。
我的问题是,当人们说随机函数不能正确生成密钥时,它们实际上是什么意思?如何检查bip39-新熵(NumberOfBytes)实际上是否产生了Mnemonic所需的完美熵?我是否可以通过公开前5个单词来检查是否可以生成12个单词(这意味着熵函数的实现是不正确的,很容易受到攻击)?
发布于 2018-09-08 20:06:42
我的问题是,当人们说随机函数不能正确生成密钥时,它们实际上是什么意思?
在密码学中,坏的随机性受到两种方式的攻击:
你关于测量熵的问题是错误的。测量熵就像它是一个统计随机数发生器,而不是一个密码随机数发生器。你说:
GenerateRandomString和GenerateRandomSalt只是基于密码/rand包生成随机字符串和字节。
这就是你所需要知道的--你不需要担心任何其他的事情。如前所述,任何测量熵的量都不会告诉你你的钥匙是安全的。相反,您需要成为密码专家来分析这些算法。对于随机性的使用者来说,您所能做的(除了使用/dev/urandom这样的另一个源之外)就是相信它已经设计得很好,并由密码专家进行了分析。
https://stackoverflow.com/questions/52238575
复制相似问题