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