]> jfr.im git - yt-dlp.git/blob - devscripts/generate_aes_testdata.py
[cleanup] Point all shebang to `python3` (#372)
[yt-dlp.git] / devscripts / generate_aes_testdata.py
1 #!/usr/bin/env python3
2 from __future__ import unicode_literals
3
4 import codecs
5 import subprocess
6
7 import os
8 import sys
9 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
10
11 from yt_dlp.utils import intlist_to_bytes
12 from yt_dlp.aes import aes_encrypt, key_expansion
13
14 secret_msg = b'Secret message goes here'
15
16
17 def hex_str(int_list):
18 return codecs.encode(intlist_to_bytes(int_list), 'hex')
19
20
21 def openssl_encode(algo, key, iv):
22 cmd = ['openssl', 'enc', '-e', '-' + algo, '-K', hex_str(key), '-iv', hex_str(iv)]
23 prog = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
24 out, _ = prog.communicate(secret_msg)
25 return out
26
27
28 iv = key = [0x20, 0x15] + 14 * [0]
29
30 r = openssl_encode('aes-128-cbc', key, iv)
31 print('aes_cbc_decrypt')
32 print(repr(r))
33
34 password = key
35 new_key = aes_encrypt(password, key_expansion(password))
36 r = openssl_encode('aes-128-ctr', new_key, iv)
37 print('aes_decrypt_text 16')
38 print(repr(r))
39
40 password = key + 16 * [0]
41 new_key = aes_encrypt(password, key_expansion(password)) * (32 // 16)
42 r = openssl_encode('aes-256-ctr', new_key, iv)
43 print('aes_decrypt_text 32')
44 print(repr(r))