1726fad2Dina K Nimeh/*
2726fad2Dina K Nimeh * CDDL HEADER START
3726fad2Dina K Nimeh *
4726fad2Dina K Nimeh * The contents of this file are subject to the terms of the
5726fad2Dina K Nimeh * Common Development and Distribution License (the "License").
6726fad2Dina K Nimeh * You may not use this file except in compliance with the License.
7726fad2Dina K Nimeh *
8726fad2Dina K Nimeh * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9726fad2Dina K Nimeh * or http://www.opensolaris.org/os/licensing.
10726fad2Dina K Nimeh * See the License for the specific language governing permissions
11726fad2Dina K Nimeh * and limitations under the License.
12726fad2Dina K Nimeh *
13726fad2Dina K Nimeh * When distributing Covered Code, include this CDDL HEADER in each
14726fad2Dina K Nimeh * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15726fad2Dina K Nimeh * If applicable, add the following below this CDDL HEADER, with the
16726fad2Dina K Nimeh * fields enclosed by brackets "[]" replaced with your own identifying
17726fad2Dina K Nimeh * information: Portions Copyright [yyyy] [name of copyright owner]
18726fad2Dina K Nimeh *
19726fad2Dina K Nimeh * CDDL HEADER END
20726fad2Dina K Nimeh */
21726fad2Dina K Nimeh
22726fad2Dina K Nimeh/*
23726fad2Dina K Nimeh * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24726fad2Dina K Nimeh */
25726fad2Dina K Nimeh
26726fad2Dina K Nimeh#ifndef _DH_IMPL_H
27726fad2Dina K Nimeh#define	_DH_IMPL_H
28726fad2Dina K Nimeh
29726fad2Dina K Nimeh#ifdef __cplusplus
30726fad2Dina K Nimehextern "C" {
31726fad2Dina K Nimeh#endif
32726fad2Dina K Nimeh
33726fad2Dina K Nimeh#include <sys/types.h>
34726fad2Dina K Nimeh#include <bignum.h>
35726fad2Dina K Nimeh
36726fad2Dina K Nimeh#define	MIN_DH_KEYLENGTH_IN_BYTES	8
37726fad2Dina K Nimeh#define	MAX_DH_KEYLENGTH_IN_BYTES	512
38726fad2Dina K Nimeh#define	DH_MIN_KEY_LEN		64
39726fad2Dina K Nimeh#define	DH_MAX_KEY_LEN		4096
40726fad2Dina K Nimeh
41726fad2Dina K Nimeh#ifdef _KERNEL
42726fad2Dina K Nimeh
43726fad2Dina K Nimeh#include <sys/sunddi.h>
44726fad2Dina K Nimeh#include <sys/crypto/common.h>
45726fad2Dina K Nimeh
46726fad2Dina K Nimeh#define	CK_RV			ulong_t
47726fad2Dina K Nimeh
48726fad2Dina K Nimeh#define	CKR_OK			CRYPTO_SUCCESS
49726fad2Dina K Nimeh#define	CKR_ARGUMENTS_BAD	CRYPTO_ARGUMENTS_BAD
50726fad2Dina K Nimeh#define	CKR_ATTRIBUTE_TYPE_INVALID	CRYPTO_ATTRIBUTE_TYPE_INVALID
51726fad2Dina K Nimeh#define	CKR_ATTRIBUTE_VALUE_INVALID	CRYPTO_ATTRIBUTE_VALUE_INVALID
52726fad2Dina K Nimeh#define	CKR_DEVICE_ERROR	CRYPTO_DEVICE_ERROR
53726fad2Dina K Nimeh#define	CKR_GENERAL_ERROR	CRYPTO_GENERAL_ERROR
54726fad2Dina K Nimeh#define	CKR_HOST_MEMORY		CRYPTO_HOST_MEMORY
55726fad2Dina K Nimeh#define	CKR_KEY_SIZE_RANGE	CRYPTO_KEY_SIZE_RANGE
56726fad2Dina K Nimeh
57726fad2Dina K Nimehint random_get_bytes(uint8_t *ran_out, size_t ran_len);
58726fad2Dina K Nimehint random_get_pseudo_bytes(uint8_t *ran_out, size_t ran_len);
59726fad2Dina K Nimeh
60726fad2Dina K Nimeh#else
61726fad2Dina K Nimeh
62726fad2Dina K Nimeh#include <security/cryptoki.h>
63726fad2Dina K Nimeh#include <security/pkcs11t.h>
64726fad2Dina K Nimeh
65726fad2Dina K Nimeh#endif	/* _KERNEL */
66726fad2Dina K Nimeh
67726fad2Dina K Nimeh
68726fad2Dina K Nimeh/* DH key using BIGNUM representations */
69726fad2Dina K Nimehtypedef struct {
70726fad2Dina K Nimeh	int 	size;		/* key size in bits */
71726fad2Dina K Nimeh	BIGNUM	p;		/* p (prime) */
72726fad2Dina K Nimeh	BIGNUM	g;		/* g (base) */
73726fad2Dina K Nimeh	BIGNUM	x;		/* private value (random) */
74726fad2Dina K Nimeh	BIGNUM	y;		/* public value (= g^x mod p) */
75726fad2Dina K Nimeh} DHkey;
76726fad2Dina K Nimeh
77726fad2Dina K Nimeh/* DH key using byte string representations, useful for parameter lists */
78726fad2Dina K Nimehtypedef struct {
79726fad2Dina K Nimeh	uint32_t prime_bits;	/* size */
80726fad2Dina K Nimeh	uchar_t	*prime;		/* p */
81726fad2Dina K Nimeh	uint32_t base_bytes;
82726fad2Dina K Nimeh	uchar_t *base;		/* g */
83726fad2Dina K Nimeh	uint32_t value_bits;	/* for both x and y */
84726fad2Dina K Nimeh	uchar_t	*private_x;	/* x */
85726fad2Dina K Nimeh	uchar_t *public_y;	/* y */
86726fad2Dina K Nimeh	int	(*rfunc)(void *, size_t);	/* random function */
87726fad2Dina K Nimeh} DHbytekey;
88726fad2Dina K Nimeh
89726fad2Dina K Nimeh
90726fad2Dina K NimehCK_RV dh_genkey_pair(DHbytekey *bkey);
91726fad2Dina K Nimeh
92726fad2Dina K NimehCK_RV dh_key_derive(DHbytekey *bkey, uint32_t key_type,
9353a3dbbJason King    uchar_t *secretkey, uint32_t *secretkey_len, int flag);
94726fad2Dina K Nimeh
95726fad2Dina K Nimeh#ifdef	__cplusplus
96726fad2Dina K Nimeh}
97726fad2Dina K Nimeh#endif
98726fad2Dina K Nimeh
99726fad2Dina K Nimeh#endif /* _DH_IMPL_H */
100