func CreateACContextWithInputEntropy(channel []byte, inputEntropy []byte) (context *ickp.SecretKey, err error) { context = new(ickp.SecretKey) context.SetNonce(0) //context.nonce = 0 context.SetBob(channel) //context.bob = channel context.Overhead = secretbox.Overhead shaEntropy, err := icutl.HashSHA3Data(inputEntropy) if err != nil { //return nil, acprotoError(-1, "CreateACContextWithInputEntropy().HashSHA3Data(): ", err) return nil, &icutl.AcError{Value: -1, Msg: "CreateACContextWithInputEntropy().HashSHA3Data(): ", Err: err} } context.SetKey(shaEntropy) //copy(context.key[:], shaEntropy) return context, nil }
func (skgen *KeyGenerator) Init(input []byte, channel []byte, nick []byte, serv []byte) (err error) { //skgen.hash = sha3.NewKeccak256 // go.crypto changed it... mlgrmlbmlbm skgen.hash = sha3.New256 if input != nil { skgen.input = make([]byte, len(input)) copy(skgen.input, input) } else { // handle empty input with crypto/rand input skgen.input = make([]byte, 8192) _, err = io.ReadFull(rand.Reader, skgen.input) if err != nil { return err } } if channel != nil { skgen.channel = make([]byte, len(channel)) copy(skgen.channel, channel) } if nick != nil { skgen.nick = make([]byte, len(nick)) copy(skgen.nick, nick) } if serv != nil { skgen.server = make([]byte, len(serv)) copy(skgen.server, serv) } prng := make([]byte, 16384) _, err = io.ReadFull(rand.Reader, prng) if err != nil { return err // fmt.Fprintf(os.Stderr, "POUET POUET Error") // fmt.Println(err) } // fmt.Fprintf(os.Stderr, "read %d random bytes\n", n) //dk := pbkdf2.Key([]byte("some password"), salt, 4096, 32, sha1.New) //func Key(password, salt []byte, iter, keyLen int, h func() hash.Hash) []byte // XXX TODO be sure of the PBKDF2 FUNCTION CALL ARGUMENTS... skgen.input_pbkdf = pbkdf2.Key(skgen.input, prng, 32768, 32, skgen.hash) // fmt.Fprintf(os.Stderr, "PBKDF LEN: %d\n", len(skgen.input_pbkdf)) // in Read() we will apply the HKDF function.. onto the PBKDF2 derived key. // XXX TODO: just to be sure implement HASH of each value instead of values // only. str_build := new(bytes.Buffer) str_build.Write(serv) str_build.WriteByte(byte(':')) str_build.Write(nick) str_build.WriteByte(byte(':')) str_build.Write(channel) skgen.info_hkdf, err = icutl.HashSHA3Data(str_build.Bytes()) if err != nil { return err } return nil }