| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Cryptographic API. |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 10 | 11 | * Copyright (c) Alan Smithee. |
|---|
| 11 | 12 | * Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk> |
|---|
| 12 | 13 | * Copyright (c) Jean-Francois Dive <jef@linuxbe.org> |
|---|
| 13 | | - * |
|---|
| 14 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 15 | | - * under the terms of the GNU General Public License as published by the Free |
|---|
| 16 | | - * Software Foundation; either version 2 of the License, or (at your option) |
|---|
| 17 | | - * any later version. |
|---|
| 18 | | - * |
|---|
| 19 | 14 | */ |
|---|
| 20 | 15 | #include <crypto/internal/hash.h> |
|---|
| 21 | 16 | #include <linux/init.h> |
|---|
| 22 | 17 | #include <linux/module.h> |
|---|
| 23 | 18 | #include <linux/mm.h> |
|---|
| 24 | | -#include <linux/cryptohash.h> |
|---|
| 25 | 19 | #include <linux/types.h> |
|---|
| 26 | 20 | #include <crypto/sha.h> |
|---|
| 27 | 21 | #include <asm/byteorder.h> |
|---|
| 28 | 22 | |
|---|
| 29 | | -extern void powerpc_sha_transform(u32 *state, const u8 *src, u32 *temp); |
|---|
| 23 | +void powerpc_sha_transform(u32 *state, const u8 *src); |
|---|
| 30 | 24 | |
|---|
| 31 | | -static int sha1_init(struct shash_desc *desc) |
|---|
| 25 | +static int powerpc_sha1_init(struct shash_desc *desc) |
|---|
| 32 | 26 | { |
|---|
| 33 | 27 | struct sha1_state *sctx = shash_desc_ctx(desc); |
|---|
| 34 | 28 | |
|---|
| .. | .. |
|---|
| 39 | 33 | return 0; |
|---|
| 40 | 34 | } |
|---|
| 41 | 35 | |
|---|
| 42 | | -static int sha1_update(struct shash_desc *desc, const u8 *data, |
|---|
| 43 | | - unsigned int len) |
|---|
| 36 | +static int powerpc_sha1_update(struct shash_desc *desc, const u8 *data, |
|---|
| 37 | + unsigned int len) |
|---|
| 44 | 38 | { |
|---|
| 45 | 39 | struct sha1_state *sctx = shash_desc_ctx(desc); |
|---|
| 46 | 40 | unsigned int partial, done; |
|---|
| .. | .. |
|---|
| 52 | 46 | src = data; |
|---|
| 53 | 47 | |
|---|
| 54 | 48 | if ((partial + len) > 63) { |
|---|
| 55 | | - u32 temp[SHA_WORKSPACE_WORDS]; |
|---|
| 56 | 49 | |
|---|
| 57 | 50 | if (partial) { |
|---|
| 58 | 51 | done = -partial; |
|---|
| .. | .. |
|---|
| 61 | 54 | } |
|---|
| 62 | 55 | |
|---|
| 63 | 56 | do { |
|---|
| 64 | | - powerpc_sha_transform(sctx->state, src, temp); |
|---|
| 57 | + powerpc_sha_transform(sctx->state, src); |
|---|
| 65 | 58 | done += 64; |
|---|
| 66 | 59 | src = data + done; |
|---|
| 67 | 60 | } while (done + 63 < len); |
|---|
| 68 | 61 | |
|---|
| 69 | | - memzero_explicit(temp, sizeof(temp)); |
|---|
| 70 | 62 | partial = 0; |
|---|
| 71 | 63 | } |
|---|
| 72 | 64 | memcpy(sctx->buffer + partial, src, len - done); |
|---|
| .. | .. |
|---|
| 76 | 68 | |
|---|
| 77 | 69 | |
|---|
| 78 | 70 | /* Add padding and return the message digest. */ |
|---|
| 79 | | -static int sha1_final(struct shash_desc *desc, u8 *out) |
|---|
| 71 | +static int powerpc_sha1_final(struct shash_desc *desc, u8 *out) |
|---|
| 80 | 72 | { |
|---|
| 81 | 73 | struct sha1_state *sctx = shash_desc_ctx(desc); |
|---|
| 82 | 74 | __be32 *dst = (__be32 *)out; |
|---|
| .. | .. |
|---|
| 89 | 81 | /* Pad out to 56 mod 64 */ |
|---|
| 90 | 82 | index = sctx->count & 0x3f; |
|---|
| 91 | 83 | padlen = (index < 56) ? (56 - index) : ((64+56) - index); |
|---|
| 92 | | - sha1_update(desc, padding, padlen); |
|---|
| 84 | + powerpc_sha1_update(desc, padding, padlen); |
|---|
| 93 | 85 | |
|---|
| 94 | 86 | /* Append length */ |
|---|
| 95 | | - sha1_update(desc, (const u8 *)&bits, sizeof(bits)); |
|---|
| 87 | + powerpc_sha1_update(desc, (const u8 *)&bits, sizeof(bits)); |
|---|
| 96 | 88 | |
|---|
| 97 | 89 | /* Store state in digest */ |
|---|
| 98 | 90 | for (i = 0; i < 5; i++) |
|---|
| .. | .. |
|---|
| 104 | 96 | return 0; |
|---|
| 105 | 97 | } |
|---|
| 106 | 98 | |
|---|
| 107 | | -static int sha1_export(struct shash_desc *desc, void *out) |
|---|
| 99 | +static int powerpc_sha1_export(struct shash_desc *desc, void *out) |
|---|
| 108 | 100 | { |
|---|
| 109 | 101 | struct sha1_state *sctx = shash_desc_ctx(desc); |
|---|
| 110 | 102 | |
|---|
| .. | .. |
|---|
| 112 | 104 | return 0; |
|---|
| 113 | 105 | } |
|---|
| 114 | 106 | |
|---|
| 115 | | -static int sha1_import(struct shash_desc *desc, const void *in) |
|---|
| 107 | +static int powerpc_sha1_import(struct shash_desc *desc, const void *in) |
|---|
| 116 | 108 | { |
|---|
| 117 | 109 | struct sha1_state *sctx = shash_desc_ctx(desc); |
|---|
| 118 | 110 | |
|---|
| .. | .. |
|---|
| 122 | 114 | |
|---|
| 123 | 115 | static struct shash_alg alg = { |
|---|
| 124 | 116 | .digestsize = SHA1_DIGEST_SIZE, |
|---|
| 125 | | - .init = sha1_init, |
|---|
| 126 | | - .update = sha1_update, |
|---|
| 127 | | - .final = sha1_final, |
|---|
| 128 | | - .export = sha1_export, |
|---|
| 129 | | - .import = sha1_import, |
|---|
| 117 | + .init = powerpc_sha1_init, |
|---|
| 118 | + .update = powerpc_sha1_update, |
|---|
| 119 | + .final = powerpc_sha1_final, |
|---|
| 120 | + .export = powerpc_sha1_export, |
|---|
| 121 | + .import = powerpc_sha1_import, |
|---|
| 130 | 122 | .descsize = sizeof(struct sha1_state), |
|---|
| 131 | 123 | .statesize = sizeof(struct sha1_state), |
|---|
| 132 | 124 | .base = { |
|---|