dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / common / crypto / dsa / dsa_impl.h
blob39758d60b0df44c64cfd59993ad52a40b5c4e354
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 _DSA_IMPL_H
27 #define _DSA_IMPL_H
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
33 #include <sys/types.h>
34 #include <bignum.h>
36 /* DSA Signature is always 40 bytes */
37 #define DSA_SIGNATURE_LENGTH 40
38 #define MIN_DSA_KEY_LEN (512 >> 3)
39 #define MAX_DSA_KEY_LEN (1024 >> 3)
41 #define DSA_SUBPRIME_BITS 160
42 #define DSA_SUBPRIME_BYTES (DSA_SUBPRIME_BITS >> 3)
44 #ifdef _KERNEL
46 #include <sys/sunddi.h>
47 #include <sys/crypto/common.h>
49 #define CK_RV int
51 #define CKR_OK CRYPTO_SUCCESS
52 #define CKR_ARGUMENTS_BAD CRYPTO_ARGUMENTS_BAD
53 #define CKR_ATTRIBUTE_VALUE_INVALID CRYPTO_ATTRIBUTE_VALUE_INVALID
54 #define CKR_DEVICE_ERROR CRYPTO_DEVICE_ERROR
55 #define CKR_GENERAL_ERROR CRYPTO_GENERAL_ERROR
56 #define CKR_HOST_MEMORY CRYPTO_HOST_MEMORY
57 #define CKR_KEY_SIZE_RANGE CRYPTO_KEY_SIZE_RANGE
58 #define CKR_SIGNATURE_INVALID CRYPTO_SIGNATURE_INVALID
60 int random_get_bytes(uint8_t *ran_out, size_t ran_len);
61 int random_get_pseudo_bytes(uint8_t *ran_out, size_t ran_len);
63 #else
65 #include <security/cryptoki.h>
66 #include <security/pkcs11t.h>
68 #endif /* _KERNEL */
71 /* DSA key using BIGNUM representations */
72 typedef struct {
73 int size; /* key size in bits */
74 BIGNUM p; /* p (<size-bit> prime) */
75 BIGNUM q; /* q (160-bit prime) */
76 BIGNUM g; /* g (the base) */
77 BIGNUM x; /* private key (< q) */
78 BIGNUM y; /* = g^x mod p */
79 BIGNUM k; /* k (random number < q) */
80 BIGNUM r; /* r (signature 1st part) */
81 BIGNUM s; /* s (signature 2st part) */
82 BIGNUM v; /* v (verification value - should be = r) */
83 BIGNUM p_rr; /* 2^(2*(32*p->len)) mod p */
84 BIGNUM q_rr; /* 2^(2*(32*q->len)) mod q */
85 } DSAkey;
87 /* DSA key using byte string representations, useful for parameter lists */
88 typedef struct {
89 uint32_t prime_bits; /* size */
90 uchar_t *prime; /* p */
91 uint32_t subprime_bits; /* = 160 */
92 uchar_t *subprime; /* q */
93 uint32_t base_bytes;
94 uchar_t *base; /* g */
95 uchar_t *private_x; /* x */
96 uint32_t private_x_bits;
97 uchar_t *public_y; /* y */
98 uint32_t public_y_bits;
99 uchar_t *signature; /* concat(r, s) */
100 int (*rfunc)(void *, size_t); /* random function */
101 } DSAbytekey;
104 CK_RV dsa_genkey_pair(DSAbytekey *bkey);
106 CK_RV dsa_sign(DSAbytekey *bkey, uchar_t *msg, uint32_t msglen, uchar_t *sig);
108 CK_RV dsa_verify(DSAbytekey *bkey, uchar_t *msg, uchar_t *sig);
110 #ifdef __cplusplus
112 #endif
114 #endif /* _DSA_IMPL_H */