blob: fb36524f1459a17b7ae4fe8c5c2e2cfee22ebba4 (
plain)
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* cryptmod.h
* STREAMS based crypto module definitions.
*
* This is a Sun-private and undocumented interface.
*/
#ifndef _SYS_CRYPTMOD_H
#define _SYS_CRYPTMOD_H
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/types.h>
#include <sys/types32.h>
#ifdef _KERNEL
#include <sys/crypto/api.h>
#endif /* _KERNEL */
#ifdef __cplusplus
extern "C" {
#endif
/*
* IOCTLs.
*/
#define CRYPTIOC (('C' << 24) | ('R' << 16) | ('Y' << 8) | 0x00)
#define CRYPTIOCSETUP (CRYPTIOC | 0x01)
#define CRYPTIOCSTOP (CRYPTIOC | 0x02)
#define CRYPTIOCSTARTENC (CRYPTIOC | 0x03)
#define CRYPTIOCSTARTDEC (CRYPTIOC | 0x04)
#define CRYPTPASSTHRU (CRYPTIOC | 0x80)
/*
* Crypto method definitions, to be used with the CRIOCSETUP ioctl.
*/
#define CRYPT_METHOD_NONE 0
#define CRYPT_METHOD_DES_CFB 101
#define CRYPT_METHOD_DES_CBC_NULL 102
#define CRYPT_METHOD_DES_CBC_MD5 103
#define CRYPT_METHOD_DES_CBC_CRC 104
#define CRYPT_METHOD_DES3_CBC_SHA1 105
#define CRYPT_METHOD_ARCFOUR_HMAC_MD5 106
#define CRYPT_METHOD_ARCFOUR_HMAC_MD5_EXP 107
#define CRYPT_METHOD_AES128 108
#define CRYPT_METHOD_AES256 109
#define CR_METHOD_OK(m) ((m) == CRYPT_METHOD_NONE || \
((m) >= CRYPT_METHOD_DES_CFB && \
(m) <= CRYPT_METHOD_AES256))
#define IS_RC4_METHOD(m) ((m) == CRYPT_METHOD_ARCFOUR_HMAC_MD5 || \
(m) == CRYPT_METHOD_ARCFOUR_HMAC_MD5_EXP)
#define IS_AES_METHOD(m) ((m) == CRYPT_METHOD_AES128 || \
(m) == CRYPT_METHOD_AES256)
/*
* Direction mask values, also to be used with the CRIOCSETUP ioctl.
*/
#define CRYPT_ENCRYPT 0x01
#define CRYPT_DECRYPT 0x02
#define CR_DIRECTION_OK(d) ((d) & (CRYPT_ENCRYPT | CRYPT_DECRYPT))
/*
* Define constants for the 'ivec_usage' fields.
*/
#define IVEC_NEVER 0x00
#define IVEC_REUSE 0x01
#define IVEC_ONETIME 0x02
#define CR_IVUSAGE_OK(iv) \
((iv) == IVEC_NEVER || (iv) == IVEC_REUSE || (iv) == IVEC_ONETIME)
#define CRYPT_SHA1_BLOCKSIZE 64
#define CRYPT_SHA1_HASHSIZE 20
#define CRYPT_DES3_KEYBYTES 21
#define CRYPT_DES3_KEYLENGTH 24
#define CRYPT_ARCFOUR_KEYBYTES 16
#define CRYPT_ARCFOUR_KEYLENGTH 16
#define CRYPT_AES128_KEYBYTES 16
#define CRYPT_AES128_KEYLENGTH 16
#define CRYPT_AES256_KEYBYTES 32
#define CRYPT_AES256_KEYLENGTH 32
#define AES_TRUNCATED_HMAC_LEN 12
/*
* Max size of initialization vector and key.
* 256 bytes = 2048 bits.
*/
#define CRYPT_MAX_KEYLEN 256
#define CRYPT_MAX_IVLEN 256
typedef uint8_t crkeylen_t;
typedef uint8_t crivlen_t;
typedef uchar_t crmeth_t;
typedef uchar_t cropt_t;
typedef uchar_t crdir_t;
typedef uchar_t crivuse_t;
/*
* Define values for the option mask field.
* These can be extended to alter the behavior
* of the module. For example, when used by kerberized
* Unix r commands (rlogind, rshd), all msgs must be
* prepended with 4 bytes of clear text data that represent
* the 'length' of the cipher text that follows.
*/
#define CRYPTOPT_NONE 0x00
#define CRYPTOPT_RCMD_MODE_V1 0x01
#define CRYPTOPT_RCMD_MODE_V2 0x02
#define ANY_RCMD_MODE(m) ((m) & (CRYPTOPT_RCMD_MODE_V1 |\
CRYPTOPT_RCMD_MODE_V2))
/* Define the size of the length field used in 'rcmd' mode */
#define RCMD_LEN_SZ sizeof (uint32_t)
#define CR_OPTIONS_OK(opt) ((opt) == CRYPTOPT_NONE || \
ANY_RCMD_MODE(opt))
/*
* Structure used by userland apps to pass data into crypto module
* with the CRIOCSETUP iotcl.
*/
struct cr_info_t {
uchar_t key[CRYPT_MAX_KEYLEN];
uchar_t ivec[CRYPT_MAX_IVLEN];
crkeylen_t keylen;
crivlen_t iveclen;
crivuse_t ivec_usage;
crdir_t direction_mask;
crmeth_t crypto_method;
cropt_t option_mask;
};
#if defined(_KERNEL)
#define RCMDV1_USAGE 1026
#define ARCFOUR_DECRYPT_USAGE 1032
#define ARCFOUR_ENCRYPT_USAGE 1028
#define AES_ENCRYPT_USAGE 1028
#define AES_DECRYPT_USAGE 1032
#define DEFAULT_DES_BLOCKLEN 8
#define DEFAULT_AES_BLOCKLEN 16
#define ARCFOUR_EXP_SALT "fortybits"
struct cipher_data_t {
char *key;
char *block;
char *ivec;
char *saveblock;
crypto_mech_type_t mech_type;
crypto_key_t *ckey; /* initial encryption key */
crypto_key_t d_encr_key; /* derived encr key */
crypto_key_t d_hmac_key; /* derived hmac key */
crypto_ctx_template_t enc_tmpl;
crypto_ctx_template_t hmac_tmpl;
crypto_context_t ctx;
size_t bytes;
crkeylen_t blocklen;
crkeylen_t keylen;
crkeylen_t ivlen;
crivuse_t ivec_usage;
crmeth_t method;
cropt_t option_mask;
};
struct rcmd_state_t {
size_t pt_len; /* Plain text length */
size_t cd_len; /* Cipher Data length */
size_t cd_rcvd; /* Cipher Data bytes received so far */
uint32_t next_len;
mblk_t *c_msg; /* mblk that will contain the new data */
};
/* Values for "ready" mask. */
#define CRYPT_WRITE_READY 0x01
#define CRYPT_READ_READY 0x02
/*
* State information for the streams module.
*/
struct tmodinfo {
struct cipher_data_t enc_data;
struct cipher_data_t dec_data;
struct rcmd_state_t rcmd_state;
uchar_t ready;
};
#endif /* _KERNEL */
#ifdef __cplusplus
}
#endif
#endif /* _SYS_CRYPTMOD_H */
|