8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / common / crypto / dh / dh_impl.h
blob17eb8a8eb8d0a003b63f35804c7fdd9eabeec095
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
26 #ifndef _DH_IMPL_H
27 #define _DH_IMPL_H
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
33 #include <sys/types.h>
34 #include <bignum.h>
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
41 #ifdef _KERNEL
43 #include <sys/sunddi.h>
44 #include <sys/crypto/common.h>
46 #define CK_RV ulong_t
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
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);
60 #else
62 #include <security/cryptoki.h>
63 #include <security/pkcs11t.h>
65 #endif /* _KERNEL */
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;
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;
90 CK_RV dh_genkey_pair(DHbytekey *bkey);
92 CK_RV dh_key_derive(DHbytekey *bkey, uint32_t key_type,
93 uchar_t *secretkey, uint32_t *secretkey_len, int flag);
95 #ifdef __cplusplus
97 #endif
99 #endif /* _DH_IMPL_H */