xref: /illumos-gate/usr/src/cmd/keyserv/keyserv_cache.h (revision 2a8bcb4efb45d99ac41c94a75c396b362c414f7f)
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 1997 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_KEYSERV_CACHE_H
28 #define	_KEYSERV_CACHE_H
29 
30 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 /* uid_t, size_t, caddr_t, u_int, etc. */
35 #include <sys/types.h>
36 /* des_block, keylen_t, algtype_t */
37 #include <rpc/key_prot.h>
38 
39 struct dhkey {
40 	u_short	length;	/* Length in bytes */
41 	u_char	key[1];	/* Binary data; allocated to correct length */
42 };
43 
44 /* Round up to multiple of four */
45 #define	ALIGN4(addr)		(4 * (((addr)+3)/4))
46 /* Round up to multiple of eight */
47 #define	ALIGN8(addr)		(8 * (((addr)+7)/8))
48 
49 /* Convert key length in bits to bytes */
50 #define	KEYLEN(keylen)		(((keylen)+7)/8)
51 
52 /* Bytes to allocate for struct dhkey holding key of specified length (bits) */
53 #define	DHKEYALLOC(keylen)	ALIGN4(sizeof (struct dhkey) + KEYLEN(keylen))
54 /* Bytes used for a struct dhkey (already allocated */
55 #define	DHKEYSIZE(dhkey_ptr)	ALIGN4(sizeof (struct dhkey) + \
56 				(dhkey_ptr)->length)
57 
58 struct cachekey3_list {
59 	keybuf3			*public;
60 	keybuf3			*secret;
61 	int			refcnt;
62 	deskeyarray		deskey;
63 	struct cachekey3_list	*next;
64 };
65 
66 #define	CACHEKEY3_LIST_SIZE(keylen)	(sizeof (struct cachekey3_list) + \
67 					2*sizeof (keybuf3) + \
68 					2*(ALIGN4(2*KEYLEN(keylen)+1)) + \
69 					3*sizeof (des_block))
70 
71 int			create_cache_file(keylen_t keylen, algtype_t algtype,
72 					int sizespec);
73 
74 int			cache_insert(keylen_t keylen, algtype_t algtype,
75 					uid_t uid,
76 					deskeyarray common, des_block key,
77 					keybuf3 *public,
78 					keybuf3 *secret);
79 
80 struct cachekey3_list	*cache_retrieve(keylen_t keylen, algtype_t algtype,
81 					uid_t uid,
82 					keybuf3 *public, des_block key);
83 
84 int			cache_remove(keylen_t keylen, algtype_t algtype,
85 					uid_t uid,
86 					keybuf3 *public);
87 
88 void			print_cache(keylen_t keylen, algtype_t algtype);
89 
90 #ifdef	__cplusplus
91 }
92 #endif
93 
94 #endif /* _KEYSERV_CACHE_H */
95