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