1 /* 2 * Copyright (c) 2022 Intel Corporation. 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ZEPHYR_DRIVERS_CRYPTO_CRYPTO_INTEL_SHA_PRIV_H_ 8 #define ZEPHYR_DRIVERS_CRYPTO_CRYPTO_INTEL_SHA_PRIV_H_ 9 10 #include <zephyr/kernel.h> 11 #include <zephyr/sys/util.h> 12 #include "crypto_intel_sha_registers.h" 13 14 #define SHA_HASH_DATA_BLOCK_LEN (64) 15 #define SHA_API_MAX_FRAG_LEN (64 * 1024 - 256) 16 #define SHA_REQUIRED_BLOCK_ALIGNMENT (512) 17 18 /* Possible SHA states */ 19 #define SHA_FIRST (2) 20 #define SHA_MIDLE (3) 21 #define SHA_LAST (0) 22 /* SHA resume flag */ 23 #define SHA_HRSM_ENABLE (1) 24 #define SHA_HRSM_DISABLE (0) 25 26 #define SHA1_ALGORITHM_HASH_SIZEOF (160 / 8) 27 #define SHA224_ALGORITHM_HASH_SIZEOF (224 / 8) 28 #define SHA256_ALGORITHM_HASH_SIZEOF (256 / 8) 29 #define SHA384_ALGORITHM_HASH_SIZEOF (384 / 8) 30 #define SHA512_ALGORITHM_HASH_SIZEOF (512 / 8) 31 32 #define SHA_MAX_SESSIONS 8 33 34 #define BYTE_SWAP32(x) \ 35 (((x >> 24) & 0x000000FF) | ((x << 24) & 0xFF000000) | ((x >> 8) & 0x0000FF00) | \ 36 ((x << 8) & 0x00FF0000)) 37 38 struct sha_hw_regs { 39 union PIBCS pibcs; 40 union PIBBA pibba; 41 union PIBS pibs; 42 union PIBFPI pibfpi; 43 union PIBRP pibrp; 44 union PIBWP pibwp; 45 union PIBSP pibsp; 46 uint32_t not_used1[5]; 47 union SHARLDW0 sharldw0; 48 union SHARLDW1 sharldw1; 49 union SHAALDW0 shaaldw0; 50 union SHAALDW1 shaaldw1; 51 union SHACTL shactl; 52 union SHASTS shasts; 53 uint32_t not_used12[2]; 54 uint8_t initial_vector[64]; 55 uint8_t sha_result[64]; 56 }; 57 58 union sha_state { 59 uint32_t full; 60 struct { 61 /* Hash state: SHA_FIRST, SHA_MIDLE or SHA_LAST */ 62 uint32_t state : 3; 63 /* Hash resume bit */ 64 uint32_t hrsm : 1; 65 uint32_t rsvd : 28; 66 } part; 67 }; 68 69 struct sha_context { 70 union SHAALDW0 shaaldw0; 71 union SHAALDW1 shaaldw1; 72 uint8_t initial_vector[SHA_HASH_DATA_BLOCK_LEN]; 73 uint8_t sha_result[SHA_HASH_DATA_BLOCK_LEN]; 74 }; 75 76 struct sha_session { 77 struct sha_context sha_ctx; 78 union sha_state state; 79 uint32_t algo; 80 bool in_use; 81 }; 82 83 struct sha_container { 84 /* pointer to DSP SHA Registers */ 85 volatile struct sha_hw_regs *dfsha; 86 }; 87 88 #endif 89