/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
#include <pthread.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <security/cryptoki.h>
#include <cryptoutil.h>
#include "softGlobal.h"
#include "softSession.h"
#include "softObject.h"
#include "softOps.h"
#include "softRSA.h"
#include "softMAC.h"
#include "softCrypt.h"
{
/* EXPORT DELETE START */
RSAbytekey k;
if (realpublic) {
&expo_len);
goto clean1;
}
} else {
&expo_len);
goto clean1;
}
}
goto clean1;
}
k.pubexpo_bytes = expo_len;
/* EXPORT DELETE END */
return (rv);
}
{
/* EXPORT DELETE START */
RSAbytekey k;
goto clean1;
}
goto clean1;
} else {
goto clean1;
}
goto clean1;
} else {
goto clean1;
}
goto clean1;
} else {
goto clean1;
}
goto clean1;
} else {
goto clean1;
}
goto clean1;
} else {
goto clean1;
}
k.prime1_bytes = prime1_len;
k.prime2_bytes = prime2_len;
k.expo1_bytes = expo1_len;
k.expo2_bytes = expo2_len;
k.coeff_bytes = coef_len;
/* EXPORT DELETE END */
return (rv);
}
/*
* Allocate a RSA context for the active encryption or decryption operation.
* This function is called without the session lock held.
*/
{
return (CKR_HOST_MEMORY);
}
/*
* Make a copy of the encryption or decryption key, and save it
* in the RSA crypto context since it will be used later for
* encryption/decryption. We don't want to hold any object reference
* on this original key while doing encryption/decryption.
*/
NULL);
/* Most likely we ran out of space. */
return (rv);
}
/* No need to hold the lock on the old object. */
return (CKR_OK);
}
{
goto clean_exit;
}
if (pEncrypted == NULL) {
/*
* Application asks for the length of the output buffer
* to hold the ciphertext.
*/
goto clean1;
}
if (mechanism == CKM_RSA_PKCS) {
/*
* Input data length needs to be <=
* modulus length-MIN_PKCS1_PADLEN.
*/
goto clean_exit;
}
} else {
/* Input data length needs to be <= modulus length. */
goto clean_exit;
}
}
/* Is the application-supplied buffer large enough? */
goto clean1;
}
if (mechanism == CKM_RSA_PKCS) {
/*
* Add PKCS padding to the input data to format a block
* type "02" encryption block.
*/
goto clean_exit;
} else {
/* Pad zeros for the leading bytes of the input data. */
}
}
sizeof (soft_rsa_ctx_t));
return (rv);
}
{
goto clean_exit;
}
goto clean_exit;
}
/*
* Application asks for the length of the output buffer
* to hold the recovered data.
*/
goto clean1;
}
if (mechanism == CKM_RSA_X_509) {
goto clean1;
}
}
goto clean_exit;
}
if (mechanism == CKM_RSA_PKCS) {
/* Strip off the PKCS block formatting data. */
goto clean_exit;
*pulDataLen = plain_len;
goto clean1;
}
*pulDataLen = plain_len;
} else {
}
sizeof (soft_rsa_ctx_t));
return (rv);
}
/*
* Allocate a RSA context for the active sign or verify operation.
* This function is called without the session lock held.
*/
{
if (sign) {
return (CKR_KEY_TYPE_INCONSISTENT);
} else {
return (CKR_KEY_TYPE_INCONSISTENT);
}
switch (pMechanism->mechanism) {
case CKM_MD5_RSA_PKCS:
break;
case CKM_SHA1_RSA_PKCS:
break;
case CKM_SHA224_RSA_PKCS:
break;
case CKM_SHA256_RSA_PKCS:
break;
case CKM_SHA384_RSA_PKCS:
break;
case CKM_SHA512_RSA_PKCS:
break;
/* These mechs are not digested, so don't set digest_mech */
case CKM_RSA_PKCS:
case CKM_RSA_X_509:
digest_mech.mechanism = 0;
break;
default:
return (CKR_MECHANISM_INVALID);
}
if (digest_mech.mechanism != 0) {
return (rv);
}
goto clean_exit;
}
NULL);
/* Most likely we ran out of space. */
goto clean_exit;
}
/* No need to hold the lock on the old object. */
if (sign) {
} else {
}
return (CKR_OK);
}
return (rv);
}
{
goto clean_exit;
}
/* Application asks for the length of the output buffer. */
goto clean1;
}
switch (mechanism) {
case CKM_RSA_PKCS:
/*
* Input data length needs to be <=
* modulus length-MIN_PKCS1_PADLEN.
*/
goto clean_exit;
}
break;
case CKM_RSA_X_509:
/* Input data length needs to be <= modulus length. */
goto clean_exit;
}
break;
}
/* Is the application-supplied buffer large enough? */
goto clean1;
}
switch (mechanism) {
case CKM_RSA_PKCS:
case CKM_MD5_RSA_PKCS:
case CKM_SHA1_RSA_PKCS:
case CKM_SHA224_RSA_PKCS:
case CKM_SHA256_RSA_PKCS:
case CKM_SHA384_RSA_PKCS:
case CKM_SHA512_RSA_PKCS:
/*
* Add PKCS padding to the input data to format a block
* type "01" encryption block.
*/
goto clean_exit;
}
break;
case CKM_RSA_X_509:
/* Pad zeros for the leading bytes of the input data. */
break;
}
/*
* Perform RSA encryption with the signer's RSA private key
* for signature process.
*/
}
}
return (rv);
}
{
goto clean_exit;
}
if (ulDataLen == 0) {
goto clean_exit;
}
goto clean_exit;
}
/*
* Perform RSA decryption with the signer's RSA public key
* for verification process.
*/
switch (mechanism) {
case CKM_RSA_PKCS:
case CKM_MD5_RSA_PKCS:
case CKM_SHA1_RSA_PKCS:
case CKM_SHA224_RSA_PKCS:
case CKM_SHA256_RSA_PKCS:
case CKM_SHA384_RSA_PKCS:
case CKM_SHA512_RSA_PKCS:
{
/*
* Strip off the encoded padding bytes in front of the
* recovered data, then compare the recovered data with
* the original data.
*/
goto clean_exit;
}
goto clean_exit;
ulDataLen) != 0) {
goto clean_exit;
}
break;
}
case CKM_RSA_X_509:
/*
* Strip off the encoded padding bytes in front of the
* recovered plain_data, then compare the input data
* with the recovered data.
*/
ulDataLen) != 0) {
goto clean_exit;
}
break;
}
}
if (rv == CKR_DATA_LEN_RANGE) {
if ((mechanism == CKM_MD5_RSA_PKCS) ||
(mechanism == CKM_SHA1_RSA_PKCS) ||
(mechanism == CKM_SHA224_RSA_PKCS) ||
(mechanism == CKM_SHA256_RSA_PKCS) ||
(mechanism == CKM_SHA384_RSA_PKCS) ||
(mechanism == CKM_SHA512_RSA_PKCS))
}
}
return (rv);
}
{
switch (type) {
case CKA_MODULUS:
if (public)
else
break;
case CKA_PUBLIC_EXPONENT:
if (public)
else
break;
case CKA_PRIVATE_EXPONENT:
break;
case CKA_PRIME_1:
break;
case CKA_PRIME_2:
break;
case CKA_EXPONENT_1:
break;
case CKA_EXPONENT_2:
break;
case CKA_COEFFICIENT:
break;
}
/* Note: no explanation found for why this is needed */
while (buf[0] == 0) { /* remove proceeding 0x00 */
buf++;
buflen--;
}
goto cleanexit;
/* Copy the attribute in the key object. */
return (rv);
}
{
RSAbytekey k;
return (CKR_ARGUMENTS_BAD);
}
return (CKR_HOST_MEMORY);
}
&template);
goto clean0;
}
#ifdef __sparcv9
/* LINTED */
#else /* !__sparcv9 */
#endif /* __sparcv9 */
&pub_expo_len);
goto clean0;
}
/* Inputs to RSA key pair generation */
/* Outputs from RSA key pair generation */
k.privexpo = private_exponent;
k.prime1_bytes = prime1_len;
k.prime2_bytes = prime2_len;
k.expo1_bytes = exponent1_len;
k.expo2_bytes = exponent2_len;
k.coeff = coefficient;
rv = rsa_genkey_pair(&k);
goto clean0;
}
/*
* Add modulus in public template, and add all eight key fields
* in private template.
*/
goto clean0;
}
goto clean0;
}
goto clean0;
}
goto clean0;
}
goto clean0;
}
goto clean0;
}
goto clean0;
}
goto clean0;
}
goto clean0;
}
return (rv);
}
return (SHA1_DER_PREFIX_Len);
}
return (SHA1_DER_PREFIX_OID_Len);
}
{
/* space enough for all mechs */
goto clean1;
}
/* Check arguments before performing message digest. */
/* Application asks for the length of the output buffer. */
goto clean1;
}
/* Is the application-supplied buffer large enough? */
goto clean1;
}
if (Final) {
} else {
}
/* free the signature key */
goto clean_exit;
}
/*
* Prepare the DER encoding of the DigestInfo value by setting it to:
* <MECH>_DER_PREFIX || H
*
* See rsa_impl.c for more details.
*/
case CKM_MD5:
break;
case CKM_SHA_1:
&der_prefix);
break;
case CKM_SHA224:
break;
case CKM_SHA256:
break;
case CKM_SHA384:
break;
case CKM_SHA512:
break;
}
/*
* Now, we are ready to sign the DER_ENCODED data
* soft_rsa_sign_common() will free the signature key.
*/
/* soft_digest_common() has freed the digest context */
return (rv);
}
{
if (Final) {
} else {
}
/* free the verification key */
goto clean_exit;
}
/*
* Prepare the DER encoding of the DigestInfo value as follows:
* MD5: MD5_DER_PREFIX || H
* SHA-1: SHA1_DER_PREFIX || H
* SHA2: SHA2_DER_PREFIX || H
*
* See rsa_impl.c for more details.
*/
case CKM_MD5:
break;
case CKM_SHA_1:
&der_prefix);
break;
case CKM_SHA224:
break;
case CKM_SHA256:
break;
case CKM_SHA384:
break;
case CKM_SHA512:
break;
}
/*
* Now, we are ready to verify the DER_ENCODED data using signature.
* soft_rsa_verify_common() will free the verification key.
*/
/* soft_digest_common() has freed the digest context */
return (rv);
}
{
goto clean_exit;
}
goto clean_exit;
}
/*
* Perform RSA decryption with the signer's RSA public key
* for verification process.
*/
switch (mechanism) {
case CKM_RSA_PKCS:
{
/*
* Strip off the encoded padding bytes in front of the
* recovered data.
*/
goto clean_exit;
}
/*
* If application asks for the length of the output
* buffer?
*/
*pulDataLen = data_len;
goto clean1;
}
/* Is the application-supplied buffer large enough? */
*pulDataLen = data_len;
goto clean1;
}
*pulDataLen = data_len;
break;
}
case CKM_RSA_X_509:
/*
* If application asks for the length of the output
* buffer?
*/
goto clean1;
}
/* Is the application-supplied buffer large enough? */
goto clean1;
}
break;
}
}
return (rv);
}