diff options
author | Wim <wim@42.be> | 2019-06-13 22:37:31 +0200 |
---|---|---|
committer | Wim <wim@42.be> | 2019-06-14 00:02:32 +0200 |
commit | ce7b749fd54be871ce62934fca7978b165809e87 (patch) | |
tree | a586345061cd3c48dd97dd81ac12141f716a212e /vendor/github.com/Rhymen/go-whatsapp/crypto | |
parent | 6617bd6609993ab70798647620dfbbcff523347e (diff) | |
download | matterbridge-msglm-ce7b749fd54be871ce62934fca7978b165809e87.tar.gz matterbridge-msglm-ce7b749fd54be871ce62934fca7978b165809e87.tar.bz2 matterbridge-msglm-ce7b749fd54be871ce62934fca7978b165809e87.zip |
Update github.com/Rhymen/go-whatsapp vendor. Fixes #843
Diffstat (limited to 'vendor/github.com/Rhymen/go-whatsapp/crypto')
-rw-r--r-- | vendor/github.com/Rhymen/go-whatsapp/crypto/hkdf/hkdf.go | 49 |
1 files changed, 22 insertions, 27 deletions
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 } |