Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

/* READ: TO DO: Make the void aesrand function work. the biggest problem right n

ID: 3592675 • Letter: #

Question

/* READ: TO DO: Make the void aesrand function work. the biggest problem right now is the counter/IV. we have to add it together then put the result into the for loop. This code is in C and using Intel intrinsics guide (SSE to speed up rounds). This code is on AES.

*/

#include

#include

#include

#include

//second function

void aesrand(unsigned char buf[], int n, uint64_t iv, __m128i round_keys[11]){

// code here

}

_mm_aesenclast_si128(round_keys[10]) //final round

}

#define EXPAND_ASSIST(v1,v2,v3,v4,shuff_const,aes_const)

v2 = _mm_aeskeygenassist_si128(v4,aes_const);

v3 = _mm_castps_si128(_mm_shuffle_ps(_mm_castsi128_ps(v3),

_mm_castsi128_ps(v1), 16));

v1 = _mm_xor_si128(v1,v3);

v3 = _mm_castps_si128(_mm_shuffle_ps(_mm_castsi128_ps(v3),

_mm_castsi128_ps(v1), 140));

v1 = _mm_xor_si128(v1,v3);

v2 = _mm_shuffle_epi32(v2,shuff_const);

v1 = _mm_xor_si128(v1,v2)

void aesrand_setup(__m128i round_keys[11], unsigned char user_key[16])

{

EXPAND_ASSIST(x0,x1,x2,x0,255,1); round_keys[1] = x0;

EXPAND_ASSIST(x0,x1,x2,x0,255,2); round_keys[2] = x0;

EXPAND_ASSIST(x0,x1,x2,x0,255,4); round_keys[3] = x0;

EXPAND_ASSIST(x0,x1,x2,x0,255,8); round_keys[4] = x0;

EXPAND_ASSIST(x0,x1,x2,x0,255,16); round_keys[5] = x0;

EXPAND_ASSIST(x0,x1,x2,x0,255,32); round_keys[6] = x0;

EXPAND_ASSIST(x0,x1,x2,x0,255,64); round_keys[7] = x0;

EXPAND_ASSIST(x0,x1,x2,x0,255,128); round_keys[8] = x0;

EXPAND_ASSIST(x0,x1,x2,x0,255,27); round_keys[9] = x0;

EXPAND_ASSIST(x0,x1,x2,x0,255,54); round_keys[10] = x0;

}

// main copied from same website.if we use openssl main, this is useless?

int main(int argc, char *argv[]) {

//unsigned char round_keys[11] = {1,2,3,4,5,6,7,8,9,10,11};

unsigned char user_key[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};

__m128i round_keys[11];

aesrand_setup(round_keys, user_key);

//printf("round key:%u ", &round_keys);

}

Explanation / Answer

#include

#include

#include

#include

//second function

void aesrand(unsigned char buf[], int n, uint64_t iv, __m128i round_keys[11]){

// code here

}

_mm_aesenclast_si128(round_keys[10]) //final round

}

#define EXPAND_ASSIST(v1,v2,v3,v4,shuff_const,aes_const)

v2 = _mm_aeskeygenassist_si128(v4,aes_const);

v3 = _mm_castps_si128(_mm_shuffle_ps(_mm_castsi128_ps(v3),

_mm_castsi128_ps(v1), 16));

v1 = _mm_xor_si128(v1,v3);

v3 = _mm_castps_si128(_mm_shuffle_ps(_mm_castsi128_ps(v3),

_mm_castsi128_ps(v1), 140));

v1 = _mm_xor_si128(v1,v3);

v2 = _mm_shuffle_epi32(v2,shuff_const);

v1 = _mm_xor_si128(v1,v2)

void aesrand_setup(__m128i round_keys[11], unsigned char user_key[16])

{

EXPAND_ASSIST(x0,x1,x2,x0,255,1); round_keys[1] = x0;

EXPAND_ASSIST(x0,x1,x2,x0,255,2); round_keys[2] = x0;

EXPAND_ASSIST(x0,x1,x2,x0,255,4); round_keys[3] = x0;

EXPAND_ASSIST(x0,x1,x2,x0,255,8); round_keys[4] = x0;

EXPAND_ASSIST(x0,x1,x2,x0,255,16); round_keys[5] = x0;

EXPAND_ASSIST(x0,x1,x2,x0,255,32); round_keys[6] = x0;

EXPAND_ASSIST(x0,x1,x2,x0,255,64); round_keys[7] = x0;

EXPAND_ASSIST(x0,x1,x2,x0,255,128); round_keys[8] = x0;

EXPAND_ASSIST(x0,x1,x2,x0,255,27); round_keys[9] = x0;

EXPAND_ASSIST(x0,x1,x2,x0,255,54); round_keys[10] = x0;

}

// main copied from same website.if we use openssl main, this is useless?

int main(int argc, char *argv[]) {

//unsigned char round_keys[11] = {1,2,3,4,5,6,7,8,9,10,11};

unsigned char user_key[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};

__m128i round_keys[11];

aesrand_setup(round_keys, user_key);

//printf("round key:%u ", &round_keys);

}