Deleted Added
full compact
aesencdec.h (255187) aesencdec.h (257757)
1/*-
2 * Copyright 2013 John-Mark Gurney <jmg@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
1/*-
2 * Copyright 2013 John-Mark Gurney <jmg@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/sys/crypto/aesni/aesencdec.h 255187 2013-09-03 18:31:23Z jmg $
26 * $FreeBSD: head/sys/crypto/aesni/aesencdec.h 257757 2013-11-06 19:14:49Z jmg $
27 *
28 */
29
30#include <wmmintrin.h>
31
32static inline void
27 *
28 */
29
30#include <wmmintrin.h>
31
32static inline void
33aesni_enc8(int rounds, const uint8_t *key_schedule, __m128i a,
33aesni_enc8(int rounds, const __m128i *keysched, __m128i a,
34 __m128i b, __m128i c, __m128i d, __m128i e, __m128i f, __m128i g,
35 __m128i h, __m128i out[8])
36{
34 __m128i b, __m128i c, __m128i d, __m128i e, __m128i f, __m128i g,
35 __m128i h, __m128i out[8])
36{
37 const __m128i *keysched = (const __m128i *)key_schedule;
38 int i;
39
40 a ^= keysched[0];
41 b ^= keysched[0];
42 c ^= keysched[0];
43 d ^= keysched[0];
44 e ^= keysched[0];
45 f ^= keysched[0];

--- 17 unchanged lines hidden (view full) ---

63 out[3] = _mm_aesenclast_si128(d, keysched[i + 1]);
64 out[4] = _mm_aesenclast_si128(e, keysched[i + 1]);
65 out[5] = _mm_aesenclast_si128(f, keysched[i + 1]);
66 out[6] = _mm_aesenclast_si128(g, keysched[i + 1]);
67 out[7] = _mm_aesenclast_si128(h, keysched[i + 1]);
68}
69
70static inline void
37 int i;
38
39 a ^= keysched[0];
40 b ^= keysched[0];
41 c ^= keysched[0];
42 d ^= keysched[0];
43 e ^= keysched[0];
44 f ^= keysched[0];

--- 17 unchanged lines hidden (view full) ---

62 out[3] = _mm_aesenclast_si128(d, keysched[i + 1]);
63 out[4] = _mm_aesenclast_si128(e, keysched[i + 1]);
64 out[5] = _mm_aesenclast_si128(f, keysched[i + 1]);
65 out[6] = _mm_aesenclast_si128(g, keysched[i + 1]);
66 out[7] = _mm_aesenclast_si128(h, keysched[i + 1]);
67}
68
69static inline void
71aesni_dec8(int rounds, const uint8_t *key_schedule, __m128i a,
70aesni_dec8(int rounds, const __m128i *keysched, __m128i a,
72 __m128i b, __m128i c, __m128i d, __m128i e, __m128i f, __m128i g,
73 __m128i h, __m128i out[8])
74{
71 __m128i b, __m128i c, __m128i d, __m128i e, __m128i f, __m128i g,
72 __m128i h, __m128i out[8])
73{
75 const __m128i *keysched = (const __m128i *)key_schedule;
76 int i;
77
78 a ^= keysched[0];
79 b ^= keysched[0];
80 c ^= keysched[0];
81 d ^= keysched[0];
82 e ^= keysched[0];
83 f ^= keysched[0];

--- 17 unchanged lines hidden (view full) ---

101 out[3] = _mm_aesdeclast_si128(d, keysched[i + 1]);
102 out[4] = _mm_aesdeclast_si128(e, keysched[i + 1]);
103 out[5] = _mm_aesdeclast_si128(f, keysched[i + 1]);
104 out[6] = _mm_aesdeclast_si128(g, keysched[i + 1]);
105 out[7] = _mm_aesdeclast_si128(h, keysched[i + 1]);
106}
107
108static inline __m128i
74 int i;
75
76 a ^= keysched[0];
77 b ^= keysched[0];
78 c ^= keysched[0];
79 d ^= keysched[0];
80 e ^= keysched[0];
81 f ^= keysched[0];

--- 17 unchanged lines hidden (view full) ---

99 out[3] = _mm_aesdeclast_si128(d, keysched[i + 1]);
100 out[4] = _mm_aesdeclast_si128(e, keysched[i + 1]);
101 out[5] = _mm_aesdeclast_si128(f, keysched[i + 1]);
102 out[6] = _mm_aesdeclast_si128(g, keysched[i + 1]);
103 out[7] = _mm_aesdeclast_si128(h, keysched[i + 1]);
104}
105
106static inline __m128i
109aesni_enc(int rounds, const uint8_t *key_schedule, const __m128i from)
107aesni_enc(int rounds, const __m128i *keysched, const __m128i from)
110{
111 __m128i tmp;
108{
109 __m128i tmp;
112 const __m128i *keysched = (const __m128i *)key_schedule;
113 int i;
114
115 tmp = from ^ keysched[0];
116
117 for (i = 0; i < rounds; i++)
118 tmp = _mm_aesenc_si128(tmp, keysched[i + 1]);
119
120 return _mm_aesenclast_si128(tmp, keysched[i + 1]);
121}
122
123static inline __m128i
110 int i;
111
112 tmp = from ^ keysched[0];
113
114 for (i = 0; i < rounds; i++)
115 tmp = _mm_aesenc_si128(tmp, keysched[i + 1]);
116
117 return _mm_aesenclast_si128(tmp, keysched[i + 1]);
118}
119
120static inline __m128i
124aesni_dec(int rounds, const uint8_t *key_schedule, const __m128i from)
121aesni_dec(int rounds, const __m128i *keysched, const __m128i from)
125{
126 __m128i tmp;
122{
123 __m128i tmp;
127 const __m128i *keysched = (const __m128i *)key_schedule;
128 int i;
129
130 tmp = from ^ keysched[0];
131
132 for (i = 0; i < rounds; i++)
133 tmp = _mm_aesdec_si128(tmp, keysched[i + 1]);
134
135 return _mm_aesdeclast_si128(tmp, keysched[i + 1]);
136}
124 int i;
125
126 tmp = from ^ keysched[0];
127
128 for (i = 0; i < rounds; i++)
129 tmp = _mm_aesdec_si128(tmp, keysched[i + 1]);
130
131 return _mm_aesdeclast_si128(tmp, keysched[i + 1]);
132}