mirror of
https://github.com/markqvist/Reticulum.git
synced 2025-05-06 08:25:57 -04:00
Added internal python-only AES-128-CBC implementation
This commit is contained in:
parent
701c624d0a
commit
68cd79768b
4 changed files with 436 additions and 13 deletions
|
@ -23,8 +23,7 @@
|
|||
import RNS.Cryptography.Provider as cp
|
||||
|
||||
if cp.PROVIDER == cp.PROVIDER_INTERNAL:
|
||||
# TODO: Use internal AES
|
||||
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
|
||||
from .aes import AES
|
||||
|
||||
elif cp.PROVIDER == cp.PROVIDER_PYCA:
|
||||
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
|
||||
|
@ -35,11 +34,8 @@ class AES_128_CBC:
|
|||
@staticmethod
|
||||
def encrypt(plaintext, key, iv):
|
||||
if cp.PROVIDER == cp.PROVIDER_INTERNAL:
|
||||
# TODO: Use internal AES
|
||||
cipher = Cipher(algorithms.AES(key), modes.CBC(iv))
|
||||
encryptor = cipher.encryptor()
|
||||
ciphertext = encryptor.update(plaintext) + encryptor.finalize()
|
||||
return ciphertext
|
||||
cipher = AES(key)
|
||||
return cipher.encrypt(plaintext, iv)
|
||||
|
||||
elif cp.PROVIDER == cp.PROVIDER_PYCA:
|
||||
cipher = Cipher(algorithms.AES(key), modes.CBC(iv))
|
||||
|
@ -50,15 +46,11 @@ class AES_128_CBC:
|
|||
@staticmethod
|
||||
def decrypt(ciphertext, key, iv):
|
||||
if cp.PROVIDER == cp.PROVIDER_INTERNAL:
|
||||
# TODO: Use internal AES
|
||||
cipher = Cipher(algorithms.AES(key), modes.CBC(iv))
|
||||
decryptor = cipher.decryptor()
|
||||
plaintext = decryptor.update(ciphertext) + decryptor.finalize()
|
||||
return plaintext
|
||||
cipher = AES(key)
|
||||
return cipher.decrypt(ciphertext, iv)
|
||||
|
||||
elif cp.PROVIDER == cp.PROVIDER_PYCA:
|
||||
cipher = Cipher(algorithms.AES(key), modes.CBC(iv))
|
||||
decryptor = cipher.decryptor()
|
||||
plaintext = decryptor.update(ciphertext) + decryptor.finalize()
|
||||
return plaintext
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue