Skip to main content

AES Stream Cipher with CFB and OpenPGP Modes

Project description

Sandra

logo

Sandra implements CFB and OpenPGP-CFB built on top of pycryptodome.

Usage

Loading Data

Sandra.load_data(

    path # str -> path to data to be loaded

)

Writing Data

Sandra.write_data(

   file_names, # name of files to be written

   file_data, # data to be written, must be the same length as file_names

   path='.' # path to write data to

)

Examples

RSA File Encryption

import Sandra

file_names, file_data = Sandra.load_data('./taylor_txt/taylor_swift_1KB.txt') 

enc_dec_rsa = Sandra.RSA(2048, Sandra.RSA_ENGINE_DOME)

ciphertext = enc_dec_rsa.encrypt(file_data[0])

print(len(ciphertext))

plaintext = enc_dec_rsa.decrypt(ciphertext)

print(plaintext == file_data[0])

Sandra.write_data(

    file_names, # name of the file to be written

    [plaintext], # data to be written, must be the same length as file_names

    path='./taylor_txt_ed' # path to write data to

)

AES CFB Mode Sample(NIST) Encryption

import Sandra

#Test Case from http://csrc.nist.gov/groups/STM/cavp/block-ciphers.html#aes

data = bytes.fromhex('fffffe00000000000000000000000000')

iv   = bytes.fromhex('fffffe00000000000000000000000000')

key  = bytes.fromhex('00000000000000000000000000000000')



enc_dec_sandra = Sandra.AES(key, Sandra.MODE_CFB, iv, segment_size=16)

ciphertext = enc_dec_sandra.encrypt(data)

plaintext = enc_dec_sandra.decrypt(ciphertext)

AES CFB Mode File Encryption

import Sandra

iv   = bytes.fromhex('fffffe00000000000000000000000000')

key  = bytes.fromhex('00000000000000000000000000000000')

file_names, file_data = Sandra.load_data('./taylor_txt/taylor_swift_1KB.txt') 

enc_dec_cfb = Sandra.AES(key, Sandra.MODE_CFB, iv, segment_size=16)

ciphertext = enc_dec_cfb.encrypt(file_data[0])

print(len(ciphertext))

plaintext = enc_dec_cfb.decrypt(ciphertext)

print(plaintext == file_data[0])

Sandra.write_data(

    file_names, # name of the file to be written

    [plaintext], # data to be written, must be same length as file_names

    path='./taylor_txt_ed' # path to write data to

)

AES OpenPGP-CFB Mode File Encryption

In This mode, the first 18 bytes of cipher text contain the encrypted IV

Padding here is unnecessary as this mode is a stream cipher

import Sandra

iv   = bytes.fromhex('fffffe00000000000000000000000000')

key  = bytes.fromhex('00000000000000000000000000000000')

file_names, file_data = Sandra.load_data('./taylor_txt/taylor_swift_1KB.txt')

print(len(file_data[0]))

file_data_padded = Sandra.pad(file_data, Sandra.AES_BLOCK_SIZE) 

print(len(file_data_padded[0]))

enc_dec_pgp = Sandra.AES(key, Sandra.MODE_OPENPGP, iv)

ciphertext = enc_dec_pgp.encrypt(file_data_padded[0])

eiv, ciphertext = ciphertext[:18], ciphertext[18:]

print(len(ciphertext))

plaintext = enc_dec_pgp.decrypt(ciphertext)

print(len(plaintext))

plaintext = Sandra.unpad(plaintext,Sandra.AES_BLOCK_SIZE)

print(len(plaintext))

print(plaintext == file_data[0])

Sandra.write_data(

    file_names, # name of the file to be written

    [plaintext], # data to be written, must be the same length as file_names

    path='./taylor_txt_ed' # path to write data to

)

Performance

To obtain a table like this one, run

import Sandra

file_names, file_data = Sandra.load_data('path/to/data')

stats = Sandra.performance_test(

    file_names, 

    file_data, 

    rsa_key_size=256,

    rsa_engine=Sandra.RSA_ENGINE_RAW,

    segment_size=64,  

    verbose=True)



stats = Sandra.performance_test(

    file_names, 

    file_data, 

    rsa_key_size=256,

    rsa_engine=Sandra.RSA_ENGINE_RAW,

    segment_size=16,  

    verbose=True)

image

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Sandra-0.0.18.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

Sandra-0.0.18-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file Sandra-0.0.18.tar.gz.

File metadata

  • Download URL: Sandra-0.0.18.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for Sandra-0.0.18.tar.gz
Algorithm Hash digest
SHA256 17ef99ad9c0b3fb23e90ae5a1d2dbf901b48967418d11ca7db0202b1b41e6921
MD5 8d938c7ef06e67145e20774c643ebe4c
BLAKE2b-256 c8cb6bd4fbebeefe44c15a1455b75182ae8dd88fe57ad06f1336a3b298fabb9c

See more details on using hashes here.

File details

Details for the file Sandra-0.0.18-py3-none-any.whl.

File metadata

  • Download URL: Sandra-0.0.18-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for Sandra-0.0.18-py3-none-any.whl
Algorithm Hash digest
SHA256 6d7eeb8f9d5abf1a8fe6b50de236f6eca0376850ffdd0e980dc73219b6860576
MD5 e34918ec774d6f74ae8a51b7643cc520
BLAKE2b-256 531abe3eb4e4de3b84abb88394123dfef05df8ddb54f3a33d09ac62cfa47f292

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page