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 */ 21726fad2aSDina K Nimeh 227c478bd9Sstevel@tonic-gate /* 23726fad2aSDina K Nimeh * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. 24*fb261280SJason King * Copyright (c) 2018, Joyent, Inc. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #ifndef _SOFTCRYPT_H 287c478bd9Sstevel@tonic-gate #define _SOFTCRYPT_H 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #ifdef __cplusplus 317c478bd9Sstevel@tonic-gate extern "C" { 327c478bd9Sstevel@tonic-gate #endif 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate #include <sys/types.h> 357c478bd9Sstevel@tonic-gate #include <security/pkcs11t.h> 3623c57df7Smcpowers #include <modes/modes.h> 377c478bd9Sstevel@tonic-gate #include <aes_impl.h> 38f66d273dSizick #include <blowfish_impl.h> 397c478bd9Sstevel@tonic-gate #include <des_impl.h> 407c478bd9Sstevel@tonic-gate #include "softObject.h" 417c478bd9Sstevel@tonic-gate #include "softSession.h" 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate #define DES_MAC_LEN (DES_BLOCK_LEN / 2) 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate typedef struct soft_des_ctx { 467c478bd9Sstevel@tonic-gate void *key_sched; /* pointer to key schedule */ 477c478bd9Sstevel@tonic-gate size_t keysched_len; /* Length of the key schedule */ 487c478bd9Sstevel@tonic-gate uint8_t ivec[DES_BLOCK_LEN]; /* initialization vector */ 497c478bd9Sstevel@tonic-gate uint8_t data[DES_BLOCK_LEN]; /* for use by update */ 507c478bd9Sstevel@tonic-gate size_t remain_len; /* for use by update */ 517c478bd9Sstevel@tonic-gate void *des_cbc; /* to be used by CBC mode */ 527c478bd9Sstevel@tonic-gate CK_KEY_TYPE key_type; /* used to determine DES or DES3 */ 537c478bd9Sstevel@tonic-gate size_t mac_len; /* digest len in bytes */ 547c478bd9Sstevel@tonic-gate } soft_des_ctx_t; 557c478bd9Sstevel@tonic-gate 56f66d273dSizick typedef struct soft_blowfish_ctx { 57f66d273dSizick void *key_sched; /* pointer to key schedule */ 58f66d273dSizick size_t keysched_len; /* Length of the key schedule */ 59f66d273dSizick uint8_t ivec[BLOWFISH_BLOCK_LEN]; /* initialization vector */ 60f66d273dSizick uint8_t data[BLOWFISH_BLOCK_LEN]; /* for use by update */ 61f66d273dSizick size_t remain_len; /* for use by update */ 62f66d273dSizick void *blowfish_cbc; /* to be used by CBC mode */ 63f66d273dSizick } soft_blowfish_ctx_t; 64f66d273dSizick 657c478bd9Sstevel@tonic-gate /* 66*fb261280SJason King * For sign/verify operations, the hash generated is AES_BLOCK_LEN bytes long, 67*fb261280SJason King * however for CKM_AES_CMAC_GENERAL, one can specify a smaller hash size if 68*fb261280SJason King * desired (the output being the output of CKM_AES_CMAC truncated to the 69*fb261280SJason King * specified size). Since this size is specified in the C_{Sign,Verify}Init() 70*fb261280SJason King * call, we must carry it through to the C_{Sign,Verify}Final() call via 71*fb261280SJason King * the mac_len field. 72*fb261280SJason King * 73*fb261280SJason King * Note that the context pointed to by aes_ctx is cleaned up as part of the 74*fb261280SJason King * soft_aes_encrypt() calls. 75*fb261280SJason King */ 76*fb261280SJason King typedef struct soft_aes_sign_ctx { 77*fb261280SJason King aes_ctx_t *aes_ctx; 78*fb261280SJason King size_t mac_len; 79*fb261280SJason King } soft_aes_sign_ctx_t; 80*fb261280SJason King 81*fb261280SJason King /* 827c478bd9Sstevel@tonic-gate * Function Prototypes. 837c478bd9Sstevel@tonic-gate */ 847c478bd9Sstevel@tonic-gate void *des_cbc_ctx_init(void *, size_t, uint8_t *, CK_KEY_TYPE); 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate CK_RV soft_des_crypt_init_common(soft_session_t *, CK_MECHANISM_PTR, 877c478bd9Sstevel@tonic-gate soft_object_t *, boolean_t); 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate CK_RV soft_des_encrypt_common(soft_session_t *, CK_BYTE_PTR, CK_ULONG, 907c478bd9Sstevel@tonic-gate CK_BYTE_PTR, CK_ULONG_PTR, boolean_t); 917c478bd9Sstevel@tonic-gate 927c478bd9Sstevel@tonic-gate CK_RV soft_des_decrypt_common(soft_session_t *, CK_BYTE_PTR, CK_ULONG, 937c478bd9Sstevel@tonic-gate CK_BYTE_PTR, CK_ULONG_PTR, boolean_t); 947c478bd9Sstevel@tonic-gate 95cd964fceSMatt Barden CK_RV soft_des_sign_verify_common(soft_session_t *, CK_BYTE_PTR, 96cd964fceSMatt Barden CK_ULONG, CK_BYTE_PTR, CK_ULONG_PTR, 97cd964fceSMatt Barden boolean_t, boolean_t); 987c478bd9Sstevel@tonic-gate 99cd964fceSMatt Barden CK_RV soft_des_sign_verify_init_common(soft_session_t *, CK_MECHANISM_PTR, 100cd964fceSMatt Barden soft_object_t *, boolean_t); 1017c478bd9Sstevel@tonic-gate 102cd964fceSMatt Barden CK_RV soft_des_mac_sign_verify_update(soft_session_t *, CK_BYTE_PTR, CK_ULONG); 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate void soft_add_pkcs7_padding(CK_BYTE *, int, CK_ULONG); 1057c478bd9Sstevel@tonic-gate 106726fad2aSDina K Nimeh CK_RV soft_remove_pkcs7_padding(CK_BYTE *, CK_ULONG, CK_ULONG *); 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate CK_RV soft_arcfour_crypt_init(soft_session_t *, CK_MECHANISM_PTR, 1097c478bd9Sstevel@tonic-gate soft_object_t *, boolean_t); 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate CK_RV soft_arcfour_crypt(crypto_active_op_t *, CK_BYTE_PTR, CK_ULONG, 1127c478bd9Sstevel@tonic-gate CK_BYTE_PTR, CK_ULONG_PTR); 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate CK_RV soft_aes_crypt_init_common(soft_session_t *, CK_MECHANISM_PTR, 1157c478bd9Sstevel@tonic-gate soft_object_t *, boolean_t); 1167c478bd9Sstevel@tonic-gate 117*fb261280SJason King CK_RV soft_aes_encrypt(soft_session_t *, CK_BYTE_PTR, CK_ULONG, 118*fb261280SJason King CK_BYTE_PTR, CK_ULONG_PTR); 119*fb261280SJason King 120*fb261280SJason King CK_RV soft_aes_decrypt(soft_session_t *, CK_BYTE_PTR, CK_ULONG, 121*fb261280SJason King CK_BYTE_PTR, CK_ULONG_PTR); 122*fb261280SJason King 123*fb261280SJason King CK_RV soft_aes_encrypt_update(soft_session_t *, CK_BYTE_PTR, CK_ULONG, 124*fb261280SJason King CK_BYTE_PTR, CK_ULONG_PTR); 125*fb261280SJason King 126*fb261280SJason King CK_RV soft_aes_decrypt_update(soft_session_t *, CK_BYTE_PTR, CK_ULONG, 127*fb261280SJason King CK_BYTE_PTR, CK_ULONG_PTR); 128*fb261280SJason King 129*fb261280SJason King CK_RV soft_aes_encrypt_final(soft_session_t *, CK_BYTE_PTR, CK_ULONG_PTR); 130*fb261280SJason King 131*fb261280SJason King CK_RV soft_aes_decrypt_final(soft_session_t *, CK_BYTE_PTR, CK_ULONG_PTR); 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate CK_RV soft_aes_decrypt_common(soft_session_t *, CK_BYTE_PTR, CK_ULONG, 1347c478bd9Sstevel@tonic-gate CK_BYTE_PTR, CK_ULONG_PTR, boolean_t); 1357c478bd9Sstevel@tonic-gate 136cd964fceSMatt Barden CK_RV soft_aes_sign_verify_common(soft_session_t *, CK_BYTE_PTR, 137cd964fceSMatt Barden CK_ULONG, CK_BYTE_PTR, CK_ULONG_PTR, 138cd964fceSMatt Barden boolean_t, boolean_t); 139cd964fceSMatt Barden 140cd964fceSMatt Barden CK_RV soft_aes_sign_verify_init_common(soft_session_t *, CK_MECHANISM_PTR, 141cd964fceSMatt Barden soft_object_t *, boolean_t); 142cd964fceSMatt Barden 143cd964fceSMatt Barden CK_RV soft_aes_mac_sign_verify_update(soft_session_t *, CK_BYTE_PTR, CK_ULONG); 144cd964fceSMatt Barden 145*fb261280SJason King void soft_aes_free_ctx(aes_ctx_t *); 146*fb261280SJason King 147f66d273dSizick void *blowfish_cbc_ctx_init(void *, size_t, uint8_t *); 148f66d273dSizick 149f66d273dSizick CK_RV soft_blowfish_crypt_init_common(soft_session_t *, CK_MECHANISM_PTR, 150f66d273dSizick soft_object_t *, boolean_t); 151f66d273dSizick 152f66d273dSizick CK_RV soft_blowfish_encrypt_common(soft_session_t *, CK_BYTE_PTR, CK_ULONG, 153f66d273dSizick CK_BYTE_PTR, CK_ULONG_PTR, boolean_t); 154f66d273dSizick 155f66d273dSizick CK_RV soft_blowfish_decrypt_common(soft_session_t *, CK_BYTE_PTR, CK_ULONG, 156f66d273dSizick CK_BYTE_PTR, CK_ULONG_PTR, boolean_t); 157f66d273dSizick 1587c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1597c478bd9Sstevel@tonic-gate } 1607c478bd9Sstevel@tonic-gate #endif 1617c478bd9Sstevel@tonic-gate 1627c478bd9Sstevel@tonic-gate #endif /* _SOFTCRYPT_H */ 163