Skip to content

Latest commit

 

History

History
150 lines (102 loc) · 4.48 KB

Readme.md

File metadata and controls

150 lines (102 loc) · 4.48 KB

SIMD-MT-AES: SIMD Multithreaded AES

Status GitHub License GitHub Release GitHub last commit GitHub top language

SIMD-MT-AES is a high-performance C++ AES encryption and decryption utility with hardware acceleration and multithreading support. It uses AES-NI for fast operations and is optimized for speed, supporting only AES-128 encryption in ECB mode.

Features

  • AES-128 Encryption and Decryption with AES-NI acceleration.
  • Multithreading Support to leverage multiple CPU cores.
  • Command-Line Tool for message and file encryption/decryption.
  • C++ Library for integration into other projects.
  • Automatic Key Management for proper key sizing.
  • PKCS5 Padding for correct block alignment.
  • ECB Mode Only support.

Building

  • Using g++

    g++ src/FastAES.cpp src/main.cpp -o bin/sm-aes.exe -maes -msse4 -m64 -O3 -std=c++11
  • Using Make

    make

Usage

Command-Line Interface (CLI)

SIMD-MT-AES can be used as a command-line tool for encrypting and decrypting messages and files.

Command-Line Options

sm-aes.exe [options]
  • -enc : Encrypt the input.
  • -dec : Decrypt the input.
  • -key <key> : Specify the encryption/decryption key.
  • -msg <text> : Specify the plaintext message to encrypt.
  • -in <file> : Specify the input file path.
  • -out <file> : Specify the output file path.
  • -thd <thread number> : Specify the number of threads.
  • -h : Display the help message.

Examples

  • Encrypt a Message:

    sm-aes.exe -enc -key mysecretkey123456 -msg "Hello, World!"
  • Decrypt a Message:

    sm-aes.exe -dec -key mysecretkey123456 -msg c080664469a3770e8424cdd0e6bb9e21
  • Encrypt a File:

    sm-aes.exe -enc -key mysecretkey123456 -in input.txt -out encrypted.bin -thd 4
  • Decrypt a File:

    sm-aes.exe -dec -key mysecretkey123456 -in encrypted.bin -out decrypted.txt

C++ Library Integration

SIMD-MT-AES can also be used as a C++ library.

Integration Instructions

  • Include Header: Add the header file FastAES.hpp to your project.

Example Usage

  • Encrypting Data:

    #include "FastAES.hpp"
    
    uint8_t key[16] = { /* Your 16-byte key here */ };
    FastAES aes(key);
    
    const char* plaintext = "Hello, World!";
    size_t length = strlen(plaintext);
    std::vector<uint8_t> ciphertext(length + 16); 
    
    aes.encrypt(reinterpret_cast<const uint8_t*>(plaintext), ciphertext.data(), length);
  • Decrypting Data:

    #include "FastAES.hpp"
    
    uint8_t key[16] = { /* Your 16-byte key here */ };
    FastAES aes(key);
    
    std::vector<uint8_t> decrypted(length);
    aes.decrypt(ciphertext.data(), decrypted.data(), length);

Benchmark

The benchmark results were obtained by measuring AES encryption and decryption for different data sizes.

For futher informations, see Benchmark.md

Results

MT-AES OPENSSL MT-AES OPENSSL
Size Operation Average Time Average Time Average Rate Average Rate
512 MB Encryption 0.0946 seconds 0.136745 seconds 5995.53 MB/s 4172.45 MB/s
Decryption 0.1013 seconds 0.125878 seconds 5608.9 MB/s 4493.89 MB/s
1024 MB Encryption 0.1864 seconds 0.244411 seconds 6117.79 MB/s 4620.16 MB/s
Decryption 0.1902 seconds 0.50546 seconds 6022.73 MB/s 3348.57 MB/s
2048 MB Encryption 0.362 seconds 0.811207 seconds 6152.65 MB/s 3781.4 MB/s
Decryption 0.609958 seconds 0.845851 seconds 4474.26 MB/s 3479.06 MB/s

Interpretation

It appear that the MT-AES is 2~2.5x faster than OpenSSL+SIMD, same for both encrypt/decrypt operations, same as rates.

Benchmark Environment

  • CPU: Intel(R) Core(TM) i7-4810MQ @ 2.80GHz, 4 cores, 8 threads
  • RAM: 16 GB DDR3 @ 1600MHz
  • OS: Windows 10 Professional (64-bit)
  • Compiler: g++ (GCC) 6.1.0

License

This project is licensed under the MIT License - see the LICENSE file for details.