2 * Glue code for the SHA256 Secure Hash Algorithm assembly implementation
3 * using NEON instructions.
5 * Copyright © 2015 Google Inc.
7 * This file is based on sha512_neon_glue.c:
8 * Copyright © 2014 Jussi Kivilinna <jussi.kivilinna@iki.fi>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation; either version 2 of the License, or (at your option)
17 #include <crypto/internal/hash.h>
18 #include <linux/cryptohash.h>
19 #include <linux/types.h>
20 #include <linux/string.h>
21 #include <crypto/sha.h>
22 #include <crypto/sha256_base.h>
23 #include <asm/byteorder.h>
27 #include "sha256_glue.h"
29 asmlinkage void sha256_block_data_order_neon(u32 *digest, const void *data,
30 unsigned int num_blks);
32 static int crypto_sha256_neon_update(struct shash_desc *desc, const u8 *data,
35 struct sha256_state *sctx = shash_desc_ctx(desc);
37 if (!may_use_simd() ||
38 (sctx->count % SHA256_BLOCK_SIZE) + len < SHA256_BLOCK_SIZE)
39 return crypto_sha256_arm_update(desc, data, len);
42 sha256_base_do_update(desc, data, len,
43 (sha256_block_fn *)sha256_block_data_order_neon);
49 static int crypto_sha256_neon_finup(struct shash_desc *desc, const u8 *data,
50 unsigned int len, u8 *out)
53 return crypto_sha256_arm_finup(desc, data, len, out);
57 sha256_base_do_update(desc, data, len,
58 (sha256_block_fn *)sha256_block_data_order_neon);
59 sha256_base_do_finalize(desc,
60 (sha256_block_fn *)sha256_block_data_order_neon);
63 return sha256_base_finish(desc, out);
66 static int crypto_sha256_neon_final(struct shash_desc *desc, u8 *out)
68 return crypto_sha256_neon_finup(desc, NULL, 0, out);
71 struct shash_alg sha256_neon_algs[] = { {
72 .digestsize = SHA256_DIGEST_SIZE,
73 .init = sha256_base_init,
74 .update = crypto_sha256_neon_update,
75 .final = crypto_sha256_neon_final,
76 .finup = crypto_sha256_neon_finup,
77 .descsize = sizeof(struct sha256_state),
80 .cra_driver_name = "sha256-neon",
82 .cra_blocksize = SHA256_BLOCK_SIZE,
83 .cra_module = THIS_MODULE,
86 .digestsize = SHA224_DIGEST_SIZE,
87 .init = sha224_base_init,
88 .update = crypto_sha256_neon_update,
89 .final = crypto_sha256_neon_final,
90 .finup = crypto_sha256_neon_finup,
91 .descsize = sizeof(struct sha256_state),
94 .cra_driver_name = "sha224-neon",
96 .cra_blocksize = SHA224_BLOCK_SIZE,
97 .cra_module = THIS_MODULE,