aboutsummaryrefslogtreecommitdiffstats
path: root/yt_dlp/aes.py
diff options
context:
space:
mode:
authorThe Hatsune Daishi <nao20010128@gmail.com>2021-11-19 10:54:10 +0900
committerGitHub <noreply@github.com>2021-11-19 07:24:10 +0530
commita04e005521ecf2eb0c4979e234ff0c4f23a3caa0 (patch)
tree33d0218a024837d8ef1d73a274633ea1cb708bf7 /yt_dlp/aes.py
parent6b993ca765753e0b04d65ec70cf787a2e9f94639 (diff)
downloadhypervideo-pre-a04e005521ecf2eb0c4979e234ff0c4f23a3caa0.tar.lz
hypervideo-pre-a04e005521ecf2eb0c4979e234ff0c4f23a3caa0.tar.xz
hypervideo-pre-a04e005521ecf2eb0c4979e234ff0c4f23a3caa0.zip
[AES] Add ECB mode (#1686)
Needed for #1688 Authored by: nao20010128nao
Diffstat (limited to 'yt_dlp/aes.py')
-rw-r--r--yt_dlp/aes.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/yt_dlp/aes.py b/yt_dlp/aes.py
index 60cdeb74e..8503e3dfd 100644
--- a/yt_dlp/aes.py
+++ b/yt_dlp/aes.py
@@ -28,6 +28,48 @@ else:
BLOCK_SIZE_BYTES = 16
+def aes_ecb_encrypt(data, key, iv=None):
+ """
+ Encrypt with aes in ECB mode
+
+ @param {int[]} data cleartext
+ @param {int[]} key 16/24/32-Byte cipher key
+ @param {int[]} iv Unused for this mode
+ @returns {int[]} encrypted data
+ """
+ expanded_key = key_expansion(key)
+ block_count = int(ceil(float(len(data)) / BLOCK_SIZE_BYTES))
+
+ encrypted_data = []
+ for i in range(block_count):
+ block = data[i * BLOCK_SIZE_BYTES: (i + 1) * BLOCK_SIZE_BYTES]
+ encrypted_data += aes_encrypt(block, expanded_key)
+ encrypted_data = encrypted_data[:len(data)]
+
+ return encrypted_data
+
+
+def aes_ecb_decrypt(data, key, iv=None):
+ """
+ Decrypt with aes in ECB mode
+
+ @param {int[]} data cleartext
+ @param {int[]} key 16/24/32-Byte cipher key
+ @param {int[]} iv Unused for this mode
+ @returns {int[]} decrypted data
+ """
+ expanded_key = key_expansion(key)
+ block_count = int(ceil(float(len(data)) / BLOCK_SIZE_BYTES))
+
+ encrypted_data = []
+ for i in range(block_count):
+ block = data[i * BLOCK_SIZE_BYTES: (i + 1) * BLOCK_SIZE_BYTES]
+ encrypted_data += aes_decrypt(block, expanded_key)
+ encrypted_data = encrypted_data[:len(data)]
+
+ return encrypted_data
+
+
def aes_ctr_decrypt(data, key, iv):
"""
Decrypt with aes in counter mode