Debian Codegraph @

sources/ippcp/pcprij128safeenc2pxca.c

raw symbols SCIP
1 /*************************************************************************
2 * Copyright (C) 2015 Intel Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *************************************************************************/
16
17 /*
18 //
19 // Purpose:
20 // Cryptography Primitive.
21 // Encrypt 128-bit data block according to Rijndael
22 // (compact S-box based implementation)
23 //
24 // Contents:
25 // Safe2Encrypt_RIJ128()
26 //
27 //
28 */
29
30 #include "owncp.h"
31
32 #if ((_IPP < _IPP_V8) && (_IPP32E < _IPP32E_U8)) /* no pshufb instruction */
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 // MixColumns4 function mixes the columns of the state matrix
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 /* clang-format off */
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 /* clang-format on */
87 {
88 Ipp32u state[4];
89
90 int round = 0;
91
92 IPP_UNREFERENCED_PARAMETER(sbox);
93
94 // copy input to the state array
95 TRANSPOSE((Ipp8u*)state, in);
96
97 // add round key to the state before starting the rounds.
98 XorRoundKey(state, (Ipp32u*)(RoundKey + 0 * 16));
99
100 // there will be Nr rounds
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 // last round
109 SubBytes((Ipp8u*)state);
110 ShiftRows(state);
111 XorRoundKey(state, (Ipp32u*)(RoundKey + Nr * 16));
112
113 // copy from the state to output
114 TRANSPOSE(out, (Ipp8u*)state);
115 }
116 #endif /* _ALG_AES_SAFE_COMPACT_SBOX_ */
117
118 #endif /* (_IPP <_IPP_V8) && (_IPP32E <_IPP32E_U8) */