softDH.c revision c64d15a587b6038b85a928885fc997da7315fbfe
/*
* 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
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <security/cryptoki.h>
#include <bignum.h>
#include <des_impl.h>
#include "softGlobal.h"
#include "softSession.h"
#include "softObject.h"
#include "softDH.h"
#include "softRandom.h"
#include "softCrypt.h"
/*
* This function converts the big integer of the specified attribute
* to an octet string and store it in the corresponding key object.
*/
{
/*
* Allocate the buffer used to store the value of key fields
* for bignum2bytestring. Since bignum only deals with a buffer
* whose size is multiple of 4, prime_len is rounded up to be
* multiple of 4.
*/
goto cleanexit;
}
switch (type) {
case CKA_VALUE:
if (public)
else
break;
case CKA_PRIME:
break;
case CKA_BASE:
break;
}
goto cleanexit;
}
/* Copy the attribute in the key object. */
return (rv);
}
/*
* This function covers the DH Key agreement.
*/
{
return (CKR_KEY_TYPE_INCONSISTENT);
}
return (CKR_KEY_TYPE_INCONSISTENT);
}
/*
* The input to the first phase shall be the Diffie-Hellman
* parameters, which include prime, base, and private-value length.
*/
return (rv);
}
goto ret0;
}
BIG_OK) {
goto ret0;
}
/* Convert the prime octet string to big integer format. */
goto ret1;
}
goto ret1;
}
/* Convert the base octet string to big integer format. */
goto ret2;
}
goto ret2;
}
&template);
goto ret2;
}
/*
* The intention of selecting a private-value length is to reduce
* the computation time for key agreement, while maintaining a
* given level of security.
*/
#ifdef __sparcv9
/* LINTED */
#else /* !__sparcv9 */
#endif /* __sparcv9 */
if (value_bits > primebit_len) {
goto ret3;
}
/* Generate DH key pair private and public values. */
!= BIG_OK) {
goto ret3;
}
!= BIG_OK) {
goto ret4;
}
/*
* The big integer of the private value shall be generated privately
* and randomly.
*/
goto ret5;
}
/*
* The base g shall be raised to the private value x modulo p to
* give an integer y, the integer public value.
*/
goto ret5;
}
/*
* The integer public value y shall be converted to an octet
* string PV of length k, the public value.
*/
goto ret5;
}
/* Convert the big integer private value to an octet string. */
goto ret5;
}
/* Convert the big integer prime to an octet string. */
goto ret5;
}
/* Convert the big integer base to an octet string. */
goto ret5;
}
if (value_bits == 0) {
}
ret5:
ret4:
ret3:
ret2:
big_finish(&bnbase);
ret1:
ret0:
return (rv);
}
{
return (rv);
}
goto ret0;
}
BIG_OK) {
goto ret0;
}
BIG_OK) {
goto ret1;
}
#ifdef __sparcv9
#else /* !__sparcv9 */
#endif /* __sparcv9 */
goto ret2;
}
goto ret3;
}
goto ret4;
}
goto ret4;
}
case CKK_DES:
break;
case CKK_DES2:
break;
case CKK_DES3:
break;
case CKK_RC4:
case CKK_AES:
case CKK_GENERIC_SECRET:
#ifdef __sparcv9
/* LINTED */
#else /* !__sparcv9 */
#endif /* __sparcv9 */
break;
}
if (keylen == 0) {
/*
* keylen == 0 only if CKA_VALUE_LEN did not specify.
*/
}
/*
* Note: No need to have "default:" case here since invalid key type
* if any has been detected at function soft_build_secret_key_object()
* before it gets here.
*/
goto ret5;
}
goto ret5;
}
/*
* The truncation removes bytes from the leading end of the
* secret value.
*/
keylen);
ret5:
ret4:
ret3:
ret2:
ret1:
ret0:
return (rv);
}