qat_algs.h revision a41e6ff1
1/*
2 *  This file is provided under a dual BSD/GPLv2 license.  When using or
3 *  redistributing this file, you may do so under either license.
4 *
5 *  GPL LICENSE SUMMARY
6 *  Copyright(c) 2015-2016 Intel Corporation.
7 *  This program is free software; you can redistribute it and/or modify
8 *  it under the terms of version 2 of the GNU General Public License as
9 *  published by the Free Software Foundation.
10 *
11 *  This program is distributed in the hope that it will be useful, but
12 *  WITHOUT ANY WARRANTY; without even the implied warranty of
13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 *  General Public License for more details.
15 *
16 *  Contact Information:
17 *  qat-linux@intel.com
18 *
19 *  BSD LICENSE
20 *  Copyright(c) 2015-2016 Intel Corporation.
21 *  Redistribution and use in source and binary forms, with or without
22 *  modification, are permitted provided that the following conditions
23 *  are met:
24 *
25 *    * Redistributions of source code must retain the above copyright
26 *      notice, this list of conditions and the following disclaimer.
27 *    * Redistributions in binary form must reproduce the above copyright
28 *      notice, this list of conditions and the following disclaimer in
29 *      the documentation and/or other materials provided with the
30 *      distribution.
31 *    * Neither the name of Intel Corporation nor the names of its
32 *      contributors may be used to endorse or promote products derived
33 *      from this software without specific prior written permission.
34 *
35 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38 *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39 *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42 *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43 *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44 *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45 *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46 */
47#ifndef _ICP_QAT_ALGS_H_
48#define _ICP_QAT_ALGS_H_
49#include <rte_memory.h>
50#include "icp_qat_hw.h"
51#include "icp_qat_fw.h"
52#include "icp_qat_fw_la.h"
53
54#define QAT_AES_HW_CONFIG_CBC_ENC(alg) \
55	ICP_QAT_HW_CIPHER_CONFIG_BUILD(ICP_QAT_HW_CIPHER_CBC_MODE, alg, \
56					ICP_QAT_HW_CIPHER_NO_CONVERT, \
57					ICP_QAT_HW_CIPHER_ENCRYPT)
58
59#define QAT_AES_HW_CONFIG_CBC_DEC(alg) \
60	ICP_QAT_HW_CIPHER_CONFIG_BUILD(ICP_QAT_HW_CIPHER_CBC_MODE, alg, \
61					ICP_QAT_HW_CIPHER_KEY_CONVERT, \
62					ICP_QAT_HW_CIPHER_DECRYPT)
63
64struct qat_alg_buf {
65	uint32_t len;
66	uint32_t resrvd;
67	uint64_t addr;
68} __rte_packed;
69
70struct qat_alg_buf_list {
71	uint64_t resrvd;
72	uint32_t num_bufs;
73	uint32_t num_mapped_bufs;
74	struct qat_alg_buf bufers[];
75} __rte_packed __rte_cache_aligned;
76
77/* Common content descriptor */
78struct qat_alg_cd {
79	struct icp_qat_hw_cipher_algo_blk cipher;
80	struct icp_qat_hw_auth_algo_blk hash;
81} __rte_packed __rte_cache_aligned;
82
83struct qat_session {
84	enum icp_qat_fw_la_cmd_id qat_cmd;
85	enum icp_qat_hw_cipher_algo qat_cipher_alg;
86	enum icp_qat_hw_cipher_dir qat_dir;
87	enum icp_qat_hw_cipher_mode qat_mode;
88	enum icp_qat_hw_auth_algo qat_hash_alg;
89	struct qat_alg_cd cd;
90	phys_addr_t cd_paddr;
91	struct icp_qat_fw_la_bulk_req fw_req;
92	struct qat_crypto_instance *inst;
93	uint8_t salt[ICP_QAT_HW_AES_BLK_SZ];
94	rte_spinlock_t lock;	/* protects this struct */
95};
96
97struct qat_alg_ablkcipher_cd {
98	struct icp_qat_hw_cipher_algo_blk *cd;
99	phys_addr_t cd_paddr;
100	struct icp_qat_fw_la_bulk_req fw_req;
101	struct qat_crypto_instance *inst;
102	rte_spinlock_t lock;	/* protects this struct */
103};
104
105int qat_get_inter_state_size(enum icp_qat_hw_auth_algo qat_hash_alg);
106
107int qat_alg_aead_session_create_content_desc_cipher(struct qat_session *cd,
108						uint8_t *enckey,
109						uint32_t enckeylen);
110
111int qat_alg_aead_session_create_content_desc_auth(struct qat_session *cdesc,
112						uint8_t *authkey,
113						uint32_t authkeylen,
114						uint32_t add_auth_data_length,
115						uint32_t digestsize,
116						unsigned int operation);
117
118void qat_alg_init_common_hdr(struct icp_qat_fw_comn_req_hdr *header);
119
120void qat_alg_ablkcipher_init_enc(struct qat_alg_ablkcipher_cd *cd,
121					int alg, const uint8_t *key,
122					unsigned int keylen);
123
124void qat_alg_ablkcipher_init_dec(struct qat_alg_ablkcipher_cd *cd,
125					int alg, const uint8_t *key,
126					unsigned int keylen);
127
128int qat_alg_validate_aes_key(int key_len, enum icp_qat_hw_cipher_algo *alg);
129int qat_alg_validate_snow3g_key(int key_len, enum icp_qat_hw_cipher_algo *alg);
130
131#endif
132