| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
#include "owncp.h" |
| 31 |
|
| 32 |
#if ((_IPP < _IPP_V8) && (_IPP32E < _IPP32E_U8)) |
| 33 |
|
| 34 |
#if (_ALG_AES_SAFE_ == _ALG_AES_SAFE_COMPACT_SBOX_) |
| 35 |
|
| 36 |
#include "pcprij128safe.h" |
| 37 |
#include "pcprij128safe2.h" |
| 38 |
#include "pcprijtables.h" |
| 39 |
|
| 40 |
IPPCP_INLINE void SubBytes(Ipp8u state[]) |
| 41 |
{ |
| 42 |
int i; |
| 43 |
for (i = 0; i < 16; i++) { |
| 44 |
state[i] = getSboxValue(state[i]); |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
IPPCP_INLINE void ShiftRows(Ipp32u* state) |
| 50 |
{ |
| 51 |
state[1] = ROR32(state[1], 8); |
| 52 |
state[2] = ROR32(state[2], 16); |
| 53 |
state[3] = ROR32(state[3], 24); |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
IPPCP_INLINE void MixColumns(Ipp32u* state) |
| 58 |
{ |
| 59 |
Ipp32u y0 = state[1] ^ state[2] ^ state[3]; |
| 60 |
Ipp32u y1 = state[0] ^ state[2] ^ state[3]; |
| 61 |
Ipp32u y2 = state[0] ^ state[1] ^ state[3]; |
| 62 |
Ipp32u y3 = state[0] ^ state[1] ^ state[2]; |
| 63 |
|
| 64 |
state[0] = xtime4(state[0]); |
| 65 |
state[1] = xtime4(state[1]); |
| 66 |
state[2] = xtime4(state[2]); |
| 67 |
state[3] = xtime4(state[3]); |
| 68 |
|
| 69 |
y0 ^= state[0] ^ state[1]; |
| 70 |
y1 ^= state[1] ^ state[2]; |
| 71 |
y2 ^= state[2] ^ state[3]; |
| 72 |
y3 ^= state[3] ^ state[0]; |
| 73 |
|
| 74 |
state[0] = y0; |
| 75 |
state[1] = y1; |
| 76 |
state[2] = y2; |
| 77 |
state[3] = y3; |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
IPP_OWN_DEFN(void, Safe2Encrypt_RIJ128, (const Ipp8u* in, |
| 82 |
Ipp8u* out, |
| 83 |
int Nr, |
| 84 |
const Ipp8u* RoundKey, |
| 85 |
const void* sbox)) |
| 86 |
|
| 87 |
{ |
| 88 |
Ipp32u state[4]; |
| 89 |
|
| 90 |
int round = 0; |
| 91 |
|
| 92 |
IPP_UNREFERENCED_PARAMETER(sbox); |
| 93 |
|
| 94 |
|
| 95 |
TRANSPOSE((Ipp8u*)state, in); |
| 96 |
|
| 97 |
|
| 98 |
XorRoundKey(state, (Ipp32u*)(RoundKey + 0 * 16)); |
| 99 |
|
| 100 |
|
| 101 |
for (round = 1; round < Nr; round++) { |
| 102 |
SubBytes((Ipp8u*)state); |
| 103 |
ShiftRows(state); |
| 104 |
MixColumns(state); |
| 105 |
XorRoundKey(state, (Ipp32u*)(RoundKey + round * 16)); |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
SubBytes((Ipp8u*)state); |
| 110 |
ShiftRows(state); |
| 111 |
XorRoundKey(state, (Ipp32u*)(RoundKey + Nr * 16)); |
| 112 |
|
| 113 |
|
| 114 |
TRANSPOSE(out, (Ipp8u*)state); |
| 115 |
} |
| 116 |
#endif |
| 117 |
|
| 118 |
#endif |