David McCullough | f0be44f | 2012-09-07 04:17:02 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Cryptographic API. |
| 3 | * Glue code for the SHA1 Secure Hash Algorithm assembler implementation |
| 4 | * |
| 5 | * This file is based on sha1_generic.c and sha1_ssse3_glue.c |
| 6 | * |
| 7 | * Copyright (c) Alan Smithee. |
| 8 | * Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk> |
| 9 | * Copyright (c) Jean-Francois Dive <jef@linuxbe.org> |
| 10 | * Copyright (c) Mathias Krause <minipli@googlemail.com> |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify it |
| 13 | * under the terms of the GNU General Public License as published by the Free |
| 14 | * Software Foundation; either version 2 of the License, or (at your option) |
| 15 | * any later version. |
| 16 | * |
| 17 | */ |
| 18 | |
| 19 | #include <crypto/internal/hash.h> |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/cryptohash.h> |
| 23 | #include <linux/types.h> |
| 24 | #include <crypto/sha.h> |
Ard Biesheuvel | 90451d6 | 2015-04-09 12:55:39 +0200 | [diff] [blame] | 25 | #include <crypto/sha1_base.h> |
David McCullough | f0be44f | 2012-09-07 04:17:02 +0800 | [diff] [blame] | 26 | #include <asm/byteorder.h> |
| 27 | |
Ard Biesheuvel | 90451d6 | 2015-04-09 12:55:39 +0200 | [diff] [blame] | 28 | #include "sha1.h" |
David McCullough | f0be44f | 2012-09-07 04:17:02 +0800 | [diff] [blame] | 29 | |
Jussi Kivilinna | 1f8673d | 2014-07-29 17:14:09 +0100 | [diff] [blame] | 30 | asmlinkage void sha1_block_data_order(u32 *digest, |
David McCullough | f0be44f | 2012-09-07 04:17:02 +0800 | [diff] [blame] | 31 | const unsigned char *data, unsigned int rounds); |
| 32 | |
Jussi Kivilinna | 6046825 | 2014-07-29 17:14:14 +0100 | [diff] [blame] | 33 | int sha1_update_arm(struct shash_desc *desc, const u8 *data, |
| 34 | unsigned int len) |
David McCullough | f0be44f | 2012-09-07 04:17:02 +0800 | [diff] [blame] | 35 | { |
Ard Biesheuvel | 90451d6 | 2015-04-09 12:55:39 +0200 | [diff] [blame] | 36 | /* make sure casting to sha1_block_fn() is safe */ |
| 37 | BUILD_BUG_ON(offsetof(struct sha1_state, state) != 0); |
David McCullough | f0be44f | 2012-09-07 04:17:02 +0800 | [diff] [blame] | 38 | |
Ard Biesheuvel | 90451d6 | 2015-04-09 12:55:39 +0200 | [diff] [blame] | 39 | return sha1_base_do_update(desc, data, len, |
| 40 | (sha1_block_fn *)sha1_block_data_order); |
David McCullough | f0be44f | 2012-09-07 04:17:02 +0800 | [diff] [blame] | 41 | } |
Jussi Kivilinna | 6046825 | 2014-07-29 17:14:14 +0100 | [diff] [blame] | 42 | EXPORT_SYMBOL_GPL(sha1_update_arm); |
David McCullough | f0be44f | 2012-09-07 04:17:02 +0800 | [diff] [blame] | 43 | |
David McCullough | f0be44f | 2012-09-07 04:17:02 +0800 | [diff] [blame] | 44 | static int sha1_final(struct shash_desc *desc, u8 *out) |
| 45 | { |
Ard Biesheuvel | 90451d6 | 2015-04-09 12:55:39 +0200 | [diff] [blame] | 46 | sha1_base_do_finalize(desc, (sha1_block_fn *)sha1_block_data_order); |
| 47 | return sha1_base_finish(desc, out); |
David McCullough | f0be44f | 2012-09-07 04:17:02 +0800 | [diff] [blame] | 48 | } |
| 49 | |
Ard Biesheuvel | 90451d6 | 2015-04-09 12:55:39 +0200 | [diff] [blame] | 50 | int sha1_finup_arm(struct shash_desc *desc, const u8 *data, |
| 51 | unsigned int len, u8 *out) |
David McCullough | f0be44f | 2012-09-07 04:17:02 +0800 | [diff] [blame] | 52 | { |
Ard Biesheuvel | 90451d6 | 2015-04-09 12:55:39 +0200 | [diff] [blame] | 53 | sha1_base_do_update(desc, data, len, |
| 54 | (sha1_block_fn *)sha1_block_data_order); |
| 55 | return sha1_final(desc, out); |
David McCullough | f0be44f | 2012-09-07 04:17:02 +0800 | [diff] [blame] | 56 | } |
Ard Biesheuvel | 90451d6 | 2015-04-09 12:55:39 +0200 | [diff] [blame] | 57 | EXPORT_SYMBOL_GPL(sha1_finup_arm); |
David McCullough | f0be44f | 2012-09-07 04:17:02 +0800 | [diff] [blame] | 58 | |
| 59 | static struct shash_alg alg = { |
| 60 | .digestsize = SHA1_DIGEST_SIZE, |
Ard Biesheuvel | 90451d6 | 2015-04-09 12:55:39 +0200 | [diff] [blame] | 61 | .init = sha1_base_init, |
Jussi Kivilinna | 6046825 | 2014-07-29 17:14:14 +0100 | [diff] [blame] | 62 | .update = sha1_update_arm, |
David McCullough | f0be44f | 2012-09-07 04:17:02 +0800 | [diff] [blame] | 63 | .final = sha1_final, |
Ard Biesheuvel | 90451d6 | 2015-04-09 12:55:39 +0200 | [diff] [blame] | 64 | .finup = sha1_finup_arm, |
Jussi Kivilinna | 1f8673d | 2014-07-29 17:14:09 +0100 | [diff] [blame] | 65 | .descsize = sizeof(struct sha1_state), |
David McCullough | f0be44f | 2012-09-07 04:17:02 +0800 | [diff] [blame] | 66 | .base = { |
| 67 | .cra_name = "sha1", |
| 68 | .cra_driver_name= "sha1-asm", |
| 69 | .cra_priority = 150, |
| 70 | .cra_flags = CRYPTO_ALG_TYPE_SHASH, |
| 71 | .cra_blocksize = SHA1_BLOCK_SIZE, |
| 72 | .cra_module = THIS_MODULE, |
| 73 | } |
| 74 | }; |
| 75 | |
| 76 | |
| 77 | static int __init sha1_mod_init(void) |
| 78 | { |
| 79 | return crypto_register_shash(&alg); |
| 80 | } |
| 81 | |
| 82 | |
| 83 | static void __exit sha1_mod_fini(void) |
| 84 | { |
| 85 | crypto_unregister_shash(&alg); |
| 86 | } |
| 87 | |
| 88 | |
| 89 | module_init(sha1_mod_init); |
| 90 | module_exit(sha1_mod_fini); |
| 91 | |
| 92 | MODULE_LICENSE("GPL"); |
| 93 | MODULE_DESCRIPTION("SHA1 Secure Hash Algorithm (ARM)"); |
Kees Cook | 5d26a10 | 2014-11-20 17:05:53 -0800 | [diff] [blame] | 94 | MODULE_ALIAS_CRYPTO("sha1"); |
David McCullough | f0be44f | 2012-09-07 04:17:02 +0800 | [diff] [blame] | 95 | MODULE_AUTHOR("David McCullough <ucdevel@gmail.com>"); |