xref: /titanic_44/usr/src/lib/pkcs11/pkcs11_softtoken/common/softDSA.h (revision 24db46411fd54f70c35b94bb952eb7ba040e43b4)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SOFTDSA_H
28 #define	_SOFTDSA_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/types.h>
37 #include <security/pkcs11t.h>
38 #include <bignum.h>
39 #include "softObject.h"
40 #include "softSession.h"
41 
42 /* DSA Signature is always 40 bytes */
43 #define	DSA_SIGNATURE_LENGTH	40
44 #define	MAX_DSA_KEY_LEN		(1024 >> 3)
45 #define	MIN_DSA_KEY_LEN		(512 >> 3)
46 
47 #define	DSA_SUBPRIME_BITS	160
48 #define	DSA_SUBPRIME_BYTES	(DSA_SUBPRIME_BITS >> 3)
49 
50 /* defined in bignumimpl.c */
51 extern	BIGNUM One, Two;
52 
53 typedef struct soft_dsa_ctx {
54 	soft_object_t *key;
55 } soft_dsa_ctx_t;
56 
57 typedef struct {
58 	int 	size;		/* key size in bits */
59 	BIGNUM	q;		/* q (160-bit prime) */
60 	BIGNUM	p;		/* p (<size-bit> prime) */
61 	BIGNUM	g;		/* g (the base) */
62 	BIGNUM	x;		/* private key (< q) */
63 	BIGNUM	y;		/* = g^x mod p */
64 	BIGNUM	k;		/* k (random number < q) */
65 	BIGNUM	r;		/* r (signiture 1st part) */
66 	BIGNUM	s;		/* s (signiture 2nd part) */
67 	BIGNUM	v;		/* v (verification value - should be = r ) */
68 	BIGNUM	p_rr;		/* 2^(2*(32*p->len)) mod p */
69 	BIGNUM	q_rr;		/* 2^(2*(32*q->len)) mod q */
70 } DSAkey;
71 
72 
73 /*
74  * Function Prototypes.
75  */
76 
77 /* DSA */
78 
79 CK_RV soft_dsa_sign_verify_init_common(soft_session_t *, CK_MECHANISM_PTR,
80 	soft_object_t *, boolean_t);
81 
82 CK_RV soft_dsa_verify(soft_session_t *, CK_BYTE_PTR, CK_ULONG,
83 	CK_BYTE_PTR, CK_ULONG);
84 
85 CK_RV soft_dsa_sign(soft_session_t *, CK_BYTE_PTR, CK_ULONG,
86 	CK_BYTE_PTR, CK_ULONG_PTR);
87 
88 BIG_ERR_CODE DSA_key_init(DSAkey *, int);
89 
90 void DSA_key_finish(DSAkey *);
91 
92 CK_RV soft_dsa_genkey_pair(soft_object_t *, soft_object_t *);
93 
94 CK_RV soft_dsa_digest_sign_common(soft_session_t *, CK_BYTE_PTR,
95     CK_ULONG, CK_BYTE_PTR, CK_ULONG_PTR, boolean_t);
96 
97 CK_RV soft_dsa_digest_verify_common(soft_session_t *, CK_BYTE_PTR,
98     CK_ULONG, CK_BYTE_PTR, CK_ULONG, boolean_t);
99 
100 #ifdef	__cplusplus
101 }
102 #endif
103 
104 #endif /* _SOFTDSA_H */
105