aboutsummaryrefslogtreecommitdiff
path: root/sys/mips/nlm/dev/sec/nlmseclib.h
blob: 038b0ae9165a052522c364b887e35cd9c12a088a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*-
 * Copyright (c) 2003-2012 Broadcom Corporation
 * All Rights Reserved
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY BROADCOM ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * $FreeBSD$
 */

#ifndef _NLMSECLIB_H_
#define	_NLMSECLIB_H_

/*
 * Cryptographic parameter definitions
 */
#define	XLP_SEC_DES_KEY_LENGTH		8	/* Bytes */
#define	XLP_SEC_3DES_KEY_LENGTH		24	/* Bytes */
#define	XLP_SEC_AES128_KEY_LENGTH	16	/* Bytes */
#define	XLP_SEC_AES192_KEY_LENGTH	24	/* Bytes */
#define	XLP_SEC_AES256_KEY_LENGTH	32	/* Bytes */
#define	XLP_SEC_AES128F8_KEY_LENGTH	32	/* Bytes */
#define	XLP_SEC_AES192F8_KEY_LENGTH	48	/* Bytes */
#define	XLP_SEC_AES256F8_KEY_LENGTH	64	/* Bytes */
#define	XLP_SEC_KASUMI_F8_KEY_LENGTH	16	/* Bytes */
#define	XLP_SEC_MAX_CRYPT_KEY_LENGTH	XLP_SEC_AES256F8_KEY_LENGTH


#define	XLP_SEC_DES_IV_LENGTH		8	/* Bytes */
#define	XLP_SEC_AES_IV_LENGTH		16	/* Bytes */
#define	XLP_SEC_ARC4_IV_LENGTH		0	/* Bytes */
#define	XLP_SEC_KASUMI_F8_IV_LENGTH	16	/* Bytes */
#define	XLP_SEC_MAX_IV_LENGTH		16	/* Bytes */
#define	XLP_SEC_IV_LENGTH_BYTES		8	/* Bytes */

#define	XLP_SEC_AES_BLOCK_SIZE		16	/* Bytes */
#define	XLP_SEC_DES_BLOCK_SIZE		8	/* Bytes */
#define	XLP_SEC_3DES_BLOCK_SIZE		8	/* Bytes */

#define	XLP_SEC_MD5_BLOCK_SIZE		64	/* Bytes */
#define	XLP_SEC_SHA1_BLOCK_SIZE		64	/* Bytes */
#define	XLP_SEC_SHA256_BLOCK_SIZE	64	/* Bytes */
#define	XLP_SEC_SHA384_BLOCK_SIZE	128	/* Bytes */
#define	XLP_SEC_SHA512_BLOCK_SIZE	128	/* Bytes */
#define	XLP_SEC_GCM_BLOCK_SIZE		16	/* XXX: Bytes */
#define	XLP_SEC_KASUMI_F9_BLOCK_SIZE	16	/* XXX: Bytes */
#define	XLP_SEC_MAX_BLOCK_SIZE		64	/* Max of MD5/SHA */
#define	XLP_SEC_MD5_LENGTH		16	/* Bytes */
#define	XLP_SEC_SHA1_LENGTH		20	/* Bytes */
#define	XLP_SEC_SHA256_LENGTH		32	/* Bytes */
#define	XLP_SEC_SHA384_LENGTH		64	/* Bytes */
#define	XLP_SEC_SHA512_LENGTH		64	/* Bytes */
#define	XLP_SEC_GCM_LENGTH		16	/* Bytes */
#define	XLP_SEC_KASUMI_F9_LENGTH	16	/* Bytes */
#define	XLP_SEC_KASUMI_F9_RESULT_LENGTH	4	/* Bytes */
#define	XLP_SEC_HMAC_LENGTH		64	/* Max of MD5/SHA/SHA256 */
#define	XLP_SEC_MAX_AUTH_KEY_LENGTH	XLP_SEC_SHA512_BLOCK_SIZE
#define	XLP_SEC_MAX_RC4_STATE_SIZE	264	/* char s[256], int i, int j */

#define	XLP_SEC_SESSION(sid)	((sid) & 0x000007ff)
#define	XLP_SEC_SID(crd,ses)	(((crd) << 28) | ((ses) & 0x7ff))

#define	CRYPTO_ERROR(msg1)	((unsigned int)msg1)

#define	NLM_CRYPTO_LEFT_REQS (CMS_DEFAULT_CREDIT/2)
#define	NLM_CRYPTO_NUM_SEGS_REQD(__bufsize)				\
	((__bufsize + NLM_CRYPTO_MAX_SEG_LEN - 1) / NLM_CRYPTO_MAX_SEG_LEN)

#define	NLM_CRYPTO_PKT_DESC_SIZE(nsegs) (32 + (nsegs * 16))

extern unsigned int creditleft;

struct xlp_sec_command {
	uint16_t session_num;
	struct cryptop *crp;
	struct cryptodesc *enccrd, *maccrd;
	struct xlp_sec_session *ses;
	struct nlm_crypto_pkt_ctrl *ctrlp;
	struct nlm_crypto_pkt_param *paramp;
	void *iv;
	uint8_t des3key[24];
	uint8_t *hashdest;
	uint8_t hashsrc;
	uint8_t hmacpad;
	uint32_t hashoff;
	uint32_t hashlen;
	uint32_t cipheroff;
	uint32_t cipherlen;
	uint32_t ivoff;
	uint32_t ivlen;
	uint32_t hashalg;
	uint32_t hashmode;
	uint32_t cipheralg;
	uint32_t ciphermode;
	uint32_t nsegs;
	uint32_t hash_dst_len; /* used to store hash alg dst size */
};

struct xlp_sec_session {
	uint32_t sessionid;
	int hs_used;
	int hs_mlen;
	uint8_t ses_iv[EALG_MAX_BLOCK_LEN];
	struct xlp_sec_command cmd;
};

/*
 * Holds data specific to nlm security accelerators
 */
struct xlp_sec_softc {
	device_t sc_dev;	/* device backpointer */
	uint64_t sec_base;
	int32_t sc_cid;
	struct xlp_sec_session *sc_sessions;
	int sc_nsessions;
	int sc_needwakeup;
	uint32_t sec_vc_start;
	uint32_t sec_vc_end;
	uint32_t sec_msgsz;
};

#ifdef NLM_SEC_DEBUG
void	print_crypto_params(struct xlp_sec_command *cmd, struct nlm_fmn_msg m);
void	xlp_sec_print_data(struct cryptop *crp);
void	print_cmd(struct xlp_sec_command *cmd);
#endif
int	nlm_crypto_form_srcdst_segs(struct xlp_sec_command *cmd);
int	nlm_crypto_do_cipher(struct xlp_sec_softc *sc,
	    struct xlp_sec_command *cmd);
int	nlm_crypto_do_digest(struct xlp_sec_softc *sc,
	    struct xlp_sec_command *cmd);
int	nlm_crypto_do_cipher_digest(struct xlp_sec_softc *sc,
	    struct xlp_sec_command *cmd);
int	nlm_get_digest_param(struct xlp_sec_command *cmd);
int	nlm_get_cipher_param(struct xlp_sec_command *cmd);

#endif /* _NLMSECLIB_H_ */