^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-512 and SHA-384 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/sha512_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) 2003 Kyle McMartin <kyle@debian.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <crypto/sha.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <asm/byteorder.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <asm/octeon/octeon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <crypto/internal/hash.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include "octeon-crypto.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * We pass everything as 64-bit. OCTEON can handle misaligned data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) static void octeon_sha512_store_hash(struct sha512_state *sctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) write_octeon_64bit_hash_sha512(sctx->state[0], 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) write_octeon_64bit_hash_sha512(sctx->state[1], 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) write_octeon_64bit_hash_sha512(sctx->state[2], 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) write_octeon_64bit_hash_sha512(sctx->state[3], 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) write_octeon_64bit_hash_sha512(sctx->state[4], 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) write_octeon_64bit_hash_sha512(sctx->state[5], 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) write_octeon_64bit_hash_sha512(sctx->state[6], 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) write_octeon_64bit_hash_sha512(sctx->state[7], 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) static void octeon_sha512_read_hash(struct sha512_state *sctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) sctx->state[0] = read_octeon_64bit_hash_sha512(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) sctx->state[1] = read_octeon_64bit_hash_sha512(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) sctx->state[2] = read_octeon_64bit_hash_sha512(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) sctx->state[3] = read_octeon_64bit_hash_sha512(3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) sctx->state[4] = read_octeon_64bit_hash_sha512(4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) sctx->state[5] = read_octeon_64bit_hash_sha512(5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) sctx->state[6] = read_octeon_64bit_hash_sha512(6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) sctx->state[7] = read_octeon_64bit_hash_sha512(7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) static void octeon_sha512_transform(const void *_block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) const u64 *block = _block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) write_octeon_64bit_block_sha512(block[0], 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) write_octeon_64bit_block_sha512(block[1], 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) write_octeon_64bit_block_sha512(block[2], 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) write_octeon_64bit_block_sha512(block[3], 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) write_octeon_64bit_block_sha512(block[4], 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) write_octeon_64bit_block_sha512(block[5], 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) write_octeon_64bit_block_sha512(block[6], 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) write_octeon_64bit_block_sha512(block[7], 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) write_octeon_64bit_block_sha512(block[8], 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) write_octeon_64bit_block_sha512(block[9], 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) write_octeon_64bit_block_sha512(block[10], 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) write_octeon_64bit_block_sha512(block[11], 11);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) write_octeon_64bit_block_sha512(block[12], 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) write_octeon_64bit_block_sha512(block[13], 13);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) write_octeon_64bit_block_sha512(block[14], 14);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) octeon_sha512_start(block[15]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) static int octeon_sha512_init(struct shash_desc *desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) struct sha512_state *sctx = shash_desc_ctx(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) sctx->state[0] = SHA512_H0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) sctx->state[1] = SHA512_H1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) sctx->state[2] = SHA512_H2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) sctx->state[3] = SHA512_H3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) sctx->state[4] = SHA512_H4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) sctx->state[5] = SHA512_H5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) sctx->state[6] = SHA512_H6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) sctx->state[7] = SHA512_H7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) sctx->count[0] = sctx->count[1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) static int octeon_sha384_init(struct shash_desc *desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) struct sha512_state *sctx = shash_desc_ctx(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) sctx->state[0] = SHA384_H0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) sctx->state[1] = SHA384_H1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) sctx->state[2] = SHA384_H2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) sctx->state[3] = SHA384_H3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) sctx->state[4] = SHA384_H4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) sctx->state[5] = SHA384_H5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) sctx->state[6] = SHA384_H6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) sctx->state[7] = SHA384_H7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) sctx->count[0] = sctx->count[1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static void __octeon_sha512_update(struct sha512_state *sctx, const u8 *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) unsigned int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) unsigned int part_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) unsigned int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) /* Compute number of bytes mod 128. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) index = sctx->count[0] % SHA512_BLOCK_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) /* Update number of bytes. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) if ((sctx->count[0] += len) < len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) sctx->count[1]++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) part_len = SHA512_BLOCK_SIZE - index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) /* Transform as many times as possible. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) if (len >= part_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) memcpy(&sctx->buf[index], data, part_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) octeon_sha512_transform(sctx->buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) for (i = part_len; i + SHA512_BLOCK_SIZE <= len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) i += SHA512_BLOCK_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) octeon_sha512_transform(&data[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) /* Buffer remaining input. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) memcpy(&sctx->buf[index], &data[i], len - i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) static int octeon_sha512_update(struct shash_desc *desc, const u8 *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) unsigned int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) struct sha512_state *sctx = shash_desc_ctx(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) struct octeon_cop2_state state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) * Small updates never reach the crypto engine, so the generic sha512 is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) * faster because of the heavyweight octeon_crypto_enable() /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) * octeon_crypto_disable().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) if ((sctx->count[0] % SHA512_BLOCK_SIZE) + len < SHA512_BLOCK_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) return crypto_sha512_update(desc, data, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) flags = octeon_crypto_enable(&state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) octeon_sha512_store_hash(sctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) __octeon_sha512_update(sctx, data, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) octeon_sha512_read_hash(sctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) octeon_crypto_disable(&state, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) static int octeon_sha512_final(struct shash_desc *desc, u8 *hash)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) struct sha512_state *sctx = shash_desc_ctx(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) static u8 padding[128] = { 0x80, };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) struct octeon_cop2_state state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) __be64 *dst = (__be64 *)hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) unsigned int pad_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) unsigned int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) __be64 bits[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) /* Save number of bits. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) bits[1] = cpu_to_be64(sctx->count[0] << 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) bits[0] = cpu_to_be64(sctx->count[1] << 3 | sctx->count[0] >> 61);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) /* Pad out to 112 mod 128. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) index = sctx->count[0] & 0x7f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) pad_len = (index < 112) ? (112 - index) : ((128+112) - index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) flags = octeon_crypto_enable(&state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) octeon_sha512_store_hash(sctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) __octeon_sha512_update(sctx, padding, pad_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) /* Append length (before padding). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) __octeon_sha512_update(sctx, (const u8 *)bits, sizeof(bits));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) octeon_sha512_read_hash(sctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) octeon_crypto_disable(&state, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /* Store state in digest. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) for (i = 0; i < 8; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) dst[i] = cpu_to_be64(sctx->state[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) /* Zeroize sensitive information. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) memset(sctx, 0, sizeof(struct sha512_state));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) static int octeon_sha384_final(struct shash_desc *desc, u8 *hash)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) u8 D[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) octeon_sha512_final(desc, D);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) memcpy(hash, D, 48);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) memzero_explicit(D, 64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) static struct shash_alg octeon_sha512_algs[2] = { {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) .digestsize = SHA512_DIGEST_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) .init = octeon_sha512_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) .update = octeon_sha512_update,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) .final = octeon_sha512_final,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) .descsize = sizeof(struct sha512_state),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) .base = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) .cra_name = "sha512",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) .cra_driver_name= "octeon-sha512",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) .cra_priority = OCTEON_CR_OPCODE_PRIORITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) .cra_blocksize = SHA512_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) .cra_module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) .digestsize = SHA384_DIGEST_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) .init = octeon_sha384_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) .update = octeon_sha512_update,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) .final = octeon_sha384_final,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) .descsize = sizeof(struct sha512_state),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) .base = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) .cra_name = "sha384",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) .cra_driver_name= "octeon-sha384",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) .cra_priority = OCTEON_CR_OPCODE_PRIORITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) .cra_blocksize = SHA384_BLOCK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) .cra_module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) } };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) static int __init octeon_sha512_mod_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if (!octeon_has_crypto())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) return -ENOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) return crypto_register_shashes(octeon_sha512_algs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) ARRAY_SIZE(octeon_sha512_algs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) static void __exit octeon_sha512_mod_fini(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) crypto_unregister_shashes(octeon_sha512_algs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) ARRAY_SIZE(octeon_sha512_algs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) module_init(octeon_sha512_mod_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) module_exit(octeon_sha512_mod_fini);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) MODULE_DESCRIPTION("SHA-512 and SHA-384 Secure Hash Algorithms (OCTEON)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) MODULE_AUTHOR("Aaro Koskinen <aaro.koskinen@iki.fi>");