1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Glue code for the SHA256 Secure Hash Algorithm assembly implementation
4 * using NEON instructions.
6 * Copyright © 2015 Google Inc.
8 * This file is based on sha512_neon_glue.c:
9 * Copyright © 2014 Jussi Kivilinna <jussi.kivilinna@iki.fi>
12 #include <crypto/internal/hash.h>
13 #include <crypto/internal/simd.h>
14 #include <linux/types.h>
15 #include <linux/string.h>
16 #include <crypto/sha2.h>
17 #include <crypto/sha256_base.h>
18 #include <asm/byteorder.h>
22 #include "sha256_glue.h"
24 asmlinkage
void sha256_block_data_order_neon(struct sha256_state
*digest
,
25 const u8
*data
, int num_blks
);
27 static int crypto_sha256_neon_update(struct shash_desc
*desc
, const u8
*data
,
30 struct sha256_state
*sctx
= shash_desc_ctx(desc
);
32 if (!crypto_simd_usable() ||
33 (sctx
->count
% SHA256_BLOCK_SIZE
) + len
< SHA256_BLOCK_SIZE
)
34 return crypto_sha256_arm_update(desc
, data
, len
);
37 sha256_base_do_update(desc
, data
, len
, sha256_block_data_order_neon
);
43 static int crypto_sha256_neon_finup(struct shash_desc
*desc
, const u8
*data
,
44 unsigned int len
, u8
*out
)
46 if (!crypto_simd_usable())
47 return crypto_sha256_arm_finup(desc
, data
, len
, out
);
51 sha256_base_do_update(desc
, data
, len
,
52 sha256_block_data_order_neon
);
53 sha256_base_do_finalize(desc
, sha256_block_data_order_neon
);
56 return sha256_base_finish(desc
, out
);
59 static int crypto_sha256_neon_final(struct shash_desc
*desc
, u8
*out
)
61 return crypto_sha256_neon_finup(desc
, NULL
, 0, out
);
64 struct shash_alg sha256_neon_algs
[] = { {
65 .digestsize
= SHA256_DIGEST_SIZE
,
66 .init
= sha256_base_init
,
67 .update
= crypto_sha256_neon_update
,
68 .final
= crypto_sha256_neon_final
,
69 .finup
= crypto_sha256_neon_finup
,
70 .descsize
= sizeof(struct sha256_state
),
73 .cra_driver_name
= "sha256-neon",
75 .cra_blocksize
= SHA256_BLOCK_SIZE
,
76 .cra_module
= THIS_MODULE
,
79 .digestsize
= SHA224_DIGEST_SIZE
,
80 .init
= sha224_base_init
,
81 .update
= crypto_sha256_neon_update
,
82 .final
= crypto_sha256_neon_final
,
83 .finup
= crypto_sha256_neon_finup
,
84 .descsize
= sizeof(struct sha256_state
),
87 .cra_driver_name
= "sha224-neon",
89 .cra_blocksize
= SHA224_BLOCK_SIZE
,
90 .cra_module
= THIS_MODULE
,