summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/Philipp15b/go-steam/cryptoutil/ecb.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/Philipp15b/go-steam/cryptoutil/ecb.go')
-rw-r--r--vendor/github.com/Philipp15b/go-steam/cryptoutil/ecb.go68
1 files changed, 68 insertions, 0 deletions
diff --git a/vendor/github.com/Philipp15b/go-steam/cryptoutil/ecb.go b/vendor/github.com/Philipp15b/go-steam/cryptoutil/ecb.go
new file mode 100644
index 00000000..4298686f
--- /dev/null
+++ b/vendor/github.com/Philipp15b/go-steam/cryptoutil/ecb.go
@@ -0,0 +1,68 @@
+package cryptoutil
+
+import (
+ "crypto/cipher"
+)
+
+// From this code review: https://codereview.appspot.com/7860047/
+// by fasmat for the Go crypto/cipher package
+
+type ecb struct {
+ b cipher.Block
+ blockSize int
+}
+
+func newECB(b cipher.Block) *ecb {
+ return &ecb{
+ b: b,
+ blockSize: b.BlockSize(),
+ }
+}
+
+type ecbEncrypter ecb
+
+// NewECBEncrypter returns a BlockMode which encrypts in electronic code book
+// mode, using the given Block.
+func newECBEncrypter(b cipher.Block) cipher.BlockMode {
+ return (*ecbEncrypter)(newECB(b))
+}
+
+func (x *ecbEncrypter) BlockSize() int { return x.blockSize }
+
+func (x *ecbEncrypter) CryptBlocks(dst, src []byte) {
+ if len(src)%x.blockSize != 0 {
+ panic("cryptoutil/ecb: input not full blocks")
+ }
+ if len(dst) < len(src) {
+ panic("cryptoutil/ecb: output smaller than input")
+ }
+ for len(src) > 0 {
+ x.b.Encrypt(dst, src[:x.blockSize])
+ src = src[x.blockSize:]
+ dst = dst[x.blockSize:]
+ }
+}
+
+type ecbDecrypter ecb
+
+// newECBDecrypter returns a BlockMode which decrypts in electronic code book
+// mode, using the given Block.
+func newECBDecrypter(b cipher.Block) cipher.BlockMode {
+ return (*ecbDecrypter)(newECB(b))
+}
+
+func (x *ecbDecrypter) BlockSize() int { return x.blockSize }
+
+func (x *ecbDecrypter) CryptBlocks(dst, src []byte) {
+ if len(src)%x.blockSize != 0 {
+ panic("cryptoutil/ecb: input not full blocks")
+ }
+ if len(dst) < len(src) {
+ panic("cryptoutil/ecb: output smaller than input")
+ }
+ for len(src) > 0 {
+ x.b.Decrypt(dst, src[:x.blockSize])
+ src = src[x.blockSize:]
+ dst = dst[x.blockSize:]
+ }
+}