diff options
author | Krzysiek Madejski <krzysztof.madejski@epf.org.pl> | 2019-02-21 20:28:13 +0100 |
---|---|---|
committer | Wim <wim@42.be> | 2019-02-21 20:28:13 +0100 |
commit | 55e79063d6edbbf4560fd14edc45ce9558afaf7a (patch) | |
tree | 9ee9470119066556210a9226ae05b2c73ebda5e6 /vendor/github.com/Rhymen/go-whatsapp/crypto/curve25519/curve.go | |
parent | 46f4bbb3b5e93ff489c0125c66b1c29fcb001e22 (diff) | |
download | matterbridge-msglm-55e79063d6edbbf4560fd14edc45ce9558afaf7a.tar.gz matterbridge-msglm-55e79063d6edbbf4560fd14edc45ce9558afaf7a.tar.bz2 matterbridge-msglm-55e79063d6edbbf4560fd14edc45ce9558afaf7a.zip |
Add initial WhatsApp support (#711)
Diffstat (limited to 'vendor/github.com/Rhymen/go-whatsapp/crypto/curve25519/curve.go')
-rw-r--r-- | vendor/github.com/Rhymen/go-whatsapp/crypto/curve25519/curve.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/vendor/github.com/Rhymen/go-whatsapp/crypto/curve25519/curve.go b/vendor/github.com/Rhymen/go-whatsapp/crypto/curve25519/curve.go new file mode 100644 index 00000000..5ddf9c9a --- /dev/null +++ b/vendor/github.com/Rhymen/go-whatsapp/crypto/curve25519/curve.go @@ -0,0 +1,44 @@ +/* +In cryptography, Curve25519 is an elliptic curve offering 128 bits of security and designed for use with the elliptic +curve Diffie–Hellman (ECDH) key agreement scheme. It is one of the fastest ECC curves and is not covered by any known +patents. The reference implementation is public domain software. The original Curve25519 paper defined it +as a Diffie–Hellman (DH) function. +*/ +package curve25519 + +import ( + "crypto/rand" + "golang.org/x/crypto/curve25519" + "io" +) + +/* +GenerateKey generates a public private key pair using Curve25519. +*/ +func GenerateKey() (privateKey *[32]byte, publicKey *[32]byte, err error) { + var pub, priv [32]byte + + _, err = io.ReadFull(rand.Reader, priv[:]) + if err != nil { + return nil, nil, err + } + + priv[0] &= 248 + priv[31] &= 127 + priv[31] |= 64 + + curve25519.ScalarBaseMult(&pub, &priv) + + return &priv, &pub, nil +} + +/* +GenerateSharedSecret generates the shared secret with a given public private key pair. +*/ +func GenerateSharedSecret(priv, pub [32]byte) []byte { + var secret [32]byte + + curve25519.ScalarMult(&secret, &priv, &pub) + + return secret[:] +} |