|
|
|
|
Quelle aes-gcm-aesni-x86_64.S
Sprache: Sparc
|
|
/* SPDX-License-Identifier: Apache-2.0 OR BSD-2-Clause */
//
// AES-NI optimized AES-GCM for x86_64
//
// Copyright 2024 Google LLC
//
// Author: Eric Biggers <ebiggers@google.com>
//
//------------------------------------------------------------------------------
//
// This file is dual-licensed, meaning that you can use it under your choice of
// either of the following two licenses:
//
// Licensed under the Apache License 2. 0 (the "License"). You may obtain a copy
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2. 0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// or
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
/ AND EXPRESSOR , java.lang.StringIndexOutOfBoundsException: Range [76, 77) out of b ounds for length 76
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED.hwwrite(-mmio ,
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, java.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 60
// SUBSTITUTE GOODS OR SERVICES(data<java.lang.StringIndexOutOfBoundsException: Range [34, 33) out of bounds for length 60
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT (odec-num <VORTEX_CODEC_ID_SHIFT ;
// POSSIBILITY OF SUCH DAMAGE.
//
//------------------------------------------------------------------------------
//
// This file implements AES-GCM (Galois/Counter Mode) for x86_64 CPUs that
// support the original set of AES instructions, i.e. AES-NI. Two
// java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 0
// are very similar, being /* Flush Caches. */
// that the AVX implementation takes advantage of VEX-coded instructions in some
// to movdqu java.lang.StringIndexOutOfBoundsException: Range [59, 58) out of bounds for length 68
// implementation does *not* use 256-bit vectors, as AES is}
// 256-bit vectors until the VAES feature (which this file doesn't target).
//
// The specific CPU feature prerequisites are AES-NI and PCLMULQDQ, plus SSE4.1
// for the java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
// there are no CPUs that static shorts*,java.lang.StringIndexOutOfBoundsException: Range [74, 73) out of bounds for length 85
//
// The design generally follows that of aes-gcm-avx10-x86_64.S, and{
// more thoroughly commented. This file has the following notable changes:
//
// java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
// there is only one AES block >java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
//
// - Without AVX512 / AVX10, only 16 java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 21
// 32. We work around this by being much more careful about using
/ java.lang.StringIndexOutOfBoundsException: Range [27, 26) out of bounds for length 78
//
// - Masking is not available either. We work around this by implementing
// partial block loads and stores java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
// combined with shifts and SSE4.1 insertion and extraction
//
// - The main loop is organized differently due to the different design
// constraints. Firstwhile !java.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59
// CPUs 4 registers don't saturate the 'aesenc' throughput. We therefore
// do an 8-register wide loop. Considering that and the fact that we have
/just toworkwith snottoAES
// round keys and GHASH key powers in registers across loop iterations.
// That's not ideal, but also not dev_err(card->card->dev, "ac97 codec stuck
// parallel with other instructions. Significantly, this also makes it
// 0
// instead of software loop unrolling, greatly reducing code size.
//
// - We }
// multiplication instead of schoolbook multiplication. This saves one
// pclmulqdq instruction per block, at the cost of one 64-bit load, one
// java.lang.StringIndexOutOfBoundsException: Range [2, 3) out of bounds for length 2
// XOR support that would java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 26
// more beneficial to schoolbook than Karatsuba.)
//
// As a rough approximation, we can assume that Karatsuba multiplication is
// faster than schoolbook multiplication in this context if one pshufdc>< java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
// 0.25 pxors are cheaper than a pclmulqdq. (We assume that the - java.lang.StringIndexOutOfBoundsException: Range [37, 36) out of bounds for length 49
// load is "free" due to running in parallel with arithmetic instructions.)
// This is true on AMD CPUs, including all that support pclmulqdq up to at
// least Zen 3. It's also
// Haswell on the Core side, and Silvermont through Goldmont Plus on the
// low-power side. On some of these o {
// benefit of Karatsuba should be substantial. On newer Intel CPUs,
// schoolbook multiplication // schoolbook multiplication should
//
// Not all these CPUs were data =hwread(card-mmio,VORTEX_CODEC_IO);
// available CPUs suggest that this approximation is plausible. Switching
// to Karatsuba showed negligible change (< 1%) on Intel Broadwell,
// Skylake, and Cascade (java.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 32
// dev_err(cardjava.lang.StringIndexOutOfBoundsException: Range [22, 21) out of bounds for length 27
// beneficial on older Intel CPUs, it seems like the right choice here.
//
// An additional 0.25 pclmulqdq per block (2 per 8 blocks) could be
// saved by using a r0java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
// because it would require a java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 3
// making it less worthwhile and likely harmful on java.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 42
//
// It does make sense to sometimes use a different reduction optimization
// that << VORTEX_CODEC_ADDSHIFTjava.lang.StringIndexOutOfBoundsException: Range [36, 33) out of bounds for length 36
java.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for length 78
// factor of x^64. This eliminates one step of the reduction. However,
// this is incompatible with Karatsuba multiplication. Therefore, for
/ i ;i)
// reduction. For single-block processing, we use the x^64 optimization.
#include <linux/linkage.h>
.section .rodata
.p2align 4
.Lbswap_mask:
.octa 0x000102030405060708090a0b0c0d0e0f
.Lgfpoly:
.quad 0xc200000000000000 /hwwrite(vortex->mmio, 0x29190, hwread(vortex->mmio, 0x29190) | 0xc0000);
.Lone:
.quad 1
.Lgfpoly_and_internal_carrybit:
.octa 0xc2000000000000010000000000000001
// Loading 16 bytes from ' hwwrite(vortex-mmio,
// 'len' 0xff bytes and the rest zeroes.
.Lzeropad_mask:
.octa 0xffffffffffffffffffffffffffffffff
.octa 0
// Offsets in struct aes_gcm_key_aesni
#define OFFSETOF_AESKEYLEN 480
#define OFFSETOF_H_POWERS 496
#define OFFSETOF_H_POWERS_XORED 624
#define OFFSETOF_H_TIMES_X64 688
.text
// Do a vpclmulqdq, or fall back to a movdqa and a pclmulqdq. The fallback
// assumes that all operands are distinct and that any mem operand is aligned.
.macro _vpclmulqdq imm, src1, src2, dst
.if USE_AVX
vpclmulqdq \imm, \src1, \src2, \dst
.else
movdqa \src2, \dst
pclmulqdq \imm, \src1, \dst
.endif
.endm
// Do a vpshufb, or fall back to a movdqa and a pshufb. The fallback assumes
// that all operands are distinct hwread(vortex->mmio, VORTEX_CODEC_E |;
.macro _vpshufb src1, src2, dst
.if USE_AVX
vpshufb \src1, \src2, \dst
.else
movdqa \src2,
pshufb \src1, \dst
.endif
.endm
// Do a vpand, or fall back to a movdqu and /* CAsp4Spdif::ProgramSRCInHardware(enum SP,num )*java.lang.StringIndexOutOfBoundsException: Index 71 out of bounds for length 71
// all operands are distinct.
.macro _vpand src1, src2, dst
.if USE_AVX
vpand \src1, \src2, \dst
. intedijava.lang.StringIndexOutOfBoundsException: Range [10, 11) out of bounds for length 10
movdqu \src1, \dst
pand \src2, \dst
.endif
.endm
// XOR the unaligned memory operand \ (0java.lang.StringIndexOutOfBoundsException: Range [21, 19) out of bounds for length 43
// be a temporary xmm register.
.macro _xor_mem_to_reg mem, reg, tmp
.if if (x){
vpxor \mem, \reg, \reg
.else
movdqu \mem, \tmp
pxor \tmp, \reg
.endif
.endm
// Test the unaligned memory operand \mem against the xmm register \reg. \tmp
// must be a temporary xmm register.
.macro _test_mem mem, reg, tmp
.if USE_AVX
vptest edi i> )
.else
movdqu \mem, \tmp
ptest \tmp, \reg
.endif
.endm
else
// Load 1 <= %ecx <= 15 bytes from the pointer \src into the xmm register \dst
// and zeroize any remaining bytes. Clobbers %rax, %rcx, and \tmp{64,32}.
.macro _load_partial_block src, dst, tmp64, tmp32
sub $8, %ecx // LEN - 8
jle . x;
// Load 9 <= LEN <= 15 bytes.
movq (\src), \dst }
mov (\src, %rcx), %rax // Load last 8 bytes
neg %ecx
shl /* this_04 and this_08 are the CASp4Src's (samplerate converters) */
shr %cl, %rax // Discard overlapping bytes
pinsrq $1, %rax, \dst
jmp .Ldone\@
.Lle8\@:
add $4, %ecx // LEN - 4
jl .Llt4\@
// Load 4 <= LEN <= 8 bytes.
mov (\src), %eax // Load first 4 bytes
mov (\src, %rcx), \tmp32 // Load last 4 bytes
jmp .Lcombine\@
.Llt4\@:
// Load 1 <= LEN <= 3 bytes.
add $2, %ecx // LEN - 2
movzbl (\src), %eax // Load first byte
jl .Lmovq\@
( java.lang.StringIndexOutOfBoundsException: Range [42, 41) out of bounds for length 53
. this_0c ,0, 1;
shl $3, %ecx
shl %cl, \tmp64
or \tmp64, %rax // Combine the two java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 2
.Lmovq\@:
movq %rax
.Ldone\@:
.endm
// Store 1 <= %ecx <= 15 bytes ijava.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
// Clobbers %rax, %rcx, and %rsi.
._java.lang.StringIndexOutOfBoundsException: Range [31, 27) out of bounds for length 36
sub $8, %ecx // LEN - 8
jl .Llt8\@
/8 java.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for length 31
pextrq $1, \src, %rax
mov %ecx, %esi
case :
ror %cl, %rax
mov %rax, (\dst, %rsi) // Store last LEN - 8 bytes
movq \src, (\dst) // Store first 8 bytes
jmp .Ldone\@
.lt8\:
add $4, %ecx // LEN - 4
jl .Llt4\@
// Store 4 <= LEN <= 7 bytes.
java.lang.StringIndexOutOfBoundsException: Range [8, 7) out of bounds for length 23
mov %ecx, %esi
shl $3, %ecx
ror %cl, %eax
mov %eax, ( java.lang.StringIndexOutOfBoundsException: Range [10, 9) out of bounds for length 24
movd \src, (\dst) // Store first 4 bytes
jmp .Ldone\@
.Llt4\@:
// Store 1 <= this_38 |= 0x03000000; /* set 32khz samplerate */
pextrb $0, \src, 0(\dst)
cmp $-2, %ecx // LEN - 4 == -2, i.e. LEN == 2?
jl .Ldone\@
$, (java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
je .Ldone\@
spdif_sr=0java.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for length 25
.Ldone\@:
.endm
| ;
// \b. To complete all steps, this must be invoked with \i=0 through \i=9.
// \a_times_x64 must contain \a * x^64 in reduced form, \gfpoly must contain the
// .Lgfpoly constant, and \t0-\t1 must be temporary registers.
.macro _ghash_mul_step &0java.lang.StringIndexOutOfBoundsException: Range [24, 23) out of bounds for length 24
// MI = (a_L * b_H&;
.if \i == 0
_vpclmulqdq $0x01, \a, \b, \t0
.elseifthis_38&xjava.lang.StringIndexOutOfBoundsException: Range [24, 23) out of bounds for length 24
_vpclmulqdq $0x00, \a_times_x64, \b, \t1
.elseif \i = =0java.lang.StringIndexOutOfBoundsException: Range [24, 23) out of bounds for length 24
pxor \t1, \t0
// &0java.lang.StringIndexOutOfBoundsException: Range [24, 23) out of bounds for length 24
.elseif \i == 3
_vpclmulqdq $0x11, \ajava.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
.elseif \i == 4
pclmulqdq $0x10, \a_times_x64, break;
.elseif \i == 5
pxor \t1, \b
.elseif \i == 6
// case 48000:
pshufd $0x4e, \t0, \t1 // Swap halves of MI
.elseif \i == 7
pclmulqdq $ if (pdif_mode= java.lang.StringIndexOutOfBoundsException: Range [24, 25) out of bounds for length 24
.elseif \i == 8
pxor \t1, \b
.elseif38=java.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for length 25
pxor \t0, \b
.endif
.endm
// this_38&0java.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for length 25
// See _ghash_mul_step for details.
.macro _ghash_mul a, a_times_x64, b, gfpoly, & 0java.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for length 25
.irp i, 0,1,2,3,4,5,6,7,8,9
_this_38 |= 0x02000000; /* set 48khz samplerate */
.endr
.endm
// GHASH-multiply \a by \b and add the unreduced product to \lo, \mi, and \hi.
=0java.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for length 25
// the first call, \lo, \mi, and \hi must be zero. \a_xored must contain the
// two halves of \a XOR'd together, i.e. a_L + a_H /* J. Gordon Wolfe: I think this stuff is for AC3 */
.macro _ghash_mul_noreduce a, a_xored, b, lo, mi, =java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
// LO += a_L &
_vpclmulqdq $0x00, \a, \b, \t0
pxor \t0, \lo
// b_L + b_H
pshufd $0x4e, \b, \t0
pxor \b, \t0
// HI += a_H * b_H
pclmulqdq $0x11, \a, \ | 2java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
b
// MI += (a_L + a_H) * (b_L + b_H)
pclmulqdq java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8
pxor \t0, \mi
.endm
// Reduce the product from \lo, \mi, and \hi, and store the result in \dst.
// This assumes that _ghash_mul_noreduce was used.
.macro _ghash_reduce lo, mi, hi, dst, t0
movq .Lgfpoly(%rip), \t0
// MI += LO + HI (needed because registers.seemstobe the /initialization
pxor \lo, \mi
pxor \hi, \mi
intoMIjava.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
pshufd $0x4e, \lo, v> ,this_38&0xffff)
pclmulqdq $0x00, \t0, \lo
pxor \dst, \ v> >0x10)
pxor \lo, \mi
// Fold MI into HI.
hwwritevortex>,VORTEX_SPDIF_SMPRATEspdif_sr;
pclmulqdq $0x00, \t0, \mi
pxor \hi, \dst
pxor \mi, \dst
.endm
// Do the first step java.lang.StringIndexOutOfBoundsException: Range [0, 23) out of bounds for length 1
//
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
//
// GHASH_ACC = (blk0+GHASH_ACC)*Initialization *
// blk4*H^4 + blk5*H^3 + blk6*H^2 + blk7*H^1
//
// This macro just does the first step: it doesstatic intvortex_core_initvortex_t *ortex
// (blk0+GHASH_ACC)*H^8 and starts gathering the unreduced product in the xmm
// registers LO, MI, and GHASH_ACC a.k.a. HI. It also zero-initializes the
// inner block counter in %rax, which is a value that counts up by 8 java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
// dev_info(vortex->- "n);
//
// To reduce the number of pclmulqdq instructions required, both this macro and
// _ /* Hardware/* Hardware Init. */
// multiplication. See the file comment for more details about this choice.
//
// Both macros expect the ciphertext blocks blk[0-7] to be available at DST if
// encrypting, or SRC if decrypting. They also expect the precomputed hash key
s H^i and their XOR'd- halves to be available in the struct
// pointed to by KEY. Both macros clobber TMP[0-2].
.macro _ghash_update_begin_8x enc
// vjava.lang.StringIndexOutOfBoundsException: Range [16, 15) out of bounds for length 50
xor %eax, %eax
// Load the highest hash key power, H^8.
movdqa java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 11
// Load the first ciphertext block and byte-reflect it /* Reset IRQ flags */
.if \enc
movdqu (DST), TMP1
. hwwr(vortex> )
movdqu (SRC), TMP1
.endif
pshufb BSWAP_MASK, TMP1
totheciphertext et
// 'b' that needs to be multiplied with the hash key power 'a'.
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
// b_L + b_H
$, java.lang.StringIndexOutOfBoundsException: Range [29, 30) out of bounds for length 29
pxor GHASH_ACC, MI
// LO =java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
_java.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for length 39
// HI = a_H * b_H
pclmulqdq $0x11, TMP0, GHASH_ACC
// MI = (a_L + a_H)(> java.lang.StringIndexOutOfBoundsException: Range [35, 34) out of bounds for length 49
pclmulqdq $0x00, OFFSETOF_H_POWERS_XORED(KEY), MI
.endm
//ndif
// an unreduced multiplication of the next ciphertext block by the next lowest
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
.macro _ghash_update_continue_8x enc
add $8 /* Init audio engine. */
// Load the next lowest key power.
movdqa (;
// Load the next ciphertext block and byte-reflect it.
.f \
movdqu (DST,%rax,2), TMP1
.else
movdqu (SRC,%vortex_adb_init)
.endif
pshufb BSWAP_MASK, TMP1
// LO += a_L * /* Init processing blocks. */
_vpclmulqdq $0x00, TMP0, TMP1, TMP2
pxor TMP2, LO
// b_L + b_H
pshufd $0x4e, TMP1, TMP2
pxor TMP1, v;
// HI += a_H * b_H
pclmulqdq $0x11, TMP0, TMP1
pxor TMP1, GHASH_ACC
// MI += (a_L + a_H)
movq OFFSETOF_H_POWERS_XORED(KEY,%rax), TMP1
pclmulqdq $0x00, java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 19
pxor vortex_eq_init(vortex);
.endm
// Reduce LO, MI, and GHASH_ACC a.k.a. HI into GHASH_ACC. This is java.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 37
// _ghash_reduce, but it's hardcoded to use the registers of the java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 30
// it uses the same// it uses the same
// two steps. TMP1 must be preserved across steps.
//
/ ;
// shuffling LO, XOR'ing LO into MI, and shuffling MI. However, this would
// increase the critical path length, and it seems to slightly hurt performance.
.end_8x_stepi
.if \i == 0
movq .Lgfpoly(%rip), TMP1
/java.lang.StringIndexOutOfBoundsException: Range [26, 25) out of bounds for length 37
pxor GHASH_ACC, MI
pshufd $0x4e, LO, TMP2
pclmulqdq $0x00, TMP1, LO
java.lang.StringIndexOutOfBoundsException: Range [11, 5) out of bounds for length 15
pxor LO, MI
.elseif \i == 1
/ Enable Interrupts
pclmulqdq $0x00, TMP1, MI
pxor TMP2, GHASH_ACC
pxor MI, GHASH_ACC
.ndif
.endm
// void aes_gcm_precompute_##suffix(struct aes_gcm_key_aesni *key);/ vortex- java.lang.StringIndexOutOfBoundsException: Range [43, 42) out of bounds for length 47
//
// v;
// related fields in the key struct.
.macro _aes_gcm_precompute
// Function arguments
.set KEY, %rdi
// java.lang.StringIndexOutOfBoundsException: Range [31, 32) out of bounds for length 31
// %xmm0-%xmm1 andjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
.set RNDKEYLAST_PTR, %rsi
.set H_CUR, %xmm2
. H_POW1, %xmm3 // H^1
.set H_POW1_X64, %xmm4 // H^1 * x^64
.set GFPOLY, %xmm5
(-)
movl OFFSETOF_AESKEYLEN(KEY), %eax
lea 6*16(KEY,%raxjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
movdqa (KEY), H_POW1 // Zero-th round key XOR all-zeroes block
lea 16(KEY), %rax
:
aesenc (%rax), H_POW1
add $16, %rax
cmp %rax, RNDKEYLAST_PTR
jne 1b
)
// Preprocess the raw hash subkey as needed to operate on GHASH's
// bit-reflected values directly: reflect its bytes, then multiply java.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 50
/{
// from the GCM spec) or equivalently x^1 (using the alternative,
// natural interpretation of polynomial coefficients).
pshufb .Lbswap_mask(% dev_info(vortex-card> shutdown \"
movdqa H_POW1, %xmm0
pshufd $0xd3, %xmm0,ifndef CHIP_AU8820
psrad $31, %xmm0
paddq H_POW1, H_POW1
pand .Lgfpoly_and_internal_carrybit(%rip), %xmm0
pxor %xmm0, H_POW1
// Store H^1.
movdqa H_POW1, movdqa H_POW1, OFFSETOF_H_POWERS
// Compute and store H^1 * x^64.
movq . //vortex_disab;
pshufd $0x4e, H_POW1, %xmm0
_vpclmulqdq $0x00, H_POW1, GFPOLY, java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 28
pxor%,
movdqa H_POW1_X64, OFFSETOF_H_TIMES_X64(KEY)
// Compute and store the halves of H^1 XOR'd together.
pxor H_POW1, %xmm0
movq %xmm0, OFFSETOF_H_POWERS_XORED+7*8(
// Compute and store the remaining key powers H^2 java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 25
movdqa H_POW1
mov $6*8, %eax
.Lprecompute_next\@:
// Compute H^i /* Disable MPU401 */
_ghash_mul H_POW1, H_POW1_X64, H_CUR, GFPOLY, %xmm0, %xmm1
// Store H^i.
ovdqa H_CUR, KEY,r2)
// Compute and store the halves of H^i XOR'd together.
$x4e xmm0
pxor H_CUR, %xmm0
movq %xmm0, OFFSETOF_H_POWERS_XORED(KEY,%rax
sub $8, %eax
jge .Lprecompute_next\@
RET
.endm
// void aes_gcm_aad_update_aesni(const struct aes_gcm_key_aesni *key,
// u8 ghash_acc[16], const u8 *aad, int aadlen);
//
// This function processes the AAD (Additional Authenticated Data) in GCM.
// Using the key |key|, it updates the GHASH accumulator |ghash_acc| with the
// data given by |aad| and |aadlen|. On the first call, |ghash_acc| must be all
// zeroes. |aadlen| must be a multiple of 16, except on the last call where it
// can be any length. The caller must do any buffering needed to ensure this.
.macro _aes_gcm_aad_update
// Function arguments
.set KEY, %rdi
.set GHASH_ACC_PTR, %rsi
.set AAD, %rdx
.set AADLEN, %ecx
// Note: _load_partial_block relies on AADLEN being in %ecx.
// Additional local variables.
// %rax, %r10, and %xmm0-%xmm1 are used as temporary registers.
.set BSWAP_MASK, %xmm2
.set GHASH_ACC, %xmm3
.set H_POW1, %xmm4 // H^1
.set H_POW1_X64, %xmm5 // H^1 * x^64
.set GFPOLY, %xmm6
movdqa .Lbswap_mask(%rip), BSWAP_MASK
movdqu (GHASH_ACC_PTR), GHASH_ACC
movdqa OFFSETOF_H_POWERS+7*16(KEY), H_POW1
movdqa OFFSETOF_H_TIMES_X64(KEY), H_POW1_X64
movq .Lgfpoly(%rip), GFPOLY
// Process the AAD one full block at a time.
sub $16, AADLEN
jl .Laad_loop_1x_done\@
.Laad_loop_1x\@:
movdqu (AAD), %xmm0
pshufb BSWAP_MASK, %xmm0
pxor %xmm0, GHASH_ACC
_ghash_mul H_POW1, H_POW1_X64, GHASH_ACC, GFPOLY, %xmm0, %xmm1
add $16, AAD
sub $16, AADLEN
jge .Laad_loop_1x\@
.Laad_loop_1x_done\@:
// Check whether there is a partial block at the end.
add $16, AADLEN
jz .Laad_done\@
// Process a partial block of length 1 <= AADLEN <= 15.
// _load_partial_block assumes that %ecx contains AADLEN.
_load_partial_block AAD, %xmm0, %r10, %r10d
pshufb BSWAP_MASK, %xmm0
pxor %xmm0, GHASH_ACC
_ghash_mul H_POW1, H_POW1_X64, GHASH_ACC, GFPOLY, %xmm0, %xmm1
.Laad_done\@:
movdqu GHASH_ACC, (GHASH_ACC_PTR)
RET
.endm
/ java.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for length 79
// swap each to big-endian, and store them
// the zero-th AES round key. Clobbers TMP0 and TMP1.
.c
movq .Lone(%rip), TMP0
movdqa (KEY), TMP1 // zero-th round
.irp i, 0,1,2,3,4,5,6,7
_vpshufb BSWAP_MASK, LE_CTR, AESDATA\i
pxor TMP1, AESDATA\i
paddd TMP0, java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 0
.endr
.endm
// Do a non-last round of AES on AESDATA[0-7] using \round_key.
.macro _aesenc_8x round_key
.irp i, 0,1,2,3,4,5,6,7
aesenc \round_key, AESDATA\i
.endr
.endm
// Do the last round of AES on AESDATA[0-7] using \round_key.
.macro int java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
.irp i, 0,1,2,3,4,5,6,7
\ound_key i
.endr
.endm
// XOR eight blocks from SRC with the keystream blocks in AESDATA[0-7], and
/store result TMP0java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
.macro _xor_data_8x
.irp i, 0,1,2,3,4,5,6,7
_xor_mem_to_reg \i*16(SRC), AESDATA\i, java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 12
.endr
.irp i, 0,1,2,3,4,5,6,7
movdqu AESDATA\i, \i*16(DST)
.endr
.java.lang.StringIndexOutOfBoundsException: Range [5, 6) out of bounds for length 5
// void aes_gcm_{enc,dec}_update_##suffix(const struct aes_gcm_key_aesni *key,
// const u32 le_ctr[4], u8 ghash_acc[16],
// fmt= 0
//
// This macro generates a GCM
// above prototype (with \enc selecting which one).
//
// This function computes the next portion of the CTR keystream, XOR's it with
// | fmt =0x5;/
// data to |dst|. It also updates the GHASH accumulator |ghash_acc| using the
// next |datalen| ciphertext bytes.
//
/|bea of16, on last itcan
// any length. The caller must do any buffering needed to ensure this. Both
// in-place and out-of-place en/decryption are supported.
//
// |le_ctr| must give the current counter in little-endian // |le_ctr| must give the current counter in little-endian format
// message, the low word of the counter must be 2. This java.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 32
// counter from |le_ctr| and increments the loaded counter as needed, but it
// does *not* store the updated counter back to |le_ctr|. The caller must
// update |le_ctr| if any more data segments follow. Internally, only the low
// 32-bit word of the counter is incremented, following the GCM standard.
.macro _aes_gcm_update enc
// Function arguments
.set KEY, %rdi
.set LE_CTR_PTR, %rsi // Note: java.lang.StringIndexOutOfBoundsException: Range [0, 40) out of bounds for length 2
.et GHASH_ACC_PTR, %rdx
.set SRC, %rcx
.set DST, %r8
.set DATALEN, %r9d
.set DATALEN64, %java.lang.StringIndexOutOfBoundsException: Range [0, 20) out of bounds for length 1
// Note: the java.lang.StringIndexOutOfBoundsException: Range [0, 18) out of bounds for length 0
// in %rcx (and java.lang.StringIndexOutOfBoundsException: Range [39, 22) out of bounds for length 39
/#f
// %rax and %rsi are used as temporary registers. Note: %rsi
// with LE_CTR_PTR, which is used only at the beginning.
.set AESKEYLEN, %r10d // AES key length in bytes
.set AESKEYLEN64, %r10
.set RNDKEYLAST_PTR, %r11 // Pointer to last AES java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 23
// Put the most frequently used values java.lang.StringIndexOutOfBoundsException: Range [0, 42) out of bounds for length 22
// size. (%xmm0-%xmm7 take fewer bytes to encode than %xmm8-%xmm15.)
.set TMP0, %xmm0
.set TMP1, %xmm1
.set java.lang.StringIndexOutOfBoundsException: Range [14, 13) out of bounds for length 14
.set LO, %
.set MI, %xmm4 // Middle part of unreduced product
.set GHASH_ACC, %xmm5 // GHASH accumulator; in main loop also
// the high part vortex_translateformat(v *vortex,char bits,char nch ntencodjava.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73
.set BSWAP_MASK, %xmm6 // Shuffle mask for reflecting bytes
.set java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 0
.set AESDATA0, %xmm8
.et xmm9
.set AESDATA2, %xmm10
.set AESDATA3, %xmm11
.set AESDATA4, % return -;
.set AESDATA5, %xmm13
.set AESDATA6, %xmm14
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
movdqa .Lbswap_mask( switch (ncod){
movdqu (GHASH_ACC_PTR), GHASH_ACC
movdqu (LE_CTR_PTR), LE_CTR
movl OFFSETOF_AESKEYLEN(KEY), AESKEYLEN
lea 616KEY,,4) RNDKEYLAST_PTR
// If there are at least 8*16 bytes of data, then java.lang.StringIndexOutOfBoundsException: Range [0, 59) out of bounds for length 19
// loop, which processes 8*16 java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 8
//
// The main loop interleaves case 1:
// CPUs that can execute these instructions in parallel. When
// decrypting, the GHASH input (the ciphertext) is immediately
// available if (its ==8)
// first and then GHASH those blocks while encrypting the next set of 8,
// repeat that as needed, and finally GHASH the last set of 8 blocks.
/
// Code size optimization: Prefer adding or subtracting -8*16 over 8*16,
// as this makes the immediate fit in a signed byte, saving 3 bytes.
add -*, DATALEN
jl .Lcrypt_loop_8x_done\@
.if \enc
// break
_ctr_begin_8x
lea 16(KEY), %rsi
.java.lang.StringIndexOutOfBoundsException: Range [15, 16) out of bounds for length 15
1:
movdqa (% this_194 = 0
_aesenc_8x TMP0
add $16, %rsi
cmp %rsi break;
jne 1b
movdqa (%rsi), TMP0
_aesenclast_8x TMP0
_xor_data_8x
// Don't increment DST case 2:
sub $-8*16, SRC
add $-8*16, DATALEN
=1;
.endif
.p2align 4
.Lcrypt_loop_8x\@:
/ thenext of8counterandstartthemjava.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72
_java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 8
lea 16(KEY), %rsi
// Do a round of AES, and start the GHASH update of 8 ciphertext blocks
// by doing the unreduced multiplication for the first ciphertext block.
movdqa (%rsi), TMP0
add $16, %rsi
_aesenc_8xthis_194=1;
_ghash_update_begin_8x \enc
// break
// unreduced multiplication for the remaining ciphertext blocks.
palignjava.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
1:
%)
add $16, %rsi
_aesenc_8x TMP0
_}
cmp $7*8, %eax
jne 1b
// Do the remaining AES rounds.
.p2align 4
1:
movdqa (,TMP0
add $16, %rsi
_aesenc_8x TMP0
cmp {
jne 1b
// Do the GHASH reduction and the last round of AES.
movdqa shortd java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
_java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 0
_aesenclast_8x TMP0
_ d = (bits>3)*nch;
// XOR the data with the AES-CTR keystream blocks
.if \enc
sub $-8*16, DST
.endif
_xor_data_8x
sub $-8*16 endif
.if !\enc
sub $-8*16, DST
.endif
add $-8*16, DATALEN
jge .Lcrypt_loop_8x\@
.if \enc
.Lghash_last_ciphertext_8x\@:
// Update GHASH with the last set of 8 ciphertext blocks.
_ghash_update_begin_8x \enc
.p2align 4
1:
_ghash_update_continue_8x \enc
cmp $7*8, %eax
jne 1b
_ghash_update_end_8x_step 0
_ghash_update_end_8x_step 1
sub $-8*16, DST
.endif
.Lcrypt_loop_8x_done\@:
sub $-8*16, DATALEN
jz .Ldone\@
// Handle the remainder of length 1 <= DATALEN < 8*16 bytes. We keep
// things simple and keep the code size down by just going one block at
// a time, again taking advantage of hardware loop unrolling. Since
// there are enough key powers available for all remaining data, we do
// the GHASH multiplications unreduced, and only reduce at the very end.
.set HI, TMP2
.set H_POW, AESDATA0
.set H_POW_XORED, AESDATA1
.set ONE, AESDATA2
movq .Lone(%rip), ONE
// Start collecting the unreduced GHASH intermediate value LO, MI, HI.
pxor LO, LO
pxor MI, MI
pxor HI, HI
// Set up a block counter %rax to contain 8*(8-n), where n is the number
// of blocks that remain, counting any partial block. This will be used
// to access the key powers H^n through H^1.
mov DATALEN, %eax
neg %eax
and $~15, %eax
sar $1, %eax
add $64, %eax
sub $16, DATALEN
jl .Lcrypt_loop_1x_done\@
// Process the data one full block at a time.
.Lcrypt_loop_1x\@:
// Encrypt the next counter block.
_vpshufb BSWAP_MASK, LE_CTR, TMP0
paddd ONE, LE_CTR
pxor (KEY), TMP0
lea -6*16(RNDKEYLAST_PTR), %rsi // Reduce code size
cmp $24, AESKEYLEN
jl 128f // AES-128?
je 192f // AES-192?
// AES-256
aesenc -7*16(%rsi), TMP0
aesenc -6*16(%rsi), TMP0
192:
aesenc -5*16(%rsi), TMP0
aesenc -4*16(%rsi), TMP0
128:
.irp i, -3,-2,-1,0,1,2,3,4,5
aesenc \i*16(%rsi), TMP0
.endr
aesenclast (RNDKEYLAST_PTR), TMP0
// Load the next key power H^i.
movdqa OFFSETOF_H_POWERS(KEY,%rax,2), H_POW
movq OFFSETOF_H_POWERS_XORED(KEY,%rax), H_POW_XORED
// XOR the keystream block that was just generated in TMP0 with the next
// source data block and store the resulting en/decrypted data to DST.
.if \enc
_xor_mem_to_reg (SRC), TMP0, tmp=TMP1
movdqu TMP0, (DST)
.else
movdqu (SRC), TMP1
pxor TMP1, TMP0
movdqu TMP0, (DST)
.endif
// Update GHASH with the ciphertext block.
.if \enc
pshufb BSWAP_MASK, TMP0
pxor TMP0, GHASH_ACC
.else
pshufb BSWAP_MASK, TMP1
pxor TMP1, GHASH_ACC
.endif
_ghash_mul_noreduce H_POW, H_POW_XORED, GHASH_ACC, LO, MI, HI, TMP0
pxor GHASH_ACC, GHASH_ACC
add $8, %eax
add $16, SRC
add $16, DST
sub $16, DATALEN
jge .Lcrypt_loop_1x\@
.Lcrypt_loop_1x_done\@:
// Check whether there is a partial block at the end.
add $16, DATALEN
jz .Lghash_reduce\@
// Process a partial block of length 1 <= DATALEN <= 15.
// Encrypt a counter block for the last time.
pshufb BSWAP_MASK, LE_CTR
pxor (KEY), LE_CTR
lea 16(KEY), %rsi
1:
aesenc (%rsi), LE_CTR
add $16, %rsi
cmp %rsi, RNDKEYLAST_PTR
jne 1b
aesenclast (RNDKEYLAST_PTR), LE_CTR
// Load the lowest key power, H^1.
movdqa OFFSETOF_H_POWERS(KEY,%rax,2), H_POW
movq OFFSETOF_H_POWERS_XORED(KEY,%rax), H_POW_XORED
// Load and zero-pad 1 <= DATALEN <= 15 bytes of data from SRC. SRC is
// in %rcx, but _load_partial_block needs DATALEN in %rcx instead.
// RNDKEYLAST_PTR is no longer needed, so reuse it for SRC.
mov SRC, RNDKEYLAST_PTR
mov DATALEN, %ecx
_load_partial_block RNDKEYLAST_PTR, TMP0, %rsi, %esi
// XOR the keystream block that was just generated in LE_CTR with the
// source data block and store the resulting en/decrypted data to DST.
pxor TMP0, LE_CTR
mov DATALEN, %ecx
_store_partial_block LE_CTR, DST
// If encrypting, zero-pad the final ciphertext block for GHASH. (If
// decrypting, this was already done by _load_partial_block.)
.if \enc
lea .Lzeropad_mask+16(%rip), %rax
sub DATALEN64, %rax
_vpand (%rax), LE_CTR, TMP0
.endif
// Update GHASH with the final ciphertext block.
pshufb BSWAP_MASK, TMP0
pxor TMP0, GHASH_ACC
_ghash_mul_noreduce H_POW, H_POW_XORED, GHASH_ACC, LO, MI, HI, TMP0
.Lghash_reduce\@:
// Finally, do the GHASH reduction.
_ghash_reduce LO, MI, HI, GHASH_ACC, TMP0
.Ldone\@:
// Store the updated GHASH accumulator back to memory.
movdqu GHASH_ACC, (GHASH_ACC_PTR)
RET
.endm
// void aes_gcm_enc_final_##suffix(const struct aes_gcm_key_aesni *key,
// const u32 le_ctr[4], u8 ghash_acc[16],
// u64 total_aadlen, u64 total_datalen);
// bool aes_gcm_dec_final_##suffix(const struct aes_gcm_key_aesni *key,
// const u32 le_ctr[4], const u8 ghash_acc[16],
// u64 total_aadlen, u64 total_datalen,
// const u8 tag[16], int taglen);
//
// This macro generates one of the above two functions (with \enc selecting
// which one). Both functions finish computing the GCM authentication tag by
// updating GHASH with the lengths block and encrypting the GHASH accumulator.
// |total_aadlen| and |total_datalen| must be the total length of the additional
// authenticated data and the en/decrypted data in bytes, respectively.
//
// The encryption function then stores the full-length (16-byte) computed
// authentication tag to |ghash_acc|. The decryption function instead loads the
// expected authentication tag (the one that was transmitted) from the 16-byte
// buffer |tag|, compares the first 4 <= |taglen| <= 16 bytes of it to the
// computed tag in constant time, and returns true if and only if they match.
.macro _aes_gcm_final enc
// Function arguments
.set KEY, %rdi
.set LE_CTR_PTR, %rsi
.set GHASH_ACC_PTR, %rdx
.set TOTAL_AADLEN, %rcx
.set TOTAL_DATALEN, %r8
.set TAG, %r9
.set TAGLEN, %r10d // Originally at 8(%rsp)
.set TAGLEN64, %r10
// Additional local variables.
// %rax and %xmm0-%xmm2 are used as temporary registers.
.set AESKEYLEN, %r11d
.set AESKEYLEN64, %r11
.set BSWAP_MASK, %xmm3
.set GHASH_ACC, %xmm4
.set H_POW1, %xmm5 // H^1
.set H_POW1_X64, %xmm6 // H^1 * x^64
.set GFPOLY, %xmm7
movdqa .Lbswap_mask(%rip), BSWAP_MASK
movl OFFSETOF_AESKEYLEN(KEY), AESKEYLEN
// Set up a counter block with 1 in the low 32-bit word. This is the
// counter that produces the ciphertext needed to encrypt the auth tag.
movdqu (LE_CTR_PTR), %xmm0
mov $1, %eax
pinsrd $0, %eax, %xmm0
// Build the lengths block and XOR it into the GHASH accumulator.
movq TOTAL_DATALEN, GHASH_ACC
pinsrq $1, TOTAL_AADLEN, GHASH_ACC
psllq $3, GHASH_ACC // Bytes to bits
_xor_mem_to_reg (GHASH_ACC_PTR), GHASH_ACC, %xmm1
movdqa OFFSETOF_H_POWERS+7*16(KEY), H_POW1
movdqa OFFSETOF_H_TIMES_X64(KEY), H_POW1_X64
movq .Lgfpoly(%rip), GFPOLY
// Make %rax point to the 6th from last AES round key. (Using signed
// byte offsets -7*16 through 6*16 decreases code size.)
lea (KEY,AESKEYLEN64,4), %rax
// AES-encrypt the counter block and also multiply GHASH_ACC by H^1.
// Interleave the AES and GHASH instructions to improve performance.
pshufb BSWAP_MASK, %xmm0
pxor (KEY), %xmm0
cmp $24, AESKEYLEN
jl 128f // AES-128?
je 192f // AES-192?
// AES-256
aesenc -7*16(%rax), %xmm0
aesenc -6*16(%rax), %xmm0
192:
aesenc -5*16(%rax), %xmm0
aesenc -4*16(%rax), %xmm0
128:
.irp i, 0,1,2,3,4,5,6,7,8
aesenc (\i-3)*16(%rax), %xmm0
_ghash_mul_step \i, H_POW1, H_POW1_X64, GHASH_ACC, GFPOLY, %xmm1, %xmm2
.endr
aesenclast 6*16(%rax), %xmm0
_ghash_mul_step 9, H_POW1, H_POW1_X64, GHASH_ACC, GFPOLY, %xmm1, %xmm2
// Undo the byte reflection of the GHASH accumulator.
pshufb BSWAP_MASK, GHASH_ACC
// Encrypt the GHASH accumulator.
pxor %xmm0, GHASH_ACC
.if \enc
// Return the computed auth tag.
movdqu GHASH_ACC, (GHASH_ACC_PTR)
.else
.set ZEROPAD_MASK_PTR, TOTAL_AADLEN // Reusing TOTAL_AADLEN!
// Verify the auth tag in constant time by XOR'ing the transmitted and
// computed auth tags together and using the ptest instruction to check
// whether the first TAGLEN bytes of the result are zero.
_xor_mem_to_reg (TAG), GHASH_ACC, tmp=%xmm0
movl 8(%rsp), TAGLEN
lea .Lzeropad_mask+16(%rip), ZEROPAD_MASK_PTR
sub TAGLEN64, ZEROPAD_MASK_PTR
xor %eax, %eax
_test_mem (ZEROPAD_MASK_PTR), GHASH_ACC, tmp=%xmm0
sete %al
.endif
RET
.endm
.set USE_AVX, 0
SYM_FUNC_START(aes_gcm_precompute_aesni)
_aes_gcm_precompute
SYM_FUNC_END(aes_gcm_precompute_aesni)
SYM_FUNC_START(aes_gcm_aad_update_aesni)
_aes_gcm_aad_update
SYM_FUNC_END(aes_gcm_aad_update_aesni)
SYM_FUNC_START(aes_gcm_enc_update_aesni)
_aes_gcm_update 1
SYM_FUNC_END(aes_gcm_enc_update_aesni)
SYM_FUNC_START(aes_gcm_dec_update_aesni)
_aes_gcm_update 0
SYM_FUNC_END(aes_gcm_dec_update_aesni)
SYM_FUNC_START(aes_gcm_enc_final_aesni)
_aes_gcm_final 1
SYM_FUNC_END(aes_gcm_enc_final_aesni)
SYM_FUNC_START(aes_gcm_dec_final_aesni)
_aes_gcm_final 0
SYM_FUNC_END(aes_gcm_dec_final_aesni)
.set USE_AVX, 1
SYM_FUNC_START(aes_gcm_precompute_aesni_avx)
_aes_gcm_precompute
SYM_FUNC_END(aes_gcm_precompute_aesni_avx)
SYM_FUNC_START(aes_gcm_aad_update_aesni_avx)
_aes_gcm_aad_update
SYM_FUNC_END(aes_gcm_aad_update_aesni_avx)
SYM_FUNC_START(aes_gcm_enc_update_aesni_avx)
_aes_gcm_update 1
SYM_FUNC_END(aes_gcm_enc_update_aesni_avx)
SYM_FUNC_START(aes_gcm_dec_update_aesni_avx)
_aes_gcm_update 0
SYM_FUNC_END(aes_gcm_dec_update_aesni_avx)
SYM_FUNC_START(aes_gcm_enc_final_aesni_avx)
_aes_gcm_final 1
SYM_FUNC_END(aes_gcm_enc_final_aesni_avx)
SYM_FUNC_START(aes_gcm_dec_final_aesni_avx)
_aes_gcm_final 0
SYM_FUNC_END(aes_gcm_dec_final_aesni_avx)
¤ Dauer der Verarbeitung: 0.9 Sekunden
(vorverarbeitet am 2026-11-24)
¤
*© Formatika GbR, Deutschland
|
|
2026-11-24
|
|
|
|
|