aesencdec.h (281606) | aesencdec.h (285254) |
---|---|
1/*- 2 * Copyright 2013 John-Mark Gurney <jmg@FreeBSD.org> | 1/*- 2 * Copyright 2013 John-Mark Gurney <jmg@FreeBSD.org> |
3 * Copyright 2015 Netflix, Inc. |
|
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 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright --- 7 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 * | 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright --- 7 unchanged lines hidden (view full) --- 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * |
26 * $FreeBSD: head/sys/crypto/aesni/aesencdec.h 281606 2015-04-16 17:42:52Z rodrigc $ | 27 * $FreeBSD: head/sys/crypto/aesni/aesencdec.h 285254 2015-07-07 20:31:09Z jmg $ |
27 * 28 */ 29 | 28 * 29 */ 30 |
31#ifndef _AESENCDEC_H_ 32#define _AESENCDEC_H_ 33 |
|
30#include <crypto/aesni/aesni_os.h> 31 32#include <wmmintrin.h> 33 34static inline void 35aesni_enc8(int rounds, const __m128i *keysched, __m128i a, 36 __m128i b, __m128i c, __m128i d, __m128i e, __m128i f, __m128i g, 37 __m128i h, __m128i out[8]) --- 62 unchanged lines hidden (view full) --- 100 out[2] = _mm_aesdeclast_si128(c, keysched[i + 1]); 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 | 34#include <crypto/aesni/aesni_os.h> 35 36#include <wmmintrin.h> 37 38static inline void 39aesni_enc8(int rounds, const __m128i *keysched, __m128i a, 40 __m128i b, __m128i c, __m128i d, __m128i e, __m128i f, __m128i g, 41 __m128i h, __m128i out[8]) --- 62 unchanged lines hidden (view full) --- 104 out[2] = _mm_aesdeclast_si128(c, keysched[i + 1]); 105 out[3] = _mm_aesdeclast_si128(d, keysched[i + 1]); 106 out[4] = _mm_aesdeclast_si128(e, keysched[i + 1]); 107 out[5] = _mm_aesdeclast_si128(f, keysched[i + 1]); 108 out[6] = _mm_aesdeclast_si128(g, keysched[i + 1]); 109 out[7] = _mm_aesdeclast_si128(h, keysched[i + 1]); 110} 111 |
112/* rounds is passed in as rounds - 1 */ |
|
108static inline __m128i 109aesni_enc(int rounds, const __m128i *keysched, const __m128i from) 110{ 111 __m128i tmp; 112 int i; 113 114 tmp = from ^ keysched[0]; | 113static inline __m128i 114aesni_enc(int rounds, const __m128i *keysched, const __m128i from) 115{ 116 __m128i tmp; 117 int i; 118 119 tmp = from ^ keysched[0]; |
115 116 for (i = 0; i < rounds; i++) | 120 for (i = 1; i < rounds; i += 2) { 121 tmp = _mm_aesenc_si128(tmp, keysched[i]); |
117 tmp = _mm_aesenc_si128(tmp, keysched[i + 1]); | 122 tmp = _mm_aesenc_si128(tmp, keysched[i + 1]); |
123 } |
|
118 | 124 |
119 return _mm_aesenclast_si128(tmp, keysched[i + 1]); | 125 tmp = _mm_aesenc_si128(tmp, keysched[rounds]); 126 return _mm_aesenclast_si128(tmp, keysched[rounds + 1]); |
120} 121 122static inline __m128i 123aesni_dec(int rounds, const __m128i *keysched, const __m128i from) 124{ 125 __m128i tmp; 126 int i; 127 128 tmp = from ^ keysched[0]; 129 | 127} 128 129static inline __m128i 130aesni_dec(int rounds, const __m128i *keysched, const __m128i from) 131{ 132 __m128i tmp; 133 int i; 134 135 tmp = from ^ keysched[0]; 136 |
130 for (i = 0; i < rounds; i++) | 137 for (i = 1; i < rounds; i += 2) { 138 tmp = _mm_aesdec_si128(tmp, keysched[i]); |
131 tmp = _mm_aesdec_si128(tmp, keysched[i + 1]); | 139 tmp = _mm_aesdec_si128(tmp, keysched[i + 1]); |
140 } |
|
132 | 141 |
133 return _mm_aesdeclast_si128(tmp, keysched[i + 1]); | 142 tmp = _mm_aesdec_si128(tmp, keysched[rounds]); 143 return _mm_aesdeclast_si128(tmp, keysched[rounds + 1]); |
134} | 144} |
145 146#endif /* _AESENCDEC_H_ */ |
|