xref: /onnv-gate/usr/src/common/crypto/dh/dh_impl.h (revision 12573:fb4ef506980f)
1*12573SDina.Nimeh@Sun.COM /*
2*12573SDina.Nimeh@Sun.COM  * CDDL HEADER START
3*12573SDina.Nimeh@Sun.COM  *
4*12573SDina.Nimeh@Sun.COM  * The contents of this file are subject to the terms of the
5*12573SDina.Nimeh@Sun.COM  * Common Development and Distribution License (the "License").
6*12573SDina.Nimeh@Sun.COM  * You may not use this file except in compliance with the License.
7*12573SDina.Nimeh@Sun.COM  *
8*12573SDina.Nimeh@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*12573SDina.Nimeh@Sun.COM  * or http://www.opensolaris.org/os/licensing.
10*12573SDina.Nimeh@Sun.COM  * See the License for the specific language governing permissions
11*12573SDina.Nimeh@Sun.COM  * and limitations under the License.
12*12573SDina.Nimeh@Sun.COM  *
13*12573SDina.Nimeh@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
14*12573SDina.Nimeh@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*12573SDina.Nimeh@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
16*12573SDina.Nimeh@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
17*12573SDina.Nimeh@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
18*12573SDina.Nimeh@Sun.COM  *
19*12573SDina.Nimeh@Sun.COM  * CDDL HEADER END
20*12573SDina.Nimeh@Sun.COM  */
21*12573SDina.Nimeh@Sun.COM 
22*12573SDina.Nimeh@Sun.COM /*
23*12573SDina.Nimeh@Sun.COM  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24*12573SDina.Nimeh@Sun.COM  */
25*12573SDina.Nimeh@Sun.COM 
26*12573SDina.Nimeh@Sun.COM #ifndef _DH_IMPL_H
27*12573SDina.Nimeh@Sun.COM #define	_DH_IMPL_H
28*12573SDina.Nimeh@Sun.COM 
29*12573SDina.Nimeh@Sun.COM #ifdef __cplusplus
30*12573SDina.Nimeh@Sun.COM extern "C" {
31*12573SDina.Nimeh@Sun.COM #endif
32*12573SDina.Nimeh@Sun.COM 
33*12573SDina.Nimeh@Sun.COM #include <sys/types.h>
34*12573SDina.Nimeh@Sun.COM #include <bignum.h>
35*12573SDina.Nimeh@Sun.COM 
36*12573SDina.Nimeh@Sun.COM #define	MIN_DH_KEYLENGTH_IN_BYTES	8
37*12573SDina.Nimeh@Sun.COM #define	MAX_DH_KEYLENGTH_IN_BYTES	512
38*12573SDina.Nimeh@Sun.COM #define	DH_MIN_KEY_LEN		64
39*12573SDina.Nimeh@Sun.COM #define	DH_MAX_KEY_LEN		4096
40*12573SDina.Nimeh@Sun.COM 
41*12573SDina.Nimeh@Sun.COM #ifdef _KERNEL
42*12573SDina.Nimeh@Sun.COM 
43*12573SDina.Nimeh@Sun.COM #include <sys/sunddi.h>
44*12573SDina.Nimeh@Sun.COM #include <sys/crypto/common.h>
45*12573SDina.Nimeh@Sun.COM 
46*12573SDina.Nimeh@Sun.COM #define	CK_RV			ulong_t
47*12573SDina.Nimeh@Sun.COM 
48*12573SDina.Nimeh@Sun.COM #define	CKR_OK			CRYPTO_SUCCESS
49*12573SDina.Nimeh@Sun.COM #define	CKR_ARGUMENTS_BAD	CRYPTO_ARGUMENTS_BAD
50*12573SDina.Nimeh@Sun.COM #define	CKR_ATTRIBUTE_TYPE_INVALID	CRYPTO_ATTRIBUTE_TYPE_INVALID
51*12573SDina.Nimeh@Sun.COM #define	CKR_ATTRIBUTE_VALUE_INVALID	CRYPTO_ATTRIBUTE_VALUE_INVALID
52*12573SDina.Nimeh@Sun.COM #define	CKR_DEVICE_ERROR	CRYPTO_DEVICE_ERROR
53*12573SDina.Nimeh@Sun.COM #define	CKR_GENERAL_ERROR	CRYPTO_GENERAL_ERROR
54*12573SDina.Nimeh@Sun.COM #define	CKR_HOST_MEMORY		CRYPTO_HOST_MEMORY
55*12573SDina.Nimeh@Sun.COM #define	CKR_KEY_SIZE_RANGE	CRYPTO_KEY_SIZE_RANGE
56*12573SDina.Nimeh@Sun.COM 
57*12573SDina.Nimeh@Sun.COM int random_get_bytes(uint8_t *ran_out, size_t ran_len);
58*12573SDina.Nimeh@Sun.COM int random_get_pseudo_bytes(uint8_t *ran_out, size_t ran_len);
59*12573SDina.Nimeh@Sun.COM 
60*12573SDina.Nimeh@Sun.COM #else
61*12573SDina.Nimeh@Sun.COM 
62*12573SDina.Nimeh@Sun.COM #include <security/cryptoki.h>
63*12573SDina.Nimeh@Sun.COM #include <security/pkcs11t.h>
64*12573SDina.Nimeh@Sun.COM 
65*12573SDina.Nimeh@Sun.COM #endif	/* _KERNEL */
66*12573SDina.Nimeh@Sun.COM 
67*12573SDina.Nimeh@Sun.COM 
68*12573SDina.Nimeh@Sun.COM /* DH key using BIGNUM representations */
69*12573SDina.Nimeh@Sun.COM typedef struct {
70*12573SDina.Nimeh@Sun.COM 	int 	size;		/* key size in bits */
71*12573SDina.Nimeh@Sun.COM 	BIGNUM	p;		/* p (prime) */
72*12573SDina.Nimeh@Sun.COM 	BIGNUM	g;		/* g (base) */
73*12573SDina.Nimeh@Sun.COM 	BIGNUM	x;		/* private value (random) */
74*12573SDina.Nimeh@Sun.COM 	BIGNUM	y;		/* public value (= g^x mod p) */
75*12573SDina.Nimeh@Sun.COM } DHkey;
76*12573SDina.Nimeh@Sun.COM 
77*12573SDina.Nimeh@Sun.COM /* DH key using byte string representations, useful for parameter lists */
78*12573SDina.Nimeh@Sun.COM typedef struct {
79*12573SDina.Nimeh@Sun.COM 	uint32_t prime_bits;	/* size */
80*12573SDina.Nimeh@Sun.COM 	uchar_t	*prime;		/* p */
81*12573SDina.Nimeh@Sun.COM 	uint32_t base_bytes;
82*12573SDina.Nimeh@Sun.COM 	uchar_t *base;		/* g */
83*12573SDina.Nimeh@Sun.COM 	uint32_t value_bits;	/* for both x and y */
84*12573SDina.Nimeh@Sun.COM 	uchar_t	*private_x;	/* x */
85*12573SDina.Nimeh@Sun.COM 	uchar_t *public_y;	/* y */
86*12573SDina.Nimeh@Sun.COM 	int	(*rfunc)(void *, size_t);	/* random function */
87*12573SDina.Nimeh@Sun.COM } DHbytekey;
88*12573SDina.Nimeh@Sun.COM 
89*12573SDina.Nimeh@Sun.COM 
90*12573SDina.Nimeh@Sun.COM CK_RV dh_genkey_pair(DHbytekey *bkey);
91*12573SDina.Nimeh@Sun.COM 
92*12573SDina.Nimeh@Sun.COM CK_RV dh_key_derive(DHbytekey *bkey, uint32_t key_type,
93*12573SDina.Nimeh@Sun.COM     uchar_t *secretkey, uint32_t *secretkey_len);
94*12573SDina.Nimeh@Sun.COM 
95*12573SDina.Nimeh@Sun.COM #ifdef	__cplusplus
96*12573SDina.Nimeh@Sun.COM }
97*12573SDina.Nimeh@Sun.COM #endif
98*12573SDina.Nimeh@Sun.COM 
99*12573SDina.Nimeh@Sun.COM #endif /* _DH_IMPL_H */
100