Electroneum
Macros | Functions
aesb.c File Reference
#include <stdint.h>
#include "int-util.h"
Include dependency graph for aesb.c:

Macros

#define TABLE_ALIGN   32
 
#define WPOLY   0x011b
 
#define N_COLS   4
 
#define AES_BLOCK_SIZE   16
 
#define RC_LENGTH   (5 * (AES_BLOCK_SIZE / 4 - 2))
 
#define LOCAL_ALIGN
 
#define rf1(r, c)   (r)
 
#define word_in(x, c)   (*((uint32_t*)(x)+(c)))
 
#define word_out(x, c, v)   (*((uint32_t*)(x)+(c)) = (v))
 
#define s(x, c)   x[c]
 
#define si(y, x, c)   (s(y,c) = word_in(x, c))
 
#define so(y, x, c)   word_out(y, c, s(x,c))
 
#define state_in(y, x)   si(y,x,0); si(y,x,1); si(y,x,2); si(y,x,3)
 
#define state_out(y, x)   so(y,x,0); so(y,x,1); so(y,x,2); so(y,x,3)
 
#define round(rm, y, x, k)   rm(y,x,k,0); rm(y,x,k,1); rm(y,x,k,2); rm(y,x,k,3)
 
#define to_byte(x)   ((x) & 0xff)
 
#define bval(x, n)   to_byte(SWAP32LE(x) >> (8 * (n)))
 
#define fwd_var(x, r, c)
 
#define fwd_rnd(y, x, k, c)   (s(y,c) = (k)[c] ^ SWAP32LE(four_tables(x,t_use(f,n),fwd_var,rf1,c)))
 
#define sb_data(w)
 
#define rc_data(w)
 
#define bytes2word(b0, b1, b2, b3)
 
#define h0(x)   (x)
 
#define w0(p)   bytes2word(p, 0, 0, 0)
 
#define w1(p)   bytes2word(0, p, 0, 0)
 
#define w2(p)   bytes2word(0, 0, p, 0)
 
#define w3(p)   bytes2word(0, 0, 0, p)
 
#define u0(p)   bytes2word(f2(p), p, p, f3(p))
 
#define u1(p)   bytes2word(f3(p), f2(p), p, p)
 
#define u2(p)   bytes2word(p, f3(p), f2(p), p)
 
#define u3(p)   bytes2word(p, p, f3(p), f2(p))
 
#define v0(p)   bytes2word(fe(p), f9(p), fd(p), fb(p))
 
#define v1(p)   bytes2word(fb(p), fe(p), f9(p), fd(p))
 
#define v2(p)   bytes2word(fd(p), fb(p), fe(p), f9(p))
 
#define v3(p)   bytes2word(f9(p), fd(p), fb(p), fe(p))
 
#define f2(x)   ((x<<1) ^ (((x>>7) & 1) * WPOLY))
 
#define f4(x)   ((x<<2) ^ (((x>>6) & 1) * WPOLY) ^ (((x>>6) & 2) * WPOLY))
 
#define f8(x)   ((x<<3) ^ (((x>>5) & 1) * WPOLY) ^ (((x>>5) & 2) * WPOLY) ^ (((x>>5) & 4) * WPOLY))
 
#define f3(x)   (f2(x) ^ x)
 
#define f9(x)   (f8(x) ^ x)
 
#define fb(x)   (f8(x) ^ f2(x) ^ x)
 
#define fd(x)   (f8(x) ^ f4(x) ^ x)
 
#define fe(x)   (f8(x) ^ f4(x) ^ f2(x))
 
#define t_dec(m, n)   t_##m##n
 
#define t_set(m, n)   t_##m##n
 
#define t_use(m, n)   t_##m##n
 
#define d_4(t, n, b, e, f, g, h)   LOCAL_ALIGN const t n[4][256] = { b(e), b(f), b(g), b(h) }
 
#define four_tables(x, tab, vf, rf, c)
 
#define STATIC
 
#define INLINE
 

Functions

 d_4 (uint32_t, t_dec(f, n), sb_data, u0, u1, u2, u3)
 
STATIC INLINE void aesb_single_round (const uint8_t *in, uint8_t *out, uint8_t *expandedKey)
 
STATIC INLINE void aesb_pseudo_round (const uint8_t *in, uint8_t *out, uint8_t *expandedKey)
 

Macro Definition Documentation

◆ AES_BLOCK_SIZE

#define AES_BLOCK_SIZE   16

◆ bval

#define bval (   x,
 
)    to_byte(SWAP32LE(x) >> (8 * (n)))

◆ bytes2word

#define bytes2word (   b0,
  b1,
  b2,
  b3 
)
Value:
(((uint32_t)(b3) << 24) | \
((uint32_t)(b2) << 16) | ((uint32_t)(b1) << 8) | (b0))

◆ d_4

#define d_4 (   t,
  n,
  b,
  e,
  f,
  g,
 
)    LOCAL_ALIGN const t n[4][256] = { b(e), b(f), b(g), b(h) }

◆ f2

#define f2 (   x)    ((x<<1) ^ (((x>>7) & 1) * WPOLY))

◆ f3

#define f3 (   x)    (f2(x) ^ x)

◆ f4

#define f4 (   x)    ((x<<2) ^ (((x>>6) & 1) * WPOLY) ^ (((x>>6) & 2) * WPOLY))

◆ f8

#define f8 (   x)    ((x<<3) ^ (((x>>5) & 1) * WPOLY) ^ (((x>>5) & 2) * WPOLY) ^ (((x>>5) & 4) * WPOLY))

◆ f9

#define f9 (   x)    (f8(x) ^ x)

◆ fb

#define fb (   x)    (f8(x) ^ f2(x) ^ x)

◆ fd

#define fd (   x)    (f8(x) ^ f4(x) ^ x)

◆ fe

#define fe (   x)    (f8(x) ^ f4(x) ^ f2(x))

◆ four_tables

#define four_tables (   x,
  tab,
  vf,
  rf,
 
)
Value:
(tab[0][bval(vf(x,0,c),rf(0,c))] \
^ tab[1][bval(vf(x,1,c),rf(1,c))] \
^ tab[2][bval(vf(x,2,c),rf(2,c))] \
^ tab[3][bval(vf(x,3,c),rf(3,c))])
#define bval(x, n)
Definition: aesb.c:54

◆ fwd_rnd

#define fwd_rnd (   y,
  x,
  k,
 
)    (s(y,c) = (k)[c] ^ SWAP32LE(four_tables(x,t_use(f,n),fwd_var,rf1,c)))

◆ fwd_var

#define fwd_var (   x,
  r,
 
)
Value:
( r == 0 ? ( c == 0 ? s(x,0) : c == 1 ? s(x,1) : c == 2 ? s(x,2) : s(x,3))\
: r == 1 ? ( c == 0 ? s(x,1) : c == 1 ? s(x,2) : c == 2 ? s(x,3) : s(x,0))\
: r == 2 ? ( c == 0 ? s(x,2) : c == 1 ? s(x,3) : c == 2 ? s(x,0) : s(x,1))\
: ( c == 0 ? s(x,3) : c == 1 ? s(x,0) : c == 2 ? s(x,1) : s(x,2)))
#define s(x, c)
Definition: aesb.c:47

◆ h0

#define h0 (   x)    (x)

◆ INLINE

#define INLINE

◆ LOCAL_ALIGN

#define LOCAL_ALIGN

◆ N_COLS

#define N_COLS   4

◆ rc_data

#define rc_data (   w)
Value:
{\
w(0x01), w(0x02), w(0x04), w(0x08), w(0x10),w(0x20), w(0x40), w(0x80),\
w(0x1b), w(0x36) }

◆ RC_LENGTH

#define RC_LENGTH   (5 * (AES_BLOCK_SIZE / 4 - 2))

◆ rf1

#define rf1 (   r,
 
)    (r)

◆ round

#define round (   rm,
  y,
  x,
 
)    rm(y,x,k,0); rm(y,x,k,1); rm(y,x,k,2); rm(y,x,k,3)

◆ s

#define s (   x,
 
)    x[c]

◆ sb_data

#define sb_data (   w)

◆ si

#define si (   y,
  x,
 
)    (s(y,c) = word_in(x, c))

◆ so

#define so (   y,
  x,
 
)    word_out(y, c, s(x,c))

◆ state_in

#define state_in (   y,
 
)    si(y,x,0); si(y,x,1); si(y,x,2); si(y,x,3)

◆ state_out

#define state_out (   y,
 
)    so(y,x,0); so(y,x,1); so(y,x,2); so(y,x,3)

◆ STATIC

#define STATIC

◆ t_dec

#define t_dec (   m,
 
)    t_##m##n

◆ t_set

#define t_set (   m,
 
)    t_##m##n

◆ t_use

#define t_use (   m,
 
)    t_##m##n

◆ TABLE_ALIGN

#define TABLE_ALIGN   32

◆ to_byte

#define to_byte (   x)    ((x) & 0xff)

◆ u0

#define u0 (   p)    bytes2word(f2(p), p, p, f3(p))

◆ u1

#define u1 (   p)    bytes2word(f3(p), f2(p), p, p)

◆ u2

#define u2 (   p)    bytes2word(p, f3(p), f2(p), p)

◆ u3

#define u3 (   p)    bytes2word(p, p, f3(p), f2(p))

◆ v0

#define v0 (   p)    bytes2word(fe(p), f9(p), fd(p), fb(p))

◆ v1

#define v1 (   p)    bytes2word(fb(p), fe(p), f9(p), fd(p))

◆ v2

#define v2 (   p)    bytes2word(fd(p), fb(p), fe(p), f9(p))

◆ v3

#define v3 (   p)    bytes2word(f9(p), fd(p), fb(p), fe(p))

◆ w0

#define w0 (   p)    bytes2word(p, 0, 0, 0)

◆ w1

#define w1 (   p)    bytes2word(0, p, 0, 0)

◆ w2

#define w2 (   p)    bytes2word(0, 0, p, 0)

◆ w3

#define w3 (   p)    bytes2word(0, 0, 0, p)

◆ word_in

#define word_in (   x,
 
)    (*((uint32_t*)(x)+(c)))

◆ word_out

#define word_out (   x,
  c,
 
)    (*((uint32_t*)(x)+(c)) = (v))

◆ WPOLY

#define WPOLY   0x011b

Function Documentation

◆ aesb_pseudo_round()

STATIC INLINE void aesb_pseudo_round ( const uint8_t *  in,
uint8_t *  out,
uint8_t *  expandedKey 
)

◆ aesb_single_round()

STATIC INLINE void aesb_single_round ( const uint8_t *  in,
uint8_t *  out,
uint8_t *  expandedKey 
)

◆ d_4()

d_4 ( uint32_t  ,
t_dec(f, n)  ,
sb_data  ,
u0  ,
u1  ,
u2  ,
u3   
)