^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Cryptographic API.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * SHA-224 and SHA-256 Secure Hash Algorithm.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Adapted for OCTEON by Aaro Koskinen <aaro.koskinen@iki.fi>.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Based on crypto/sha256_generic.c, which is:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Copyright (c) Jean-Luc Cooke <jlcooke@certainkey.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * SHA224 Support Copyright 2007 Intel Corporation <jonathan.lynch@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <crypto/sha.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <asm/byteorder.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <asm/octeon/octeon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <crypto/internal/hash.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include "octeon-crypto.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * We pass everything as 64-bit. OCTEON can handle misaligned data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) static void octeon_sha256_store_hash(struct sha256_state *sctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) u64 *hash = (u64 *)sctx->state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) write_octeon_64bit_hash_dword(hash[0], 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) write_octeon_64bit_hash_dword(hash[1], 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) write_octeon_64bit_hash_dword(hash[2], 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) write_octeon_64bit_hash_dword(hash[3], 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) static void octeon_sha256_read_hash(struct sha256_state *sctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) u64 *hash = (u64 *)sctx->state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) hash[0] = read_octeon_64bit_hash_dword(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) hash[1] = read_octeon_64bit_hash_dword(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) hash[2] = read_octeon_64bit_hash_dword(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) hash[3] = read_octeon_64bit_hash_dword(3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) static void octeon_sha256_transform(const void *_block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) const u64 *block = _block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) write_octeon_64bit_block_dword(block[0], 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) write_octeon_64bit_block_dword(block[1], 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) write_octeon_64bit_block_dword(block[2], 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) write_octeon_64bit_block_dword(block[3], 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) write_octeon_64bit_block_dword(block[4], 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) write_octeon_64bit_block_dword(block[5], 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) write_octeon_64bit_block_dword(block[6], 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) octeon_sha256_start(block[7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) static int octeon_sha224_init(struct shash_desc *desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct sha256_state *sctx = shash_desc_ctx(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) sctx->state[0] = SHA224_H0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) sctx->state[1] = SHA224_H1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) sctx->state[2] = SHA224_H2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) sctx->state[3] = SHA224_H3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) sctx->state[4] = SHA224_H4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) sctx->state[5] = SHA224_H5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) sctx->state[6] = SHA224_H6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) sctx->state[7] = SHA224_H7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) sctx->count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) static int octeon_sha256_init(struct shash_desc *desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct sha256_state *sctx = shash_desc_ctx(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) sctx->state[0] = SHA256_H0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) sctx->state[1] = SHA256_H1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) sctx->state[2] = SHA256_H2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) sctx->state[3] = SHA256_H3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) sctx->state[4] = SHA256_H4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) sctx->state[5] = SHA256_H5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) sctx->state[6] = SHA256_H6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) sctx->state[7] = SHA256_H7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) sctx->count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static void __octeon_sha256_update(struct sha256_state *sctx, const u8 *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) unsigned int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) unsigned int partial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) unsigned int done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) const u8 *src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) partial = sctx->count % SHA256_BLOCK_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) sctx->count += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) done = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) src = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if ((partial + len) >= SHA256_BLOCK_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) if (partial) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) done = -partial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) memcpy(sctx->buf + partial, data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) done + SHA256_BLOCK_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) src = sctx->buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) octeon_sha256_transform(src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) done += SHA256_BLOCK_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) src = data + done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) } while (done + SHA256_BLOCK_SIZE <= len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) partial = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) memcpy(sctx->buf + partial, src, len - done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static int octeon_sha256_update(struct shash_desc *desc, const u8 *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) unsigned int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) struct sha256_state *sctx = shash_desc_ctx(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) struct octeon_cop2_state state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) * Small updates never reach the crypto engine, so the generic sha256 is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) * faster because of the heavyweight octeon_crypto_enable() /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) * octeon_crypto_disable().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) if ((sctx->count % SHA256_BLOCK_SIZE) + len < SHA256_BLOCK_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) return crypto_sha256_update(desc, data, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) flags = octeon_crypto_enable(&state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) octeon_sha256_store_hash(sctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) __octeon_sha256_update(sctx, data, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) octeon_sha256_read_hash(sctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) octeon_crypto_disable(&state, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) static int octeon_sha256_final(struct shash_desc *desc, u8 *out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) struct sha256_state *sctx = shash_desc_ctx(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) static const u8 padding[64] = { 0x80, };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) struct octeon_cop2_state state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) __be32 *dst = (__be32 *)out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) unsigned int pad_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) unsigned int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) __be64 bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) /* Save number of bits. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) bits = cpu_to_be64(sctx->count << 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) /* Pad out to 56 mod 64. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) index = sctx->count & 0x3f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) pad_len = (index < 56) ? (56 - index) : ((64+56) - index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) flags = octeon_crypto_enable(&state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) octeon_sha256_store_hash(sctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) __octeon_sha256_update(sctx, padding, pad_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) /* Append length (before padding). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) __octeon_sha256_update(sctx, (const u8 *)&bits, sizeof(bits));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) octeon_sha256_read_hash(sctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) octeon_crypto_disable(&state, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) /* Store state in digest */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) for (i = 0; i < 8; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) dst[i] = cpu_to_be32(sctx->state[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) /* Zeroize sensitive information. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) memset(sctx, 0, sizeof(*sctx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) static int octeon_sha224_final(struct shash_desc *desc, u8 *hash)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) u8 D[SHA256_DIGEST_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) octeon_sha256_final(desc, D);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) memcpy(hash, D, SHA224_DIGEST_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) memzero_explicit(D, SHA256_DIGEST_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) static int octeon_sha256_export(struct shash_desc *desc, void *out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) struct sha256_state *sctx = shash_desc_ctx(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) memcpy(out, sctx, sizeof(*sctx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) static int octeon_sha256_import(struct shash_desc *desc, const void *in)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) struct sha256_state *sctx = shash_desc_ctx(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) memcpy(sctx, in, sizeof(*sctx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) static struct shash_alg octeon_sha256_algs[2] = { {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) .digestsize = SHA256_DIGEST_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) .init = octeon_sha256_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) .update = octeon_sha256_update,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) .final = octeon_sha256_final,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) .export = octeon_sha256_export,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) .import = octeon_sha256_import,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) .descsize = sizeof(struct sha256_state),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) .statesize = sizeof(struct sha256_state),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) .base = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) .cra_name = "sha256",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) .cra_driver_name= "octeon-sha256",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) .cra_priority = OCTEON_CR_OPCODE_PRIORITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) .cra_blocksize = SHA256_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) .cra_module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) .digestsize = SHA224_DIGEST_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) .init = octeon_sha224_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) .update = octeon_sha256_update,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) .final = octeon_sha224_final,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) .descsize = sizeof(struct sha256_state),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) .base = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) .cra_name = "sha224",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) .cra_driver_name= "octeon-sha224",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) .cra_blocksize = SHA224_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) .cra_module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) } };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) static int __init octeon_sha256_mod_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) if (!octeon_has_crypto())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) return -ENOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) return crypto_register_shashes(octeon_sha256_algs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) ARRAY_SIZE(octeon_sha256_algs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) static void __exit octeon_sha256_mod_fini(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) crypto_unregister_shashes(octeon_sha256_algs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) ARRAY_SIZE(octeon_sha256_algs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) module_init(octeon_sha256_mod_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) module_exit(octeon_sha256_mod_fini);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) MODULE_DESCRIPTION("SHA-224 and SHA-256 Secure Hash Algorithm (OCTEON)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) MODULE_AUTHOR("Aaro Koskinen <aaro.koskinen@iki.fi>");