Rizin
unix-like reverse engineering framework and cli tools
aes-set-key-internal.c File Reference
#include "aes-internal.h"
#include <assert.h>
#include "macros.h"

Go to the source code of this file.

Functions

void _nettle_aes_set_key (unsigned nr, unsigned nk, uint32_t *subkeys, const uint8_t *key)
 

Function Documentation

◆ _nettle_aes_set_key()

void _nettle_aes_set_key ( unsigned  nr,
unsigned  nk,
uint32_t subkeys,
const uint8_t key 
)

Definition at line 50 of file aes-set-key-internal.c.

52 {
53  static const uint8_t rcon[10] = {
54  0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x1b,0x36,
55  };
56  const uint8_t *rp;
57  unsigned lastkey, i;
58  uint32_t t;
59 
60  assert(nk != 0);
61  lastkey = (AES_BLOCK_SIZE/4) * (nr + 1);
62 
63  for (i=0, rp = rcon; i<nk; i++)
64  subkeys[i] = LE_READ_UINT32(key + i*4);
65 
66  for (i=nk; i<lastkey; i++)
67  {
68  t = subkeys[i-1];
69  if (i % nk == 0)
70  t = SUBBYTE(ROTL32(24, t), aes_sbox) ^ *rp++;
71 
72  else if (nk > 6 && (i%nk) == 4)
73  t = SUBBYTE(t, aes_sbox);
74 
75  subkeys[i] = subkeys[i-nk] ^ t;
76  }
77 }
#define SUBBYTE(x, box)
Definition: aes-internal.h:85
#define aes_sbox
Definition: aes-internal.h:103
lzma_index ** i
Definition: index.h:629
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len key
Definition: sflib.h:118
static char * rp[]
Definition: i8080dis.c:36
assert(limit<=UINT32_MAX/2)
#define ROTL32(n, x)
Definition: macros.h:157
#define LE_READ_UINT32(p)
Definition: macros.h:122
unsigned int uint32_t
Definition: sftypes.h:29
unsigned char uint8_t
Definition: sftypes.h:31
#define AES_BLOCK_SIZE
Definition: zipint.h:77

References AES_BLOCK_SIZE, aes_sbox, assert(), i, key, LE_READ_UINT32, ROTL32, rp, and SUBBYTE.

Referenced by nettle_aes128_set_encrypt_key(), nettle_aes192_set_encrypt_key(), and nettle_aes256_set_encrypt_key().