Skip to content

Commit 5a24b5d

Browse files
committed
update uint encryption
1 parent 9126ab9 commit 5a24b5d

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

coti/crypto_utils.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from cryptography.hazmat.primitives.asymmetric import padding
66
from cryptography.hazmat.primitives.asymmetric import rsa
77
from eth_keys import keys
8-
from math import ceil
98

109
block_size = AES.block_size
1110
address_size = 20
@@ -21,7 +20,6 @@ def encrypt(key, plaintext):
2120

2221
# Ensure key size is 128 bits (16 bytes)
2322
if len(key) != block_size:
24-
print(len(key), block_size)
2523
raise ValueError("Key size must be 128 bits.")
2624

2725
# Create a new AES cipher block using the provided key
@@ -120,7 +118,10 @@ def build_input_text(plaintext, user_aes_key, sender, contract, function_selecto
120118
# Convert the ct to an integer
121119
int_cipher_text = int.from_bytes(ct, byteorder='big')
122120

123-
return int_cipher_text, signature
121+
return {
122+
'ciphertext': int_cipher_text,
123+
'signature': signature
124+
}
124125

125126

126127
def build_string_input_text(plaintext, user_aes_key, sender, contract, function_selector, signing_key):
@@ -133,13 +134,12 @@ def build_string_input_text(plaintext, user_aes_key, sender, contract, function_
133134

134135
encoded_plaintext = bytearray(list(plaintext.encode('utf-8')))
135136

136-
for i in range(ceil(len(encoded_plaintext) / 8)):
137-
start_idx = i * 8
137+
for start_idx in range(0, len(encoded_plaintext), 8):
138138
end_idx = min(start_idx + 8, len(encoded_plaintext))
139139

140140
byte_arr = encoded_plaintext[start_idx:end_idx] + bytearray(8 - (end_idx - start_idx))
141141

142-
ct_int, sig = build_input_text(
142+
it_int = build_input_text(
143143
int.from_bytes(byte_arr, 'big'),
144144
user_aes_key,
145145
sender,
@@ -148,8 +148,8 @@ def build_string_input_text(plaintext, user_aes_key, sender, contract, function_
148148
signing_key
149149
)
150150

151-
input_text['ciphertext']['value'].append(ct_int)
152-
input_text['signature'].append(sig)
151+
input_text['ciphertext']['value'].append(it_int['ciphertext'])
152+
input_text['signature'].append(it_int['signature'])
153153

154154
return input_text
155155

0 commit comments

Comments
 (0)