1*7117739aSEric Biggers /* SPDX-License-Identifier: GPL-2.0-or-later */ 2*7117739aSEric Biggers /* 3*7117739aSEric Biggers * Cryptographic API. 4*7117739aSEric Biggers * 5*7117739aSEric Biggers * SHA-512 and SHA-384 Secure Hash Algorithm. 6*7117739aSEric Biggers * 7*7117739aSEric Biggers * Adapted for OCTEON by Aaro Koskinen <aaro.koskinen@iki.fi>. 8*7117739aSEric Biggers * 9*7117739aSEric Biggers * Based on crypto/sha512_generic.c, which is: 10*7117739aSEric Biggers * 11*7117739aSEric Biggers * Copyright (c) Jean-Luc Cooke <jlcooke@certainkey.com> 12*7117739aSEric Biggers * Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk> 13*7117739aSEric Biggers * Copyright (c) 2003 Kyle McMartin <kyle@debian.org> 14*7117739aSEric Biggers */ 15*7117739aSEric Biggers 16*7117739aSEric Biggers #include <asm/octeon/crypto.h> 17*7117739aSEric Biggers #include <asm/octeon/octeon.h> 18*7117739aSEric Biggers 19*7117739aSEric Biggers /* 20*7117739aSEric Biggers * We pass everything as 64-bit. OCTEON can handle misaligned data. 21*7117739aSEric Biggers */ 22*7117739aSEric Biggers 23*7117739aSEric Biggers static void sha512_blocks(struct sha512_block_state *state, 24*7117739aSEric Biggers const u8 *data, size_t nblocks) 25*7117739aSEric Biggers { 26*7117739aSEric Biggers struct octeon_cop2_state cop2_state; 27*7117739aSEric Biggers unsigned long flags; 28*7117739aSEric Biggers 29*7117739aSEric Biggers if (!octeon_has_crypto()) 30*7117739aSEric Biggers return sha512_blocks_generic(state, data, nblocks); 31*7117739aSEric Biggers 32*7117739aSEric Biggers flags = octeon_crypto_enable(&cop2_state); 33*7117739aSEric Biggers write_octeon_64bit_hash_sha512(state->h[0], 0); 34*7117739aSEric Biggers write_octeon_64bit_hash_sha512(state->h[1], 1); 35*7117739aSEric Biggers write_octeon_64bit_hash_sha512(state->h[2], 2); 36*7117739aSEric Biggers write_octeon_64bit_hash_sha512(state->h[3], 3); 37*7117739aSEric Biggers write_octeon_64bit_hash_sha512(state->h[4], 4); 38*7117739aSEric Biggers write_octeon_64bit_hash_sha512(state->h[5], 5); 39*7117739aSEric Biggers write_octeon_64bit_hash_sha512(state->h[6], 6); 40*7117739aSEric Biggers write_octeon_64bit_hash_sha512(state->h[7], 7); 41*7117739aSEric Biggers 42*7117739aSEric Biggers do { 43*7117739aSEric Biggers const u64 *block = (const u64 *)data; 44*7117739aSEric Biggers 45*7117739aSEric Biggers write_octeon_64bit_block_sha512(block[0], 0); 46*7117739aSEric Biggers write_octeon_64bit_block_sha512(block[1], 1); 47*7117739aSEric Biggers write_octeon_64bit_block_sha512(block[2], 2); 48*7117739aSEric Biggers write_octeon_64bit_block_sha512(block[3], 3); 49*7117739aSEric Biggers write_octeon_64bit_block_sha512(block[4], 4); 50*7117739aSEric Biggers write_octeon_64bit_block_sha512(block[5], 5); 51*7117739aSEric Biggers write_octeon_64bit_block_sha512(block[6], 6); 52*7117739aSEric Biggers write_octeon_64bit_block_sha512(block[7], 7); 53*7117739aSEric Biggers write_octeon_64bit_block_sha512(block[8], 8); 54*7117739aSEric Biggers write_octeon_64bit_block_sha512(block[9], 9); 55*7117739aSEric Biggers write_octeon_64bit_block_sha512(block[10], 10); 56*7117739aSEric Biggers write_octeon_64bit_block_sha512(block[11], 11); 57*7117739aSEric Biggers write_octeon_64bit_block_sha512(block[12], 12); 58*7117739aSEric Biggers write_octeon_64bit_block_sha512(block[13], 13); 59*7117739aSEric Biggers write_octeon_64bit_block_sha512(block[14], 14); 60*7117739aSEric Biggers octeon_sha512_start(block[15]); 61*7117739aSEric Biggers 62*7117739aSEric Biggers data += SHA512_BLOCK_SIZE; 63*7117739aSEric Biggers } while (--nblocks); 64*7117739aSEric Biggers 65*7117739aSEric Biggers state->h[0] = read_octeon_64bit_hash_sha512(0); 66*7117739aSEric Biggers state->h[1] = read_octeon_64bit_hash_sha512(1); 67*7117739aSEric Biggers state->h[2] = read_octeon_64bit_hash_sha512(2); 68*7117739aSEric Biggers state->h[3] = read_octeon_64bit_hash_sha512(3); 69*7117739aSEric Biggers state->h[4] = read_octeon_64bit_hash_sha512(4); 70*7117739aSEric Biggers state->h[5] = read_octeon_64bit_hash_sha512(5); 71*7117739aSEric Biggers state->h[6] = read_octeon_64bit_hash_sha512(6); 72*7117739aSEric Biggers state->h[7] = read_octeon_64bit_hash_sha512(7); 73*7117739aSEric Biggers octeon_crypto_disable(&cop2_state, flags); 74*7117739aSEric Biggers } 75