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  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _SOFTDSA_H
27 #define	_SOFTDSA_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 #include <sys/types.h>
36 #include <security/pkcs11t.h>
37 #include <bignum.h>
38 #include "softObject.h"
39 #include "softSession.h"
40 
41 /* DSA Signature is always 40 bytes */
42 #define	DSA_SIGNATURE_LENGTH	40
43 #define	MAX_DSA_KEY_LEN		(1024 >> 3)
44 #define	MIN_DSA_KEY_LEN		(512 >> 3)
45 
46 #define	DSA_SUBPRIME_BITS	160
47 #define	DSA_SUBPRIME_BYTES	(DSA_SUBPRIME_BITS >> 3)
48 
49 typedef struct soft_dsa_ctx {
50 	soft_object_t *key;
51 } soft_dsa_ctx_t;
52 
53 typedef struct {
54 	int 	size;		/* key size in bits */
55 	BIGNUM	q;		/* q (160-bit prime) */
56 	BIGNUM	p;		/* p (<size-bit> prime) */
57 	BIGNUM	g;		/* g (the base) */
58 	BIGNUM	x;		/* private key (< q) */
59 	BIGNUM	y;		/* = g^x mod p */
60 	BIGNUM	k;		/* k (random number < q) */
61 	BIGNUM	r;		/* r (signiture 1st part) */
62 	BIGNUM	s;		/* s (signiture 2nd part) */
63 	BIGNUM	v;		/* v (verification value - should be = r ) */
64 	BIGNUM	p_rr;		/* 2^(2*(32*p->len)) mod p */
65 	BIGNUM	q_rr;		/* 2^(2*(32*q->len)) mod q */
66 } DSAkey;
67 
68 
69 /*
70  * Function Prototypes.
71  */
72 
73 /* DSA */
74 
75 CK_RV soft_dsa_sign_verify_init_common(soft_session_t *, CK_MECHANISM_PTR,
76 	soft_object_t *, boolean_t);
77 
78 CK_RV soft_dsa_verify(soft_session_t *, CK_BYTE_PTR, CK_ULONG,
79 	CK_BYTE_PTR, CK_ULONG);
80 
81 CK_RV soft_dsa_sign(soft_session_t *, CK_BYTE_PTR, CK_ULONG,
82 	CK_BYTE_PTR, CK_ULONG_PTR);
83 
84 BIG_ERR_CODE DSA_key_init(DSAkey *, int);
85 
86 void DSA_key_finish(DSAkey *);
87 
88 CK_RV soft_dsa_genkey_pair(soft_object_t *, soft_object_t *);
89 
90 CK_RV soft_dsa_digest_sign_common(soft_session_t *, CK_BYTE_PTR,
91     CK_ULONG, CK_BYTE_PTR, CK_ULONG_PTR, boolean_t);
92 
93 CK_RV soft_dsa_digest_verify_common(soft_session_t *, CK_BYTE_PTR,
94     CK_ULONG, CK_BYTE_PTR, CK_ULONG, boolean_t);
95 
96 #ifdef	__cplusplus
97 }
98 #endif
99 
100 #endif /* _SOFTDSA_H */
101