1999-07-12 20:08:42 +00:00
|
|
|
/*
|
2009-06-11 23:47:56 +00:00
|
|
|
* Portions Copyright (C) 2004-2009 Internet Systems Consortium, Inc. ("ISC")
|
2004-03-05 05:14:21 +00:00
|
|
|
* Portions Copyright (C) 2000-2002 Internet Software Consortium.
|
2007-06-18 23:47:57 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC AND NETWORK ASSOCIATES DISCLAIMS
|
|
|
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE
|
|
|
|
* FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
|
|
|
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
2000-06-21 22:38:33 +00:00
|
|
|
* Portions Copyright (C) 1995-2000 by Network Associates, Inc.
|
2000-08-01 01:33:37 +00:00
|
|
|
*
|
2007-08-28 07:20:43 +00:00
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
1999-07-12 20:08:42 +00:00
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
2000-08-01 01:33:37 +00:00
|
|
|
*
|
2004-03-05 05:14:21 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC AND NETWORK ASSOCIATES DISCLAIMS
|
|
|
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE
|
|
|
|
* FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
|
|
|
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
1999-07-12 20:08:42 +00:00
|
|
|
*/
|
2000-04-29 02:02:38 +00:00
|
|
|
|
2009-10-24 09:46:19 +00:00
|
|
|
/* $Id: dst_internal.h,v 1.22 2009/10/24 09:46:19 fdupont Exp $ */
|
2000-06-22 22:00:42 +00:00
|
|
|
|
2000-04-29 02:02:38 +00:00
|
|
|
#ifndef DST_DST_INTERNAL_H
|
|
|
|
#define DST_DST_INTERNAL_H 1
|
|
|
|
|
1999-07-12 20:08:42 +00:00
|
|
|
#include <isc/lang.h>
|
|
|
|
#include <isc/buffer.h>
|
|
|
|
#include <isc/int.h>
|
2001-08-28 03:58:29 +00:00
|
|
|
#include <isc/magic.h>
|
1999-07-12 20:08:42 +00:00
|
|
|
#include <isc/region.h>
|
2001-11-07 23:03:54 +00:00
|
|
|
#include <isc/types.h>
|
2006-12-04 01:54:53 +00:00
|
|
|
#include <isc/md5.h>
|
|
|
|
#include <isc/sha1.h>
|
2009-10-22 02:21:31 +00:00
|
|
|
#include <isc/sha2.h>
|
2009-07-19 04:18:05 +00:00
|
|
|
#include <isc/stdtime.h>
|
2006-12-04 01:54:53 +00:00
|
|
|
#include <isc/hmacmd5.h>
|
|
|
|
#include <isc/hmacsha.h>
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2009-07-19 04:18:05 +00:00
|
|
|
#include <dns/time.h>
|
|
|
|
|
1999-07-12 20:08:42 +00:00
|
|
|
#include <dst/dst.h>
|
|
|
|
|
2006-12-04 01:54:53 +00:00
|
|
|
#ifdef OPENSSL
|
|
|
|
#include <openssl/dh.h>
|
|
|
|
#include <openssl/dsa.h>
|
|
|
|
#include <openssl/err.h>
|
2008-03-31 14:42:51 +00:00
|
|
|
#include <openssl/evp.h>
|
2006-12-04 01:54:53 +00:00
|
|
|
#include <openssl/objects.h>
|
|
|
|
#include <openssl/rsa.h>
|
|
|
|
#endif
|
|
|
|
|
1999-07-12 20:08:42 +00:00
|
|
|
ISC_LANG_BEGINDECLS
|
|
|
|
|
2009-06-10 00:27:22 +00:00
|
|
|
#define KEY_MAGIC ISC_MAGIC('D','S','T','K')
|
|
|
|
#define CTX_MAGIC ISC_MAGIC('D','S','T','C')
|
2001-01-17 01:08:08 +00:00
|
|
|
|
|
|
|
#define VALID_KEY(x) ISC_MAGIC_VALID(x, KEY_MAGIC)
|
|
|
|
#define VALID_CTX(x) ISC_MAGIC_VALID(x, CTX_MAGIC)
|
|
|
|
|
2001-11-07 23:03:54 +00:00
|
|
|
extern isc_mem_t *dst__memory_pool;
|
|
|
|
|
1999-07-12 20:08:42 +00:00
|
|
|
/***
|
|
|
|
*** Types
|
|
|
|
***/
|
|
|
|
|
2000-06-02 23:36:14 +00:00
|
|
|
typedef struct dst_func dst_func_t;
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2009-06-10 00:27:22 +00:00
|
|
|
typedef struct dst_hmacmd5_key dst_hmacmd5_key_t;
|
2006-12-04 01:54:53 +00:00
|
|
|
typedef struct dst_hmacsha1_key dst_hmacsha1_key_t;
|
|
|
|
typedef struct dst_hmacsha224_key dst_hmacsha224_key_t;
|
|
|
|
typedef struct dst_hmacsha256_key dst_hmacsha256_key_t;
|
|
|
|
typedef struct dst_hmacsha384_key dst_hmacsha384_key_t;
|
|
|
|
typedef struct dst_hmacsha512_key dst_hmacsha512_key_t;
|
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*% DST Key Structure */
|
1999-07-12 20:08:42 +00:00
|
|
|
struct dst_key {
|
|
|
|
unsigned int magic;
|
2005-04-27 04:57:32 +00:00
|
|
|
dns_name_t * key_name; /*%< name of the key */
|
|
|
|
unsigned int key_size; /*%< size of the key in bits */
|
|
|
|
unsigned int key_proto; /*%< protocols this key is used for */
|
|
|
|
unsigned int key_alg; /*%< algorithm of the key */
|
|
|
|
isc_uint32_t key_flags; /*%< flags of the public key */
|
|
|
|
isc_uint16_t key_id; /*%< identifier of the key */
|
2006-01-27 02:35:15 +00:00
|
|
|
isc_uint16_t key_bits; /*%< hmac digest bits */
|
2005-04-27 04:57:32 +00:00
|
|
|
dns_rdataclass_t key_class; /*%< class of the key record */
|
|
|
|
isc_mem_t *mctx; /*%< memory context */
|
2008-03-31 14:42:51 +00:00
|
|
|
char *engine; /*%< engine name (HSM) */
|
|
|
|
char *label; /*%< engine label (HSM) */
|
2006-12-04 01:54:53 +00:00
|
|
|
union {
|
|
|
|
void *generic;
|
|
|
|
gss_ctx_id_t gssctx;
|
|
|
|
#ifdef OPENSSL
|
2009-09-23 11:16:50 +00:00
|
|
|
#if !defined(USE_EVP) || !USE_EVP
|
2006-12-04 01:54:53 +00:00
|
|
|
RSA *rsa;
|
2008-03-31 14:42:51 +00:00
|
|
|
#endif
|
2006-12-04 01:54:53 +00:00
|
|
|
DSA *dsa;
|
|
|
|
DH *dh;
|
2008-03-31 14:42:51 +00:00
|
|
|
EVP_PKEY *pkey;
|
2006-12-04 01:54:53 +00:00
|
|
|
#endif
|
|
|
|
dst_hmacmd5_key_t *hmacmd5;
|
|
|
|
dst_hmacsha1_key_t *hmacsha1;
|
|
|
|
dst_hmacsha224_key_t *hmacsha224;
|
|
|
|
dst_hmacsha256_key_t *hmacsha256;
|
|
|
|
dst_hmacsha384_key_t *hmacsha384;
|
|
|
|
dst_hmacsha512_key_t *hmacsha512;
|
2008-04-01 23:47:10 +00:00
|
|
|
|
2006-12-04 01:54:53 +00:00
|
|
|
} keydata; /*%< pointer to key in crypto pkg fmt */
|
2009-07-19 04:18:05 +00:00
|
|
|
|
2009-10-09 06:09:21 +00:00
|
|
|
isc_stdtime_t times[DST_MAX_TIMES + 1]; /*%< timing metadata */
|
|
|
|
isc_boolean_t timeset[DST_MAX_TIMES + 1]; /*%< data set? */
|
|
|
|
isc_stdtime_t nums[DST_MAX_NUMERIC + 1]; /*%< numeric metadata */
|
|
|
|
isc_boolean_t numset[DST_MAX_NUMERIC + 1]; /*%< data set? */
|
2009-09-02 06:29:01 +00:00
|
|
|
|
|
|
|
int fmt_major; /*%< private key format, major version */
|
|
|
|
int fmt_minor; /*%< private key format, minor version */
|
|
|
|
|
2009-07-19 04:18:05 +00:00
|
|
|
dst_func_t * func; /*%< crypto package specific functions */
|
1999-07-12 20:08:42 +00:00
|
|
|
};
|
|
|
|
|
2000-06-02 18:57:51 +00:00
|
|
|
struct dst_context {
|
|
|
|
unsigned int magic;
|
|
|
|
dst_key_t *key;
|
|
|
|
isc_mem_t *mctx;
|
2006-12-04 01:54:53 +00:00
|
|
|
union {
|
|
|
|
void *generic;
|
|
|
|
dst_gssapi_signverifyctx_t *gssctx;
|
|
|
|
isc_md5_t *md5ctx;
|
|
|
|
isc_sha1_t *sha1ctx;
|
2009-10-22 02:21:31 +00:00
|
|
|
isc_sha256_t *sha256ctx;
|
|
|
|
isc_sha512_t *sha512ctx;
|
2006-12-04 01:54:53 +00:00
|
|
|
isc_hmacmd5_t *hmacmd5ctx;
|
|
|
|
isc_hmacsha1_t *hmacsha1ctx;
|
|
|
|
isc_hmacsha224_t *hmacsha224ctx;
|
|
|
|
isc_hmacsha256_t *hmacsha256ctx;
|
|
|
|
isc_hmacsha384_t *hmacsha384ctx;
|
|
|
|
isc_hmacsha512_t *hmacsha512ctx;
|
2008-03-31 14:42:51 +00:00
|
|
|
#ifdef OPENSSL
|
|
|
|
EVP_MD_CTX *evp_md_ctx;
|
|
|
|
#endif
|
2006-12-04 01:54:53 +00:00
|
|
|
} ctxdata;
|
2000-06-02 18:57:51 +00:00
|
|
|
};
|
|
|
|
|
1999-07-12 20:08:42 +00:00
|
|
|
struct dst_func {
|
2000-06-02 18:57:51 +00:00
|
|
|
/*
|
|
|
|
* Context functions
|
|
|
|
*/
|
|
|
|
isc_result_t (*createctx)(dst_key_t *key, dst_context_t *dctx);
|
|
|
|
void (*destroyctx)(dst_context_t *dctx);
|
|
|
|
isc_result_t (*adddata)(dst_context_t *dctx, const isc_region_t *data);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Key operations
|
|
|
|
*/
|
|
|
|
isc_result_t (*sign)(dst_context_t *dctx, isc_buffer_t *sig);
|
|
|
|
isc_result_t (*verify)(dst_context_t *dctx, const isc_region_t *sig);
|
2000-03-06 20:06:01 +00:00
|
|
|
isc_result_t (*computesecret)(const dst_key_t *pub,
|
1999-09-27 16:55:45 +00:00
|
|
|
const dst_key_t *priv,
|
|
|
|
isc_buffer_t *secret);
|
1999-07-12 20:08:42 +00:00
|
|
|
isc_boolean_t (*compare)(const dst_key_t *key1, const dst_key_t *key2);
|
1999-09-27 16:55:45 +00:00
|
|
|
isc_boolean_t (*paramcompare)(const dst_key_t *key1,
|
|
|
|
const dst_key_t *key2);
|
2009-10-24 09:46:19 +00:00
|
|
|
isc_result_t (*generate)(dst_key_t *key, int parms,
|
|
|
|
void (*callback)(int));
|
1999-09-23 20:54:38 +00:00
|
|
|
isc_boolean_t (*isprivate)(const dst_key_t *key);
|
2000-06-02 18:57:51 +00:00
|
|
|
void (*destroy)(dst_key_t *key);
|
|
|
|
|
1999-07-12 20:08:42 +00:00
|
|
|
/* conversion functions */
|
2000-06-02 18:57:51 +00:00
|
|
|
isc_result_t (*todns)(const dst_key_t *key, isc_buffer_t *data);
|
|
|
|
isc_result_t (*fromdns)(dst_key_t *key, isc_buffer_t *data);
|
2000-06-06 21:58:16 +00:00
|
|
|
isc_result_t (*tofile)(const dst_key_t *key, const char *directory);
|
2009-09-03 04:09:58 +00:00
|
|
|
isc_result_t (*parse)(dst_key_t *key,
|
|
|
|
isc_lex_t *lexer,
|
|
|
|
dst_key_t *pub);
|
2001-11-06 20:47:59 +00:00
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
void (*cleanup)(void);
|
2008-03-31 14:42:51 +00:00
|
|
|
|
|
|
|
isc_result_t (*fromlabel)(dst_key_t *key, const char *engine,
|
|
|
|
const char *label, const char *pin);
|
1999-07-12 20:08:42 +00:00
|
|
|
};
|
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*%
|
2000-06-02 23:36:14 +00:00
|
|
|
* Initializers
|
|
|
|
*/
|
2009-10-05 17:30:49 +00:00
|
|
|
isc_result_t dst__openssl_init(const char *engine);
|
2000-06-09 22:32:20 +00:00
|
|
|
|
2000-06-06 21:58:16 +00:00
|
|
|
isc_result_t dst__hmacmd5_init(struct dst_func **funcp);
|
2006-01-27 02:35:15 +00:00
|
|
|
isc_result_t dst__hmacsha1_init(struct dst_func **funcp);
|
|
|
|
isc_result_t dst__hmacsha224_init(struct dst_func **funcp);
|
|
|
|
isc_result_t dst__hmacsha256_init(struct dst_func **funcp);
|
|
|
|
isc_result_t dst__hmacsha384_init(struct dst_func **funcp);
|
|
|
|
isc_result_t dst__hmacsha512_init(struct dst_func **funcp);
|
2000-09-16 01:12:21 +00:00
|
|
|
isc_result_t dst__opensslrsa_init(struct dst_func **funcp);
|
2000-06-06 21:58:16 +00:00
|
|
|
isc_result_t dst__openssldsa_init(struct dst_func **funcp);
|
|
|
|
isc_result_t dst__openssldh_init(struct dst_func **funcp);
|
2000-08-17 02:04:22 +00:00
|
|
|
isc_result_t dst__gssapi_init(struct dst_func **funcp);
|
2000-06-06 21:58:16 +00:00
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*%
|
2000-06-06 21:58:16 +00:00
|
|
|
* Destructors
|
|
|
|
*/
|
2000-06-09 23:31:55 +00:00
|
|
|
void dst__openssl_destroy(void);
|
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*%
|
2000-05-02 03:54:17 +00:00
|
|
|
* Memory allocators using the DST memory pool.
|
|
|
|
*/
|
2000-06-09 22:32:20 +00:00
|
|
|
void * dst__mem_alloc(size_t size);
|
|
|
|
void dst__mem_free(void *ptr);
|
|
|
|
void * dst__mem_realloc(void *ptr, size_t size);
|
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*%
|
2000-06-09 22:32:20 +00:00
|
|
|
* Entropy retriever using the DST entropy pool.
|
|
|
|
*/
|
2000-06-09 23:31:55 +00:00
|
|
|
isc_result_t dst__entropy_getdata(void *buf, unsigned int len,
|
|
|
|
isc_boolean_t pseudo);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2006-12-04 01:54:53 +00:00
|
|
|
/*
|
|
|
|
* Entropy status hook.
|
|
|
|
*/
|
|
|
|
unsigned int dst__entropy_status(void);
|
|
|
|
|
1999-07-12 20:08:42 +00:00
|
|
|
ISC_LANG_ENDDECLS
|
|
|
|
|
2000-04-29 02:02:38 +00:00
|
|
|
#endif /* DST_DST_INTERNAL_H */
|
2005-04-27 04:57:32 +00:00
|
|
|
/*! \file */
|