5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 /*
27 * Blowfish provider for the Kernel Cryptographic Framework (KCF)
28 */
29
30 #include <sys/types.h>
31 #include <sys/systm.h>
32 #include <sys/modctl.h>
33 #include <sys/cmn_err.h>
34 #include <sys/ddi.h>
35 #include <sys/crypto/common.h>
36 #include <sys/crypto/spi.h>
37 #include <sys/sysmacros.h>
38 #include <sys/strsun.h>
39 #include <sys/note.h>
40 #include <modes/modes.h>
41 #include <blowfish/blowfish_impl.h>
42
43 extern struct mod_ops mod_cryptoops;
44
302 case BLOWFISH_CBC_MECH_INFO_TYPE:
303 blowfish_ctx = cbc_alloc_ctx(kmflag);
304 break;
305 }
306 if (blowfish_ctx == NULL)
307 return (CRYPTO_HOST_MEMORY);
308
309 rv = blowfish_common_init_ctx(blowfish_ctx, template, mechanism,
310 key, kmflag);
311 if (rv != CRYPTO_SUCCESS) {
312 crypto_free_mode_ctx(blowfish_ctx);
313 return (rv);
314 }
315
316 ctx->cc_provider_private = blowfish_ctx;
317
318 return (CRYPTO_SUCCESS);
319 }
320
321 static void
322 blowfish_copy_block64(uint8_t *in, uint64_t *out)
323 {
324 if (IS_P2ALIGNED(in, sizeof (uint64_t))) {
325 /* LINTED: pointer alignment */
326 out[0] = *(uint64_t *)&in[0];
327 } else {
328 uint8_t *iv8 = (uint8_t *)&out[0];
329
330 BLOWFISH_COPY_BLOCK(in, iv8);
331 }
332 }
333
334 /* ARGSUSED */
335 static int
336 blowfish_encrypt(crypto_ctx_t *ctx, crypto_data_t *plaintext,
337 crypto_data_t *ciphertext, crypto_req_handle_t req)
338 {
339 int ret;
340
341 blowfish_ctx_t *blowfish_ctx;
342
|
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25 /*
26 * Copyright 2015 by Saso Kiselkov. All rights reserved.
27 */
28
29 /*
30 * Blowfish provider for the Kernel Cryptographic Framework (KCF)
31 */
32
33 #include <sys/types.h>
34 #include <sys/systm.h>
35 #include <sys/modctl.h>
36 #include <sys/cmn_err.h>
37 #include <sys/ddi.h>
38 #include <sys/crypto/common.h>
39 #include <sys/crypto/spi.h>
40 #include <sys/sysmacros.h>
41 #include <sys/strsun.h>
42 #include <sys/note.h>
43 #include <modes/modes.h>
44 #include <blowfish/blowfish_impl.h>
45
46 extern struct mod_ops mod_cryptoops;
47
305 case BLOWFISH_CBC_MECH_INFO_TYPE:
306 blowfish_ctx = cbc_alloc_ctx(kmflag);
307 break;
308 }
309 if (blowfish_ctx == NULL)
310 return (CRYPTO_HOST_MEMORY);
311
312 rv = blowfish_common_init_ctx(blowfish_ctx, template, mechanism,
313 key, kmflag);
314 if (rv != CRYPTO_SUCCESS) {
315 crypto_free_mode_ctx(blowfish_ctx);
316 return (rv);
317 }
318
319 ctx->cc_provider_private = blowfish_ctx;
320
321 return (CRYPTO_SUCCESS);
322 }
323
324 static void
325 blowfish_copy_block64(const uint8_t *in, uint64_t *out)
326 {
327 if (IS_P2ALIGNED(in, sizeof (uint64_t))) {
328 /* LINTED: pointer alignment */
329 out[0] = *(uint64_t *)&in[0];
330 } else {
331 uint8_t *iv8 = (uint8_t *)&out[0];
332
333 BLOWFISH_COPY_BLOCK(in, iv8);
334 }
335 }
336
337 /* ARGSUSED */
338 static int
339 blowfish_encrypt(crypto_ctx_t *ctx, crypto_data_t *plaintext,
340 crypto_data_t *ciphertext, crypto_req_handle_t req)
341 {
342 int ret;
343
344 blowfish_ctx_t *blowfish_ctx;
345
|