#ifndef _SOFTCRYPT_H
#define _SOFTCRYPT_H
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/types.h>
#include <security/pkcs11t.h>
#include <modes/modes.h>
#include <aes_impl.h>
#include <blowfish_impl.h>
#include <des_impl.h>
#include "softObject.h"
#include "softSession.h"
#define DES_MAC_LEN (DES_BLOCK_LEN / 2)
typedef struct soft_des_ctx {
void *key_sched;
size_t keysched_len;
uint8_t ivec[DES_BLOCK_LEN];
uint8_t data[DES_BLOCK_LEN];
size_t remain_len;
void *des_cbc;
CK_KEY_TYPE key_type;
size_t mac_len;
} soft_des_ctx_t;
typedef struct soft_blowfish_ctx {
void *key_sched;
size_t keysched_len;
uint8_t ivec[BLOWFISH_BLOCK_LEN];
uint8_t data[BLOWFISH_BLOCK_LEN];
size_t remain_len;
void *blowfish_cbc;
} soft_blowfish_ctx_t;
typedef struct soft_aes_sign_ctx {
aes_ctx_t *aes_ctx;
size_t mac_len;
} soft_aes_sign_ctx_t;
void *des_cbc_ctx_init(void *, size_t, uint8_t *, CK_KEY_TYPE);
CK_RV soft_des_crypt_init_common(soft_session_t *, CK_MECHANISM_PTR,
soft_object_t *, boolean_t);
CK_RV soft_des_encrypt_common(soft_session_t *, CK_BYTE_PTR, CK_ULONG,
CK_BYTE_PTR, CK_ULONG_PTR, boolean_t);
CK_RV soft_des_decrypt_common(soft_session_t *, CK_BYTE_PTR, CK_ULONG,
CK_BYTE_PTR, CK_ULONG_PTR, boolean_t);
CK_RV soft_des_sign_verify_common(soft_session_t *, CK_BYTE_PTR,
CK_ULONG, CK_BYTE_PTR, CK_ULONG_PTR,
boolean_t, boolean_t);
CK_RV soft_des_sign_verify_init_common(soft_session_t *, CK_MECHANISM_PTR,
soft_object_t *, boolean_t);
CK_RV soft_des_mac_sign_verify_update(soft_session_t *, CK_BYTE_PTR, CK_ULONG);
void soft_add_pkcs7_padding(CK_BYTE *, int, CK_ULONG);
CK_RV soft_remove_pkcs7_padding(CK_BYTE *, CK_ULONG, CK_ULONG *);
CK_RV soft_arcfour_crypt_init(soft_session_t *, CK_MECHANISM_PTR,
soft_object_t *, boolean_t);
CK_RV soft_arcfour_crypt(crypto_active_op_t *, CK_BYTE_PTR, CK_ULONG,
CK_BYTE_PTR, CK_ULONG_PTR);
CK_RV soft_aes_crypt_init_common(soft_session_t *, CK_MECHANISM_PTR,
soft_object_t *, boolean_t);
CK_RV soft_aes_encrypt(soft_session_t *, CK_BYTE_PTR, CK_ULONG,
CK_BYTE_PTR, CK_ULONG_PTR);
CK_RV soft_aes_decrypt(soft_session_t *, CK_BYTE_PTR, CK_ULONG,
CK_BYTE_PTR, CK_ULONG_PTR);
CK_RV soft_aes_encrypt_update(soft_session_t *, CK_BYTE_PTR, CK_ULONG,
CK_BYTE_PTR, CK_ULONG_PTR);
CK_RV soft_aes_decrypt_update(soft_session_t *, CK_BYTE_PTR, CK_ULONG,
CK_BYTE_PTR, CK_ULONG_PTR);
CK_RV soft_aes_encrypt_final(soft_session_t *, CK_BYTE_PTR, CK_ULONG_PTR);
CK_RV soft_aes_decrypt_final(soft_session_t *, CK_BYTE_PTR, CK_ULONG_PTR);
CK_RV soft_aes_decrypt_common(soft_session_t *, CK_BYTE_PTR, CK_ULONG,
CK_BYTE_PTR, CK_ULONG_PTR, boolean_t);
CK_RV soft_aes_sign_verify_common(soft_session_t *, CK_BYTE_PTR,
CK_ULONG, CK_BYTE_PTR, CK_ULONG_PTR,
boolean_t, boolean_t);
CK_RV soft_aes_sign_verify_init_common(soft_session_t *, CK_MECHANISM_PTR,
soft_object_t *, boolean_t);
CK_RV soft_aes_mac_sign_verify_update(soft_session_t *, CK_BYTE_PTR, CK_ULONG);
void soft_aes_free_ctx(aes_ctx_t *);
void *blowfish_cbc_ctx_init(void *, size_t, uint8_t *);
CK_RV soft_blowfish_crypt_init_common(soft_session_t *, CK_MECHANISM_PTR,
soft_object_t *, boolean_t);
CK_RV soft_blowfish_encrypt_common(soft_session_t *, CK_BYTE_PTR, CK_ULONG,
CK_BYTE_PTR, CK_ULONG_PTR, boolean_t);
CK_RV soft_blowfish_decrypt_common(soft_session_t *, CK_BYTE_PTR, CK_ULONG,
CK_BYTE_PTR, CK_ULONG_PTR, boolean_t);
#ifdef __cplusplus
}
#endif
#endif