Blame lib/dns/dst_internal.h

Packit 5ce601
/*
Packit 5ce601
 * Portions Copyright (C) Internet Systems Consortium, Inc. ("ISC")
Packit 5ce601
 *
Packit 5ce601
 * This Source Code Form is subject to the terms of the Mozilla Public
Packit 5ce601
 * License, v. 2.0. If a copy of the MPL was not distributed with this
Packit Service 704ed8
 * file, you can obtain one at https://mozilla.org/MPL/2.0/.
Packit 5ce601
 *
Packit 5ce601
 * See the COPYRIGHT file distributed with this work for additional
Packit 5ce601
 * information regarding copyright ownership.
Packit 5ce601
 *
Packit 5ce601
 * Portions Copyright (C) Network Associates, Inc.
Packit 5ce601
 *
Packit 5ce601
 * Permission to use, copy, modify, and/or distribute this software for any
Packit 5ce601
 * purpose with or without fee is hereby granted, provided that the above
Packit 5ce601
 * copyright notice and this permission notice appear in all copies.
Packit 5ce601
 *
Packit 5ce601
 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC AND NETWORK ASSOCIATES DISCLAIMS
Packit 5ce601
 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
Packit 5ce601
 * WARRANTIES OF MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE
Packit 5ce601
 * FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
Packit 5ce601
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
Packit 5ce601
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
Packit 5ce601
 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Packit 5ce601
 */
Packit 5ce601
Packit 5ce601
Packit 5ce601
#ifndef DST_DST_INTERNAL_H
Packit 5ce601
#define DST_DST_INTERNAL_H 1
Packit 5ce601
Packit 5ce601
#include <inttypes.h>
Packit 5ce601
#include <stdbool.h>
Packit 5ce601
Packit 5ce601
#include <isc/lang.h>
Packit 5ce601
#include <isc/buffer.h>
Packit 5ce601
#include <isc/magic.h>
Packit 5ce601
#include <isc/region.h>
Packit 5ce601
#include <isc/types.h>
Packit 5ce601
#include <isc/md5.h>
Packit 5ce601
#include <isc/refcount.h>
Packit 5ce601
#include <isc/sha1.h>
Packit 5ce601
#include <isc/sha2.h>
Packit 5ce601
#include <isc/stdtime.h>
Packit 5ce601
#include <isc/hmacmd5.h>
Packit 5ce601
#include <isc/hmacsha.h>
Packit 5ce601
Packit 5ce601
#include <pk11/site.h>
Packit 5ce601
Packit 5ce601
#include <dns/time.h>
Packit 5ce601
Packit 5ce601
#include <dst/dst.h>
Packit 5ce601
Packit 5ce601
#ifdef OPENSSL
Packit 5ce601
#ifndef PK11_DH_DISABLE
Packit 5ce601
#include <openssl/dh.h>
Packit 5ce601
#endif
Packit 5ce601
#ifndef PK11_DSA_DISABLE
Packit 5ce601
#include <openssl/dsa.h>
Packit 5ce601
#endif
Packit 5ce601
#include <openssl/err.h>
Packit 5ce601
#include <openssl/evp.h>
Packit 5ce601
#include <openssl/objects.h>
Packit 5ce601
#include <openssl/rsa.h>
Packit 5ce601
#endif
Packit 5ce601
Packit 5ce601
ISC_LANG_BEGINDECLS
Packit 5ce601
Packit 5ce601
#define KEY_MAGIC	ISC_MAGIC('D','S','T','K')
Packit 5ce601
#define CTX_MAGIC	ISC_MAGIC('D','S','T','C')
Packit 5ce601
Packit 5ce601
#define VALID_KEY(x) ISC_MAGIC_VALID(x, KEY_MAGIC)
Packit 5ce601
#define VALID_CTX(x) ISC_MAGIC_VALID(x, CTX_MAGIC)
Packit 5ce601
Packit 5ce601
LIBDNS_EXTERNAL_DATA extern isc_mem_t *dst__memory_pool;
Packit 5ce601
Packit 5ce601
/***
Packit 5ce601
 *** Types
Packit 5ce601
 ***/
Packit 5ce601
Packit 5ce601
typedef struct dst_func dst_func_t;
Packit 5ce601
Packit 5ce601
#ifndef PK11_MD5_DISABLE
Packit 5ce601
typedef struct dst_hmacmd5_key	  dst_hmacmd5_key_t;
Packit 5ce601
#endif
Packit 5ce601
typedef struct dst_hmacsha1_key   dst_hmacsha1_key_t;
Packit 5ce601
typedef struct dst_hmacsha224_key dst_hmacsha224_key_t;
Packit 5ce601
typedef struct dst_hmacsha256_key dst_hmacsha256_key_t;
Packit 5ce601
typedef struct dst_hmacsha384_key dst_hmacsha384_key_t;
Packit 5ce601
typedef struct dst_hmacsha512_key dst_hmacsha512_key_t;
Packit 5ce601
Packit 5ce601
/*%
Packit 5ce601
 * Indicate whether a DST context will be used for signing
Packit 5ce601
 * or for verification
Packit 5ce601
 */
Packit 5ce601
typedef enum { DO_SIGN, DO_VERIFY } dst_use_t;
Packit 5ce601
Packit 5ce601
/*% DST Key Structure */
Packit 5ce601
struct dst_key {
Packit 5ce601
	unsigned int	magic;
Packit 5ce601
	isc_refcount_t	refs;
Packit 5ce601
	dns_name_t *	key_name;	/*%< name of the key */
Packit 5ce601
	unsigned int	key_size;	/*%< size of the key in bits */
Packit 5ce601
	unsigned int	key_proto;	/*%< protocols this key is used for */
Packit 5ce601
	unsigned int	key_alg;	/*%< algorithm of the key */
Packit 5ce601
	uint32_t	key_flags;	/*%< flags of the public key */
Packit 5ce601
	uint16_t	key_id;		/*%< identifier of the key */
Packit 5ce601
	uint16_t	key_rid;	/*%< identifier of the key when
Packit 5ce601
					     revoked */
Packit 5ce601
	uint16_t	key_bits;	/*%< hmac digest bits */
Packit 5ce601
	dns_rdataclass_t key_class;	/*%< class of the key record */
Packit 5ce601
	dns_ttl_t	key_ttl;	/*%< default/initial dnskey ttl */
Packit 5ce601
	isc_mem_t	*mctx;		/*%< memory context */
Packit 5ce601
	char		*engine;	/*%< engine name (HSM) */
Packit 5ce601
	char		*label;		/*%< engine label (HSM) */
Packit 5ce601
	union {
Packit 5ce601
		void *generic;
Packit 5ce601
		gss_ctx_id_t gssctx;
Packit 5ce601
#ifdef OPENSSL
Packit 5ce601
#if !defined(USE_EVP) || !USE_EVP
Packit 5ce601
		RSA *rsa;
Packit 5ce601
#endif
Packit 5ce601
#ifndef PK11_DSA_DISABLE
Packit 5ce601
		DSA *dsa;
Packit 5ce601
#endif
Packit 5ce601
#ifndef PK11_DH_DISABLE
Packit 5ce601
		DH *dh;
Packit 5ce601
#endif
Packit 5ce601
		EVP_PKEY *pkey;
Packit 5ce601
#elif PKCS11CRYPTO
Packit 5ce601
		pk11_object_t *pkey;
Packit 5ce601
#endif
Packit 5ce601
#ifndef PK11_MD5_DISABLE
Packit 5ce601
		dst_hmacmd5_key_t *hmacmd5;
Packit 5ce601
#endif
Packit 5ce601
		dst_hmacsha1_key_t *hmacsha1;
Packit 5ce601
		dst_hmacsha224_key_t *hmacsha224;
Packit 5ce601
		dst_hmacsha256_key_t *hmacsha256;
Packit 5ce601
		dst_hmacsha384_key_t *hmacsha384;
Packit 5ce601
		dst_hmacsha512_key_t *hmacsha512;
Packit 5ce601
Packit 5ce601
	} keydata;			/*%< pointer to key in crypto pkg fmt */
Packit 5ce601
Packit 5ce601
	isc_stdtime_t	times[DST_MAX_TIMES + 1];    /*%< timing metadata */
Packit 5ce601
	bool	timeset[DST_MAX_TIMES + 1];  /*%< data set? */
Packit 5ce601
	isc_stdtime_t	nums[DST_MAX_NUMERIC + 1];   /*%< numeric metadata */
Packit 5ce601
	bool	numset[DST_MAX_NUMERIC + 1]; /*%< data set? */
Packit 5ce601
	bool 	inactive;      /*%< private key not present as it is
Packit 5ce601
					    inactive */
Packit 5ce601
	bool 	external;      /*%< external key */
Packit 5ce601
Packit 5ce601
	int		fmt_major;     /*%< private key format, major version */
Packit 5ce601
	int		fmt_minor;     /*%< private key format, minor version */
Packit 5ce601
Packit 5ce601
	dst_func_t *    func;	       /*%< crypto package specific functions */
Packit 5ce601
	isc_buffer_t   *key_tkeytoken; /*%< TKEY token data */
Packit 5ce601
};
Packit 5ce601
Packit 5ce601
struct dst_context {
Packit 5ce601
	unsigned int magic;
Packit 5ce601
	dst_use_t use;
Packit 5ce601
	dst_key_t *key;
Packit 5ce601
	isc_mem_t *mctx;
Packit 5ce601
	isc_logcategory_t *category;
Packit 5ce601
	union {
Packit 5ce601
		void *generic;
Packit 5ce601
		dst_gssapi_signverifyctx_t *gssctx;
Packit 5ce601
#ifndef PK11_MD5_DISABLE
Packit 5ce601
		isc_md5_t *md5ctx;
Packit 5ce601
#endif
Packit 5ce601
		isc_sha1_t *sha1ctx;
Packit 5ce601
		isc_sha256_t *sha256ctx;
Packit 5ce601
		isc_sha512_t *sha512ctx;
Packit 5ce601
#ifndef PK11_MD5_DISABLE
Packit 5ce601
		isc_hmacmd5_t *hmacmd5ctx;
Packit 5ce601
#endif
Packit 5ce601
		isc_hmacsha1_t *hmacsha1ctx;
Packit 5ce601
		isc_hmacsha224_t *hmacsha224ctx;
Packit 5ce601
		isc_hmacsha256_t *hmacsha256ctx;
Packit 5ce601
		isc_hmacsha384_t *hmacsha384ctx;
Packit 5ce601
		isc_hmacsha512_t *hmacsha512ctx;
Packit 5ce601
#ifdef OPENSSL
Packit 5ce601
		EVP_MD_CTX *evp_md_ctx;
Packit 5ce601
#elif PKCS11CRYPTO
Packit 5ce601
		pk11_context_t *pk11_ctx;
Packit 5ce601
#endif
Packit 5ce601
	} ctxdata;
Packit 5ce601
};
Packit 5ce601
Packit 5ce601
struct dst_func {
Packit 5ce601
	/*
Packit 5ce601
	 * Context functions
Packit 5ce601
	 */
Packit 5ce601
	isc_result_t (*createctx)(dst_key_t *key, dst_context_t *dctx);
Packit 5ce601
	isc_result_t (*createctx2)(dst_key_t *key, int maxbits,
Packit 5ce601
				   dst_context_t *dctx);
Packit 5ce601
	void (*destroyctx)(dst_context_t *dctx);
Packit 5ce601
	isc_result_t (*adddata)(dst_context_t *dctx, const isc_region_t *data);
Packit 5ce601
Packit 5ce601
	/*
Packit 5ce601
	 * Key operations
Packit 5ce601
	 */
Packit 5ce601
	isc_result_t (*sign)(dst_context_t *dctx, isc_buffer_t *sig);
Packit 5ce601
	isc_result_t (*verify)(dst_context_t *dctx, const isc_region_t *sig);
Packit 5ce601
	isc_result_t (*verify2)(dst_context_t *dctx, int maxbits,
Packit 5ce601
				const isc_region_t *sig);
Packit 5ce601
	isc_result_t (*computesecret)(const dst_key_t *pub,
Packit 5ce601
				      const dst_key_t *priv,
Packit 5ce601
				      isc_buffer_t *secret);
Packit 5ce601
	bool (*compare)(const dst_key_t *key1, const dst_key_t *key2);
Packit 5ce601
	bool (*paramcompare)(const dst_key_t *key1,
Packit 5ce601
				      const dst_key_t *key2);
Packit 5ce601
	isc_result_t (*generate)(dst_key_t *key, int parms,
Packit 5ce601
				 void (*callback)(int));
Packit 5ce601
	bool (*isprivate)(const dst_key_t *key);
Packit 5ce601
	void (*destroy)(dst_key_t *key);
Packit 5ce601
Packit 5ce601
	/* conversion functions */
Packit 5ce601
	isc_result_t (*todns)(const dst_key_t *key, isc_buffer_t *data);
Packit 5ce601
	isc_result_t (*fromdns)(dst_key_t *key, isc_buffer_t *data);
Packit 5ce601
	isc_result_t (*tofile)(const dst_key_t *key, const char *directory);
Packit 5ce601
	isc_result_t (*parse)(dst_key_t *key,
Packit 5ce601
			      isc_lex_t *lexer,
Packit 5ce601
			      dst_key_t *pub);
Packit 5ce601
Packit 5ce601
	/* cleanup */
Packit 5ce601
	void (*cleanup)(void);
Packit 5ce601
Packit 5ce601
	isc_result_t (*fromlabel)(dst_key_t *key, const char *engine,
Packit 5ce601
				  const char *label, const char *pin);
Packit 5ce601
	isc_result_t (*dump)(dst_key_t *key, isc_mem_t *mctx, char **buffer,
Packit 5ce601
			     int *length);
Packit 5ce601
	isc_result_t (*restore)(dst_key_t *key, const char *keystr);
Packit 5ce601
};
Packit 5ce601
Packit 5ce601
/*%
Packit 5ce601
 * Initializers
Packit 5ce601
 */
Packit 5ce601
isc_result_t dst__openssl_init(const char *engine);
Packit 5ce601
#define dst__pkcs11_init pk11_initialize
Packit 5ce601
Packit 5ce601
#ifndef PK11_MD5_DISABLE
Packit 5ce601
isc_result_t dst__hmacmd5_init(struct dst_func **funcp);
Packit 5ce601
#endif
Packit 5ce601
isc_result_t dst__hmacsha1_init(struct dst_func **funcp);
Packit 5ce601
isc_result_t dst__hmacsha224_init(struct dst_func **funcp);
Packit 5ce601
isc_result_t dst__hmacsha256_init(struct dst_func **funcp);
Packit 5ce601
isc_result_t dst__hmacsha384_init(struct dst_func **funcp);
Packit 5ce601
isc_result_t dst__hmacsha512_init(struct dst_func **funcp);
Packit 5ce601
isc_result_t dst__opensslrsa_init(struct dst_func **funcp,
Packit 5ce601
				  unsigned char algorithm);
Packit Service d3afd5
isc_result_t dst__pkcs11rsa_init(struct dst_func **funcp);
Packit 5ce601
#ifndef PK11_DSA_DISABLE
Packit 5ce601
isc_result_t dst__openssldsa_init(struct dst_func **funcp);
Packit 5ce601
isc_result_t dst__pkcs11dsa_init(struct dst_func **funcp);
Packit 5ce601
#endif
Packit 5ce601
#ifndef PK11_DH_DISABLE
Packit 5ce601
isc_result_t dst__openssldh_init(struct dst_func **funcp);
Packit 5ce601
isc_result_t dst__pkcs11dh_init(struct dst_func **funcp);
Packit 5ce601
#endif
Packit 5ce601
isc_result_t dst__gssapi_init(struct dst_func **funcp);
Packit 5ce601
#ifdef HAVE_OPENSSL_ECDSA
Packit 5ce601
isc_result_t dst__opensslecdsa_init(struct dst_func **funcp);
Packit 5ce601
#endif
Packit 5ce601
#if defined(HAVE_OPENSSL_ED25519) || defined(HAVE_OPENSSL_ED448)
Packit 5ce601
isc_result_t dst__openssleddsa_init(struct dst_func **funcp);
Packit 5ce601
#endif
Packit 5ce601
#ifdef HAVE_PKCS11_ECDSA
Packit 5ce601
isc_result_t dst__pkcs11ecdsa_init(struct dst_func **funcp);
Packit 5ce601
#endif
Packit 5ce601
#if defined(HAVE_PKCS11_ED25519) || defined(HAVE_PKCS11_ED448)
Packit 5ce601
isc_result_t dst__pkcs11eddsa_init(struct dst_func **funcp);
Packit 5ce601
#endif
Packit 5ce601
#ifdef HAVE_OPENSSL_GOST
Packit 5ce601
isc_result_t dst__opensslgost_init(struct dst_func **funcp);
Packit 5ce601
#endif
Packit 5ce601
#ifdef HAVE_PKCS11_GOST
Packit 5ce601
isc_result_t dst__pkcs11gost_init(struct dst_func **funcp);
Packit 5ce601
#endif
Packit 5ce601
Packit 5ce601
/*%
Packit 5ce601
 * Destructors
Packit 5ce601
 */
Packit 5ce601
void dst__openssl_destroy(void);
Packit 5ce601
#define dst__pkcs11_destroy pk11_finalize
Packit 5ce601
Packit 5ce601
/*%
Packit 5ce601
 * Memory allocators using the DST memory pool.
Packit 5ce601
 */
Packit 5ce601
void * dst__mem_alloc(size_t size);
Packit 5ce601
void   dst__mem_free(void *ptr);
Packit 5ce601
void * dst__mem_realloc(void *ptr, size_t size);
Packit 5ce601
Packit 5ce601
/*%
Packit 5ce601
 * Entropy retriever using the DST entropy pool.
Packit 5ce601
 */
Packit 5ce601
isc_result_t dst__entropy_getdata(void *buf, unsigned int len,
Packit 5ce601
				  bool pseudo);
Packit 5ce601
Packit 5ce601
/*
Packit 5ce601
 * Entropy status hook.
Packit 5ce601
 */
Packit 5ce601
unsigned int dst__entropy_status(void);
Packit 5ce601
Packit 5ce601
ISC_LANG_ENDDECLS
Packit 5ce601
Packit 5ce601
#endif /* DST_DST_INTERNAL_H */
Packit 5ce601
/*! \file */