项目作者: TheLeopardsH

项目描述 :
Advanced Encryption Standard (AES) in C language
高级语言: C
项目地址: git://github.com/TheLeopardsH/AES-in-C.git
创建时间: 2020-01-22T08:01:11Z
项目社区:https://github.com/TheLeopardsH/AES-in-C

开源协议:

下载


AES-in-C

Advanced Encryption Standard (AES) in C language

```c
you can calculate sbox through following C code

define ROTL8(x,shift) ((uint8_t) ((x) << (shift)) | ((x) >> (8 - (shift))))

void initialize_aes_sbox(uint8_t sbox[256]) {
uint8_t p = 1, q = 1;

  1. /* loop invariant: p * q == 1 in the Galois field */
  2. do {
  3. /* multiply p by 3 */
  4. p = p ^ (p << 1) ^ (p & 0x80 ? 0x1B : 0);
  5. /* divide q by 3 (equals multiplication by 0xf6) */
  6. q ^= q << 1;
  7. q ^= q << 2;
  8. q ^= q << 4;
  9. q ^= q & 0x80 ? 0x09 : 0;
  10. /* compute the affine transformation */
  11. uint8_t xformed = q ^ ROTL8(q, 1) ^ ROTL8(q, 2) ^ ROTL8(q, 3) ^ ROTL8(q, 4);
  12. sbox[p] = xformed ^ 0x63;
  13. } while (p != 1);
  14. /* 0 is a special case since it has no inverse */
  15. sbox[0] = 0x63