162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * Intel SHA Extensions optimized implementation of a SHA-256 update function
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * This file is provided under a dual BSD/GPLv2 license.  When using or
562306a36Sopenharmony_ci * redistributing this file, you may do so under either license.
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * GPL LICENSE SUMMARY
862306a36Sopenharmony_ci *
962306a36Sopenharmony_ci * Copyright(c) 2015 Intel Corporation.
1062306a36Sopenharmony_ci *
1162306a36Sopenharmony_ci * This program is free software; you can redistribute it and/or modify
1262306a36Sopenharmony_ci * it under the terms of version 2 of the GNU General Public License as
1362306a36Sopenharmony_ci * published by the Free Software Foundation.
1462306a36Sopenharmony_ci *
1562306a36Sopenharmony_ci * This program is distributed in the hope that it will be useful, but
1662306a36Sopenharmony_ci * WITHOUT ANY WARRANTY; without even the implied warranty of
1762306a36Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1862306a36Sopenharmony_ci * General Public License for more details.
1962306a36Sopenharmony_ci *
2062306a36Sopenharmony_ci * Contact Information:
2162306a36Sopenharmony_ci * 	Sean Gulley <sean.m.gulley@intel.com>
2262306a36Sopenharmony_ci * 	Tim Chen <tim.c.chen@linux.intel.com>
2362306a36Sopenharmony_ci *
2462306a36Sopenharmony_ci * BSD LICENSE
2562306a36Sopenharmony_ci *
2662306a36Sopenharmony_ci * Copyright(c) 2015 Intel Corporation.
2762306a36Sopenharmony_ci *
2862306a36Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
2962306a36Sopenharmony_ci * modification, are permitted provided that the following conditions
3062306a36Sopenharmony_ci * are met:
3162306a36Sopenharmony_ci *
3262306a36Sopenharmony_ci * 	* Redistributions of source code must retain the above copyright
3362306a36Sopenharmony_ci * 	  notice, this list of conditions and the following disclaimer.
3462306a36Sopenharmony_ci * 	* Redistributions in binary form must reproduce the above copyright
3562306a36Sopenharmony_ci * 	  notice, this list of conditions and the following disclaimer in
3662306a36Sopenharmony_ci * 	  the documentation and/or other materials provided with the
3762306a36Sopenharmony_ci * 	  distribution.
3862306a36Sopenharmony_ci * 	* Neither the name of Intel Corporation nor the names of its
3962306a36Sopenharmony_ci * 	  contributors may be used to endorse or promote products derived
4062306a36Sopenharmony_ci * 	  from this software without specific prior written permission.
4162306a36Sopenharmony_ci *
4262306a36Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4362306a36Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
4462306a36Sopenharmony_ci * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
4562306a36Sopenharmony_ci * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
4662306a36Sopenharmony_ci * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
4762306a36Sopenharmony_ci * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
4862306a36Sopenharmony_ci * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
4962306a36Sopenharmony_ci * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
5062306a36Sopenharmony_ci * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
5162306a36Sopenharmony_ci * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
5262306a36Sopenharmony_ci * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5362306a36Sopenharmony_ci *
5462306a36Sopenharmony_ci */
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ci#include <linux/linkage.h>
5762306a36Sopenharmony_ci#include <linux/cfi_types.h>
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci#define DIGEST_PTR	%rdi	/* 1st arg */
6062306a36Sopenharmony_ci#define DATA_PTR	%rsi	/* 2nd arg */
6162306a36Sopenharmony_ci#define NUM_BLKS	%rdx	/* 3rd arg */
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci#define SHA256CONSTANTS	%rax
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci#define MSG		%xmm0
6662306a36Sopenharmony_ci#define STATE0		%xmm1
6762306a36Sopenharmony_ci#define STATE1		%xmm2
6862306a36Sopenharmony_ci#define MSGTMP0		%xmm3
6962306a36Sopenharmony_ci#define MSGTMP1		%xmm4
7062306a36Sopenharmony_ci#define MSGTMP2		%xmm5
7162306a36Sopenharmony_ci#define MSGTMP3		%xmm6
7262306a36Sopenharmony_ci#define MSGTMP4		%xmm7
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci#define SHUF_MASK	%xmm8
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_ci#define ABEF_SAVE	%xmm9
7762306a36Sopenharmony_ci#define CDGH_SAVE	%xmm10
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_ci/*
8062306a36Sopenharmony_ci * Intel SHA Extensions optimized implementation of a SHA-256 update function
8162306a36Sopenharmony_ci *
8262306a36Sopenharmony_ci * The function takes a pointer to the current hash values, a pointer to the
8362306a36Sopenharmony_ci * input data, and a number of 64 byte blocks to process.  Once all blocks have
8462306a36Sopenharmony_ci * been processed, the digest pointer is  updated with the resulting hash value.
8562306a36Sopenharmony_ci * The function only processes complete blocks, there is no functionality to
8662306a36Sopenharmony_ci * store partial blocks.  All message padding and hash value initialization must
8762306a36Sopenharmony_ci * be done outside the update function.
8862306a36Sopenharmony_ci *
8962306a36Sopenharmony_ci * The indented lines in the loop are instructions related to rounds processing.
9062306a36Sopenharmony_ci * The non-indented lines are instructions related to the message schedule.
9162306a36Sopenharmony_ci *
9262306a36Sopenharmony_ci * void sha256_ni_transform(uint32_t *digest, const void *data,
9362306a36Sopenharmony_ci		uint32_t numBlocks);
9462306a36Sopenharmony_ci * digest : pointer to digest
9562306a36Sopenharmony_ci * data: pointer to input data
9662306a36Sopenharmony_ci * numBlocks: Number of blocks to process
9762306a36Sopenharmony_ci */
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ci.text
10062306a36Sopenharmony_ciSYM_TYPED_FUNC_START(sha256_ni_transform)
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_ci	shl		$6, NUM_BLKS		/*  convert to bytes */
10362306a36Sopenharmony_ci	jz		.Ldone_hash
10462306a36Sopenharmony_ci	add		DATA_PTR, NUM_BLKS	/* pointer to end of data */
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_ci	/*
10762306a36Sopenharmony_ci	 * load initial hash values
10862306a36Sopenharmony_ci	 * Need to reorder these appropriately
10962306a36Sopenharmony_ci	 * DCBA, HGFE -> ABEF, CDGH
11062306a36Sopenharmony_ci	 */
11162306a36Sopenharmony_ci	movdqu		0*16(DIGEST_PTR), STATE0
11262306a36Sopenharmony_ci	movdqu		1*16(DIGEST_PTR), STATE1
11362306a36Sopenharmony_ci
11462306a36Sopenharmony_ci	pshufd		$0xB1, STATE0,  STATE0		/* CDAB */
11562306a36Sopenharmony_ci	pshufd		$0x1B, STATE1,  STATE1		/* EFGH */
11662306a36Sopenharmony_ci	movdqa		STATE0, MSGTMP4
11762306a36Sopenharmony_ci	palignr		$8, STATE1,  STATE0		/* ABEF */
11862306a36Sopenharmony_ci	pblendw		$0xF0, MSGTMP4, STATE1		/* CDGH */
11962306a36Sopenharmony_ci
12062306a36Sopenharmony_ci	movdqa		PSHUFFLE_BYTE_FLIP_MASK(%rip), SHUF_MASK
12162306a36Sopenharmony_ci	lea		K256(%rip), SHA256CONSTANTS
12262306a36Sopenharmony_ci
12362306a36Sopenharmony_ci.Lloop0:
12462306a36Sopenharmony_ci	/* Save hash values for addition after rounds */
12562306a36Sopenharmony_ci	movdqa		STATE0, ABEF_SAVE
12662306a36Sopenharmony_ci	movdqa		STATE1, CDGH_SAVE
12762306a36Sopenharmony_ci
12862306a36Sopenharmony_ci	/* Rounds 0-3 */
12962306a36Sopenharmony_ci	movdqu		0*16(DATA_PTR), MSG
13062306a36Sopenharmony_ci	pshufb		SHUF_MASK, MSG
13162306a36Sopenharmony_ci	movdqa		MSG, MSGTMP0
13262306a36Sopenharmony_ci		paddd		0*16(SHA256CONSTANTS), MSG
13362306a36Sopenharmony_ci		sha256rnds2	STATE0, STATE1
13462306a36Sopenharmony_ci		pshufd 		$0x0E, MSG, MSG
13562306a36Sopenharmony_ci		sha256rnds2	STATE1, STATE0
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_ci	/* Rounds 4-7 */
13862306a36Sopenharmony_ci	movdqu		1*16(DATA_PTR), MSG
13962306a36Sopenharmony_ci	pshufb		SHUF_MASK, MSG
14062306a36Sopenharmony_ci	movdqa		MSG, MSGTMP1
14162306a36Sopenharmony_ci		paddd		1*16(SHA256CONSTANTS), MSG
14262306a36Sopenharmony_ci		sha256rnds2	STATE0, STATE1
14362306a36Sopenharmony_ci		pshufd 		$0x0E, MSG, MSG
14462306a36Sopenharmony_ci		sha256rnds2	STATE1, STATE0
14562306a36Sopenharmony_ci	sha256msg1	MSGTMP1, MSGTMP0
14662306a36Sopenharmony_ci
14762306a36Sopenharmony_ci	/* Rounds 8-11 */
14862306a36Sopenharmony_ci	movdqu		2*16(DATA_PTR), MSG
14962306a36Sopenharmony_ci	pshufb		SHUF_MASK, MSG
15062306a36Sopenharmony_ci	movdqa		MSG, MSGTMP2
15162306a36Sopenharmony_ci		paddd		2*16(SHA256CONSTANTS), MSG
15262306a36Sopenharmony_ci		sha256rnds2	STATE0, STATE1
15362306a36Sopenharmony_ci		pshufd 		$0x0E, MSG, MSG
15462306a36Sopenharmony_ci		sha256rnds2	STATE1, STATE0
15562306a36Sopenharmony_ci	sha256msg1	MSGTMP2, MSGTMP1
15662306a36Sopenharmony_ci
15762306a36Sopenharmony_ci	/* Rounds 12-15 */
15862306a36Sopenharmony_ci	movdqu		3*16(DATA_PTR), MSG
15962306a36Sopenharmony_ci	pshufb		SHUF_MASK, MSG
16062306a36Sopenharmony_ci	movdqa		MSG, MSGTMP3
16162306a36Sopenharmony_ci		paddd		3*16(SHA256CONSTANTS), MSG
16262306a36Sopenharmony_ci		sha256rnds2	STATE0, STATE1
16362306a36Sopenharmony_ci	movdqa		MSGTMP3, MSGTMP4
16462306a36Sopenharmony_ci	palignr		$4, MSGTMP2, MSGTMP4
16562306a36Sopenharmony_ci	paddd		MSGTMP4, MSGTMP0
16662306a36Sopenharmony_ci	sha256msg2	MSGTMP3, MSGTMP0
16762306a36Sopenharmony_ci		pshufd 		$0x0E, MSG, MSG
16862306a36Sopenharmony_ci		sha256rnds2	STATE1, STATE0
16962306a36Sopenharmony_ci	sha256msg1	MSGTMP3, MSGTMP2
17062306a36Sopenharmony_ci
17162306a36Sopenharmony_ci	/* Rounds 16-19 */
17262306a36Sopenharmony_ci	movdqa		MSGTMP0, MSG
17362306a36Sopenharmony_ci		paddd		4*16(SHA256CONSTANTS), MSG
17462306a36Sopenharmony_ci		sha256rnds2	STATE0, STATE1
17562306a36Sopenharmony_ci	movdqa		MSGTMP0, MSGTMP4
17662306a36Sopenharmony_ci	palignr		$4, MSGTMP3, MSGTMP4
17762306a36Sopenharmony_ci	paddd		MSGTMP4, MSGTMP1
17862306a36Sopenharmony_ci	sha256msg2	MSGTMP0, MSGTMP1
17962306a36Sopenharmony_ci		pshufd 		$0x0E, MSG, MSG
18062306a36Sopenharmony_ci		sha256rnds2	STATE1, STATE0
18162306a36Sopenharmony_ci	sha256msg1	MSGTMP0, MSGTMP3
18262306a36Sopenharmony_ci
18362306a36Sopenharmony_ci	/* Rounds 20-23 */
18462306a36Sopenharmony_ci	movdqa		MSGTMP1, MSG
18562306a36Sopenharmony_ci		paddd		5*16(SHA256CONSTANTS), MSG
18662306a36Sopenharmony_ci		sha256rnds2	STATE0, STATE1
18762306a36Sopenharmony_ci	movdqa		MSGTMP1, MSGTMP4
18862306a36Sopenharmony_ci	palignr		$4, MSGTMP0, MSGTMP4
18962306a36Sopenharmony_ci	paddd		MSGTMP4, MSGTMP2
19062306a36Sopenharmony_ci	sha256msg2	MSGTMP1, MSGTMP2
19162306a36Sopenharmony_ci		pshufd 		$0x0E, MSG, MSG
19262306a36Sopenharmony_ci		sha256rnds2	STATE1, STATE0
19362306a36Sopenharmony_ci	sha256msg1	MSGTMP1, MSGTMP0
19462306a36Sopenharmony_ci
19562306a36Sopenharmony_ci	/* Rounds 24-27 */
19662306a36Sopenharmony_ci	movdqa		MSGTMP2, MSG
19762306a36Sopenharmony_ci		paddd		6*16(SHA256CONSTANTS), MSG
19862306a36Sopenharmony_ci		sha256rnds2	STATE0, STATE1
19962306a36Sopenharmony_ci	movdqa		MSGTMP2, MSGTMP4
20062306a36Sopenharmony_ci	palignr		$4, MSGTMP1, MSGTMP4
20162306a36Sopenharmony_ci	paddd		MSGTMP4, MSGTMP3
20262306a36Sopenharmony_ci	sha256msg2	MSGTMP2, MSGTMP3
20362306a36Sopenharmony_ci		pshufd 		$0x0E, MSG, MSG
20462306a36Sopenharmony_ci		sha256rnds2	STATE1, STATE0
20562306a36Sopenharmony_ci	sha256msg1	MSGTMP2, MSGTMP1
20662306a36Sopenharmony_ci
20762306a36Sopenharmony_ci	/* Rounds 28-31 */
20862306a36Sopenharmony_ci	movdqa		MSGTMP3, MSG
20962306a36Sopenharmony_ci		paddd		7*16(SHA256CONSTANTS), MSG
21062306a36Sopenharmony_ci		sha256rnds2	STATE0, STATE1
21162306a36Sopenharmony_ci	movdqa		MSGTMP3, MSGTMP4
21262306a36Sopenharmony_ci	palignr		$4, MSGTMP2, MSGTMP4
21362306a36Sopenharmony_ci	paddd		MSGTMP4, MSGTMP0
21462306a36Sopenharmony_ci	sha256msg2	MSGTMP3, MSGTMP0
21562306a36Sopenharmony_ci		pshufd 		$0x0E, MSG, MSG
21662306a36Sopenharmony_ci		sha256rnds2	STATE1, STATE0
21762306a36Sopenharmony_ci	sha256msg1	MSGTMP3, MSGTMP2
21862306a36Sopenharmony_ci
21962306a36Sopenharmony_ci	/* Rounds 32-35 */
22062306a36Sopenharmony_ci	movdqa		MSGTMP0, MSG
22162306a36Sopenharmony_ci		paddd		8*16(SHA256CONSTANTS), MSG
22262306a36Sopenharmony_ci		sha256rnds2	STATE0, STATE1
22362306a36Sopenharmony_ci	movdqa		MSGTMP0, MSGTMP4
22462306a36Sopenharmony_ci	palignr		$4, MSGTMP3, MSGTMP4
22562306a36Sopenharmony_ci	paddd		MSGTMP4, MSGTMP1
22662306a36Sopenharmony_ci	sha256msg2	MSGTMP0, MSGTMP1
22762306a36Sopenharmony_ci		pshufd 		$0x0E, MSG, MSG
22862306a36Sopenharmony_ci		sha256rnds2	STATE1, STATE0
22962306a36Sopenharmony_ci	sha256msg1	MSGTMP0, MSGTMP3
23062306a36Sopenharmony_ci
23162306a36Sopenharmony_ci	/* Rounds 36-39 */
23262306a36Sopenharmony_ci	movdqa		MSGTMP1, MSG
23362306a36Sopenharmony_ci		paddd		9*16(SHA256CONSTANTS), MSG
23462306a36Sopenharmony_ci		sha256rnds2	STATE0, STATE1
23562306a36Sopenharmony_ci	movdqa		MSGTMP1, MSGTMP4
23662306a36Sopenharmony_ci	palignr		$4, MSGTMP0, MSGTMP4
23762306a36Sopenharmony_ci	paddd		MSGTMP4, MSGTMP2
23862306a36Sopenharmony_ci	sha256msg2	MSGTMP1, MSGTMP2
23962306a36Sopenharmony_ci		pshufd 		$0x0E, MSG, MSG
24062306a36Sopenharmony_ci		sha256rnds2	STATE1, STATE0
24162306a36Sopenharmony_ci	sha256msg1	MSGTMP1, MSGTMP0
24262306a36Sopenharmony_ci
24362306a36Sopenharmony_ci	/* Rounds 40-43 */
24462306a36Sopenharmony_ci	movdqa		MSGTMP2, MSG
24562306a36Sopenharmony_ci		paddd		10*16(SHA256CONSTANTS), MSG
24662306a36Sopenharmony_ci		sha256rnds2	STATE0, STATE1
24762306a36Sopenharmony_ci	movdqa		MSGTMP2, MSGTMP4
24862306a36Sopenharmony_ci	palignr		$4, MSGTMP1, MSGTMP4
24962306a36Sopenharmony_ci	paddd		MSGTMP4, MSGTMP3
25062306a36Sopenharmony_ci	sha256msg2	MSGTMP2, MSGTMP3
25162306a36Sopenharmony_ci		pshufd 		$0x0E, MSG, MSG
25262306a36Sopenharmony_ci		sha256rnds2	STATE1, STATE0
25362306a36Sopenharmony_ci	sha256msg1	MSGTMP2, MSGTMP1
25462306a36Sopenharmony_ci
25562306a36Sopenharmony_ci	/* Rounds 44-47 */
25662306a36Sopenharmony_ci	movdqa		MSGTMP3, MSG
25762306a36Sopenharmony_ci		paddd		11*16(SHA256CONSTANTS), MSG
25862306a36Sopenharmony_ci		sha256rnds2	STATE0, STATE1
25962306a36Sopenharmony_ci	movdqa		MSGTMP3, MSGTMP4
26062306a36Sopenharmony_ci	palignr		$4, MSGTMP2, MSGTMP4
26162306a36Sopenharmony_ci	paddd		MSGTMP4, MSGTMP0
26262306a36Sopenharmony_ci	sha256msg2	MSGTMP3, MSGTMP0
26362306a36Sopenharmony_ci		pshufd 		$0x0E, MSG, MSG
26462306a36Sopenharmony_ci		sha256rnds2	STATE1, STATE0
26562306a36Sopenharmony_ci	sha256msg1	MSGTMP3, MSGTMP2
26662306a36Sopenharmony_ci
26762306a36Sopenharmony_ci	/* Rounds 48-51 */
26862306a36Sopenharmony_ci	movdqa		MSGTMP0, MSG
26962306a36Sopenharmony_ci		paddd		12*16(SHA256CONSTANTS), MSG
27062306a36Sopenharmony_ci		sha256rnds2	STATE0, STATE1
27162306a36Sopenharmony_ci	movdqa		MSGTMP0, MSGTMP4
27262306a36Sopenharmony_ci	palignr		$4, MSGTMP3, MSGTMP4
27362306a36Sopenharmony_ci	paddd		MSGTMP4, MSGTMP1
27462306a36Sopenharmony_ci	sha256msg2	MSGTMP0, MSGTMP1
27562306a36Sopenharmony_ci		pshufd 		$0x0E, MSG, MSG
27662306a36Sopenharmony_ci		sha256rnds2	STATE1, STATE0
27762306a36Sopenharmony_ci	sha256msg1	MSGTMP0, MSGTMP3
27862306a36Sopenharmony_ci
27962306a36Sopenharmony_ci	/* Rounds 52-55 */
28062306a36Sopenharmony_ci	movdqa		MSGTMP1, MSG
28162306a36Sopenharmony_ci		paddd		13*16(SHA256CONSTANTS), MSG
28262306a36Sopenharmony_ci		sha256rnds2	STATE0, STATE1
28362306a36Sopenharmony_ci	movdqa		MSGTMP1, MSGTMP4
28462306a36Sopenharmony_ci	palignr		$4, MSGTMP0, MSGTMP4
28562306a36Sopenharmony_ci	paddd		MSGTMP4, MSGTMP2
28662306a36Sopenharmony_ci	sha256msg2	MSGTMP1, MSGTMP2
28762306a36Sopenharmony_ci		pshufd 		$0x0E, MSG, MSG
28862306a36Sopenharmony_ci		sha256rnds2	STATE1, STATE0
28962306a36Sopenharmony_ci
29062306a36Sopenharmony_ci	/* Rounds 56-59 */
29162306a36Sopenharmony_ci	movdqa		MSGTMP2, MSG
29262306a36Sopenharmony_ci		paddd		14*16(SHA256CONSTANTS), MSG
29362306a36Sopenharmony_ci		sha256rnds2	STATE0, STATE1
29462306a36Sopenharmony_ci	movdqa		MSGTMP2, MSGTMP4
29562306a36Sopenharmony_ci	palignr		$4, MSGTMP1, MSGTMP4
29662306a36Sopenharmony_ci	paddd		MSGTMP4, MSGTMP3
29762306a36Sopenharmony_ci	sha256msg2	MSGTMP2, MSGTMP3
29862306a36Sopenharmony_ci		pshufd 		$0x0E, MSG, MSG
29962306a36Sopenharmony_ci		sha256rnds2	STATE1, STATE0
30062306a36Sopenharmony_ci
30162306a36Sopenharmony_ci	/* Rounds 60-63 */
30262306a36Sopenharmony_ci	movdqa		MSGTMP3, MSG
30362306a36Sopenharmony_ci		paddd		15*16(SHA256CONSTANTS), MSG
30462306a36Sopenharmony_ci		sha256rnds2	STATE0, STATE1
30562306a36Sopenharmony_ci		pshufd 		$0x0E, MSG, MSG
30662306a36Sopenharmony_ci		sha256rnds2	STATE1, STATE0
30762306a36Sopenharmony_ci
30862306a36Sopenharmony_ci	/* Add current hash values with previously saved */
30962306a36Sopenharmony_ci	paddd		ABEF_SAVE, STATE0
31062306a36Sopenharmony_ci	paddd		CDGH_SAVE, STATE1
31162306a36Sopenharmony_ci
31262306a36Sopenharmony_ci	/* Increment data pointer and loop if more to process */
31362306a36Sopenharmony_ci	add		$64, DATA_PTR
31462306a36Sopenharmony_ci	cmp		NUM_BLKS, DATA_PTR
31562306a36Sopenharmony_ci	jne		.Lloop0
31662306a36Sopenharmony_ci
31762306a36Sopenharmony_ci	/* Write hash values back in the correct order */
31862306a36Sopenharmony_ci	pshufd		$0x1B, STATE0,  STATE0		/* FEBA */
31962306a36Sopenharmony_ci	pshufd		$0xB1, STATE1,  STATE1		/* DCHG */
32062306a36Sopenharmony_ci	movdqa		STATE0, MSGTMP4
32162306a36Sopenharmony_ci	pblendw		$0xF0, STATE1,  STATE0		/* DCBA */
32262306a36Sopenharmony_ci	palignr		$8, MSGTMP4, STATE1		/* HGFE */
32362306a36Sopenharmony_ci
32462306a36Sopenharmony_ci	movdqu		STATE0, 0*16(DIGEST_PTR)
32562306a36Sopenharmony_ci	movdqu		STATE1, 1*16(DIGEST_PTR)
32662306a36Sopenharmony_ci
32762306a36Sopenharmony_ci.Ldone_hash:
32862306a36Sopenharmony_ci
32962306a36Sopenharmony_ci	RET
33062306a36Sopenharmony_ciSYM_FUNC_END(sha256_ni_transform)
33162306a36Sopenharmony_ci
33262306a36Sopenharmony_ci.section	.rodata.cst256.K256, "aM", @progbits, 256
33362306a36Sopenharmony_ci.align 64
33462306a36Sopenharmony_ciK256:
33562306a36Sopenharmony_ci	.long	0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5
33662306a36Sopenharmony_ci	.long	0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5
33762306a36Sopenharmony_ci	.long	0xd807aa98,0x12835b01,0x243185be,0x550c7dc3
33862306a36Sopenharmony_ci	.long	0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174
33962306a36Sopenharmony_ci	.long	0xe49b69c1,0xefbe4786,0x0fc19dc6,0x240ca1cc
34062306a36Sopenharmony_ci	.long	0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da
34162306a36Sopenharmony_ci	.long	0x983e5152,0xa831c66d,0xb00327c8,0xbf597fc7
34262306a36Sopenharmony_ci	.long	0xc6e00bf3,0xd5a79147,0x06ca6351,0x14292967
34362306a36Sopenharmony_ci	.long	0x27b70a85,0x2e1b2138,0x4d2c6dfc,0x53380d13
34462306a36Sopenharmony_ci	.long	0x650a7354,0x766a0abb,0x81c2c92e,0x92722c85
34562306a36Sopenharmony_ci	.long	0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3
34662306a36Sopenharmony_ci	.long	0xd192e819,0xd6990624,0xf40e3585,0x106aa070
34762306a36Sopenharmony_ci	.long	0x19a4c116,0x1e376c08,0x2748774c,0x34b0bcb5
34862306a36Sopenharmony_ci	.long	0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3
34962306a36Sopenharmony_ci	.long	0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208
35062306a36Sopenharmony_ci	.long	0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2
35162306a36Sopenharmony_ci
35262306a36Sopenharmony_ci.section	.rodata.cst16.PSHUFFLE_BYTE_FLIP_MASK, "aM", @progbits, 16
35362306a36Sopenharmony_ci.align 16
35462306a36Sopenharmony_ciPSHUFFLE_BYTE_FLIP_MASK:
35562306a36Sopenharmony_ci	.octa 0x0c0d0e0f08090a0b0405060700010203
356