ReactOS  0.4.13-dev-1148-g9b75b67
mvAesAlg.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MAXBC   (128/32)
 
#define MAXKC   (256/32)
 
#define MAXROUNDS   14
 

Functions

int rijndaelKeySched (MV_U8 k[4][MAXKC], int keyBits, int blockBits, MV_U8 rk[MAXROUNDS+1][4][MAXBC])
 
int rijndaelEncrypt128 (MV_U8 a[4][MAXBC], MV_U8 rk[MAXROUNDS+1][4][MAXBC], int rounds)
 
int rijndaelDecrypt128 (MV_U8 a[4][MAXBC], MV_U8 rk[MAXROUNDS+1][4][MAXBC], int rounds)
 

Macro Definition Documentation

◆ MAXBC

#define MAXBC   (128/32)

Definition at line 9 of file mvAesAlg.h.

◆ MAXKC

#define MAXKC   (256/32)

Definition at line 10 of file mvAesAlg.h.

◆ MAXROUNDS

#define MAXROUNDS   14

Definition at line 11 of file mvAesAlg.h.

Function Documentation

◆ rijndaelDecrypt128()

int rijndaelDecrypt128 ( MV_U8  a[4][MAXBC],
MV_U8  rk[MAXROUNDS+1][4][MAXBC],
int  rounds 
)

Definition at line 277 of file mvAesAlg.c.

278 {
279  int r, BC, ROUNDS;
280 
281  BC = 4;
282  ROUNDS = rounds;
283 
284  /* To decrypt: apply the inverse operations of the encrypt routine,
285  * in opposite order
286  *
287  * (KeyAddition is an involution: it 's equal to its inverse)
288  * (the inverse of Substitution with table S is Substitution with the inverse table of S)
289  * (the inverse of Shiftrow is Shiftrow over a suitable distance)
290  */
291 
292  /* First the special round:
293  * without InvMixColumn
294  * with extra KeyAddition
295  */
296  KeyAddition(a,rk[ROUNDS],BC);
297  ShiftRow128Dec(a);
298  Substitution(a,Si);
299 
300  /* ROUNDS-1 ordinary rounds
301  */
302  for(r = ROUNDS-1; r > 0; r--) {
303  KeyAddition(a,rk[r],BC);
304  InvMixColumn(a);
305  ShiftRow128Dec(a);
306  Substitution(a,Si);
307 
308  }
309 
310  /* End with the extra key addition
311  */
312 
313  KeyAddition(a,rk[0],BC);
314 
315  return 0;
316 }
void Substitution(MV_U8 a[4][MAXBC], MV_U8 box[256])
Definition: mvAesAlg.c:134
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
void KeyAddition(MV_U8 a[4][MAXBC], MV_U8 rk[4][MAXBC], MV_U8 BC)
Definition: mvAesAlg.c:33
void ShiftRow128Dec(MV_U8 a[4][MAXBC])
Definition: mvAesAlg.c:88
void InvMixColumn(MV_U8 a[4][MAXBC])
Definition: mvAesAlg.c:161
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204

◆ rijndaelEncrypt128()

int rijndaelEncrypt128 ( MV_U8  a[4][MAXBC],
MV_U8  rk[MAXROUNDS+1][4][MAXBC],
int  rounds 
)

Definition at line 244 of file mvAesAlg.c.

245 {
246  /* Encryption of one block.
247  */
248  int r, BC, ROUNDS;
249 
250  BC = 4;
251  ROUNDS = rounds;
252 
253  /* begin with a key addition
254  */
255 
256  KeyAddition(a,rk[0],BC);
257 
258  /* ROUNDS-1 ordinary rounds
259  */
260  for(r = 1; r < ROUNDS; r++) {
261  Substitution(a,S);
262  ShiftRow128Enc(a);
263  MixColumn(a, rk[r]);
264  /*KeyAddition(a,rk[r],BC);*/
265  }
266 
267  /* Last round is special: there is no MixColumn
268  */
269  Substitution(a,S);
270  ShiftRow128Enc(a);
271  KeyAddition(a,rk[ROUNDS],BC);
272 
273  return 0;
274 }
void Substitution(MV_U8 a[4][MAXBC], MV_U8 box[256])
Definition: mvAesAlg.c:134
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
void KeyAddition(MV_U8 a[4][MAXBC], MV_U8 rk[4][MAXBC], MV_U8 BC)
Definition: mvAesAlg.c:33
Definition: movable.cpp:7
void MixColumn(MV_U8 a[4][MAXBC], MV_U8 rk[4][MAXBC])
Definition: mvAesAlg.c:144
void ShiftRow128Enc(MV_U8 a[4][MAXBC])
Definition: mvAesAlg.c:44
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204

◆ rijndaelKeySched()

int rijndaelKeySched ( MV_U8  k[4][MAXKC],
int  keyBits,
int  blockBits,
MV_U8  rk[MAXROUNDS+1][4][MAXBC] 
)

Definition at line 179 of file mvAesAlg.c.

180 {
181  /* Calculate the necessary round keys
182  * The number of calculations depends on keyBits and blockBits
183  */
184  int KC, BC, ROUNDS;
185  int i, j, t, rconpointer = 0;
186  MV_U8 tk[4][MAXKC];
187 
188  switch (keyBits) {
189  case 128: KC = 4; break;
190  case 192: KC = 6; break;
191  case 256: KC = 8; break;
192  default : return (-1);
193  }
194 
195  switch (blockBits) {
196  case 128: BC = 4; break;
197  case 192: BC = 6; break;
198  case 256: BC = 8; break;
199  default : return (-2);
200  }
201 
202  switch (keyBits >= blockBits ? keyBits : blockBits) {
203  case 128: ROUNDS = 10; break;
204  case 192: ROUNDS = 12; break;
205  case 256: ROUNDS = 14; break;
206  default : return (-3); /* this cannot happen */
207  }
208 
209 
210  for(j = 0; j < KC; j++)
211  for(i = 0; i < 4; i++)
212  tk[i][j] = k[i][j];
213  t = 0;
214  /* copy values into round key array */
215  for(j = 0; (j < KC) && (t < (ROUNDS+1)*BC); j++, t++)
216  for(i = 0; i < 4; i++) W[t / BC][i][t % BC] = tk[i][j];
217 
218  while (t < (ROUNDS+1)*BC) { /* while not enough round key material calculated */
219  /* calculate new values */
220  for(i = 0; i < 4; i++)
221  tk[i][0] ^= S[tk[(i+1)%4][KC-1]];
222  tk[0][0] ^= rcon[rconpointer++];
223 
224  if (KC != 8)
225  for(j = 1; j < KC; j++)
226  for(i = 0; i < 4; i++) tk[i][j] ^= tk[i][j-1];
227  else {
228  for(j = 1; j < KC/2; j++)
229  for(i = 0; i < 4; i++) tk[i][j] ^= tk[i][j-1];
230  for(i = 0; i < 4; i++) tk[i][KC/2] ^= S[tk[i][KC/2 - 1]];
231  for(j = KC/2 + 1; j < KC; j++)
232  for(i = 0; i < 4; i++) tk[i][j] ^= tk[i][j-1];
233  }
234  /* copy values into round key array */
235  for(j = 0; (j < KC) && (t < (ROUNDS+1)*BC); j++, t++)
236  for(i = 0; i < 4; i++) W[t / BC][i][t % BC] = tk[i][j];
237  }
238 
239  return 0;
240 }
GLdouble GLdouble t
Definition: gl.h:2047
Definition: movable.cpp:7
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
Definition: polytest.cpp:35
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
static const ulong32 rcon[]
Definition: aes.c:923
unsigned char MV_U8
Definition: mvOs.h:4
int k
Definition: mpi.c:3369
#define MAXKC
Definition: mvAesAlg.h:10