17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 523c57df7Smcpowers * Common Development and Distribution License (the "License"). 623c57df7Smcpowers * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 21*726fad2aSDina K Nimeh 227c478bd9Sstevel@tonic-gate /* 23*726fad2aSDina K Nimeh * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #ifndef _SOFTCRYPT_H 277c478bd9Sstevel@tonic-gate #define _SOFTCRYPT_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #ifdef __cplusplus 307c478bd9Sstevel@tonic-gate extern "C" { 317c478bd9Sstevel@tonic-gate #endif 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate #include <sys/types.h> 347c478bd9Sstevel@tonic-gate #include <security/pkcs11t.h> 3523c57df7Smcpowers #include <modes/modes.h> 367c478bd9Sstevel@tonic-gate #include <aes_impl.h> 37f66d273dSizick #include <blowfish_impl.h> 387c478bd9Sstevel@tonic-gate #include <des_impl.h> 397c478bd9Sstevel@tonic-gate #include "softObject.h" 407c478bd9Sstevel@tonic-gate #include "softSession.h" 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate #define DES_MAC_LEN (DES_BLOCK_LEN / 2) 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate typedef struct soft_des_ctx { 457c478bd9Sstevel@tonic-gate void *key_sched; /* pointer to key schedule */ 467c478bd9Sstevel@tonic-gate size_t keysched_len; /* Length of the key schedule */ 477c478bd9Sstevel@tonic-gate uint8_t ivec[DES_BLOCK_LEN]; /* initialization vector */ 487c478bd9Sstevel@tonic-gate uint8_t data[DES_BLOCK_LEN]; /* for use by update */ 497c478bd9Sstevel@tonic-gate size_t remain_len; /* for use by update */ 507c478bd9Sstevel@tonic-gate void *des_cbc; /* to be used by CBC mode */ 517c478bd9Sstevel@tonic-gate CK_KEY_TYPE key_type; /* used to determine DES or DES3 */ 527c478bd9Sstevel@tonic-gate size_t mac_len; /* digest len in bytes */ 537c478bd9Sstevel@tonic-gate } soft_des_ctx_t; 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate typedef struct soft_aes_ctx { 567c478bd9Sstevel@tonic-gate void *key_sched; /* pointer to key schedule */ 577c478bd9Sstevel@tonic-gate size_t keysched_len; /* Length of the key schedule */ 587c478bd9Sstevel@tonic-gate uint8_t ivec[AES_BLOCK_LEN]; /* initialization vector */ 597c478bd9Sstevel@tonic-gate uint8_t data[AES_BLOCK_LEN]; /* for use by update */ 607c478bd9Sstevel@tonic-gate size_t remain_len; /* for use by update */ 617c478bd9Sstevel@tonic-gate void *aes_cbc; /* to be used by CBC mode */ 627c478bd9Sstevel@tonic-gate } soft_aes_ctx_t; 637c478bd9Sstevel@tonic-gate 64f66d273dSizick typedef struct soft_blowfish_ctx { 65f66d273dSizick void *key_sched; /* pointer to key schedule */ 66f66d273dSizick size_t keysched_len; /* Length of the key schedule */ 67f66d273dSizick uint8_t ivec[BLOWFISH_BLOCK_LEN]; /* initialization vector */ 68f66d273dSizick uint8_t data[BLOWFISH_BLOCK_LEN]; /* for use by update */ 69f66d273dSizick size_t remain_len; /* for use by update */ 70f66d273dSizick void *blowfish_cbc; /* to be used by CBC mode */ 71f66d273dSizick } soft_blowfish_ctx_t; 72f66d273dSizick 737c478bd9Sstevel@tonic-gate /* 747c478bd9Sstevel@tonic-gate * Function Prototypes. 757c478bd9Sstevel@tonic-gate */ 767c478bd9Sstevel@tonic-gate void *des_cbc_ctx_init(void *, size_t, uint8_t *, CK_KEY_TYPE); 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate CK_RV soft_des_crypt_init_common(soft_session_t *, CK_MECHANISM_PTR, 797c478bd9Sstevel@tonic-gate soft_object_t *, boolean_t); 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate CK_RV soft_des_encrypt_common(soft_session_t *, CK_BYTE_PTR, CK_ULONG, 827c478bd9Sstevel@tonic-gate CK_BYTE_PTR, CK_ULONG_PTR, boolean_t); 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate CK_RV soft_des_decrypt_common(soft_session_t *, CK_BYTE_PTR, CK_ULONG, 857c478bd9Sstevel@tonic-gate CK_BYTE_PTR, CK_ULONG_PTR, boolean_t); 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate CK_RV soft_des_sign_verify_common(soft_session_t *session_p, CK_BYTE_PTR pData, 887c478bd9Sstevel@tonic-gate CK_ULONG ulDataLen, CK_BYTE_PTR pSigned, CK_ULONG_PTR pulSignedLen, 897c478bd9Sstevel@tonic-gate boolean_t sign_op, boolean_t Final); 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate CK_RV soft_des_sign_verify_init_common(soft_session_t *session_p, 927c478bd9Sstevel@tonic-gate CK_MECHANISM_PTR pMechanism, soft_object_t *key_p, boolean_t sign_op); 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate CK_RV soft_des_mac_sign_verify_update(soft_session_t *session_p, 957c478bd9Sstevel@tonic-gate CK_BYTE_PTR pPart, CK_ULONG ulPartLen); 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate void soft_add_pkcs7_padding(CK_BYTE *, int, CK_ULONG); 987c478bd9Sstevel@tonic-gate 99*726fad2aSDina K Nimeh CK_RV soft_remove_pkcs7_padding(CK_BYTE *, CK_ULONG, CK_ULONG *); 1007c478bd9Sstevel@tonic-gate 1017c478bd9Sstevel@tonic-gate CK_RV soft_arcfour_crypt_init(soft_session_t *, CK_MECHANISM_PTR, 1027c478bd9Sstevel@tonic-gate soft_object_t *, boolean_t); 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate CK_RV soft_arcfour_crypt(crypto_active_op_t *, CK_BYTE_PTR, CK_ULONG, 1057c478bd9Sstevel@tonic-gate CK_BYTE_PTR, CK_ULONG_PTR); 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate void *aes_cbc_ctx_init(void *, size_t, uint8_t *); 10823c57df7Smcpowers void *aes_ctr_ctx_init(void *, size_t, uint8_t *); 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate CK_RV soft_aes_crypt_init_common(soft_session_t *, CK_MECHANISM_PTR, 1117c478bd9Sstevel@tonic-gate soft_object_t *, boolean_t); 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate CK_RV soft_aes_encrypt_common(soft_session_t *, CK_BYTE_PTR, CK_ULONG, 1147c478bd9Sstevel@tonic-gate CK_BYTE_PTR, CK_ULONG_PTR, boolean_t); 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate CK_RV soft_aes_decrypt_common(soft_session_t *, CK_BYTE_PTR, CK_ULONG, 1177c478bd9Sstevel@tonic-gate CK_BYTE_PTR, CK_ULONG_PTR, boolean_t); 1187c478bd9Sstevel@tonic-gate 119f66d273dSizick void *blowfish_cbc_ctx_init(void *, size_t, uint8_t *); 120f66d273dSizick 121f66d273dSizick CK_RV soft_blowfish_crypt_init_common(soft_session_t *, CK_MECHANISM_PTR, 122f66d273dSizick soft_object_t *, boolean_t); 123f66d273dSizick 124f66d273dSizick CK_RV soft_blowfish_encrypt_common(soft_session_t *, CK_BYTE_PTR, CK_ULONG, 125f66d273dSizick CK_BYTE_PTR, CK_ULONG_PTR, boolean_t); 126f66d273dSizick 127f66d273dSizick CK_RV soft_blowfish_decrypt_common(soft_session_t *, CK_BYTE_PTR, CK_ULONG, 128f66d273dSizick CK_BYTE_PTR, CK_ULONG_PTR, boolean_t); 129f66d273dSizick 1307c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1317c478bd9Sstevel@tonic-gate } 1327c478bd9Sstevel@tonic-gate #endif 1337c478bd9Sstevel@tonic-gate 1347c478bd9Sstevel@tonic-gate #endif /* _SOFTCRYPT_H */ 135