Skip to content

Conversation

@mathoudebine
Copy link
Owner

@mathoudebine mathoudebine commented Oct 28, 2025

Might also add support for the following models:

  • Turing 9.2" (1920x462)
  • Turing 5.2" (1280x720)
  • Turing 8" (1280x800)

@mathoudebine mathoudebine changed the title Support Turing Smart Display 8.8" V1.1 Support Turing Smart Display 8.8" V1.x Oct 28, 2025
@mathoudebine mathoudebine linked an issue Oct 28, 2025 that may be closed by this pull request
cipher = DES.new(key, DES.MODE_CBC, key)
padded_len = (len(data) + 7) // 8 * 8
padded_data = data.ljust(padded_len, b'\x00')
return cipher.encrypt(padded_data)

Check failure

Code scanning / CodeQL

Use of a broken or weak cryptographic algorithm High

The cryptographic algorithm DES
is broken or weak, and should not be used.

Copilot Autofix

AI 3 days ago

To fix the issue, replace the use of DES with AES. Update both imports and code so that encrypt_with_des is converted to encrypt_with_aes, using parameters suitable for AES. This involves importing AES from Crypto.Cipher, replacing the key and IV to match AES requirements (key lengths of 16, 24, or 32 bytes; IV length of exactly 16 bytes for AES-CBC), and padding plaintext to a multiple of AES block size (16 bytes). Update usages of both the encryption method and key/IV selection. You should edit the regions touching lines 33 (import), the definition of encrypt_with_des (~lines 56–61), and the related usages in encrypt_command_packet.

We need to:

  • Replace from Crypto.Cipher import DES with from Crypto.Cipher import AES.
  • Replace encrypt_with_des and its logic with an AES version (encrypt_with_aes), updating padding and key sizing.
  • Update any references to DES keys/constants and method calls to match AES requirements (key/IV).
  • Update usages in encrypt_command_packet accordingly.
Suggested changeset 1
library/lcd/lcd_comm_turing_usb.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/library/lcd/lcd_comm_turing_usb.py b/library/lcd/lcd_comm_turing_usb.py
--- a/library/lcd/lcd_comm_turing_usb.py
+++ b/library/lcd/lcd_comm_turing_usb.py
@@ -30,7 +30,7 @@
 
 import usb.core
 import usb.util
-from Crypto.Cipher import DES
+from Crypto.Cipher import AES
 from PIL import Image
 
 from library.log import logger
@@ -53,16 +53,18 @@
     return packet
 
 
-def encrypt_with_des(key: bytes, data: bytes) -> bytes:
-    cipher = DES.new(key, DES.MODE_CBC, key)
-    padded_len = (len(data) + 7) // 8 * 8
+def encrypt_with_aes(key: bytes, iv: bytes, data: bytes) -> bytes:
+    cipher = AES.new(key, AES.MODE_CBC, iv)
+    block_size = AES.block_size  # 16 bytes
+    padded_len = (len(data) + block_size - 1) // block_size * block_size
     padded_data = data.ljust(padded_len, b'\x00')
     return cipher.encrypt(padded_data)
 
-
 def encrypt_command_packet(data: bytearray) -> bytearray:
-    des_key = b'slv3tuzx'
-    encrypted = encrypt_with_des(des_key, data)
+    # AES requires key of length 16, 24, or 32 bytes, and IV of length 16 bytes (block size)
+    aes_key = b'slv3tuzx12345678'  # NOTE: must be 16 bytes for AES-128; adjust as needed.
+    aes_iv = b'\x00' * 16          # Fixed IV for example; ideally, use a random IV and transmit it with the packet.
+    encrypted = encrypt_with_aes(aes_key, aes_iv, data)
     final_packet = bytearray(512)
     final_packet[:len(encrypted)] = encrypted
     final_packet[510] = 161
EOF
@@ -30,7 +30,7 @@

import usb.core
import usb.util
from Crypto.Cipher import DES
from Crypto.Cipher import AES
from PIL import Image

from library.log import logger
@@ -53,16 +53,18 @@
return packet


def encrypt_with_des(key: bytes, data: bytes) -> bytes:
cipher = DES.new(key, DES.MODE_CBC, key)
padded_len = (len(data) + 7) // 8 * 8
def encrypt_with_aes(key: bytes, iv: bytes, data: bytes) -> bytes:
cipher = AES.new(key, AES.MODE_CBC, iv)
block_size = AES.block_size # 16 bytes
padded_len = (len(data) + block_size - 1) // block_size * block_size
padded_data = data.ljust(padded_len, b'\x00')
return cipher.encrypt(padded_data)


def encrypt_command_packet(data: bytearray) -> bytearray:
des_key = b'slv3tuzx'
encrypted = encrypt_with_des(des_key, data)
# AES requires key of length 16, 24, or 32 bytes, and IV of length 16 bytes (block size)
aes_key = b'slv3tuzx12345678' # NOTE: must be 16 bytes for AES-128; adjust as needed.
aes_iv = b'\x00' * 16 # Fixed IV for example; ideally, use a random IV and transmit it with the packet.
encrypted = encrypt_with_aes(aes_key, aes_iv, data)
final_packet = bytearray(512)
final_packet[:len(encrypted)] = encrypted
final_packet[510] = 161
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Turing 8.8" New Hardware Revision v1.x not supported

2 participants