17c478bd9Sstevel@tonic-gate #ifndef DST_INTERNAL_H
27c478bd9Sstevel@tonic-gate #define DST_INTERNAL_H
37c478bd9Sstevel@tonic-gate 
47c478bd9Sstevel@tonic-gate /*
57c478bd9Sstevel@tonic-gate  * Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc.
67c478bd9Sstevel@tonic-gate  *
77c478bd9Sstevel@tonic-gate  * Permission to use, copy modify, and distribute this software for any
87c478bd9Sstevel@tonic-gate  * purpose with or without fee is hereby granted, provided that the above
97c478bd9Sstevel@tonic-gate  * copyright notice and this permission notice appear in all copies.
107c478bd9Sstevel@tonic-gate  *
117c478bd9Sstevel@tonic-gate  * THE SOFTWARE IS PROVIDED "AS IS" AND TRUSTED INFORMATION SYSTEMS
127c478bd9Sstevel@tonic-gate  * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
137c478bd9Sstevel@tonic-gate  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL
147c478bd9Sstevel@tonic-gate  * TRUSTED INFORMATION SYSTEMS BE LIABLE FOR ANY SPECIAL, DIRECT,
157c478bd9Sstevel@tonic-gate  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
167c478bd9Sstevel@tonic-gate  * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
177c478bd9Sstevel@tonic-gate  * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
187c478bd9Sstevel@tonic-gate  * WITH THE USE OR PERFORMANCE OF THE SOFTWARE.
197c478bd9Sstevel@tonic-gate  */
207c478bd9Sstevel@tonic-gate #include <limits.h>
217c478bd9Sstevel@tonic-gate #include <sys/param.h>
227c478bd9Sstevel@tonic-gate #if (!defined(BSD)) || (BSD < 199306)
237c478bd9Sstevel@tonic-gate # include <sys/bitypes.h>
247c478bd9Sstevel@tonic-gate #else
257c478bd9Sstevel@tonic-gate # include <sys/types.h>
267c478bd9Sstevel@tonic-gate #endif
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #ifndef PATH_MAX
297c478bd9Sstevel@tonic-gate # ifdef POSIX_PATH_MAX
307c478bd9Sstevel@tonic-gate #  define PATH_MAX POSIX_PATH_MAX
317c478bd9Sstevel@tonic-gate # else
32*9525b14bSRao Shoaib #  define PATH_MAX 255 /*%< this is the value of POSIX_PATH_MAX */
337c478bd9Sstevel@tonic-gate # endif
347c478bd9Sstevel@tonic-gate #endif
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate typedef struct dst_key {
37*9525b14bSRao Shoaib 	char	*dk_key_name;   /*%< name of the key */
38*9525b14bSRao Shoaib 	int	dk_key_size;    /*%< this is the size of the key in bits */
39*9525b14bSRao Shoaib 	int	dk_proto;       /*%< what protocols this key can be used for */
40*9525b14bSRao Shoaib 	int	dk_alg;         /*%< algorithm number from key record */
41*9525b14bSRao Shoaib 	u_int32_t dk_flags;     /*%< and the flags of the public key */
42*9525b14bSRao Shoaib 	u_int16_t dk_id;        /*%< identifier of the key */
43*9525b14bSRao Shoaib 	void	*dk_KEY_struct; /*%< pointer to key in crypto pkg fmt */
44*9525b14bSRao Shoaib 	struct dst_func *dk_func; /*%< point to cryptto pgk specific function table */
457c478bd9Sstevel@tonic-gate } DST_KEY;
467c478bd9Sstevel@tonic-gate #define HAS_DST_KEY
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate #include <isc/dst.h>
497c478bd9Sstevel@tonic-gate /*
507c478bd9Sstevel@tonic-gate  * define what crypto systems are supported for RSA,
517c478bd9Sstevel@tonic-gate  * BSAFE is prefered over RSAREF; only one can be set at any time
527c478bd9Sstevel@tonic-gate  */
537c478bd9Sstevel@tonic-gate #if defined(BSAFE) && defined(RSAREF)
547c478bd9Sstevel@tonic-gate # error "Cannot have both BSAFE and RSAREF defined"
557c478bd9Sstevel@tonic-gate #endif
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate /* Declare dst_lib specific constants */
587c478bd9Sstevel@tonic-gate #define KEY_FILE_FORMAT "1.2"
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate /* suffixes for key file names */
617c478bd9Sstevel@tonic-gate #define PRIVATE_KEY		"private"
627c478bd9Sstevel@tonic-gate #define PUBLIC_KEY		"key"
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate /* error handling */
657c478bd9Sstevel@tonic-gate #ifdef REPORT_ERRORS
667c478bd9Sstevel@tonic-gate #define EREPORT(str)		printf str
677c478bd9Sstevel@tonic-gate #else
687c478bd9Sstevel@tonic-gate #define EREPORT(str)		(void)0
697c478bd9Sstevel@tonic-gate #endif
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate /* use our own special macro to FRRE memory */
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate #ifndef SAFE_FREE
747c478bd9Sstevel@tonic-gate #define SAFE_FREE(a) \
757c478bd9Sstevel@tonic-gate do{if(a != NULL){memset(a,0, sizeof(*a)); free(a); a=NULL;}} while (0)
76*9525b14bSRao Shoaib #define SAFE_FREE2(a,s) if (a != NULL && (long)s > 0){memset(a,0, s);free(a); a=NULL;}
777c478bd9Sstevel@tonic-gate #endif
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate typedef struct dst_func {
807c478bd9Sstevel@tonic-gate 	int (*sign)(const int mode, DST_KEY *key, void **context,
817c478bd9Sstevel@tonic-gate 		     const u_int8_t *data, const int len,
827c478bd9Sstevel@tonic-gate 		     u_int8_t *signature, const int sig_len);
837c478bd9Sstevel@tonic-gate 	int (*verify)(const int mode, DST_KEY *key, void **context,
847c478bd9Sstevel@tonic-gate 		       const u_int8_t *data, const int len,
857c478bd9Sstevel@tonic-gate 		       const u_int8_t *signature, const int sig_len);
867c478bd9Sstevel@tonic-gate 	int (*compare)(const DST_KEY *key1, const DST_KEY *key2);
877c478bd9Sstevel@tonic-gate 	int (*generate)(DST_KEY *key, int parms);
887c478bd9Sstevel@tonic-gate 	void *(*destroy)(void *key);
897c478bd9Sstevel@tonic-gate 	/* conversion functions */
907c478bd9Sstevel@tonic-gate 	int (*to_dns_key)(const DST_KEY *key, u_int8_t *out,
917c478bd9Sstevel@tonic-gate 			   const int out_len);
927c478bd9Sstevel@tonic-gate 	int (*from_dns_key)(DST_KEY *key, const u_int8_t *str,
937c478bd9Sstevel@tonic-gate 			     const int str_len);
947c478bd9Sstevel@tonic-gate 	int (*to_file_fmt)(const DST_KEY *key, char *out,
957c478bd9Sstevel@tonic-gate 			    const int out_len);
967c478bd9Sstevel@tonic-gate 	int (*from_file_fmt)(DST_KEY *key, const char *out,
977c478bd9Sstevel@tonic-gate 			      const int out_len);
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate } dst_func;
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate extern dst_func *dst_t_func[DST_MAX_ALGS];
1027c478bd9Sstevel@tonic-gate extern const char *key_file_fmt_str;
1037c478bd9Sstevel@tonic-gate extern const char *dst_path;
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate #ifndef DST_HASH_SIZE
106*9525b14bSRao Shoaib #define DST_HASH_SIZE 20	/*%< RIPEMD160 and SHA-1 are 20 bytes MD5 is 16 */
1077c478bd9Sstevel@tonic-gate #endif
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate int dst_bsafe_init(void);
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate int dst_rsaref_init(void);
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate int dst_hmac_md5_init(void);
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate int dst_cylink_init(void);
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate int dst_eay_dss_init(void);
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate /* from higher level support routines */
1207c478bd9Sstevel@tonic-gate int       dst_s_calculate_bits( const u_int8_t *str, const int max_bits);
1217c478bd9Sstevel@tonic-gate int       dst_s_verify_str( const char **buf, const char *str);
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate /* conversion between dns names and key file names */
1257c478bd9Sstevel@tonic-gate size_t    dst_s_filename_length( const char *name, const char *suffix);
1267c478bd9Sstevel@tonic-gate int       dst_s_build_filename(  char *filename, const char *name,
1277c478bd9Sstevel@tonic-gate 			         u_int16_t id, int alg, const char *suffix,
1287c478bd9Sstevel@tonic-gate 			         size_t filename_length);
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate FILE      *dst_s_fopen (const char *filename, const char *mode, int perm);
1317c478bd9Sstevel@tonic-gate 
132*9525b14bSRao Shoaib /*%
1337c478bd9Sstevel@tonic-gate  * read and write network byte order into u_int?_t
1347c478bd9Sstevel@tonic-gate  *  all of these should be retired
1357c478bd9Sstevel@tonic-gate  */
1367c478bd9Sstevel@tonic-gate u_int16_t dst_s_get_int16( const u_int8_t *buf);
1377c478bd9Sstevel@tonic-gate void      dst_s_put_int16( u_int8_t *buf, const u_int16_t val);
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate u_int32_t dst_s_get_int32( const u_int8_t *buf);
1407c478bd9Sstevel@tonic-gate void      dst_s_put_int32( u_int8_t *buf, const u_int32_t val);
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate #ifdef DUMP
1437c478bd9Sstevel@tonic-gate # undef DUMP
1447c478bd9Sstevel@tonic-gate # define DUMP(a,b,c,d) dst_s_dump(a,b,c,d)
1457c478bd9Sstevel@tonic-gate #else
1467c478bd9Sstevel@tonic-gate # define DUMP(a,b,c,d)
1477c478bd9Sstevel@tonic-gate #endif
1487c478bd9Sstevel@tonic-gate void
1497c478bd9Sstevel@tonic-gate dst_s_dump(const int mode, const u_char *data, const int size,
1507c478bd9Sstevel@tonic-gate             const char *msg);
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate #endif /* DST_INTERNAL_H */
155*9525b14bSRao Shoaib /*! \file */
156