2019-05-27 14:55:01 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2015-04-03 18:03:40 +08:00
|
|
|
/*
|
|
|
|
* Glue code for the SHA256 Secure Hash Algorithm assembly implementation
|
|
|
|
* using NEON instructions.
|
|
|
|
*
|
2018-08-24 08:01:26 +08:00
|
|
|
* Copyright © 2015 Google Inc.
|
2015-04-03 18:03:40 +08:00
|
|
|
*
|
|
|
|
* This file is based on sha512_neon_glue.c:
|
2018-08-24 08:01:26 +08:00
|
|
|
* Copyright © 2014 Jussi Kivilinna <jussi.kivilinna@iki.fi>
|
2015-04-03 18:03:40 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <crypto/internal/hash.h>
|
2019-03-13 13:12:49 +08:00
|
|
|
#include <crypto/internal/simd.h>
|
2015-04-03 18:03:40 +08:00
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/string.h>
|
2020-11-13 13:20:21 +08:00
|
|
|
#include <crypto/sha2.h>
|
2015-04-09 18:55:42 +08:00
|
|
|
#include <crypto/sha256_base.h>
|
2015-04-03 18:03:40 +08:00
|
|
|
#include <asm/byteorder.h>
|
|
|
|
#include <asm/simd.h>
|
|
|
|
#include <asm/neon.h>
|
2015-04-09 18:55:42 +08:00
|
|
|
|
2015-04-03 18:03:40 +08:00
|
|
|
#include "sha256_glue.h"
|
|
|
|
|
|
|
|
asmlinkage void sha256_block_data_order_neon(u32 *digest, const void *data,
|
2015-04-09 18:55:42 +08:00
|
|
|
unsigned int num_blks);
|
2015-04-03 18:03:40 +08:00
|
|
|
|
2019-09-02 04:35:24 +08:00
|
|
|
static int crypto_sha256_neon_update(struct shash_desc *desc, const u8 *data,
|
|
|
|
unsigned int len)
|
2015-04-03 18:03:40 +08:00
|
|
|
{
|
|
|
|
struct sha256_state *sctx = shash_desc_ctx(desc);
|
|
|
|
|
2019-03-13 13:12:49 +08:00
|
|
|
if (!crypto_simd_usable() ||
|
2015-04-09 18:55:42 +08:00
|
|
|
(sctx->count % SHA256_BLOCK_SIZE) + len < SHA256_BLOCK_SIZE)
|
|
|
|
return crypto_sha256_arm_update(desc, data, len);
|
2015-04-03 18:03:40 +08:00
|
|
|
|
2015-04-09 18:55:42 +08:00
|
|
|
kernel_neon_begin();
|
|
|
|
sha256_base_do_update(desc, data, len,
|
|
|
|
(sha256_block_fn *)sha256_block_data_order_neon);
|
|
|
|
kernel_neon_end();
|
2015-04-03 18:03:40 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-09-02 04:35:24 +08:00
|
|
|
static int crypto_sha256_neon_finup(struct shash_desc *desc, const u8 *data,
|
|
|
|
unsigned int len, u8 *out)
|
2015-04-03 18:03:40 +08:00
|
|
|
{
|
2019-03-13 13:12:49 +08:00
|
|
|
if (!crypto_simd_usable())
|
2015-04-09 18:55:42 +08:00
|
|
|
return crypto_sha256_arm_finup(desc, data, len, out);
|
|
|
|
|
|
|
|
kernel_neon_begin();
|
|
|
|
if (len)
|
|
|
|
sha256_base_do_update(desc, data, len,
|
|
|
|
(sha256_block_fn *)sha256_block_data_order_neon);
|
|
|
|
sha256_base_do_finalize(desc,
|
|
|
|
(sha256_block_fn *)sha256_block_data_order_neon);
|
|
|
|
kernel_neon_end();
|
|
|
|
|
|
|
|
return sha256_base_finish(desc, out);
|
2015-04-03 18:03:40 +08:00
|
|
|
}
|
|
|
|
|
2019-09-02 04:35:24 +08:00
|
|
|
static int crypto_sha256_neon_final(struct shash_desc *desc, u8 *out)
|
2015-04-03 18:03:40 +08:00
|
|
|
{
|
2019-09-02 04:35:24 +08:00
|
|
|
return crypto_sha256_neon_finup(desc, NULL, 0, out);
|
2015-04-03 18:03:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct shash_alg sha256_neon_algs[] = { {
|
|
|
|
.digestsize = SHA256_DIGEST_SIZE,
|
2015-04-09 18:55:42 +08:00
|
|
|
.init = sha256_base_init,
|
2019-09-02 04:35:24 +08:00
|
|
|
.update = crypto_sha256_neon_update,
|
|
|
|
.final = crypto_sha256_neon_final,
|
|
|
|
.finup = crypto_sha256_neon_finup,
|
2015-04-03 18:03:40 +08:00
|
|
|
.descsize = sizeof(struct sha256_state),
|
|
|
|
.base = {
|
|
|
|
.cra_name = "sha256",
|
|
|
|
.cra_driver_name = "sha256-neon",
|
|
|
|
.cra_priority = 250,
|
|
|
|
.cra_blocksize = SHA256_BLOCK_SIZE,
|
|
|
|
.cra_module = THIS_MODULE,
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
.digestsize = SHA224_DIGEST_SIZE,
|
2015-04-09 18:55:42 +08:00
|
|
|
.init = sha224_base_init,
|
2019-09-02 04:35:24 +08:00
|
|
|
.update = crypto_sha256_neon_update,
|
|
|
|
.final = crypto_sha256_neon_final,
|
|
|
|
.finup = crypto_sha256_neon_finup,
|
2015-04-03 18:03:40 +08:00
|
|
|
.descsize = sizeof(struct sha256_state),
|
|
|
|
.base = {
|
|
|
|
.cra_name = "sha224",
|
|
|
|
.cra_driver_name = "sha224-neon",
|
|
|
|
.cra_priority = 250,
|
|
|
|
.cra_blocksize = SHA224_BLOCK_SIZE,
|
|
|
|
.cra_module = THIS_MODULE,
|
|
|
|
}
|
|
|
|
} };
|