Skip to content
项目

关于

C++ AES 实现

安全与隐私

这些数字如何统计

实测星标增长

24小时
0
7天
+1
15天
+2
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

AES

C++ AES(Advanced Encryption Standard) implementation

Build Status

Usage

This class is very simple to use:

...
unsigned char plain[] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; //plaintext example
unsigned char key[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; //key example
unsigned int plainLen = 16 * sizeof(unsigned char);  //bytes in plaintext

AES aes(AESKeyLength::AES_128);  // 128 - key length, can be 128, 192 or 256
c = aes.EncryptECB(plain, plainLen, key);
// now variable c contains plainLen bytes - ciphertext
...
delete[] c;

Or for vectors:

...
vector<unsigned char> plain = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; //plaintext example
vector<unsigned char> key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; //key example

AES aes(AESKeyLength::AES_128);
c = aes.EncryptECB(plain, key);
// now vector c contains ciphertext
...

ECB, CBC, CFB modes are supported.

Important notes

  • This library does not provide any padding. Plaintext and ciphertext length in bytes must be divisible by 16. If length doesn't satisfy this condition exception will be thrown. You can use any padding before encryption if necessary
  • This library does not provide any key derivation function. Key length must 128/192/256 bits respectively. You can use any KDF before encryption if necessary

Links

Development:

  1. git clone https://github.com/SergeyBel/AES.git
  2. docker-compose up -d
  3. use make commands

There are four executables in bin folder:

  • test - run tests
  • debug - version for debugging (main code will be taken from dev/main.cpp)
  • profile - version for profiling with gprof (main code will be taken from dev/main.cpp)
  • speedtest - performance speed test (main code will be taken from speedtest/main.cpp)
  • release - version with optimization (main code will be taken from dev/main.cpp)

Build commands:

  • make build_all - build all targets
  • make build_test - build test target
  • make build_debug - build debug target
  • make build_profile - build profile target
  • make build_speed_test - build speedtest target
  • make build_release - build release target
  • make style_fix - fix code style
  • make test - run tests
  • make debug - run debug version
  • make profile - run profile version
  • make speed_test - run performance speed test
  • make release - run release version
  • make clean - clean bin directory

探索相关项目

加载中…