micro-aes

允许许可的 AES 实现,优化了在微型控制器上的运行。「A permissively licensed AES implementation optimised for running on micro-controllers.」

Github星跟蹤圖

micro-aes

GitHub release
C
Build Status
MIT

A permissively licensed Advanced Encryption Standard (AES) implementation optimised for running on micro-controllers.

This library has been developed and open sourced by AndrewCarterUK (Twitter) from SmarterDM. We are always on the lookout for programming talent, so please message me if you are interested in this sort of work.

License

Like all technology firms, here at SmarterDM we rely heavily on open source software. In turn, we like to contribute back to the open source community when we can. This library is provided free of charge, under the terms of the MIT license.

Although there is no obligation to do so, we would really appreciate it if you could get in touch and let us know how you are using our software.

Features

  • Does not use dynamic memory allocation
  • Uses timing-safe algorithms in place of lookup tables (where possible) to reduce code size
  • API designed for use in a low memory environment (cipher text overwrites plain text on encryption)

Important Note

This library provides the basic AES operations for encrypting and decrypting data. There are different ways to apply a block cipher (called the modes of operation), but this library does not deal with them.

It is very important to understand these modes of operation if you intend to use AES encryption (or any block cipher).

The two most simplest modes are ECB (not very secure) and CBC (much more secure).

An example implementation of CBC mode is presented below.

API

// AES-256
void aes_256_init    (aes_256_context_t *context, uint8_t key[32]);
void aes_256_encrypt (aes_256_context_t *context, uint8_t block[16]);
void aes_256_decrypt (aes_256_context_t *context, uint8_t block[16]);

// AES-192
void aes_192_init    (aes_192_context_t *context, uint8_t key[24]);
void aes_192_encrypt (aes_192_context_t *context, uint8_t block[16]);
void aes_192_decrypt (aes_192_context_t *context, uint8_t block[16]);

// AES-128
void aes_128_init    (aes_128_context_t *context, uint8_t key[16]);
void aes_128_encrypt (aes_128_context_t *context, uint8_t block[16]);
void aes_128_decrypt (aes_128_context_t *context, uint8_t block[16]);

Usage Example: Cipher Block Chaining (CBC)

The functions below show an example implementation of CBC mode using this AES library. The init() function must be called again between the encryption and decryption procedures.

aes_128_context_t context;
uint8_t current_vector[16];

void init(uint8_t key[16], uint8_t initialization_vector[16])
{
  // Initialise the context with the key
  aes_128_init(&context, key);

  // Copy the IV into the current vector array
  memcpy(current_vector, initialization_vector, 16);
}

void encrypt(uint8_t block[16])
{
  int i;

  // XOR the current vector with the block before encrypting
  for (i = 0; i < 16; i++) {
    block[i] ^= current_vector[i];
  }

  // Encrypt the block
  aes_128_encrypt(&context, block);

  // Copy the cipher output to the current vector
  memcpy(current_vector, block, 16);
}

void decrypt(uint8_t block[16])
{
  uint8_t temp_vector[16];
  int i;

  // Copy the cipher output to the temporary vector
  memcpy(temp_vector, block, 16);

  // Decrypt the block
  aes_128_decrypt(&context, block);

  // XOR the output with the current vector to fully decrypt
  for (i = 0; i < 16; i++) {
    block[i] ^= current_vector[i];
  }

  // Copy the temporary vector to the current vector
  memcpy(current_vector, temp_vector, 16);
}

主要指標

概覽
名稱與所有者SmarterDM/micro-aes
主編程語言C
編程語言C (語言數: 3)
平台
許可證MIT License
所有者活动
創建於2016-11-07 18:22:39
推送於2019-02-12 15:58:46
最后一次提交2019-02-12 15:57:13
發布數2
最新版本名稱v1.0.1 (發布於 )
第一版名稱v1.0.0 (發布於 )
用户参与
星數55
關注者數5
派生數7
提交數38
已啟用問題?
問題數2
打開的問題數1
拉請求數4
打開的拉請求數0
關閉的拉請求數0
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?