diff options
| author | Mistivia <i@mistivia.com> | 2025-11-02 15:27:18 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2025-11-02 15:27:18 +0800 |
| commit | e9c24f4af7ed56760f6db7941827d09f6db9020b (patch) | |
| tree | 62128c43b883ce5e3148113350978755779bb5de /teleirc/matterbridge/vendor/github.com/Rhymen/go-whatsapp/crypto/hkdf | |
| parent | 58d5e7cfda4781d8a57ec52aefd02983835c301a (diff) | |
add matterbridge
Diffstat (limited to 'teleirc/matterbridge/vendor/github.com/Rhymen/go-whatsapp/crypto/hkdf')
| -rw-r--r-- | teleirc/matterbridge/vendor/github.com/Rhymen/go-whatsapp/crypto/hkdf/hkdf.go | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/teleirc/matterbridge/vendor/github.com/Rhymen/go-whatsapp/crypto/hkdf/hkdf.go b/teleirc/matterbridge/vendor/github.com/Rhymen/go-whatsapp/crypto/hkdf/hkdf.go new file mode 100644 index 0000000..3d7361f --- /dev/null +++ b/teleirc/matterbridge/vendor/github.com/Rhymen/go-whatsapp/crypto/hkdf/hkdf.go @@ -0,0 +1,47 @@ +/* +HKDF is a simple key derivation function (KDF) based on +a hash-based message authentication code (HMAC). It was initially proposed by its authors as a building block in +various protocols and applications, as well as to discourage the proliferation of multiple KDF mechanisms. +The main approach HKDF follows is the "extract-then-expand" paradigm, where the KDF logically consists of two modules: +the first stage takes the input keying material and "extracts" from it a fixed-length pseudorandom key, and then the +second stage "expands" this key into several additional pseudorandom keys (the output of the KDF). +*/ +package hkdf + +import ( + "crypto/sha256" + "fmt" + "golang.org/x/crypto/hkdf" + "io" +) + +/* +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 == "" { + /* + 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 { + /* + 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 +} |
