/*
* 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 "softObject.h"
#include "softOps.h"
#include "softSession.h"
#include "softMAC.h"
/*
* IPAD = 0x36 repeated 48 times for ssl md5, repeated 40 times for ssl sha1
* OPAD = 0x5C repeated 48 times for ssl md5, repeated 40 times for ssl sha1
*/
0x36363636, 0x36363636, 0x36363636, 0x36363636, 0x36363636,
0x36363636, 0x36363636, 0x36363636, 0x36363636, 0x36363636,
0x36363636, 0x36363636};
0x36363636, 0x36363636, 0x36363636, 0x36363636, 0x36363636,
0x36363636, 0x36363636, 0x36363636, 0x36363636, 0x36363636};
0x5c5c5c5c, 0x5c5c5c5c, 0x5c5c5c5c, 0x5c5c5c5c, 0x5c5c5c5c,
0x5c5c5c5c, 0x5c5c5c5c, 0x5c5c5c5c, 0x5c5c5c5c, 0x5c5c5c5c,
0x5c5c5c5c, 0x5c5c5c5c};
0x5c5c5c5c, 0x5c5c5c5c, 0x5c5c5c5c, 0x5c5c5c5c, 0x5c5c5c5c,
0x5c5c5c5c, 0x5c5c5c5c, 0x5c5c5c5c, 0x5c5c5c5c, 0x5c5c5c5c};
/*
* Allocate and initialize a HMAC context, and save the context pointer in
* the session struct. For General-length HMAC, checks the length in the
* parameter to see if it is in the right range.
*/
{
return (CKR_KEY_TYPE_INCONSISTENT);
}
return (CKR_HOST_MEMORY);
}
switch (pMechanism->mechanism) {
case CKM_MD5_HMAC:
break;
case CKM_SHA_1_HMAC:
break;
case CKM_SHA224_HMAC:
break;
case CKM_SHA256_HMAC:
break;
case CKM_SHA384_HMAC:
break;
case CKM_SHA512_HMAC:
break;
case CKM_MD5_HMAC_GENERAL:
case CKM_SSL3_MD5_MAC:
if ((pMechanism->ulParameterLen !=
sizeof (CK_MAC_GENERAL_PARAMS)) &&
return (CKR_MECHANISM_PARAM_INVALID);
}
break;
case CKM_SSL3_SHA1_MAC:
case CKM_SHA_1_HMAC_GENERAL:
if ((pMechanism->ulParameterLen !=
sizeof (CK_MAC_GENERAL_PARAMS)) &&
return (CKR_MECHANISM_PARAM_INVALID);
}
break;
case CKM_SHA224_HMAC_GENERAL:
case CKM_SHA256_HMAC_GENERAL:
if ((pMechanism->ulParameterLen !=
sizeof (CK_MAC_GENERAL_PARAMS)) &&
return (CKR_MECHANISM_PARAM_INVALID);
}
break;
case CKM_SHA384_HMAC_GENERAL:
case CKM_SHA512_HMAC_GENERAL:
if ((pMechanism->ulParameterLen !=
sizeof (CK_MAC_GENERAL_PARAMS)) &&
return (CKR_MECHANISM_PARAM_INVALID);
}
break;
}
/* Initialize a MAC context. */
return (rv);
if (sign_op) {
} else {
}
return (CKR_OK);
}
/*
* Initialize a HMAC context.
*/
{
switch (mech) {
case CKM_SSL3_MD5_MAC:
{
return (CKR_KEY_SIZE_RANGE);
}
/* SSL MAC is HASH(key + opad + HASH(key + ipad + data)) */
break;
}
case CKM_MD5_HMAC_GENERAL:
case CKM_MD5_HMAC:
{
/*
* Hash the key when it is longer than 64 bytes.
*/
return (rv);
&hash_len);
return (rv);
} else {
}
break;
}
case CKM_SSL3_SHA1_MAC:
{
return (CKR_KEY_SIZE_RANGE);
}
/* SSL MAC is HASH(key + opad + HASH(key + ipad + data)) */
break;
}
case CKM_SHA_1_HMAC_GENERAL:
case CKM_SHA_1_HMAC:
{
/*
* Hash the key when it is longer than 64 bytes.
*/
return (rv);
&hash_len);
return (rv);
} else {
}
break;
}
case CKM_SHA224_HMAC:
case CKM_SHA224_HMAC_GENERAL:
{
/*
* Hash the key when it is longer than 64 bytes.
*/
return (rv);
&hash_len);
return (rv);
} else {
}
break;
}
case CKM_SHA256_HMAC:
case CKM_SHA256_HMAC_GENERAL:
{
/*
* Hash the key when it is longer than 64 bytes.
*/
return (rv);
&hash_len);
return (rv);
} else {
}
break;
}
case CKM_SHA384_HMAC:
case CKM_SHA384_HMAC_GENERAL:
{
/*
* Hash the key when it is longer than 64 bytes.
*/
return (rv);
&hash_len);
return (rv);
} else {
}
break;
}
case CKM_SHA512_HMAC:
case CKM_SHA512_HMAC_GENERAL:
{
/*
* Hash the key when it is longer than 64 bytes.
*/
return (rv);
&hash_len);
return (rv);
} else {
}
break;
}
}
return (rv);
}
/*
* Called by soft_sign(), soft_sign_final(), soft_verify() or
* soft_verify_final().
*/
{
if (sign_op) {
/*
* If application asks for the length of the output buffer
* to hold the signature?
*/
return (CKR_OK);
}
/* Is the application-supplied buffer large enough? */
return (CKR_BUFFER_TOO_SMALL);
}
} else {
}
switch (mechanism) {
case CKM_SSL3_MD5_MAC:
case CKM_MD5_HMAC_GENERAL:
case CKM_MD5_HMAC:
/* Called by soft_sign() or soft_verify(). */
}
break;
case CKM_SSL3_SHA1_MAC:
case CKM_SHA_1_HMAC_GENERAL:
case CKM_SHA_1_HMAC:
/* Called by soft_sign() or soft_verify(). */
}
break;
case CKM_SHA224_HMAC_GENERAL:
case CKM_SHA224_HMAC:
/* Called by soft_sign() or soft_verify(). */
pSigned);
break;
case CKM_SHA256_HMAC_GENERAL:
case CKM_SHA256_HMAC:
/* Called by soft_sign() or soft_verify(). */
pSigned);
break;
case CKM_SHA384_HMAC_GENERAL:
case CKM_SHA384_HMAC:
/* Called by soft_sign() or soft_verify(). */
pSigned);
break;
case CKM_SHA512_HMAC_GENERAL:
case CKM_SHA512_HMAC:
/* Called by soft_sign() or soft_verify(). */
pSigned);
};
if (sign_op) {
} else {
}
return (CKR_OK);
}
/*
* Called by soft_sign_update() or soft_verify_update().
*/
{
if (sign_op) {
} else {
}
switch (mechanism) {
case CKM_SSL3_MD5_MAC:
case CKM_MD5_HMAC_GENERAL:
case CKM_MD5_HMAC:
partlen);
break;
case CKM_SSL3_SHA1_MAC:
case CKM_SHA_1_HMAC_GENERAL:
case CKM_SHA_1_HMAC:
partlen);
break;
case CKM_SHA224_HMAC_GENERAL:
case CKM_SHA224_HMAC:
case CKM_SHA256_HMAC_GENERAL:
case CKM_SHA256_HMAC:
case CKM_SHA384_HMAC_GENERAL:
case CKM_SHA384_HMAC:
case CKM_SHA512_HMAC_GENERAL:
case CKM_SHA512_HMAC:
partlen);
break;
}
return (CKR_OK);
}
/*
* The following 2 functions expect the MAC key to be already copied to
* ipad and opad.
*/
void
{
int i;
/* XOR key with ipad (0x36) and opad (0x5c) */
for (i = 0; i < MD5_HMAC_INTS_PER_BLOCK; i++) {
ipad[i] ^= 0x36363636;
opad[i] ^= 0x5c5c5c5c;
}
}
void
{
int i;
/* XOR key with ipad (0x36) and opad (0x5c) */
for (i = 0; i < SHA1_HMAC_INTS_PER_BLOCK; i++) {
ipad[i] ^= 0x36363636;
opad[i] ^= 0x5c5c5c5c;
}
}
void
{
int i;
/* XOR key with ipad (0x36) and opad (0x5c) */
for (i = 0; i < blocks_per_int64; i ++) {
ipad[i] ^= 0x3636363636363636ULL;
opad[i] ^= 0x5c5c5c5c5c5c5c5cULL;
}
/* perform SHA2 on ipad */
/* perform SHA2 on opad */
}