1 /* 2 * Copyright (C) 2016 Cavium, Inc. 3 * 4 * This program is free software; you can redistribute it and/or modify it 5 * under the terms of version 2 of the GNU General Public License 6 * as published by the Free Software Foundation. 7 */ 8 9 #ifndef _CPTVF_ALGS_H_ 10 #define _CPTVF_ALGS_H_ 11 12 #include "request_manager.h" 13 14 #define MAX_DEVICES 16 15 #define MAJOR_OP_FC 0x33 16 #define MAX_ENC_KEY_SIZE 32 17 #define MAX_HASH_KEY_SIZE 64 18 #define MAX_KEY_SIZE (MAX_ENC_KEY_SIZE + MAX_HASH_KEY_SIZE) 19 #define CONTROL_WORD_LEN 8 20 #define KEY2_OFFSET 48 21 22 #define DMA_MODE_FLAG(dma_mode) \ 23 (((dma_mode) == DMA_GATHER_SCATTER) ? (1 << 7) : 0) 24 25 enum req_type { 26 AE_CORE_REQ, 27 SE_CORE_REQ, 28 }; 29 30 enum cipher_type { 31 DES3_CBC = 0x1, 32 DES3_ECB = 0x2, 33 AES_CBC = 0x3, 34 AES_ECB = 0x4, 35 AES_CFB = 0x5, 36 AES_CTR = 0x6, 37 AES_GCM = 0x7, 38 AES_XTS = 0x8 39 }; 40 41 enum aes_type { 42 AES_128_BIT = 0x1, 43 AES_192_BIT = 0x2, 44 AES_256_BIT = 0x3 45 }; 46 47 union encr_ctrl { 48 u64 flags; 49 struct { 50 #if defined(__BIG_ENDIAN_BITFIELD) 51 u64 enc_cipher:4; 52 u64 reserved1:1; 53 u64 aes_key:2; 54 u64 iv_source:1; 55 u64 hash_type:4; 56 u64 reserved2:3; 57 u64 auth_input_type:1; 58 u64 mac_len:8; 59 u64 reserved3:8; 60 u64 encr_offset:16; 61 u64 iv_offset:8; 62 u64 auth_offset:8; 63 #else 64 u64 auth_offset:8; 65 u64 iv_offset:8; 66 u64 encr_offset:16; 67 u64 reserved3:8; 68 u64 mac_len:8; 69 u64 auth_input_type:1; 70 u64 reserved2:3; 71 u64 hash_type:4; 72 u64 iv_source:1; 73 u64 aes_key:2; 74 u64 reserved1:1; 75 u64 enc_cipher:4; 76 #endif 77 } e; 78 }; 79 80 struct enc_context { 81 union encr_ctrl enc_ctrl; 82 u8 encr_key[32]; 83 u8 encr_iv[16]; 84 }; 85 86 struct fchmac_context { 87 u8 ipad[64]; 88 u8 opad[64]; /* or OPAD */ 89 }; 90 91 struct fc_context { 92 struct enc_context enc; 93 struct fchmac_context hmac; 94 }; 95 96 struct cvm_enc_ctx { 97 u32 key_len; 98 u8 enc_key[MAX_KEY_SIZE]; 99 }; 100 101 struct cvm_des3_ctx { 102 u32 key_len; 103 u8 des3_key[MAX_KEY_SIZE]; 104 }; 105 106 struct cvm_req_ctx { 107 struct cpt_request_info cpt_req; 108 u64 control_word; 109 struct fc_context fctx; 110 }; 111 112 int cptvf_do_request(void *cptvf, struct cpt_request_info *req); 113 #endif /*_CPTVF_ALGS_H_*/ 114