]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - sys/mips/nlm/dev/sec/nlmseclib.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / sys / mips / nlm / dev / sec / nlmseclib.h
1 /*-
2  * Copyright (c) 2003-2012 Broadcom Corporation
3  * All Rights Reserved
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in
13  *    the documentation and/or other materials provided with the
14  *    distribution.
15  * 
16  * THIS SOFTWARE IS PROVIDED BY BROADCOM ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * $FreeBSD$
29  */
30
31 #ifndef _NLMSECLIB_H_
32 #define _NLMSECLIB_H_
33
34 /*
35  * Cryptographic parameter definitions
36  */
37 #define XLP_SEC_DES_KEY_LENGTH          8       /* Bytes */
38 #define XLP_SEC_3DES_KEY_LENGTH         24      /* Bytes */
39 #define XLP_SEC_AES128_KEY_LENGTH       16      /* Bytes */
40 #define XLP_SEC_AES192_KEY_LENGTH       24      /* Bytes */
41 #define XLP_SEC_AES256_KEY_LENGTH       32      /* Bytes */
42 #define XLP_SEC_AES128F8_KEY_LENGTH     32      /* Bytes */
43 #define XLP_SEC_AES192F8_KEY_LENGTH     48      /* Bytes */
44 #define XLP_SEC_AES256F8_KEY_LENGTH     64      /* Bytes */
45 #define XLP_SEC_KASUMI_F8_KEY_LENGTH    16      /* Bytes */
46 #define XLP_SEC_MAX_CRYPT_KEY_LENGTH    XLP_SEC_AES256F8_KEY_LENGTH
47
48
49 #define XLP_SEC_DES_IV_LENGTH           8       /* Bytes */
50 #define XLP_SEC_AES_IV_LENGTH           16      /* Bytes */
51 #define XLP_SEC_ARC4_IV_LENGTH          0       /* Bytes */
52 #define XLP_SEC_KASUMI_F8_IV_LENGTH     16      /* Bytes */
53 #define XLP_SEC_MAX_IV_LENGTH           16      /* Bytes */
54 #define XLP_SEC_IV_LENGTH_BYTES         8       /* Bytes */
55
56 #define XLP_SEC_AES_BLOCK_SIZE          16      /* Bytes */
57 #define XLP_SEC_DES_BLOCK_SIZE          8       /* Bytes */
58 #define XLP_SEC_3DES_BLOCK_SIZE         8       /* Bytes */
59
60 #define XLP_SEC_MD5_BLOCK_SIZE          64      /* Bytes */
61 #define XLP_SEC_SHA1_BLOCK_SIZE         64      /* Bytes */
62 #define XLP_SEC_SHA256_BLOCK_SIZE       64      /* Bytes */
63 #define XLP_SEC_SHA384_BLOCK_SIZE       128     /* Bytes */
64 #define XLP_SEC_SHA512_BLOCK_SIZE       128     /* Bytes */
65 #define XLP_SEC_GCM_BLOCK_SIZE          16      /* XXX: Bytes */
66 #define XLP_SEC_KASUMI_F9_BLOCK_SIZE    16      /* XXX: Bytes */
67 #define XLP_SEC_MAX_BLOCK_SIZE          64      /* Max of MD5/SHA */
68 #define XLP_SEC_MD5_LENGTH              16      /* Bytes */
69 #define XLP_SEC_SHA1_LENGTH             20      /* Bytes */
70 #define XLP_SEC_SHA256_LENGTH           32      /* Bytes */
71 #define XLP_SEC_SHA384_LENGTH           64      /* Bytes */
72 #define XLP_SEC_SHA512_LENGTH           64      /* Bytes */
73 #define XLP_SEC_GCM_LENGTH              16      /* Bytes */
74 #define XLP_SEC_KASUMI_F9_LENGTH        16      /* Bytes */
75 #define XLP_SEC_KASUMI_F9_RESULT_LENGTH 4       /* Bytes */
76 #define XLP_SEC_HMAC_LENGTH             64      /* Max of MD5/SHA/SHA256 */
77 #define XLP_SEC_MAX_AUTH_KEY_LENGTH     XLP_SEC_SHA512_BLOCK_SIZE
78 #define XLP_SEC_MAX_RC4_STATE_SIZE      264     /* char s[256], int i, int j */
79
80 #define XLP_SEC_SESSION(sid)    ((sid) & 0x000007ff)
81 #define XLP_SEC_SID(crd,ses)    (((crd) << 28) | ((ses) & 0x7ff))
82
83 #define CRYPTO_ERROR(msg1)      ((unsigned int)msg1)
84
85 #define NLM_CRYPTO_LEFT_REQS (CMS_DEFAULT_CREDIT/2)
86 #define NLM_CRYPTO_NUM_SEGS_REQD(__bufsize)                             \
87         ((__bufsize + NLM_CRYPTO_MAX_SEG_LEN - 1) / NLM_CRYPTO_MAX_SEG_LEN)
88
89 #define NLM_CRYPTO_PKT_DESC_SIZE(nsegs) (32 + (nsegs * 16))
90
91 extern unsigned int creditleft;
92
93 struct xlp_sec_command {
94         uint16_t session_num;
95         struct cryptop *crp;
96         struct cryptodesc *enccrd, *maccrd;
97         struct xlp_sec_session *ses;
98         struct nlm_crypto_pkt_ctrl *ctrlp;
99         struct nlm_crypto_pkt_param *paramp;
100         void *iv;
101         uint8_t des3key[24];
102         uint8_t *hashdest;
103         uint8_t hashsrc;
104         uint8_t hmacpad;
105         uint32_t hashoff;
106         uint32_t hashlen;
107         uint32_t cipheroff;
108         uint32_t cipherlen;     
109         uint32_t ivoff;
110         uint32_t ivlen;
111         uint32_t hashalg;
112         uint32_t hashmode;
113         uint32_t cipheralg;
114         uint32_t ciphermode;    
115         uint32_t nsegs;
116         uint32_t hash_dst_len; /* used to store hash alg dst size */
117 };
118
119 struct xlp_sec_session {
120         uint32_t sessionid;
121         int hs_used;
122         int hs_mlen;
123         uint8_t ses_iv[EALG_MAX_BLOCK_LEN];
124         struct xlp_sec_command cmd;
125 };
126
127 /*
128  * Holds data specific to nlm security accelerators
129  */
130 struct xlp_sec_softc {
131         device_t sc_dev;        /* device backpointer */
132         uint64_t sec_base;
133         int32_t sc_cid;
134         struct xlp_sec_session *sc_sessions;
135         int sc_nsessions;
136         int sc_needwakeup;
137         uint32_t sec_vc_start;
138         uint32_t sec_vc_end;
139         uint32_t sec_msgsz;
140 };
141
142 #ifdef NLM_SEC_DEBUG
143 void    print_crypto_params(struct xlp_sec_command *cmd, struct nlm_fmn_msg m);
144 void    xlp_sec_print_data(struct cryptop *crp);
145 void    print_cmd(struct xlp_sec_command *cmd);
146 #endif
147 int     nlm_crypto_form_srcdst_segs(struct xlp_sec_command *cmd);
148 int     nlm_crypto_do_cipher(struct xlp_sec_softc *sc,
149             struct xlp_sec_command *cmd);
150 int     nlm_crypto_do_digest(struct xlp_sec_softc *sc,
151             struct xlp_sec_command *cmd);
152 int     nlm_crypto_do_cipher_digest(struct xlp_sec_softc *sc,
153             struct xlp_sec_command *cmd);
154 int     nlm_get_digest_param(struct xlp_sec_command *cmd);
155 int     nlm_get_cipher_param(struct xlp_sec_command *cmd);
156
157 #endif /* _NLMSECLIB_H_ */