linux/drivers/crypto/marvell/octeontx2/otx2_cptvf_algs.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0-only
   2 * Copyright (C) 2020 Marvell.
   3 */
   4
   5#ifndef __OTX2_CPT_ALGS_H
   6#define __OTX2_CPT_ALGS_H
   7
   8#include <crypto/hash.h>
   9#include <crypto/skcipher.h>
  10#include <crypto/aead.h>
  11#include "otx2_cpt_common.h"
  12
  13#define OTX2_CPT_MAX_ENC_KEY_SIZE    32
  14#define OTX2_CPT_MAX_HASH_KEY_SIZE   64
  15#define OTX2_CPT_MAX_KEY_SIZE (OTX2_CPT_MAX_ENC_KEY_SIZE + \
  16                               OTX2_CPT_MAX_HASH_KEY_SIZE)
  17enum otx2_cpt_request_type {
  18        OTX2_CPT_ENC_DEC_REQ            = 0x1,
  19        OTX2_CPT_AEAD_ENC_DEC_REQ       = 0x2,
  20        OTX2_CPT_AEAD_ENC_DEC_NULL_REQ  = 0x3,
  21        OTX2_CPT_PASSTHROUGH_REQ        = 0x4
  22};
  23
  24enum otx2_cpt_major_opcodes {
  25        OTX2_CPT_MAJOR_OP_MISC = 0x01,
  26        OTX2_CPT_MAJOR_OP_FC   = 0x33,
  27        OTX2_CPT_MAJOR_OP_HMAC = 0x35,
  28};
  29
  30enum otx2_cpt_cipher_type {
  31        OTX2_CPT_CIPHER_NULL = 0x0,
  32        OTX2_CPT_DES3_CBC = 0x1,
  33        OTX2_CPT_DES3_ECB = 0x2,
  34        OTX2_CPT_AES_CBC  = 0x3,
  35        OTX2_CPT_AES_ECB  = 0x4,
  36        OTX2_CPT_AES_CFB  = 0x5,
  37        OTX2_CPT_AES_CTR  = 0x6,
  38        OTX2_CPT_AES_GCM  = 0x7,
  39        OTX2_CPT_AES_XTS  = 0x8
  40};
  41
  42enum otx2_cpt_mac_type {
  43        OTX2_CPT_MAC_NULL = 0x0,
  44        OTX2_CPT_MD5      = 0x1,
  45        OTX2_CPT_SHA1     = 0x2,
  46        OTX2_CPT_SHA224   = 0x3,
  47        OTX2_CPT_SHA256   = 0x4,
  48        OTX2_CPT_SHA384   = 0x5,
  49        OTX2_CPT_SHA512   = 0x6,
  50        OTX2_CPT_GMAC     = 0x7
  51};
  52
  53enum otx2_cpt_aes_key_len {
  54        OTX2_CPT_AES_128_BIT = 0x1,
  55        OTX2_CPT_AES_192_BIT = 0x2,
  56        OTX2_CPT_AES_256_BIT = 0x3
  57};
  58
  59union otx2_cpt_encr_ctrl {
  60        u64 u;
  61        struct {
  62#if defined(__BIG_ENDIAN_BITFIELD)
  63                u64 enc_cipher:4;
  64                u64 reserved_59:1;
  65                u64 aes_key:2;
  66                u64 iv_source:1;
  67                u64 mac_type:4;
  68                u64 reserved_49_51:3;
  69                u64 auth_input_type:1;
  70                u64 mac_len:8;
  71                u64 reserved_32_39:8;
  72                u64 encr_offset:16;
  73                u64 iv_offset:8;
  74                u64 auth_offset:8;
  75#else
  76                u64 auth_offset:8;
  77                u64 iv_offset:8;
  78                u64 encr_offset:16;
  79                u64 reserved_32_39:8;
  80                u64 mac_len:8;
  81                u64 auth_input_type:1;
  82                u64 reserved_49_51:3;
  83                u64 mac_type:4;
  84                u64 iv_source:1;
  85                u64 aes_key:2;
  86                u64 reserved_59:1;
  87                u64 enc_cipher:4;
  88#endif
  89        } e;
  90};
  91
  92struct otx2_cpt_cipher {
  93        const char *name;
  94        u8 value;
  95};
  96
  97struct otx2_cpt_fc_enc_ctx {
  98        union otx2_cpt_encr_ctrl enc_ctrl;
  99        u8 encr_key[32];
 100        u8 encr_iv[16];
 101};
 102
 103union otx2_cpt_fc_hmac_ctx {
 104        struct {
 105                u8 ipad[64];
 106                u8 opad[64];
 107        } e;
 108        struct {
 109                u8 hmac_calc[64]; /* HMAC calculated */
 110                u8 hmac_recv[64]; /* HMAC received */
 111        } s;
 112};
 113
 114struct otx2_cpt_fc_ctx {
 115        struct otx2_cpt_fc_enc_ctx enc;
 116        union otx2_cpt_fc_hmac_ctx hmac;
 117};
 118
 119struct otx2_cpt_enc_ctx {
 120        u32 key_len;
 121        u8 enc_key[OTX2_CPT_MAX_KEY_SIZE];
 122        u8 cipher_type;
 123        u8 key_type;
 124        u8 enc_align_len;
 125        struct crypto_skcipher *fbk_cipher;
 126};
 127
 128union otx2_cpt_offset_ctrl {
 129        u64 flags;
 130        struct {
 131#if defined(__BIG_ENDIAN_BITFIELD)
 132                u64 reserved:32;
 133                u64 enc_data_offset:16;
 134                u64 iv_offset:8;
 135                u64 auth_offset:8;
 136#else
 137                u64 auth_offset:8;
 138                u64 iv_offset:8;
 139                u64 enc_data_offset:16;
 140                u64 reserved:32;
 141#endif
 142        } e;
 143};
 144
 145struct otx2_cpt_req_ctx {
 146        struct otx2_cpt_req_info cpt_req;
 147        union otx2_cpt_offset_ctrl ctrl_word;
 148        struct otx2_cpt_fc_ctx fctx;
 149        union {
 150                struct skcipher_request sk_fbk_req;
 151                struct aead_request fbk_req;
 152        };
 153};
 154
 155struct otx2_cpt_sdesc {
 156        struct shash_desc shash;
 157};
 158
 159struct otx2_cpt_aead_ctx {
 160        u8 key[OTX2_CPT_MAX_KEY_SIZE];
 161        struct crypto_shash *hashalg;
 162        struct otx2_cpt_sdesc *sdesc;
 163        struct crypto_aead *fbk_cipher;
 164        u8 *ipad;
 165        u8 *opad;
 166        u32 enc_key_len;
 167        u32 auth_key_len;
 168        u8 cipher_type;
 169        u8 mac_type;
 170        u8 key_type;
 171        u8 is_trunc_hmac;
 172        u8 enc_align_len;
 173};
 174int otx2_cpt_crypto_init(struct pci_dev *pdev, struct module *mod,
 175                         int num_queues, int num_devices);
 176void otx2_cpt_crypto_exit(struct pci_dev *pdev, struct module *mod);
 177
 178#endif /* __OTX2_CPT_ALGS_H */
 179