diff options
author | Wim <wim@42.be> | 2017-06-22 01:00:27 +0200 |
---|---|---|
committer | Wim <wim@42.be> | 2017-06-22 01:00:27 +0200 |
commit | 1f914618538920db4bfec7b106ee97038b157c9b (patch) | |
tree | 6bd0ab107fe1673dbacdf9dfd10004289cd7bfab /vendor/github.com/Philipp15b/go-steam/cryptoutil/cryptoutil.go | |
parent | 1f9874102aaca09ce5e0289beff376c307b8c57b (diff) | |
download | matterbridge-msglm-1f914618538920db4bfec7b106ee97038b157c9b.tar.gz matterbridge-msglm-1f914618538920db4bfec7b106ee97038b157c9b.tar.bz2 matterbridge-msglm-1f914618538920db4bfec7b106ee97038b157c9b.zip |
Add vendor (steam)
Diffstat (limited to 'vendor/github.com/Philipp15b/go-steam/cryptoutil/cryptoutil.go')
-rw-r--r-- | vendor/github.com/Philipp15b/go-steam/cryptoutil/cryptoutil.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/vendor/github.com/Philipp15b/go-steam/cryptoutil/cryptoutil.go b/vendor/github.com/Philipp15b/go-steam/cryptoutil/cryptoutil.go new file mode 100644 index 00000000..b44f8d26 --- /dev/null +++ b/vendor/github.com/Philipp15b/go-steam/cryptoutil/cryptoutil.go @@ -0,0 +1,38 @@ +package cryptoutil
+
+import (
+ "crypto/aes"
+ "crypto/cipher"
+ "crypto/rand"
+)
+
+// Performs an encryption using AES/CBC/PKCS7
+// with a random IV prepended using AES/ECB/None.
+func SymmetricEncrypt(ciph cipher.Block, src []byte) []byte {
+ // get a random IV and ECB encrypt it
+ iv := make([]byte, aes.BlockSize, aes.BlockSize)
+ _, err := rand.Read(iv)
+ if err != nil {
+ panic(err)
+ }
+ encryptedIv := make([]byte, aes.BlockSize, aes.BlockSize)
+ newECBEncrypter(ciph).CryptBlocks(encryptedIv, iv)
+
+ // pad it, copy the IV to the first 16 bytes and encrypt the rest with CBC
+ encrypted := padPKCS7WithIV(src)
+ copy(encrypted, encryptedIv)
+ cipher.NewCBCEncrypter(ciph, iv).CryptBlocks(encrypted[aes.BlockSize:], encrypted[aes.BlockSize:])
+ return encrypted
+}
+
+// Decrypts data from the reader using AES/CBC/PKCS7 with an IV
+// prepended using AES/ECB/None. The src slice may not be used anymore.
+func SymmetricDecrypt(ciph cipher.Block, src []byte) []byte {
+ iv := src[:aes.BlockSize]
+ newECBDecrypter(ciph).CryptBlocks(iv, iv)
+
+ data := src[aes.BlockSize:]
+ cipher.NewCBCDecrypter(ciph, iv).CryptBlocks(data, data)
+
+ return unpadPKCS7(data)
+}
|