| Summary: | AES encryption algorithm output is wrong | ||
|---|---|---|---|
| Product: | Base System | Reporter: | Ramana Yarlagadda <ramana.yarlagadda> |
| Component: | kern | Assignee: | suz |
| Status: | Closed FIXED | ||
| Severity: | Affects Only Me | ||
| Priority: | Normal | ||
| Version: | Unspecified | ||
| Hardware: | Any | ||
| OS: | Any | ||
State Changed From-To: open->closed the proposed patch is committed Responsible Changed From-To: freebsd-bugs->suz |
The BSD4.5 supports AES cryptographic algorithms. And i am using this algorithm in my application. Before i integrated this with my code tried the algorithm calling with a known pattern ( i have taken known pattern from AES standard) to make sure that i am using it properly. I was getting the output correct for the first block and the rest of the blocks differ from the expected output. And as a second step , i just decrypted the output from the Encry- ption algorithms.The first block matches with the expected output. And in the remaining blocks contains the output value same as the first block. The reason was though the pointer to input data is moved properly, the data is not copied from the new location. So always only the first block of the message gets encrypted. Fix: FILE: sys/crypto/rijndael/rijndael-api-fst.c. FUNCTION: I added one statement which marked with ******** in the following code case MODE_CBC: #if 1 /*STRICT_ALIGN*/ bcopy(cipher->IV, block, 16); bcopy(input, iv, 16); ((word32*)block)[0] ^= ((word32*)iv)[0]; ((word32*)block)[1] ^= ((word32*)iv)[1]; ((word32*)block)[2] ^= ((word32*)iv)[2]; ((word32*)block)[3] ^= ((word32*)iv)[3]; #else ((word32*)block)[0] = ((word32*)cipher->IV)[0] ^ ((word32*)inp ut)[0]; ((word32*)block)[1] = ((word32*)cipher->IV)[1] ^ ((word32*)inp ut)[1]; ((word32*)block)[2] = ((word32*)cipher->IV)[2] ^ ((word32*)inp ut)[2]; ((word32*)block)[3] = ((word32*)cipher->IV)[3] ^ ((word32*)inp ut)[3]; #endif rijndaelEncrypt(block, outBuffer, key->keySched, key->ROUNDS); input += 16; for (i = numBlocks - 1; i > 0; i--) { #if 1 /*STRICT_ALIGN*/ bcopy(outBuffer, block, 16); ********* bcopy(input, iv, 16); // ramana ************** /* basically with out the above stmt the input is always theh first block */ ((word32*)block)[0] ^= ((word32*)iv)[0]; ((word32*)block)[1] ^= ((word32*)iv)[1]; ((word32*)block)[2] ^= ((word32*)iv)[2]; ((word32*)block)[3] ^= ((word32*)iv)[3]; #else ((word32*)block)[0] = ((word32*)outBuffer)[0] ^ ((word 32*)input)[0]; ((word32*)block)[1] = ((word32*)outBuffer)[1] ^ ((word 32*)input)[1]; ((word32*)block)[2] = ((word32*)outBuffer)[2] ^ ((word 32*)input)[2]; ((word32*)block)[3] = ((word32*)outBuffer)[3] ^ ((word 32*)input)[3]; #endif outBuffer += 16; rijndaelEncrypt(block, outBuffer, key->keySched, key-> ROUNDS); input += 16; } break;