File: aes.h

package info (click to toggle)
aeskeyfind 1%3A1.0-11
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 196 kB
  • sloc: ansic: 577; python: 53; sh: 47; makefile: 17
file content (27 lines) | stat: -rw-r--r-- 712 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#ifndef __AES_H__
#define __AES_H__

typedef uint32_t aeskey_t[4];
typedef uint32_t keyexp_t[44];

extern uint8_t sbox[256];
extern uint8_t rcon[255];

// Perform the AES key core operation on a word.
// (Assumes the standard byte order.)
static inline uint32_t key_core(uint32_t k, int i) {
    uint32_t t = 0;
    for (int j=0; j<4; j++)
        t = set_byte(t, (j-1+4)%4, sbox[get_byte(k,j)]);
    return set_byte(t, 0, get_byte(t,0) ^ rcon[i]);
}

// Run each byte of a word through the sbox separately for word 4 of 256-bit AES.
static inline uint32_t sbox_bytes(uint32_t k) {
    uint32_t r = 0;
    for (int j=0; j<4; j++)
        r = set_byte(r,j,sbox[get_byte(k,j)]);
    return r;
}

#endif//__AES_H__