Debian Codegraph @

sources/ippcp/pcpaes_192keyexpansion_ni.c

raw symbols SCIP
1 /*************************************************************************
2 * Copyright (C) 2016 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. AES keys expansion
21 //
22 // Contents:
23 // aes192_KeyExpansion_NI()
24 //
25 */
26
27 #include "owndefs.h"
28 #include "owncp.h"
29 #include "pcpaesm.h"
30 #include "pcpaes_keys_ni.h"
31 #include "pcptool.h"
32
33 #if (_AES_NI_ENABLING_ == _FEATURE_ON_) || (_AES_NI_ENABLING_ == _FEATURE_TICKTOCK_)
34
35 //////////////////////////////////////////////////////////////////////
36 /*
37 // AES-192 key expansion
38 */
39 static void aes192_assist(__m128i* temp1, __m128i* temp2, __m128i* temp3)
40 {
41 __m128i temp4;
42 *temp2 = _mm_shuffle_epi32(*temp2, 0x55);
43 temp4 = _mm_slli_si128(*temp1, 0x4);
44 *temp1 = _mm_xor_si128(*temp1, temp4);
45 temp4 = _mm_slli_si128(temp4, 0x4);
46 *temp1 = _mm_xor_si128(*temp1, temp4);
47 temp4 = _mm_slli_si128(temp4, 0x4);
48 *temp1 = _mm_xor_si128(*temp1, temp4);
49 *temp1 = _mm_xor_si128(*temp1, *temp2);
50 *temp2 = _mm_shuffle_epi32(*temp1, 0xff);
51 temp4 = _mm_slli_si128(*temp3, 0x4);
52 *temp3 = _mm_xor_si128(*temp3, temp4);
53 *temp3 = _mm_xor_si128(*temp3, *temp2);
54 }
55
56 IPP_OWN_DEFN(void, aes192_KeyExpansion_NI, (Ipp8u * keyExp, const Ipp8u* userkey))
57 {
58 __m128i* pKeySchedule = (__m128i*)keyExp;
59
60 __m128i temp[3];
61 /*
62 temp[0] = temp1
63 temp[1] = temp2
64 temp[2] = temp3
65 */
66
67 temp[0] = _mm_loadu_si128((__m128i*)userkey);
68
69 temp[2] = _mm_cvtsi64_si128(((Ipp64s*)(userkey + 16))[0]);
70 //_mm_loadu_si128((__m128i*)(userkey+16)); // read 8 bytes only other are zero
71
72 pKeySchedule[0] = temp[0];
73 pKeySchedule[1] = temp[2];
74 temp[1] = _mm_aeskeygenassist_si128(temp[2], 0x1);
75 aes192_assist(&temp[0], &temp[1], &temp[2]);
76 pKeySchedule[1] = _mm_unpacklo_epi64(pKeySchedule[1], temp[0]);
77 pKeySchedule[2] = _mm_alignr_epi8(temp[2], temp[0], 8);
78
79 temp[1] = _mm_aeskeygenassist_si128(temp[2], 0x2);
80 aes192_assist(&temp[0], &temp[1], &temp[2]);
81 pKeySchedule[3] = temp[0];
82 pKeySchedule[4] = temp[2];
83 temp[1] = _mm_aeskeygenassist_si128(temp[2], 0x4);
84 aes192_assist(&temp[0], &temp[1], &temp[2]);
85 pKeySchedule[4] = _mm_unpacklo_epi64(pKeySchedule[4], temp[0]);
86 pKeySchedule[5] = _mm_alignr_epi8(temp[2], temp[0], 8);
87
88 temp[1] = _mm_aeskeygenassist_si128(temp[2], 0x8);
89 aes192_assist(&temp[0], &temp[1], &temp[2]);
90 pKeySchedule[6] = temp[0];
91 pKeySchedule[7] = temp[2];
92 temp[1] = _mm_aeskeygenassist_si128(temp[2], 0x10);
93 aes192_assist(&temp[0], &temp[1], &temp[2]);
94 pKeySchedule[7] = _mm_unpacklo_epi64(pKeySchedule[7], temp[0]);
95 pKeySchedule[8] = _mm_alignr_epi8(temp[2], temp[0], 8);
96
97 temp[1] = _mm_aeskeygenassist_si128(temp[2], 0x20);
98 aes192_assist(&temp[0], &temp[1], &temp[2]);
99 pKeySchedule[9] = temp[0];
100 pKeySchedule[10] = temp[2];
101 temp[1] = _mm_aeskeygenassist_si128(temp[2], 0x40);
102 aes192_assist(&temp[0], &temp[1], &temp[2]);
103 pKeySchedule[10] = _mm_unpacklo_epi64(pKeySchedule[10], temp[0]);
104 pKeySchedule[11] = _mm_alignr_epi8(temp[2], temp[0], 8);
105
106 temp[1] = _mm_aeskeygenassist_si128(temp[2], 0x80);
107 aes192_assist(&temp[0], &temp[1], &temp[2]);
108 pKeySchedule[12] = temp[0];
109
110 /* clear secret data */
111 PurgeBlock(temp, sizeof(temp));
112 }
113
114 #endif /* #if (_AES_NI_ENABLING_==_FEATURE_ON_) || (_AES_NI_ENABLING_==_FEATURE_TICKTOCK_) */