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/cryptohash.h>
15 #include <linux/types.h>
16 #include <linux/string.h>
17 #include <crypto/sha.h>
18 #include <crypto/sha256_base.h>
19 #include <asm/byteorder.h>
23 #include "sha256_glue.h"
25 asmlinkage
void sha256_block_data_order_neon(u32
*digest
, const void *data
,
26 unsigned int num_blks
);
28 static int crypto_sha256_neon_update(struct shash_desc
*desc
, const u8
*data
,
31 struct sha256_state
*sctx
= shash_desc_ctx(desc
);
33 if (!crypto_simd_usable() ||
34 (sctx
->count
% SHA256_BLOCK_SIZE
) + len
< SHA256_BLOCK_SIZE
)
35 return crypto_sha256_arm_update(desc
, data
, len
);
38 sha256_base_do_update(desc
, data
, len
,
39 (sha256_block_fn
*)sha256_block_data_order_neon
);
45 static int crypto_sha256_neon_finup(struct shash_desc
*desc
, const u8
*data
,
46 unsigned int len
, u8
*out
)
48 if (!crypto_simd_usable())
49 return crypto_sha256_arm_finup(desc
, data
, len
, out
);
53 sha256_base_do_update(desc
, data
, len
,
54 (sha256_block_fn
*)sha256_block_data_order_neon
);
55 sha256_base_do_finalize(desc
,
56 (sha256_block_fn
*)sha256_block_data_order_neon
);
59 return sha256_base_finish(desc
, out
);
62 static int crypto_sha256_neon_final(struct shash_desc
*desc
, u8
*out
)
64 return crypto_sha256_neon_finup(desc
, NULL
, 0, out
);
67 struct shash_alg sha256_neon_algs
[] = { {
68 .digestsize
= SHA256_DIGEST_SIZE
,
69 .init
= sha256_base_init
,
70 .update
= crypto_sha256_neon_update
,
71 .final
= crypto_sha256_neon_final
,
72 .finup
= crypto_sha256_neon_finup
,
73 .descsize
= sizeof(struct sha256_state
),
76 .cra_driver_name
= "sha256-neon",
78 .cra_blocksize
= SHA256_BLOCK_SIZE
,
79 .cra_module
= THIS_MODULE
,
82 .digestsize
= SHA224_DIGEST_SIZE
,
83 .init
= sha224_base_init
,
84 .update
= crypto_sha256_neon_update
,
85 .final
= crypto_sha256_neon_final
,
86 .finup
= crypto_sha256_neon_finup
,
87 .descsize
= sizeof(struct sha256_state
),
90 .cra_driver_name
= "sha224-neon",
92 .cra_blocksize
= SHA224_BLOCK_SIZE
,
93 .cra_module
= THIS_MODULE
,