4
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2025-06-27 21:39:22 +00:00

Update github.com/Rhymen/go-whatsapp vendor. Fixes #843

This commit is contained in:
Wim
2019-06-13 22:37:31 +02:00
parent 6617bd6609
commit ce7b749fd5
12 changed files with 213 additions and 58 deletions

View File

@ -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
}