1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 /* 3 * SHA-256 Secure Hash Algorithm. 4 * 5 * Adapted for OCTEON by Aaro Koskinen <aaro.koskinen@iki.fi>. 6 * 7 * Based on crypto/sha256_generic.c, which is: 8 * 9 * Copyright (c) Jean-Luc Cooke <jlcooke@certainkey.com> 10 * Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk> 11 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> 12 * SHA224 Support Copyright 2007 Intel Corporation <jonathan.lynch@intel.com> 13 */ 14 15 #include <asm/octeon/crypto.h> 16 #include <asm/octeon/octeon.h> 17 18 /* 19 * We pass everything as 64-bit. OCTEON can handle misaligned data. 20 */ 21 22 static void sha256_blocks(struct sha256_block_state *state, 23 const u8 *data, size_t nblocks) 24 { 25 struct octeon_cop2_state cop2_state; 26 u64 *state64 = (u64 *)state; 27 unsigned long flags; 28 29 if (!octeon_has_crypto()) 30 return sha256_blocks_generic(state, data, nblocks); 31 32 flags = octeon_crypto_enable(&cop2_state); 33 write_octeon_64bit_hash_dword(state64[0], 0); 34 write_octeon_64bit_hash_dword(state64[1], 1); 35 write_octeon_64bit_hash_dword(state64[2], 2); 36 write_octeon_64bit_hash_dword(state64[3], 3); 37 38 do { 39 const u64 *block = (const u64 *)data; 40 41 write_octeon_64bit_block_dword(block[0], 0); 42 write_octeon_64bit_block_dword(block[1], 1); 43 write_octeon_64bit_block_dword(block[2], 2); 44 write_octeon_64bit_block_dword(block[3], 3); 45 write_octeon_64bit_block_dword(block[4], 4); 46 write_octeon_64bit_block_dword(block[5], 5); 47 write_octeon_64bit_block_dword(block[6], 6); 48 octeon_sha256_start(block[7]); 49 50 data += SHA256_BLOCK_SIZE; 51 } while (--nblocks); 52 53 state64[0] = read_octeon_64bit_hash_dword(0); 54 state64[1] = read_octeon_64bit_hash_dword(1); 55 state64[2] = read_octeon_64bit_hash_dword(2); 56 state64[3] = read_octeon_64bit_hash_dword(3); 57 octeon_crypto_disable(&cop2_state, flags); 58 } 59