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?
已存档?
是复刻?
已锁定?
是镜像?
是私有?