Example #1
0
void deCrypt_AES128(const cryptData_t cryptedText[CRYPT_BSIZE],
					plainData_t plainText[PLAIN_BSIZE], 
					expKey_t expKey[KSCH_AES128_SIZE]) {
					
	uint8_t state[4*NB];				
	uint32_t* ptr, *statePtr;
	uint8_t i, round;

	/* copy plain input into state to initialize */
    ptr = (uint32_t*) &cryptedText[0];
	statePtr = (uint32_t*) &state[0];
	for(i=0;i<NB;i++)
		*statePtr++ = *ptr++;

	/* first iteration, round 0 */
	/* take the key from the bottom of the array */
	addRoundkey((uint32_t*) &state[0], &expKey[NB*NR_AES128]);
	
	
	/* Go from the next downto Nround - 1 iterations */
	for(round=(NR_AES128 - 1); round > 0; round--) {
	
		statePtr = (uint32_t*) &state[0];
		for(i=0;i<NB;i++) {
			*statePtr = invSubWord(*statePtr);
			statePtr++ ;
		}
		invShiftRows(state);
		invMixColumns((uint32_t*) &state[0]);
		addRoundkey((uint32_t*) &state[0], &expKey[round*NB]);
	}
	
	/* last iteration, round 0 */
	statePtr = (uint32_t*) &state[0];
	for(i=0;i<NB;i++) {
			*statePtr = invSubWord(*statePtr);
			statePtr++ ;
	}
	invShiftRows(state);
	addRoundkey((uint32_t*) &state[0], &expKey[0]);

	/* now copy back the crypted text into the buffer */
    ptr = (uint32_t*) &plainText[0];
	statePtr = (uint32_t*) &state[0];
	for(i=0;i<NB;i++)
		*ptr++ = *statePtr++;						
					
};
Example #2
0
void crypt_AES128(	const plainData_t plainText[PLAIN_BSIZE], 
					cryptData_t cryptedText[CRYPT_BSIZE], 
					expKey_t expKey[KSCH_AES128_SIZE]) {
					
	uint8_t state[4*NB];
	uint32_t* ptr, *statePtr;
	uint8_t i, round;

	/* copy plain input into state to initialize */
    ptr = (uint32_t*) &plainText[0];
	statePtr = (uint32_t*) &state[0];
	for(i=0;i<NB;i++)
		*statePtr++ = *ptr++;

	/* first iteration, round 0 */		
	addRoundkey((uint32_t*) &state[0], &expKey[0]);
	
	
	/* Nround - 1 iterations */
	for(round=1;round<NR_AES128;round++) {
	
		statePtr = (uint32_t*) &state[0];
		for(i=0;i<NB;i++) 
			*statePtr++ = subWord(*statePtr);
		shiftRows(state);
		mixColumns((uint32_t*) &state[0]);
		addRoundkey((uint32_t*) &state[0], &expKey[round*NB]);
	}
	
	/* last iteration, round 11 */
	statePtr = (uint32_t*) &state[0];
	for(i=0;i<NB;i++) 
			*statePtr++ = subWord(*statePtr);
	shiftRows(state);
	addRoundkey((uint32_t*) &state[0], &expKey[(NR_AES128)*NB]);

	/* now copy back the crypted text into the buffer */
    ptr = (uint32_t*) &cryptedText[0];
	statePtr = (uint32_t*) &state[0];
	for(i=0;i<NB;i++)
		*ptr++ = *statePtr++;	
	
}