1 /* |
|
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. Oracle designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Oracle in the LICENSE file that accompanied this code. |
|
10 * |
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
|
15 * accompanied this code). |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License version |
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 * |
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 * or visit www.oracle.com if you need additional information or have any |
|
23 * questions. |
|
24 */ |
|
25 |
|
26 #ifndef _LIBSOFTCRYPTO_H |
|
27 #define _LIBSOFTCRYPTO_H |
|
28 |
|
29 #include <sys/types.h> |
|
30 #include <stdio.h> |
|
31 #include <stdlib.h> |
|
32 #include <errno.h> |
|
33 #include <unistd.h> |
|
34 #include <strings.h> |
|
35 |
|
36 typedef enum ucrypto_mech { |
|
37 CRYPTO_AES_ECB = 1, |
|
38 CRYPTO_AES_CBC, |
|
39 CRYPTO_AES_CBC_PAD, |
|
40 CRYPTO_AES_CTR, |
|
41 CRYPTO_AES_CCM, |
|
42 CRYPTO_AES_GCM, |
|
43 CRYPTO_AES_GMAC, |
|
44 CRYPTO_AES_CFB128, |
|
45 CRYPTO_RSA_PKCS = 31, |
|
46 CRYPTO_RSA_X_509, |
|
47 CRYPTO_MD5_RSA_PKCS, |
|
48 CRYPTO_SHA1_RSA_PKCS, |
|
49 CRYPTO_SHA256_RSA_PKCS, |
|
50 CRYPTO_SHA384_RSA_PKCS, |
|
51 CRYPTO_SHA512_RSA_PKCS |
|
52 } ucrypto_mech_t; |
|
53 |
|
54 typedef struct crypto_ctx { |
|
55 void *cc_provider; |
|
56 uint_t cc_session; |
|
57 void *cc_provider_private; /* owned by provider */ |
|
58 void *cc_framework_private; /* owned by framework */ |
|
59 uint32_t cc_flags; /* flags */ |
|
60 void *cc_opstate; /* state */ |
|
61 } crypto_ctx_t; |
|
62 |
|
63 extern int ucrypto_encrypt_init(crypto_ctx_t *context, |
|
64 ucrypto_mech_t mech_type, uchar_t *key_str, size_t key_len, |
|
65 void *iv, size_t iv_len); |
|
66 |
|
67 extern int ucrypto_encrypt_update(crypto_ctx_t *context, uchar_t *in, |
|
68 size_t in_len, uchar_t *out, size_t *out_len); |
|
69 |
|
70 extern int ucrypto_encrypt_final(crypto_ctx_t *context, uchar_t *out, |
|
71 size_t *out_len); |
|
72 |
|
73 /* Encrypt atomic */ |
|
74 extern int ucrypto_encrypt(ucrypto_mech_t mech_type, uchar_t *key_str, |
|
75 size_t key_len, void *iv, size_t iv_len, uchar_t *in, |
|
76 size_t in_len, uchar_t *out, size_t *out_len); |
|
77 |
|
78 /* Decrypt multi-part */ |
|
79 extern int ucrypto_decrypt_init(crypto_ctx_t *context, |
|
80 ucrypto_mech_t mech_type, uchar_t *key_str, size_t key_len, |
|
81 void *iv, size_t iv_len); |
|
82 |
|
83 extern int ucrypto_decrypt_update(crypto_ctx_t *context, uchar_t *in, |
|
84 size_t in_len, uchar_t *out, size_t *out_len); |
|
85 |
|
86 extern int ucrypto_decrypt_final(crypto_ctx_t *context, uchar_t *out, |
|
87 size_t *out_len); |
|
88 |
|
89 /* Decrypt atomic */ |
|
90 extern int ucrypto_decrypt(ucrypto_mech_t mech_type, uchar_t *key_str, |
|
91 size_t key_len, void *iv, size_t iv_len, uchar_t *in, |
|
92 size_t in_len, uchar_t *out, size_t *out_len); |
|
93 |
|
94 /* Sign multi-part */ |
|
95 extern int ucrypto_sign_init(crypto_ctx_t *context, ucrypto_mech_t mech_type, |
|
96 uchar_t *key_str, size_t key_len, void *iv, size_t iv_len); |
|
97 |
|
98 extern int ucrypto_sign_update(crypto_ctx_t *context, |
|
99 uchar_t *data_str, size_t data_len); |
|
100 |
|
101 extern int ucrypto_sign_final(crypto_ctx_t *context, |
|
102 uchar_t *sig_str, size_t *sig_len); |
|
103 |
|
104 /* Sign atomic */ |
|
105 extern int ucrypto_sign(ucrypto_mech_t mech_type, |
|
106 uchar_t *key_str, size_t key_len, void *iv, size_t iv_len, |
|
107 uchar_t *data_str, size_t data_len, uchar_t *sig_str, size_t *sig_len); |
|
108 |
|
109 /* Verify multi-part */ |
|
110 extern int ucrypto_verify_init(crypto_ctx_t *context, ucrypto_mech_t mech_type, |
|
111 uchar_t *key_str, size_t key_len, void *iv, size_t iv_len); |
|
112 |
|
113 extern int ucrypto_verify_update(crypto_ctx_t *context, |
|
114 uchar_t *data_str, size_t data_len); |
|
115 |
|
116 extern int ucrypto_verify_final(crypto_ctx_t *context, |
|
117 uchar_t *sig_str, size_t *sig_len); |
|
118 |
|
119 /* Verify atomic */ |
|
120 extern int ucrypto_verify(ucrypto_mech_t mech_type, |
|
121 uchar_t *key_str, size_t key_len, void *iv, size_t iv_len, |
|
122 uchar_t *data_str, size_t data_len, uchar_t *sig, size_t *sig_len); |
|
123 |
|
124 extern int ucrypto_get_mechlist(char *str); |
|
125 |
|
126 extern const char *ucrypto_id2mech(ucrypto_mech_t mech_type); |
|
127 |
|
128 extern ucrypto_mech_t ucrypto_mech2id(const char *str); |
|
129 |
|
130 extern int ucrypto_version(); |
|
131 |
|
132 typedef struct CK_AES_CTR_PARAMS { |
|
133 ulong_t ulCounterBits; |
|
134 uint8_t cb[16]; |
|
135 } CK_AES_CTR_PARAMS; |
|
136 |
|
137 typedef struct CK_AES_GCM_PARAMS { |
|
138 uchar_t *pIv; |
|
139 ulong_t ulIvLen; |
|
140 ulong_t ulIvBits; |
|
141 uchar_t *pAAD; |
|
142 ulong_t ulAADLen; |
|
143 ulong_t ulTagBits; |
|
144 } CK_AES_GCM_PARAMS; |
|
145 |
|
146 typedef struct crypto_object_attribute { |
|
147 uint64_t oa_type; /* attribute type */ |
|
148 caddr_t oa_value; /* attribute value */ |
|
149 ssize_t oa_value_len; /* length of attribute value */ |
|
150 } crypto_object_attribute_t; |
|
151 |
|
152 /* Attribute types to use for passing a RSA public key or a private key. */ |
|
153 #define SUN_CKA_MODULUS 0x00000120 |
|
154 #define SUN_CKA_MODULUS_BITS 0x00000121 |
|
155 #define SUN_CKA_PUBLIC_EXPONENT 0x00000122 |
|
156 #define SUN_CKA_PRIVATE_EXPONENT 0x00000123 |
|
157 #define SUN_CKA_PRIME_1 0x00000124 |
|
158 #define SUN_CKA_PRIME_2 0x00000125 |
|
159 #define SUN_CKA_EXPONENT_1 0x00000126 |
|
160 #define SUN_CKA_EXPONENT_2 0x00000127 |
|
161 #define SUN_CKA_COEFFICIENT 0x00000128 |
|
162 #define SUN_CKA_PRIME 0x00000130 |
|
163 #define SUN_CKA_SUBPRIME 0x00000131 |
|
164 #define SUN_CKA_BASE 0x00000132 |
|
165 |
|
166 #define CKK_EC 0x00000003 |
|
167 #define CKK_GENERIC_SECRET 0x00000010 |
|
168 #define CKK_RC4 0x00000012 |
|
169 #define CKK_AES 0x0000001F |
|
170 #define CKK_DES 0x00000013 |
|
171 #define CKK_DES2 0x00000014 |
|
172 #define CKK_DES3 0x00000015 |
|
173 |
|
174 #define CKO_PUBLIC_KEY 0x00000002 |
|
175 #define CKO_PRIVATE_KEY 0x00000003 |
|
176 #define CKA_CLASS 0x00000000 |
|
177 #define CKA_VALUE 0x00000011 |
|
178 #define CKA_KEY_TYPE 0x00000100 |
|
179 #define CKA_VALUE_LEN 0x00000161 |
|
180 #define CKA_EC_PARAMS 0x00000180 |
|
181 #define CKA_EC_POINT 0x00000181 |
|
182 |
|
183 #endif /* _LIBSOFTCRYPTO_H */ |
|