From ce7b749fd54be871ce62934fca7978b165809e87 Mon Sep 17 00:00:00 2001 From: Wim Date: Thu, 13 Jun 2019 22:37:31 +0200 Subject: Update github.com/Rhymen/go-whatsapp vendor. Fixes #843 --- .../Rhymen/go-whatsapp/crypto/hkdf/hkdf.go | 49 ++++++++++------------ 1 file changed, 22 insertions(+), 27 deletions(-) (limited to 'vendor/github.com/Rhymen/go-whatsapp/crypto/hkdf') diff --git a/vendor/github.com/Rhymen/go-whatsapp/crypto/hkdf/hkdf.go b/vendor/github.com/Rhymen/go-whatsapp/crypto/hkdf/hkdf.go index e0be0587..3d7361f0 100644 --- a/vendor/github.com/Rhymen/go-whatsapp/crypto/hkdf/hkdf.go +++ b/vendor/github.com/Rhymen/go-whatsapp/crypto/hkdf/hkdf.go @@ -9,7 +9,6 @@ second stage "expands" this key into several additional pseudorandom keys (the o package hkdf import ( - "crypto/hmac" "crypto/sha256" "fmt" "golang.org/x/crypto/hkdf" @@ -20,33 +19,29 @@ import ( Expand expands a given key with the HKDF algorithm. */ func Expand(key []byte, length int, info string) ([]byte, error) { + var h io.Reader if info == "" { - keyBlock := hmac.New(sha256.New, key) - var out, last []byte - - var blockIndex byte = 1 - for i := 0; len(out) < length; i++ { - keyBlock.Reset() - //keyBlock.Write(append(append(last, []byte(info)...), blockIndex)) - keyBlock.Write(last) - keyBlock.Write([]byte(info)) - keyBlock.Write([]byte{blockIndex}) - last = keyBlock.Sum(nil) - blockIndex += 1 - out = append(out, last...) - } - return out[:length], nil + /* + Only used during initial login + Pseudorandom Key is provided by server and has not to be created + */ + h = hkdf.Expand(sha256.New, key, []byte(info)) } else { - h := hkdf.New(sha256.New, key, nil, []byte(info)) - out := make([]byte, length) - n, err := io.ReadAtLeast(h, out, length) - if err != nil { - return nil, err - } - if n != length { - return nil, fmt.Errorf("new key to short") - } - - return out[:length], nil + /* + Used every other time + Pseudorandom Key is created during kdf.New + This is the normal that crypto/hkdf is used + */ + h = hkdf.New(sha256.New, key, nil, []byte(info)) + } + out := make([]byte, length) + n, err := io.ReadAtLeast(h, out, length) + if err != nil { + return nil, err } + if n != length { + return nil, fmt.Errorf("new key to short") + } + + return out, nil } -- cgit v1.2.3