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