Blame lib/dns/pkcs11dsa_link.c

Packit Service ae04f2
/*
Packit Service ae04f2
 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
Packit Service ae04f2
 *
Packit Service ae04f2
 * This Source Code Form is subject to the terms of the Mozilla Public
Packit Service ae04f2
 * License, v. 2.0. If a copy of the MPL was not distributed with this
Packit Service ae04f2
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
Packit Service ae04f2
 *
Packit Service ae04f2
 * See the COPYRIGHT file distributed with this work for additional
Packit Service ae04f2
 * information regarding copyright ownership.
Packit Service ae04f2
 */
Packit Service ae04f2
Packit Service ae04f2
#ifdef PKCS11CRYPTO
Packit Service ae04f2
Packit Service ae04f2
#include <config.h>
Packit Service ae04f2
Packit Service ae04f2
#include <pk11/site.h>
Packit Service ae04f2
Packit Service ae04f2
#ifndef PK11_DSA_DISABLE
Packit Service ae04f2
Packit Service ae04f2
#include <string.h>
Packit Service ae04f2
#include <stdbool.h>
Packit Service ae04f2
Packit Service ae04f2
#include <isc/entropy.h>
Packit Service ae04f2
#include <isc/mem.h>
Packit Service ae04f2
#include <isc/safe.h>
Packit Service ae04f2
#include <isc/sha1.h>
Packit Service ae04f2
#include <isc/util.h>
Packit Service ae04f2
Packit Service ae04f2
#include <dst/result.h>
Packit Service ae04f2
Packit Service ae04f2
#include "dst_internal.h"
Packit Service ae04f2
#include "dst_parse.h"
Packit Service ae04f2
#include "dst_pkcs11.h"
Packit Service ae04f2
Packit Service ae04f2
#include <pk11/internal.h>
Packit Service ae04f2
Packit Service ae04f2
/*
Packit Service ae04f2
 * FIPS 186-2 DSA keys:
Packit Service ae04f2
 *  mechanisms:
Packit Service ae04f2
 *    CKM_DSA_SHA1,
Packit Service ae04f2
 *    CKM_DSA_KEY_PAIR_GEN,
Packit Service ae04f2
 *    CKM_DSA_PARAMETER_GEN
Packit Service ae04f2
 *  domain parameters:
Packit Service ae04f2
 *    object class CKO_DOMAIN_PARAMETERS
Packit Service ae04f2
 *    key type CKK_DSA
Packit Service ae04f2
 *    attribute CKA_PRIME (prime p)
Packit Service ae04f2
 *    attribute CKA_SUBPRIME (subprime q)
Packit Service ae04f2
 *    attribute CKA_BASE (base g)
Packit Service ae04f2
 *    optional attribute CKA_PRIME_BITS (p length in bits)
Packit Service ae04f2
 *  public keys:
Packit Service ae04f2
 *    object class CKO_PUBLIC_KEY
Packit Service ae04f2
 *    key type CKK_DSA
Packit Service ae04f2
 *    attribute CKA_PRIME (prime p)
Packit Service ae04f2
 *    attribute CKA_SUBPRIME (subprime q)
Packit Service ae04f2
 *    attribute CKA_BASE (base g)
Packit Service ae04f2
 *    attribute CKA_VALUE (public value y)
Packit Service ae04f2
 *  private keys:
Packit Service ae04f2
 *    object class CKO_PRIVATE_KEY
Packit Service ae04f2
 *    key type CKK_DSA
Packit Service ae04f2
 *    attribute CKA_PRIME (prime p)
Packit Service ae04f2
 *    attribute CKA_SUBPRIME (subprime q)
Packit Service ae04f2
 *    attribute CKA_BASE (base g)
Packit Service ae04f2
 *    attribute CKA_VALUE (private value x)
Packit Service ae04f2
 *  reuse CKA_PRIVATE_EXPONENT for key pair private value
Packit Service ae04f2
 */
Packit Service ae04f2
Packit Service ae04f2
#define CKA_VALUE2	CKA_PRIVATE_EXPONENT
Packit Service ae04f2
Packit Service ae04f2
#define DST_RET(a) {ret = a; goto err;}
Packit Service ae04f2
Packit Service ae04f2
static CK_BBOOL truevalue = TRUE;
Packit Service ae04f2
static CK_BBOOL falsevalue = FALSE;
Packit Service ae04f2
Packit Service ae04f2
static isc_result_t pkcs11dsa_todns(const dst_key_t *key, isc_buffer_t *data);
Packit Service ae04f2
static void pkcs11dsa_destroy(dst_key_t *key);
Packit Service ae04f2
Packit Service ae04f2
static isc_result_t
Packit Service ae04f2
pkcs11dsa_createctx_sign(dst_key_t *key, dst_context_t *dctx) {
Packit Service ae04f2
	CK_RV rv;
Packit Service ae04f2
	CK_MECHANISM mech = { CKM_DSA_SHA1, NULL, 0 };
Packit Service ae04f2
	CK_OBJECT_CLASS keyClass = CKO_PRIVATE_KEY;
Packit Service ae04f2
	CK_KEY_TYPE keyType = CKK_DSA;
Packit Service ae04f2
	CK_ATTRIBUTE keyTemplate[] =
Packit Service ae04f2
	{
Packit Service ae04f2
		{ CKA_CLASS, &keyClass, (CK_ULONG) sizeof(keyClass) },
Packit Service ae04f2
		{ CKA_KEY_TYPE, &keyType, (CK_ULONG) sizeof(keyType) },
Packit Service ae04f2
		{ CKA_TOKEN, &falsevalue, (CK_ULONG) sizeof(falsevalue) },
Packit Service ae04f2
		{ CKA_PRIVATE, &falsevalue, (CK_ULONG) sizeof(falsevalue) },
Packit Service ae04f2
		{ CKA_SENSITIVE, &falsevalue, (CK_ULONG) sizeof(falsevalue) },
Packit Service ae04f2
		{ CKA_SIGN, &truevalue, (CK_ULONG) sizeof(truevalue) },
Packit Service ae04f2
		{ CKA_PRIME, NULL, 0 },
Packit Service ae04f2
		{ CKA_SUBPRIME, NULL, 0 },
Packit Service ae04f2
		{ CKA_BASE, NULL, 0 },
Packit Service ae04f2
		{ CKA_VALUE, NULL, 0 }
Packit Service ae04f2
	};
Packit Service ae04f2
	CK_ATTRIBUTE *attr;
Packit Service ae04f2
	pk11_object_t *dsa;
Packit Service ae04f2
	pk11_context_t *pk11_ctx;
Packit Service ae04f2
	isc_result_t ret;
Packit Service ae04f2
	unsigned int i;
Packit Service ae04f2
Packit Service ae04f2
	REQUIRE(key != NULL);
Packit Service ae04f2
	dsa = key->keydata.pkey;
Packit Service ae04f2
	REQUIRE(dsa != NULL);
Packit Service ae04f2
Packit Service ae04f2
	pk11_ctx = (pk11_context_t *) isc_mem_get(dctx->mctx,
Packit Service ae04f2
						  sizeof(*pk11_ctx));
Packit Service ae04f2
	if (pk11_ctx == NULL)
Packit Service ae04f2
		return (ISC_R_NOMEMORY);
Packit Service ae04f2
	ret = pk11_get_session(pk11_ctx, OP_DSA, true, false,
Packit Service ae04f2
			       dsa->reqlogon, NULL,
Packit Service ae04f2
			       pk11_get_best_token(OP_DSA));
Packit Service ae04f2
	if (ret != ISC_R_SUCCESS)
Packit Service ae04f2
		goto err;
Packit Service ae04f2
Packit Service ae04f2
	if (dsa->ontoken && (dsa->object != CK_INVALID_HANDLE)) {
Packit Service ae04f2
		pk11_ctx->ontoken = dsa->ontoken;
Packit Service ae04f2
		pk11_ctx->object = dsa->object;
Packit Service ae04f2
		goto token_key;
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	for (attr = pk11_attribute_first(dsa);
Packit Service ae04f2
	     attr != NULL;
Packit Service ae04f2
	     attr = pk11_attribute_next(dsa, attr))
Packit Service ae04f2
		switch (attr->type) {
Packit Service ae04f2
		case CKA_PRIME:
Packit Service ae04f2
			INSIST(keyTemplate[6].type == attr->type);
Packit Service ae04f2
			keyTemplate[6].pValue = isc_mem_get(dctx->mctx,
Packit Service ae04f2
							    attr->ulValueLen);
Packit Service ae04f2
			if (keyTemplate[6].pValue == NULL)
Packit Service ae04f2
				DST_RET(ISC_R_NOMEMORY);
Packit Service ae04f2
			memmove(keyTemplate[6].pValue, attr->pValue,
Packit Service ae04f2
				attr->ulValueLen);
Packit Service ae04f2
			keyTemplate[6].ulValueLen = attr->ulValueLen;
Packit Service ae04f2
			break;
Packit Service ae04f2
		case CKA_SUBPRIME:
Packit Service ae04f2
			INSIST(keyTemplate[7].type == attr->type);
Packit Service ae04f2
			keyTemplate[7].pValue = isc_mem_get(dctx->mctx,
Packit Service ae04f2
							    attr->ulValueLen);
Packit Service ae04f2
			if (keyTemplate[7].pValue == NULL)
Packit Service ae04f2
				DST_RET(ISC_R_NOMEMORY);
Packit Service ae04f2
			memmove(keyTemplate[7].pValue, attr->pValue,
Packit Service ae04f2
				attr->ulValueLen);
Packit Service ae04f2
			keyTemplate[7].ulValueLen = attr->ulValueLen;
Packit Service ae04f2
			break;
Packit Service ae04f2
		case CKA_BASE:
Packit Service ae04f2
			INSIST(keyTemplate[8].type == attr->type);
Packit Service ae04f2
			keyTemplate[8].pValue = isc_mem_get(dctx->mctx,
Packit Service ae04f2
							    attr->ulValueLen);
Packit Service ae04f2
			if (keyTemplate[8].pValue == NULL)
Packit Service ae04f2
				DST_RET(ISC_R_NOMEMORY);
Packit Service ae04f2
			memmove(keyTemplate[8].pValue, attr->pValue,
Packit Service ae04f2
				attr->ulValueLen);
Packit Service ae04f2
			keyTemplate[8].ulValueLen = attr->ulValueLen;
Packit Service ae04f2
			break;
Packit Service ae04f2
		case CKA_VALUE2:
Packit Service ae04f2
			INSIST(keyTemplate[9].type == CKA_VALUE);
Packit Service ae04f2
			keyTemplate[9].pValue = isc_mem_get(dctx->mctx,
Packit Service ae04f2
							    attr->ulValueLen);
Packit Service ae04f2
			if (keyTemplate[9].pValue == NULL)
Packit Service ae04f2
				DST_RET(ISC_R_NOMEMORY);
Packit Service ae04f2
			memmove(keyTemplate[9].pValue, attr->pValue,
Packit Service ae04f2
				attr->ulValueLen);
Packit Service ae04f2
			keyTemplate[9].ulValueLen = attr->ulValueLen;
Packit Service ae04f2
			break;
Packit Service ae04f2
		}
Packit Service ae04f2
	pk11_ctx->object = CK_INVALID_HANDLE;
Packit Service ae04f2
	pk11_ctx->ontoken = false;
Packit Service ae04f2
	PK11_RET(pkcs_C_CreateObject,
Packit Service ae04f2
		 (pk11_ctx->session,
Packit Service ae04f2
		  keyTemplate, (CK_ULONG) 10,
Packit Service ae04f2
		  &pk11_ctx->object),
Packit Service ae04f2
		 ISC_R_FAILURE);
Packit Service ae04f2
Packit Service ae04f2
    token_key:
Packit Service ae04f2
Packit Service ae04f2
	PK11_RET(pkcs_C_SignInit,
Packit Service ae04f2
		 (pk11_ctx->session, &mech, pk11_ctx->object),
Packit Service ae04f2
		 ISC_R_FAILURE);
Packit Service ae04f2
Packit Service ae04f2
	dctx->ctxdata.pk11_ctx = pk11_ctx;
Packit Service ae04f2
Packit Service ae04f2
	for (i = 6; i <= 9; i++)
Packit Service ae04f2
		if (keyTemplate[i].pValue != NULL) {
Packit Service ae04f2
			isc_safe_memwipe(keyTemplate[i].pValue,
Packit Service ae04f2
					 keyTemplate[i].ulValueLen);
Packit Service ae04f2
			isc_mem_put(dctx->mctx,
Packit Service ae04f2
				    keyTemplate[i].pValue,
Packit Service ae04f2
				    keyTemplate[i].ulValueLen);
Packit Service ae04f2
		}
Packit Service ae04f2
Packit Service ae04f2
	return (ISC_R_SUCCESS);
Packit Service ae04f2
Packit Service ae04f2
    err:
Packit Service ae04f2
	if (!pk11_ctx->ontoken && (pk11_ctx->object != CK_INVALID_HANDLE))
Packit Service ae04f2
		(void) pkcs_C_DestroyObject(pk11_ctx->session, pk11_ctx->object);
Packit Service ae04f2
	for (i = 6; i <= 9; i++)
Packit Service ae04f2
		if (keyTemplate[i].pValue != NULL) {
Packit Service ae04f2
			isc_safe_memwipe(keyTemplate[i].pValue,
Packit Service ae04f2
					 keyTemplate[i].ulValueLen);
Packit Service ae04f2
			isc_mem_put(dctx->mctx,
Packit Service ae04f2
				    keyTemplate[i].pValue,
Packit Service ae04f2
				    keyTemplate[i].ulValueLen);
Packit Service ae04f2
		}
Packit Service ae04f2
	pk11_return_session(pk11_ctx);
Packit Service ae04f2
	isc_safe_memwipe(pk11_ctx, sizeof(*pk11_ctx));
Packit Service ae04f2
	isc_mem_put(dctx->mctx, pk11_ctx, sizeof(*pk11_ctx));
Packit Service ae04f2
Packit Service ae04f2
	return (ret);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
static isc_result_t
Packit Service ae04f2
pkcs11dsa_createctx_verify(dst_key_t *key, dst_context_t *dctx) {
Packit Service ae04f2
	CK_RV rv;
Packit Service ae04f2
	CK_MECHANISM mech = { CKM_DSA_SHA1, NULL, 0 };
Packit Service ae04f2
	CK_OBJECT_CLASS keyClass = CKO_PUBLIC_KEY;
Packit Service ae04f2
	CK_KEY_TYPE keyType = CKK_DSA;
Packit Service ae04f2
	CK_ATTRIBUTE keyTemplate[] =
Packit Service ae04f2
	{
Packit Service ae04f2
		{ CKA_CLASS, &keyClass, (CK_ULONG) sizeof(keyClass) },
Packit Service ae04f2
		{ CKA_KEY_TYPE, &keyType, (CK_ULONG) sizeof(keyType) },
Packit Service ae04f2
		{ CKA_TOKEN, &falsevalue, (CK_ULONG) sizeof(falsevalue) },
Packit Service ae04f2
		{ CKA_PRIVATE, &falsevalue, (CK_ULONG) sizeof(falsevalue) },
Packit Service ae04f2
		{ CKA_VERIFY, &truevalue, (CK_ULONG) sizeof(truevalue) },
Packit Service ae04f2
		{ CKA_PRIME, NULL, 0 },
Packit Service ae04f2
		{ CKA_SUBPRIME, NULL, 0 },
Packit Service ae04f2
		{ CKA_BASE, NULL, 0 },
Packit Service ae04f2
		{ CKA_VALUE, NULL, 0 }
Packit Service ae04f2
	};
Packit Service ae04f2
	CK_ATTRIBUTE *attr;
Packit Service ae04f2
	pk11_object_t *dsa;
Packit Service ae04f2
	pk11_context_t *pk11_ctx;
Packit Service ae04f2
	isc_result_t ret;
Packit Service ae04f2
	unsigned int i;
Packit Service ae04f2
Packit Service ae04f2
	dsa = key->keydata.pkey;
Packit Service ae04f2
	REQUIRE(dsa != NULL);
Packit Service ae04f2
	pk11_ctx = (pk11_context_t *) isc_mem_get(dctx->mctx,
Packit Service ae04f2
						  sizeof(*pk11_ctx));
Packit Service ae04f2
	if (pk11_ctx == NULL)
Packit Service ae04f2
		return (ISC_R_NOMEMORY);
Packit Service ae04f2
	ret = pk11_get_session(pk11_ctx, OP_DSA, true, false,
Packit Service ae04f2
			       dsa->reqlogon, NULL,
Packit Service ae04f2
			       pk11_get_best_token(OP_DSA));
Packit Service ae04f2
	if (ret != ISC_R_SUCCESS)
Packit Service ae04f2
		goto err;
Packit Service ae04f2
Packit Service ae04f2
	if (dsa->ontoken && (dsa->object != CK_INVALID_HANDLE)) {
Packit Service ae04f2
		pk11_ctx->ontoken = dsa->ontoken;
Packit Service ae04f2
		pk11_ctx->object = dsa->object;
Packit Service ae04f2
		goto token_key;
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	for (attr = pk11_attribute_first(dsa);
Packit Service ae04f2
	     attr != NULL;
Packit Service ae04f2
	     attr = pk11_attribute_next(dsa, attr))
Packit Service ae04f2
		switch (attr->type) {
Packit Service ae04f2
		case CKA_PRIME:
Packit Service ae04f2
			INSIST(keyTemplate[5].type == attr->type);
Packit Service ae04f2
			keyTemplate[5].pValue = isc_mem_get(dctx->mctx,
Packit Service ae04f2
							    attr->ulValueLen);
Packit Service ae04f2
			if (keyTemplate[5].pValue == NULL)
Packit Service ae04f2
				DST_RET(ISC_R_NOMEMORY);
Packit Service ae04f2
			memmove(keyTemplate[5].pValue, attr->pValue,
Packit Service ae04f2
				attr->ulValueLen);
Packit Service ae04f2
			keyTemplate[5].ulValueLen = attr->ulValueLen;
Packit Service ae04f2
			break;
Packit Service ae04f2
		case CKA_SUBPRIME:
Packit Service ae04f2
			INSIST(keyTemplate[6].type == attr->type);
Packit Service ae04f2
			keyTemplate[6].pValue = isc_mem_get(dctx->mctx,
Packit Service ae04f2
							    attr->ulValueLen);
Packit Service ae04f2
			if (keyTemplate[6].pValue == NULL)
Packit Service ae04f2
				DST_RET(ISC_R_NOMEMORY);
Packit Service ae04f2
			memmove(keyTemplate[6].pValue, attr->pValue,
Packit Service ae04f2
				attr->ulValueLen);
Packit Service ae04f2
			keyTemplate[6].ulValueLen = attr->ulValueLen;
Packit Service ae04f2
			break;
Packit Service ae04f2
		case CKA_BASE:
Packit Service ae04f2
			INSIST(keyTemplate[7].type == attr->type);
Packit Service ae04f2
			keyTemplate[7].pValue = isc_mem_get(dctx->mctx,
Packit Service ae04f2
							    attr->ulValueLen);
Packit Service ae04f2
			if (keyTemplate[7].pValue == NULL)
Packit Service ae04f2
				DST_RET(ISC_R_NOMEMORY);
Packit Service ae04f2
			memmove(keyTemplate[7].pValue, attr->pValue,
Packit Service ae04f2
				attr->ulValueLen);
Packit Service ae04f2
			keyTemplate[7].ulValueLen = attr->ulValueLen;
Packit Service ae04f2
			break;
Packit Service ae04f2
		case CKA_VALUE:
Packit Service ae04f2
			INSIST(keyTemplate[8].type == attr->type);
Packit Service ae04f2
			keyTemplate[8].pValue = isc_mem_get(dctx->mctx,
Packit Service ae04f2
							    attr->ulValueLen);
Packit Service ae04f2
			if (keyTemplate[8].pValue == NULL)
Packit Service ae04f2
				DST_RET(ISC_R_NOMEMORY);
Packit Service ae04f2
			memmove(keyTemplate[8].pValue, attr->pValue,
Packit Service ae04f2
				attr->ulValueLen);
Packit Service ae04f2
			keyTemplate[8].ulValueLen = attr->ulValueLen;
Packit Service ae04f2
			break;
Packit Service ae04f2
		}
Packit Service ae04f2
	pk11_ctx->object = CK_INVALID_HANDLE;
Packit Service ae04f2
	pk11_ctx->ontoken = false;
Packit Service ae04f2
	PK11_RET(pkcs_C_CreateObject,
Packit Service ae04f2
		 (pk11_ctx->session,
Packit Service ae04f2
		  keyTemplate, (CK_ULONG) 9,
Packit Service ae04f2
		  &pk11_ctx->object),
Packit Service ae04f2
		 ISC_R_FAILURE);
Packit Service ae04f2
Packit Service ae04f2
    token_key:
Packit Service ae04f2
Packit Service ae04f2
	PK11_RET(pkcs_C_VerifyInit,
Packit Service ae04f2
		 (pk11_ctx->session, &mech, pk11_ctx->object),
Packit Service ae04f2
		 ISC_R_FAILURE);
Packit Service ae04f2
Packit Service ae04f2
	dctx->ctxdata.pk11_ctx = pk11_ctx;
Packit Service ae04f2
Packit Service ae04f2
	for (i = 5; i <= 8; i++)
Packit Service ae04f2
		if (keyTemplate[i].pValue != NULL) {
Packit Service ae04f2
			isc_safe_memwipe(keyTemplate[i].pValue,
Packit Service ae04f2
					 keyTemplate[i].ulValueLen);
Packit Service ae04f2
			isc_mem_put(dctx->mctx,
Packit Service ae04f2
				    keyTemplate[i].pValue,
Packit Service ae04f2
				    keyTemplate[i].ulValueLen);
Packit Service ae04f2
		}
Packit Service ae04f2
Packit Service ae04f2
	return (ISC_R_SUCCESS);
Packit Service ae04f2
Packit Service ae04f2
    err:
Packit Service ae04f2
	if (!pk11_ctx->ontoken && (pk11_ctx->object != CK_INVALID_HANDLE))
Packit Service ae04f2
		(void) pkcs_C_DestroyObject(pk11_ctx->session, pk11_ctx->object);
Packit Service ae04f2
	for (i = 5; i <= 8; i++)
Packit Service ae04f2
		if (keyTemplate[i].pValue != NULL) {
Packit Service ae04f2
			isc_safe_memwipe(keyTemplate[i].pValue,
Packit Service ae04f2
					 keyTemplate[i].ulValueLen);
Packit Service ae04f2
			isc_mem_put(dctx->mctx,
Packit Service ae04f2
				    keyTemplate[i].pValue,
Packit Service ae04f2
				    keyTemplate[i].ulValueLen);
Packit Service ae04f2
		}
Packit Service ae04f2
	pk11_return_session(pk11_ctx);
Packit Service ae04f2
	isc_safe_memwipe(pk11_ctx, sizeof(*pk11_ctx));
Packit Service ae04f2
	isc_mem_put(dctx->mctx, pk11_ctx, sizeof(*pk11_ctx));
Packit Service ae04f2
Packit Service ae04f2
	return (ret);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
static isc_result_t
Packit Service ae04f2
pkcs11dsa_createctx(dst_key_t *key, dst_context_t *dctx) {
Packit Service ae04f2
	if (dctx->use == DO_SIGN)
Packit Service ae04f2
		return (pkcs11dsa_createctx_sign(key, dctx));
Packit Service ae04f2
	else
Packit Service ae04f2
		return (pkcs11dsa_createctx_verify(key, dctx));
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
static void
Packit Service ae04f2
pkcs11dsa_destroyctx(dst_context_t *dctx) {
Packit Service ae04f2
	pk11_context_t *pk11_ctx = dctx->ctxdata.pk11_ctx;
Packit Service ae04f2
Packit Service ae04f2
	if (pk11_ctx != NULL) {
Packit Service ae04f2
		if (!pk11_ctx->ontoken &&
Packit Service ae04f2
		    (pk11_ctx->object != CK_INVALID_HANDLE))
Packit Service ae04f2
			(void) pkcs_C_DestroyObject(pk11_ctx->session,
Packit Service ae04f2
					       pk11_ctx->object);
Packit Service ae04f2
		pk11_return_session(pk11_ctx);
Packit Service ae04f2
		isc_safe_memwipe(pk11_ctx, sizeof(*pk11_ctx));
Packit Service ae04f2
		isc_mem_put(dctx->mctx, pk11_ctx, sizeof(*pk11_ctx));
Packit Service ae04f2
		dctx->ctxdata.pk11_ctx = NULL;
Packit Service ae04f2
	}
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
static isc_result_t
Packit Service ae04f2
pkcs11dsa_adddata(dst_context_t *dctx, const isc_region_t *data) {
Packit Service ae04f2
	CK_RV rv;
Packit Service ae04f2
	pk11_context_t *pk11_ctx = dctx->ctxdata.pk11_ctx;
Packit Service ae04f2
	isc_result_t ret = ISC_R_SUCCESS;
Packit Service ae04f2
Packit Service ae04f2
	if (dctx->use == DO_SIGN)
Packit Service ae04f2
		PK11_CALL(pkcs_C_SignUpdate,
Packit Service ae04f2
			  (pk11_ctx->session,
Packit Service ae04f2
			   (CK_BYTE_PTR) data->base,
Packit Service ae04f2
			   (CK_ULONG) data->length),
Packit Service ae04f2
			  ISC_R_FAILURE);
Packit Service ae04f2
	else
Packit Service ae04f2
		PK11_CALL(pkcs_C_VerifyUpdate,
Packit Service ae04f2
			  (pk11_ctx->session,
Packit Service ae04f2
			   (CK_BYTE_PTR) data->base,
Packit Service ae04f2
			   (CK_ULONG) data->length),
Packit Service ae04f2
			  ISC_R_FAILURE);
Packit Service ae04f2
	return (ret);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
static isc_result_t
Packit Service ae04f2
pkcs11dsa_sign(dst_context_t *dctx, isc_buffer_t *sig) {
Packit Service ae04f2
	CK_RV rv;
Packit Service ae04f2
	CK_ULONG siglen = ISC_SHA1_DIGESTLENGTH * 2;
Packit Service ae04f2
	isc_region_t r;
Packit Service ae04f2
	pk11_context_t *pk11_ctx = dctx->ctxdata.pk11_ctx;
Packit Service ae04f2
	isc_result_t ret = ISC_R_SUCCESS;
Packit Service ae04f2
	unsigned int klen;
Packit Service ae04f2
Packit Service ae04f2
	isc_buffer_availableregion(sig, &r);
Packit Service ae04f2
	if (r.length < ISC_SHA1_DIGESTLENGTH * 2 + 1)
Packit Service ae04f2
		return (ISC_R_NOSPACE);
Packit Service ae04f2
Packit Service ae04f2
	PK11_RET(pkcs_C_SignFinal,
Packit Service ae04f2
		 (pk11_ctx->session, (CK_BYTE_PTR) r.base + 1, &siglen),
Packit Service ae04f2
		 DST_R_SIGNFAILURE);
Packit Service ae04f2
	if (siglen != ISC_SHA1_DIGESTLENGTH * 2)
Packit Service ae04f2
		return (DST_R_SIGNFAILURE);
Packit Service ae04f2
Packit Service ae04f2
	klen = (dctx->key->key_size - 512)/64;
Packit Service ae04f2
	if (klen > 255)
Packit Service ae04f2
		return (ISC_R_FAILURE);
Packit Service ae04f2
	*r.base = klen;
Packit Service ae04f2
	isc_buffer_add(sig, ISC_SHA1_DIGESTLENGTH * 2 + 1);
Packit Service ae04f2
Packit Service ae04f2
    err:
Packit Service ae04f2
	return (ret);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
static isc_result_t
Packit Service ae04f2
pkcs11dsa_verify(dst_context_t *dctx, const isc_region_t *sig) {
Packit Service ae04f2
	CK_RV rv;
Packit Service ae04f2
	pk11_context_t *pk11_ctx = dctx->ctxdata.pk11_ctx;
Packit Service ae04f2
	isc_result_t ret = ISC_R_SUCCESS;
Packit Service ae04f2
Packit Service ae04f2
	PK11_CALL(pkcs_C_VerifyFinal,
Packit Service ae04f2
		  (pk11_ctx->session,
Packit Service ae04f2
		   (CK_BYTE_PTR) sig->base + 1,
Packit Service ae04f2
		   (CK_ULONG) sig->length - 1),
Packit Service ae04f2
		  DST_R_VERIFYFAILURE);
Packit Service ae04f2
	return (ret);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
static bool
Packit Service ae04f2
pkcs11dsa_compare(const dst_key_t *key1, const dst_key_t *key2) {
Packit Service ae04f2
	pk11_object_t *dsa1, *dsa2;
Packit Service ae04f2
	CK_ATTRIBUTE *attr1, *attr2;
Packit Service ae04f2
Packit Service ae04f2
	dsa1 = key1->keydata.pkey;
Packit Service ae04f2
	dsa2 = key2->keydata.pkey;
Packit Service ae04f2
Packit Service ae04f2
	if ((dsa1 == NULL) && (dsa2 == NULL))
Packit Service ae04f2
		return (true);
Packit Service ae04f2
	else if ((dsa1 == NULL) || (dsa2 == NULL))
Packit Service ae04f2
		return (false);
Packit Service ae04f2
Packit Service ae04f2
	attr1 = pk11_attribute_bytype(dsa1, CKA_PRIME);
Packit Service ae04f2
	attr2 = pk11_attribute_bytype(dsa2, CKA_PRIME);
Packit Service ae04f2
	if ((attr1 == NULL) && (attr2 == NULL))
Packit Service ae04f2
		return (true);
Packit Service ae04f2
	else if ((attr1 == NULL) || (attr2 == NULL) ||
Packit Service ae04f2
		 (attr1->ulValueLen != attr2->ulValueLen) ||
Packit Service ae04f2
		 !isc_safe_memequal(attr1->pValue, attr2->pValue,
Packit Service ae04f2
				    attr1->ulValueLen))
Packit Service ae04f2
		return (false);
Packit Service ae04f2
Packit Service ae04f2
	attr1 = pk11_attribute_bytype(dsa1, CKA_SUBPRIME);
Packit Service ae04f2
	attr2 = pk11_attribute_bytype(dsa2, CKA_SUBPRIME);
Packit Service ae04f2
	if ((attr1 == NULL) && (attr2 == NULL))
Packit Service ae04f2
		return (true);
Packit Service ae04f2
	else if ((attr1 == NULL) || (attr2 == NULL) ||
Packit Service ae04f2
		 (attr1->ulValueLen != attr2->ulValueLen) ||
Packit Service ae04f2
		 !isc_safe_memequal(attr1->pValue, attr2->pValue,
Packit Service ae04f2
				    attr1->ulValueLen))
Packit Service ae04f2
		return (false);
Packit Service ae04f2
Packit Service ae04f2
	attr1 = pk11_attribute_bytype(dsa1, CKA_BASE);
Packit Service ae04f2
	attr2 = pk11_attribute_bytype(dsa2, CKA_BASE);
Packit Service ae04f2
	if ((attr1 == NULL) && (attr2 == NULL))
Packit Service ae04f2
		return (true);
Packit Service ae04f2
	else if ((attr1 == NULL) || (attr2 == NULL) ||
Packit Service ae04f2
		 (attr1->ulValueLen != attr2->ulValueLen) ||
Packit Service ae04f2
		 !isc_safe_memequal(attr1->pValue, attr2->pValue,
Packit Service ae04f2
				    attr1->ulValueLen))
Packit Service ae04f2
		return (false);
Packit Service ae04f2
Packit Service ae04f2
	attr1 = pk11_attribute_bytype(dsa1, CKA_VALUE);
Packit Service ae04f2
	attr2 = pk11_attribute_bytype(dsa2, CKA_VALUE);
Packit Service ae04f2
	if ((attr1 == NULL) && (attr2 == NULL))
Packit Service ae04f2
		return (true);
Packit Service ae04f2
	else if ((attr1 == NULL) || (attr2 == NULL) ||
Packit Service ae04f2
		 (attr1->ulValueLen != attr2->ulValueLen) ||
Packit Service ae04f2
		 !isc_safe_memequal(attr1->pValue, attr2->pValue,
Packit Service ae04f2
				    attr1->ulValueLen))
Packit Service ae04f2
		return (false);
Packit Service ae04f2
Packit Service ae04f2
	attr1 = pk11_attribute_bytype(dsa1, CKA_VALUE2);
Packit Service ae04f2
	attr2 = pk11_attribute_bytype(dsa2, CKA_VALUE2);
Packit Service ae04f2
	if (((attr1 != NULL) || (attr2 != NULL)) &&
Packit Service ae04f2
	    ((attr1 == NULL) || (attr2 == NULL) ||
Packit Service ae04f2
	     (attr1->ulValueLen != attr2->ulValueLen) ||
Packit Service ae04f2
	     !isc_safe_memequal(attr1->pValue, attr2->pValue,
Packit Service ae04f2
				attr1->ulValueLen)))
Packit Service ae04f2
		return (false);
Packit Service ae04f2
Packit Service ae04f2
	if (!dsa1->ontoken && !dsa2->ontoken)
Packit Service ae04f2
		return (true);
Packit Service ae04f2
	else if (dsa1->ontoken || dsa2->ontoken ||
Packit Service ae04f2
		 (dsa1->object != dsa2->object))
Packit Service ae04f2
		return (false);
Packit Service ae04f2
Packit Service ae04f2
	return (true);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
static isc_result_t
Packit Service ae04f2
pkcs11dsa_generate(dst_key_t *key, int unused, void (*callback)(int)) {
Packit Service ae04f2
	CK_RV rv;
Packit Service ae04f2
	CK_MECHANISM mech = { CKM_DSA_PARAMETER_GEN, NULL, 0 };
Packit Service ae04f2
	CK_OBJECT_HANDLE dp = CK_INVALID_HANDLE;
Packit Service ae04f2
	CK_OBJECT_CLASS dpClass = CKO_DOMAIN_PARAMETERS;
Packit Service ae04f2
	CK_KEY_TYPE  keyType = CKK_DSA;
Packit Service ae04f2
	CK_ULONG bits = 0;
Packit Service ae04f2
	CK_ATTRIBUTE dpTemplate[] =
Packit Service ae04f2
	{
Packit Service ae04f2
		{ CKA_CLASS, &dpClass, (CK_ULONG) sizeof(dpClass) },
Packit Service ae04f2
		{ CKA_KEY_TYPE, &keyType, (CK_ULONG) sizeof(keyType) },
Packit Service ae04f2
		{ CKA_TOKEN, &falsevalue, (CK_ULONG) sizeof(falsevalue) },
Packit Service ae04f2
		{ CKA_PRIVATE, &falsevalue, (CK_ULONG) sizeof(falsevalue) },
Packit Service ae04f2
		{ CKA_PRIME_BITS, &bits, (CK_ULONG) sizeof(bits) },
Packit Service ae04f2
	};
Packit Service ae04f2
	CK_OBJECT_HANDLE pub = CK_INVALID_HANDLE;
Packit Service ae04f2
	CK_OBJECT_CLASS pubClass = CKO_PUBLIC_KEY;
Packit Service ae04f2
	CK_ATTRIBUTE pubTemplate[] =
Packit Service ae04f2
	{
Packit Service ae04f2
		{ CKA_CLASS, &pubClass, (CK_ULONG) sizeof(pubClass) },
Packit Service ae04f2
		{ CKA_KEY_TYPE, &keyType, (CK_ULONG) sizeof(keyType) },
Packit Service ae04f2
		{ CKA_TOKEN, &falsevalue, (CK_ULONG) sizeof(falsevalue) },
Packit Service ae04f2
		{ CKA_PRIVATE, &falsevalue, (CK_ULONG) sizeof(falsevalue) },
Packit Service ae04f2
		{ CKA_VERIFY, &truevalue, (CK_ULONG) sizeof(truevalue) },
Packit Service ae04f2
		{ CKA_PRIME, NULL, 0 },
Packit Service ae04f2
		{ CKA_SUBPRIME, NULL, 0 },
Packit Service ae04f2
		{ CKA_BASE, NULL, 0 }
Packit Service ae04f2
	};
Packit Service ae04f2
	CK_OBJECT_HANDLE priv = CK_INVALID_HANDLE;
Packit Service ae04f2
	CK_OBJECT_HANDLE privClass = CKO_PRIVATE_KEY;
Packit Service ae04f2
	CK_ATTRIBUTE privTemplate[] =
Packit Service ae04f2
	{
Packit Service ae04f2
		{ CKA_CLASS, &privClass, (CK_ULONG) sizeof(privClass) },
Packit Service ae04f2
		{ CKA_KEY_TYPE, &keyType, (CK_ULONG) sizeof(keyType) },
Packit Service ae04f2
		{ CKA_TOKEN, &falsevalue, (CK_ULONG) sizeof(falsevalue) },
Packit Service ae04f2
		{ CKA_PRIVATE, &falsevalue, (CK_ULONG) sizeof(falsevalue) },
Packit Service ae04f2
		{ CKA_SENSITIVE, &falsevalue, (CK_ULONG) sizeof(falsevalue) },
Packit Service ae04f2
		{ CKA_EXTRACTABLE, &truevalue, (CK_ULONG) sizeof(truevalue) },
Packit Service ae04f2
		{ CKA_SIGN, &truevalue, (CK_ULONG) sizeof(truevalue) },
Packit Service ae04f2
	};
Packit Service ae04f2
	CK_ATTRIBUTE *attr;
Packit Service ae04f2
	pk11_object_t *dsa;
Packit Service ae04f2
	pk11_context_t *pk11_ctx;
Packit Service ae04f2
	isc_result_t ret;
Packit Service ae04f2
	unsigned int i;
Packit Service ae04f2
Packit Service ae04f2
	UNUSED(unused);
Packit Service ae04f2
	UNUSED(callback);
Packit Service ae04f2
Packit Service ae04f2
	pk11_ctx = (pk11_context_t *) isc_mem_get(key->mctx,
Packit Service ae04f2
						  sizeof(*pk11_ctx));
Packit Service ae04f2
	if (pk11_ctx == NULL)
Packit Service ae04f2
		return (ISC_R_NOMEMORY);
Packit Service ae04f2
	ret = pk11_get_session(pk11_ctx, OP_DSA, true, false,
Packit Service ae04f2
			       false, NULL, pk11_get_best_token(OP_DSA));
Packit Service ae04f2
	if (ret != ISC_R_SUCCESS)
Packit Service ae04f2
		goto err;
Packit Service ae04f2
Packit Service ae04f2
	bits = key->key_size;
Packit Service ae04f2
	PK11_RET(pkcs_C_GenerateKey,
Packit Service ae04f2
		 (pk11_ctx->session, &mech, dpTemplate, (CK_ULONG) 5, &dp),
Packit Service ae04f2
		 DST_R_CRYPTOFAILURE);
Packit Service ae04f2
Packit Service ae04f2
	dsa = (pk11_object_t *) isc_mem_get(key->mctx, sizeof(*dsa));
Packit Service ae04f2
	if (dsa == NULL)
Packit Service ae04f2
		DST_RET(ISC_R_NOMEMORY);
Packit Service ae04f2
	memset(dsa, 0, sizeof(*dsa));
Packit Service ae04f2
	key->keydata.pkey = dsa;
Packit Service ae04f2
	dsa->repr = (CK_ATTRIBUTE *) isc_mem_get(key->mctx, sizeof(*attr) * 5);
Packit Service ae04f2
	if (dsa->repr == NULL)
Packit Service ae04f2
		DST_RET(ISC_R_NOMEMORY);
Packit Service ae04f2
	memset(dsa->repr, 0, sizeof(*attr) * 5);
Packit Service ae04f2
	dsa->attrcnt = 5;
Packit Service ae04f2
Packit Service ae04f2
	attr = dsa->repr;
Packit Service ae04f2
	attr[0].type = CKA_PRIME;
Packit Service ae04f2
	attr[1].type = CKA_SUBPRIME;
Packit Service ae04f2
	attr[2].type = CKA_BASE;
Packit Service ae04f2
	attr[3].type = CKA_VALUE;
Packit Service ae04f2
	attr[4].type = CKA_VALUE2;
Packit Service ae04f2
Packit Service ae04f2
	PK11_RET(pkcs_C_GetAttributeValue,
Packit Service ae04f2
		 (pk11_ctx->session, dp, attr, 3),
Packit Service ae04f2
		 DST_R_CRYPTOFAILURE);
Packit Service ae04f2
Packit Service ae04f2
	for (i = 0; i <= 2; i++) {
Packit Service ae04f2
		attr[i].pValue = isc_mem_get(key->mctx, attr[i].ulValueLen);
Packit Service ae04f2
		if (attr[i].pValue == NULL)
Packit Service ae04f2
			DST_RET(ISC_R_NOMEMORY);
Packit Service ae04f2
		memset(attr[i].pValue, 0, attr[i].ulValueLen);
Packit Service ae04f2
	}
Packit Service ae04f2
	PK11_RET(pkcs_C_GetAttributeValue,
Packit Service ae04f2
		 (pk11_ctx->session, dp, attr, 3),
Packit Service ae04f2
		 DST_R_CRYPTOFAILURE);
Packit Service ae04f2
	pubTemplate[5].pValue = attr[0].pValue;
Packit Service ae04f2
	pubTemplate[5].ulValueLen = attr[0].ulValueLen;
Packit Service ae04f2
	pubTemplate[6].pValue = attr[1].pValue;
Packit Service ae04f2
	pubTemplate[6].ulValueLen = attr[1].ulValueLen;
Packit Service ae04f2
	pubTemplate[7].pValue = attr[2].pValue;
Packit Service ae04f2
	pubTemplate[7].ulValueLen = attr[2].ulValueLen;
Packit Service ae04f2
Packit Service ae04f2
	mech.mechanism = CKM_DSA_KEY_PAIR_GEN;
Packit Service ae04f2
	PK11_RET(pkcs_C_GenerateKeyPair,
Packit Service ae04f2
		 (pk11_ctx->session, &mech,
Packit Service ae04f2
		  pubTemplate, (CK_ULONG) 8,
Packit Service ae04f2
		  privTemplate, (CK_ULONG) 7,
Packit Service ae04f2
		  &pub, &priv),
Packit Service ae04f2
		 DST_R_CRYPTOFAILURE);
Packit Service ae04f2
Packit Service ae04f2
	attr = dsa->repr;
Packit Service ae04f2
	attr += 3;
Packit Service ae04f2
	PK11_RET(pkcs_C_GetAttributeValue,
Packit Service ae04f2
		 (pk11_ctx->session, pub, attr, 1),
Packit Service ae04f2
		 DST_R_CRYPTOFAILURE);
Packit Service ae04f2
	attr->pValue = isc_mem_get(key->mctx, attr->ulValueLen);
Packit Service ae04f2
	if (attr->pValue == NULL)
Packit Service ae04f2
		DST_RET(ISC_R_NOMEMORY);
Packit Service ae04f2
	memset(attr->pValue, 0, attr->ulValueLen);
Packit Service ae04f2
	PK11_RET(pkcs_C_GetAttributeValue,
Packit Service ae04f2
		 (pk11_ctx->session, pub, attr, 1),
Packit Service ae04f2
		 DST_R_CRYPTOFAILURE);
Packit Service ae04f2
Packit Service ae04f2
	attr++;
Packit Service ae04f2
	attr->type = CKA_VALUE;
Packit Service ae04f2
	PK11_RET(pkcs_C_GetAttributeValue,
Packit Service ae04f2
		 (pk11_ctx->session, priv, attr, 1),
Packit Service ae04f2
		 DST_R_CRYPTOFAILURE);
Packit Service ae04f2
	attr->pValue = isc_mem_get(key->mctx, attr->ulValueLen);
Packit Service ae04f2
	if (attr->pValue == NULL)
Packit Service ae04f2
		DST_RET(ISC_R_NOMEMORY);
Packit Service ae04f2
	memset(attr->pValue, 0, attr->ulValueLen);
Packit Service ae04f2
	PK11_RET(pkcs_C_GetAttributeValue,
Packit Service ae04f2
		 (pk11_ctx->session, priv, attr, 1),
Packit Service ae04f2
		 DST_R_CRYPTOFAILURE);
Packit Service ae04f2
	attr->type = CKA_VALUE2;
Packit Service ae04f2
Packit Service ae04f2
	(void) pkcs_C_DestroyObject(pk11_ctx->session, priv);
Packit Service ae04f2
	(void) pkcs_C_DestroyObject(pk11_ctx->session, pub);
Packit Service ae04f2
	(void) pkcs_C_DestroyObject(pk11_ctx->session, dp);
Packit Service ae04f2
	pk11_return_session(pk11_ctx);
Packit Service ae04f2
	isc_safe_memwipe(pk11_ctx, sizeof(*pk11_ctx));
Packit Service ae04f2
	isc_mem_put(key->mctx, pk11_ctx, sizeof(*pk11_ctx));
Packit Service ae04f2
Packit Service ae04f2
	return (ISC_R_SUCCESS);
Packit Service ae04f2
Packit Service ae04f2
    err:
Packit Service ae04f2
	pkcs11dsa_destroy(key);
Packit Service ae04f2
	if (priv != CK_INVALID_HANDLE)
Packit Service ae04f2
		(void) pkcs_C_DestroyObject(pk11_ctx->session, priv);
Packit Service ae04f2
	if (pub != CK_INVALID_HANDLE)
Packit Service ae04f2
		(void) pkcs_C_DestroyObject(pk11_ctx->session, pub);
Packit Service ae04f2
	if (dp != CK_INVALID_HANDLE)
Packit Service ae04f2
		(void) pkcs_C_DestroyObject(pk11_ctx->session, dp);
Packit Service ae04f2
	pk11_return_session(pk11_ctx);
Packit Service ae04f2
	isc_safe_memwipe(pk11_ctx, sizeof(*pk11_ctx));
Packit Service ae04f2
	isc_mem_put(key->mctx, pk11_ctx, sizeof(*pk11_ctx));
Packit Service ae04f2
Packit Service ae04f2
	return (ret);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
static bool
Packit Service ae04f2
pkcs11dsa_isprivate(const dst_key_t *key) {
Packit Service ae04f2
	pk11_object_t *dsa = key->keydata.pkey;
Packit Service ae04f2
	CK_ATTRIBUTE *attr;
Packit Service ae04f2
Packit Service ae04f2
	if (dsa == NULL)
Packit Service ae04f2
		return (false);
Packit Service ae04f2
	attr = pk11_attribute_bytype(dsa, CKA_VALUE2);
Packit Service ae04f2
	return (attr != NULL || dsa->ontoken);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
static void
Packit Service ae04f2
pkcs11dsa_destroy(dst_key_t *key) {
Packit Service ae04f2
	pk11_object_t *dsa = key->keydata.pkey;
Packit Service ae04f2
	CK_ATTRIBUTE *attr;
Packit Service ae04f2
Packit Service ae04f2
	if (dsa == NULL)
Packit Service ae04f2
		return;
Packit Service ae04f2
Packit Service ae04f2
	INSIST((dsa->object == CK_INVALID_HANDLE) || dsa->ontoken);
Packit Service ae04f2
Packit Service ae04f2
	for (attr = pk11_attribute_first(dsa);
Packit Service ae04f2
	     attr != NULL;
Packit Service ae04f2
	     attr = pk11_attribute_next(dsa, attr))
Packit Service ae04f2
		switch (attr->type) {
Packit Service ae04f2
		case CKA_PRIME:
Packit Service ae04f2
		case CKA_SUBPRIME:
Packit Service ae04f2
		case CKA_BASE:
Packit Service ae04f2
		case CKA_VALUE:
Packit Service ae04f2
		case CKA_VALUE2:
Packit Service ae04f2
			if (attr->pValue != NULL) {
Packit Service ae04f2
				isc_safe_memwipe(attr->pValue,
Packit Service ae04f2
						 attr->ulValueLen);
Packit Service ae04f2
				isc_mem_put(key->mctx,
Packit Service ae04f2
					    attr->pValue,
Packit Service ae04f2
					    attr->ulValueLen);
Packit Service ae04f2
			}
Packit Service ae04f2
			break;
Packit Service ae04f2
		}
Packit Service ae04f2
	if (dsa->repr != NULL) {
Packit Service ae04f2
		isc_safe_memwipe(dsa->repr, dsa->attrcnt * sizeof(*attr));
Packit Service ae04f2
		isc_mem_put(key->mctx,
Packit Service ae04f2
			    dsa->repr,
Packit Service ae04f2
			    dsa->attrcnt * sizeof(*attr));
Packit Service ae04f2
	}
Packit Service ae04f2
	isc_safe_memwipe(dsa, sizeof(*dsa));
Packit Service ae04f2
	isc_mem_put(key->mctx, dsa, sizeof(*dsa));
Packit Service ae04f2
	key->keydata.pkey = NULL;
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
Packit Service ae04f2
static isc_result_t
Packit Service ae04f2
pkcs11dsa_todns(const dst_key_t *key, isc_buffer_t *data) {
Packit Service ae04f2
	pk11_object_t *dsa;
Packit Service ae04f2
	CK_ATTRIBUTE *attr;
Packit Service ae04f2
	isc_region_t r;
Packit Service ae04f2
	int dnslen;
Packit Service ae04f2
	unsigned int t, p_bytes;
Packit Service ae04f2
	CK_ATTRIBUTE *prime = NULL, *subprime = NULL;
Packit Service ae04f2
	CK_ATTRIBUTE *base = NULL, *pub_key = NULL;
Packit Service ae04f2
	CK_BYTE *cp;
Packit Service ae04f2
Packit Service ae04f2
	REQUIRE(key->keydata.pkey != NULL);
Packit Service ae04f2
Packit Service ae04f2
	dsa = key->keydata.pkey;
Packit Service ae04f2
Packit Service ae04f2
	for (attr = pk11_attribute_first(dsa);
Packit Service ae04f2
	     attr != NULL;
Packit Service ae04f2
	     attr = pk11_attribute_next(dsa, attr))
Packit Service ae04f2
		switch (attr->type) {
Packit Service ae04f2
		case CKA_PRIME:
Packit Service ae04f2
			prime = attr;
Packit Service ae04f2
			break;
Packit Service ae04f2
		case CKA_SUBPRIME:
Packit Service ae04f2
			subprime = attr;
Packit Service ae04f2
			break;
Packit Service ae04f2
		case CKA_BASE:
Packit Service ae04f2
			base = attr;
Packit Service ae04f2
			break;
Packit Service ae04f2
		case CKA_VALUE:
Packit Service ae04f2
			pub_key = attr;
Packit Service ae04f2
			break;
Packit Service ae04f2
		}
Packit Service ae04f2
	REQUIRE((prime != NULL) && (subprime != NULL) &&
Packit Service ae04f2
		(base != NULL) && (pub_key != NULL));
Packit Service ae04f2
Packit Service ae04f2
	isc_buffer_availableregion(data, &r);
Packit Service ae04f2
Packit Service ae04f2
	t = (prime->ulValueLen - 64) / 8;
Packit Service ae04f2
	if (t > 8)
Packit Service ae04f2
		return (DST_R_INVALIDPUBLICKEY);
Packit Service ae04f2
	p_bytes = 64 + 8 * t;
Packit Service ae04f2
Packit Service ae04f2
	dnslen = 1 + (key->key_size * 3)/8 + ISC_SHA1_DIGESTLENGTH;
Packit Service ae04f2
	if (r.length < (unsigned int) dnslen)
Packit Service ae04f2
		return (ISC_R_NOSPACE);
Packit Service ae04f2
Packit Service ae04f2
	memset(r.base, 0, dnslen);
Packit Service ae04f2
	*r.base = t;
Packit Service ae04f2
	isc_region_consume(&r, 1);
Packit Service ae04f2
Packit Service ae04f2
	cp = (CK_BYTE *) subprime->pValue;
Packit Service ae04f2
	memmove(r.base + ISC_SHA1_DIGESTLENGTH - subprime->ulValueLen,
Packit Service ae04f2
		cp, subprime->ulValueLen);
Packit Service ae04f2
	isc_region_consume(&r, ISC_SHA1_DIGESTLENGTH);
Packit Service ae04f2
	cp = (CK_BYTE *) prime->pValue;
Packit Service ae04f2
	memmove(r.base + key->key_size/8 - prime->ulValueLen,
Packit Service ae04f2
		cp, prime->ulValueLen);
Packit Service ae04f2
	isc_region_consume(&r, p_bytes);
Packit Service ae04f2
	cp = (CK_BYTE *) base->pValue;
Packit Service ae04f2
	memmove(r.base + key->key_size/8 - base->ulValueLen,
Packit Service ae04f2
		cp, base->ulValueLen);
Packit Service ae04f2
	isc_region_consume(&r, p_bytes);
Packit Service ae04f2
	cp = (CK_BYTE *) pub_key->pValue;
Packit Service ae04f2
	memmove(r.base + key->key_size/8 - pub_key->ulValueLen,
Packit Service ae04f2
		cp, pub_key->ulValueLen);
Packit Service ae04f2
	isc_region_consume(&r, p_bytes);
Packit Service ae04f2
Packit Service ae04f2
	isc_buffer_add(data, dnslen);
Packit Service ae04f2
Packit Service ae04f2
	return (ISC_R_SUCCESS);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
static isc_result_t
Packit Service ae04f2
pkcs11dsa_fromdns(dst_key_t *key, isc_buffer_t *data) {
Packit Service ae04f2
	pk11_object_t *dsa;
Packit Service ae04f2
	isc_region_t r;
Packit Service ae04f2
	unsigned int t, p_bytes;
Packit Service ae04f2
	CK_BYTE *prime, *subprime, *base, *pub_key;
Packit Service ae04f2
	CK_ATTRIBUTE *attr;
Packit Service ae04f2
Packit Service ae04f2
	isc_buffer_remainingregion(data, &r);
Packit Service ae04f2
	if (r.length == 0)
Packit Service ae04f2
		return (ISC_R_SUCCESS);
Packit Service ae04f2
Packit Service ae04f2
	dsa = (pk11_object_t *) isc_mem_get(key->mctx, sizeof(*dsa));
Packit Service ae04f2
	if (dsa == NULL)
Packit Service ae04f2
		return (ISC_R_NOMEMORY);
Packit Service ae04f2
	memset(dsa, 0, sizeof(*dsa));
Packit Service ae04f2
Packit Service ae04f2
	t = (unsigned int) *r.base;
Packit Service ae04f2
	isc_region_consume(&r, 1);
Packit Service ae04f2
	if (t > 8) {
Packit Service ae04f2
		isc_safe_memwipe(dsa, sizeof(*dsa));
Packit Service ae04f2
		isc_mem_put(key->mctx, dsa, sizeof(*dsa));
Packit Service ae04f2
		return (DST_R_INVALIDPUBLICKEY);
Packit Service ae04f2
	}
Packit Service ae04f2
	p_bytes = 64 + 8 * t;
Packit Service ae04f2
Packit Service ae04f2
	if (r.length < ISC_SHA1_DIGESTLENGTH + 3 * p_bytes) {
Packit Service ae04f2
		isc_safe_memwipe(dsa, sizeof(*dsa));
Packit Service ae04f2
		isc_mem_put(key->mctx, dsa, sizeof(*dsa));
Packit Service ae04f2
		return (DST_R_INVALIDPUBLICKEY);
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	subprime = r.base;
Packit Service ae04f2
	isc_region_consume(&r, ISC_SHA1_DIGESTLENGTH);
Packit Service ae04f2
Packit Service ae04f2
	prime = r.base;
Packit Service ae04f2
	isc_region_consume(&r, p_bytes);
Packit Service ae04f2
Packit Service ae04f2
	base = r.base;
Packit Service ae04f2
	isc_region_consume(&r, p_bytes);
Packit Service ae04f2
Packit Service ae04f2
	pub_key = r.base;
Packit Service ae04f2
	isc_region_consume(&r, p_bytes);
Packit Service ae04f2
Packit Service ae04f2
	key->key_size = p_bytes * 8;
Packit Service ae04f2
Packit Service ae04f2
	isc_buffer_forward(data, 1 + ISC_SHA1_DIGESTLENGTH + 3 * p_bytes);
Packit Service ae04f2
Packit Service ae04f2
	dsa->repr = (CK_ATTRIBUTE *) isc_mem_get(key->mctx, sizeof(*attr) * 4);
Packit Service ae04f2
	if (dsa->repr == NULL)
Packit Service ae04f2
		goto nomemory;
Packit Service ae04f2
	memset(dsa->repr, 0, sizeof(*attr) * 4);
Packit Service ae04f2
	dsa->attrcnt = 4;
Packit Service ae04f2
Packit Service ae04f2
	attr = dsa->repr;
Packit Service ae04f2
	attr[0].type = CKA_PRIME;
Packit Service ae04f2
	attr[0].pValue = isc_mem_get(key->mctx, p_bytes);
Packit Service ae04f2
	if (attr[0].pValue == NULL)
Packit Service ae04f2
		goto nomemory;
Packit Service ae04f2
	memmove(attr[0].pValue, prime, p_bytes);
Packit Service ae04f2
	attr[0].ulValueLen = p_bytes;
Packit Service ae04f2
Packit Service ae04f2
	attr[1].type = CKA_SUBPRIME;
Packit Service ae04f2
	attr[1].pValue = isc_mem_get(key->mctx, ISC_SHA1_DIGESTLENGTH);
Packit Service ae04f2
	if (attr[1].pValue == NULL)
Packit Service ae04f2
		goto nomemory;
Packit Service ae04f2
	memmove(attr[1].pValue, subprime, ISC_SHA1_DIGESTLENGTH);
Packit Service ae04f2
	attr[1].ulValueLen = ISC_SHA1_DIGESTLENGTH;
Packit Service ae04f2
Packit Service ae04f2
	attr[2].type = CKA_BASE;
Packit Service ae04f2
	attr[2].pValue = isc_mem_get(key->mctx, p_bytes);
Packit Service ae04f2
	if (attr[2].pValue == NULL)
Packit Service ae04f2
		goto nomemory;
Packit Service ae04f2
	memmove(attr[2].pValue, base, p_bytes);
Packit Service ae04f2
	attr[2].ulValueLen = p_bytes;
Packit Service ae04f2
Packit Service ae04f2
	attr[3].type = CKA_VALUE;
Packit Service ae04f2
	attr[3].pValue = isc_mem_get(key->mctx, p_bytes);
Packit Service ae04f2
	if (attr[3].pValue == NULL)
Packit Service ae04f2
		goto nomemory;
Packit Service ae04f2
	memmove(attr[3].pValue, pub_key, p_bytes);
Packit Service ae04f2
	attr[3].ulValueLen = p_bytes;
Packit Service ae04f2
Packit Service ae04f2
	key->keydata.pkey = dsa;
Packit Service ae04f2
Packit Service ae04f2
	return (ISC_R_SUCCESS);
Packit Service ae04f2
Packit Service ae04f2
    nomemory:
Packit Service ae04f2
	for (attr = pk11_attribute_first(dsa);
Packit Service ae04f2
	     attr != NULL;
Packit Service ae04f2
	     attr = pk11_attribute_next(dsa, attr))
Packit Service ae04f2
		switch (attr->type) {
Packit Service ae04f2
		case CKA_PRIME:
Packit Service ae04f2
		case CKA_SUBPRIME:
Packit Service ae04f2
		case CKA_BASE:
Packit Service ae04f2
		case CKA_VALUE:
Packit Service ae04f2
			if (attr->pValue != NULL) {
Packit Service ae04f2
				isc_safe_memwipe(attr->pValue,
Packit Service ae04f2
						 attr->ulValueLen);
Packit Service ae04f2
				isc_mem_put(key->mctx,
Packit Service ae04f2
					    attr->pValue,
Packit Service ae04f2
					    attr->ulValueLen);
Packit Service ae04f2
			}
Packit Service ae04f2
			break;
Packit Service ae04f2
		}
Packit Service ae04f2
	if (dsa->repr != NULL) {
Packit Service ae04f2
		isc_safe_memwipe(dsa->repr, dsa->attrcnt * sizeof(*attr));
Packit Service ae04f2
		isc_mem_put(key->mctx,
Packit Service ae04f2
			    dsa->repr,
Packit Service ae04f2
			    dsa->attrcnt * sizeof(*attr));
Packit Service ae04f2
	}
Packit Service ae04f2
	isc_safe_memwipe(dsa, sizeof(*dsa));
Packit Service ae04f2
	isc_mem_put(key->mctx, dsa, sizeof(*dsa));
Packit Service ae04f2
	return (ISC_R_NOMEMORY);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
static isc_result_t
Packit Service ae04f2
pkcs11dsa_tofile(const dst_key_t *key, const char *directory) {
Packit Service ae04f2
	int cnt = 0;
Packit Service ae04f2
	pk11_object_t *dsa;
Packit Service ae04f2
	CK_ATTRIBUTE *attr;
Packit Service ae04f2
	CK_ATTRIBUTE *prime = NULL, *subprime = NULL, *base = NULL;
Packit Service ae04f2
	CK_ATTRIBUTE *pub_key = NULL, *priv_key = NULL;
Packit Service ae04f2
	dst_private_t priv;
Packit Service ae04f2
	unsigned char bufs[5][128];
Packit Service ae04f2
Packit Service ae04f2
	if (key->keydata.pkey == NULL)
Packit Service ae04f2
		return (DST_R_NULLKEY);
Packit Service ae04f2
Packit Service ae04f2
	if (key->external) {
Packit Service ae04f2
		priv.nelements = 0;
Packit Service ae04f2
		return (dst__privstruct_writefile(key, &priv, directory));
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	dsa = key->keydata.pkey;
Packit Service ae04f2
Packit Service ae04f2
	for (attr = pk11_attribute_first(dsa);
Packit Service ae04f2
	     attr != NULL;
Packit Service ae04f2
	     attr = pk11_attribute_next(dsa, attr))
Packit Service ae04f2
		switch (attr->type) {
Packit Service ae04f2
		case CKA_PRIME:
Packit Service ae04f2
			prime = attr;
Packit Service ae04f2
			break;
Packit Service ae04f2
		case CKA_SUBPRIME:
Packit Service ae04f2
			subprime = attr;
Packit Service ae04f2
			break;
Packit Service ae04f2
		case CKA_BASE:
Packit Service ae04f2
			base = attr;
Packit Service ae04f2
			break;
Packit Service ae04f2
		case CKA_VALUE:
Packit Service ae04f2
			pub_key = attr;
Packit Service ae04f2
			break;
Packit Service ae04f2
		case CKA_VALUE2:
Packit Service ae04f2
			priv_key = attr;
Packit Service ae04f2
			break;
Packit Service ae04f2
		}
Packit Service ae04f2
	if ((prime == NULL) || (subprime == NULL) || (base == NULL) ||
Packit Service ae04f2
	    (pub_key == NULL) || (priv_key ==NULL))
Packit Service ae04f2
		return (DST_R_NULLKEY);
Packit Service ae04f2
Packit Service ae04f2
	priv.elements[cnt].tag = TAG_DSA_PRIME;
Packit Service ae04f2
	priv.elements[cnt].length = (unsigned short) prime->ulValueLen;
Packit Service ae04f2
	memmove(bufs[cnt], prime->pValue, prime->ulValueLen);
Packit Service ae04f2
	priv.elements[cnt].data = bufs[cnt];
Packit Service ae04f2
	cnt++;
Packit Service ae04f2
Packit Service ae04f2
	priv.elements[cnt].tag = TAG_DSA_SUBPRIME;
Packit Service ae04f2
	priv.elements[cnt].length = (unsigned short) subprime->ulValueLen;
Packit Service ae04f2
	memmove(bufs[cnt], subprime->pValue, subprime->ulValueLen);
Packit Service ae04f2
	priv.elements[cnt].data = bufs[cnt];
Packit Service ae04f2
	cnt++;
Packit Service ae04f2
Packit Service ae04f2
	priv.elements[cnt].tag = TAG_DSA_BASE;
Packit Service ae04f2
	priv.elements[cnt].length = (unsigned short) base->ulValueLen;
Packit Service ae04f2
	memmove(bufs[cnt], base->pValue, base->ulValueLen);
Packit Service ae04f2
	priv.elements[cnt].data = bufs[cnt];
Packit Service ae04f2
	cnt++;
Packit Service ae04f2
Packit Service ae04f2
	priv.elements[cnt].tag = TAG_DSA_PRIVATE;
Packit Service ae04f2
	priv.elements[cnt].length = (unsigned short) priv_key->ulValueLen;
Packit Service ae04f2
	memmove(bufs[cnt], priv_key->pValue, priv_key->ulValueLen);
Packit Service ae04f2
	priv.elements[cnt].data = bufs[cnt];
Packit Service ae04f2
	cnt++;
Packit Service ae04f2
Packit Service ae04f2
	priv.elements[cnt].tag = TAG_DSA_PUBLIC;
Packit Service ae04f2
	priv.elements[cnt].length = (unsigned short) pub_key->ulValueLen;
Packit Service ae04f2
	memmove(bufs[cnt], pub_key->pValue, pub_key->ulValueLen);
Packit Service ae04f2
	priv.elements[cnt].data = bufs[cnt];
Packit Service ae04f2
	cnt++;
Packit Service ae04f2
Packit Service ae04f2
	priv.nelements = cnt;
Packit Service ae04f2
	return (dst__privstruct_writefile(key, &priv, directory));
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
static isc_result_t
Packit Service ae04f2
pkcs11dsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) {
Packit Service ae04f2
	dst_private_t priv;
Packit Service ae04f2
	isc_result_t ret;
Packit Service ae04f2
	int i;
Packit Service ae04f2
	pk11_object_t *dsa = NULL;
Packit Service ae04f2
	CK_ATTRIBUTE *attr;
Packit Service ae04f2
	isc_mem_t *mctx = key->mctx;
Packit Service ae04f2
Packit Service ae04f2
	/* read private key file */
Packit Service ae04f2
	ret = dst__privstruct_parse(key, DST_ALG_DSA, lexer, mctx, &priv;;
Packit Service ae04f2
	if (ret != ISC_R_SUCCESS)
Packit Service ae04f2
		return (ret);
Packit Service ae04f2
Packit Service ae04f2
	if (key->external) {
Packit Service ae04f2
		if (priv.nelements != 0)
Packit Service ae04f2
			DST_RET(DST_R_INVALIDPRIVATEKEY);
Packit Service ae04f2
		if (pub == NULL)
Packit Service ae04f2
			DST_RET(DST_R_INVALIDPRIVATEKEY);
Packit Service ae04f2
Packit Service ae04f2
		key->keydata.pkey = pub->keydata.pkey;
Packit Service ae04f2
		pub->keydata.pkey = NULL;
Packit Service ae04f2
		key->key_size = pub->key_size;
Packit Service ae04f2
Packit Service ae04f2
		dst__privstruct_free(&priv, mctx);
Packit Service ae04f2
		isc_safe_memwipe(&priv, sizeof(priv));
Packit Service ae04f2
Packit Service ae04f2
		return (ISC_R_SUCCESS);
Packit Service ae04f2
	}
Packit Service ae04f2
Packit Service ae04f2
	dsa = (pk11_object_t *) isc_mem_get(key->mctx, sizeof(*dsa));
Packit Service ae04f2
	if (dsa == NULL)
Packit Service ae04f2
		DST_RET(ISC_R_NOMEMORY);
Packit Service ae04f2
	memset(dsa, 0, sizeof(*dsa));
Packit Service ae04f2
	key->keydata.pkey = dsa;
Packit Service ae04f2
Packit Service ae04f2
	dsa->repr = (CK_ATTRIBUTE *) isc_mem_get(key->mctx, sizeof(*attr) * 5);
Packit Service ae04f2
	if (dsa->repr == NULL)
Packit Service ae04f2
		DST_RET(ISC_R_NOMEMORY);
Packit Service ae04f2
	memset(dsa->repr, 0, sizeof(*attr) * 5);
Packit Service ae04f2
	dsa->attrcnt = 5;
Packit Service ae04f2
	attr = dsa->repr;
Packit Service ae04f2
	attr[0].type = CKA_PRIME;
Packit Service ae04f2
	attr[1].type = CKA_SUBPRIME;
Packit Service ae04f2
	attr[2].type = CKA_BASE;
Packit Service ae04f2
	attr[3].type = CKA_VALUE;
Packit Service ae04f2
	attr[4].type = CKA_VALUE2;
Packit Service ae04f2
Packit Service ae04f2
	for (i = 0; i < priv.nelements; i++) {
Packit Service ae04f2
		CK_BYTE *bn;
Packit Service ae04f2
Packit Service ae04f2
		bn = isc_mem_get(key->mctx, priv.elements[i].length);
Packit Service ae04f2
		if (bn == NULL)
Packit Service ae04f2
			DST_RET(ISC_R_NOMEMORY);
Packit Service ae04f2
		memmove(bn, priv.elements[i].data, priv.elements[i].length);
Packit Service ae04f2
Packit Service ae04f2
		switch (priv.elements[i].tag) {
Packit Service ae04f2
			case TAG_DSA_PRIME:
Packit Service ae04f2
				attr = pk11_attribute_bytype(dsa, CKA_PRIME);
Packit Service ae04f2
				INSIST(attr != NULL);
Packit Service ae04f2
				attr->pValue = bn;
Packit Service ae04f2
				attr->ulValueLen = priv.elements[i].length;
Packit Service ae04f2
				break;
Packit Service ae04f2
			case TAG_DSA_SUBPRIME:
Packit Service ae04f2
				attr = pk11_attribute_bytype(dsa,
Packit Service ae04f2
							     CKA_SUBPRIME);
Packit Service ae04f2
				INSIST(attr != NULL);
Packit Service ae04f2
				attr->pValue = bn;
Packit Service ae04f2
				attr->ulValueLen = priv.elements[i].length;
Packit Service ae04f2
				break;
Packit Service ae04f2
			case TAG_DSA_BASE:
Packit Service ae04f2
				attr = pk11_attribute_bytype(dsa, CKA_BASE);
Packit Service ae04f2
				INSIST(attr != NULL);
Packit Service ae04f2
				attr->pValue = bn;
Packit Service ae04f2
				attr->ulValueLen = priv.elements[i].length;
Packit Service ae04f2
				break;
Packit Service ae04f2
			case TAG_DSA_PRIVATE:
Packit Service ae04f2
				attr = pk11_attribute_bytype(dsa, CKA_VALUE2);
Packit Service ae04f2
				INSIST(attr != NULL);
Packit Service ae04f2
				attr->pValue = bn;
Packit Service ae04f2
				attr->ulValueLen = priv.elements[i].length;
Packit Service ae04f2
				break;
Packit Service ae04f2
			case TAG_DSA_PUBLIC:
Packit Service ae04f2
				attr = pk11_attribute_bytype(dsa, CKA_VALUE);
Packit Service ae04f2
				INSIST(attr != NULL);
Packit Service ae04f2
				attr->pValue = bn;
Packit Service ae04f2
				attr->ulValueLen = priv.elements[i].length;
Packit Service ae04f2
				break;
Packit Service ae04f2
		}
Packit Service ae04f2
	}
Packit Service ae04f2
	dst__privstruct_free(&priv, mctx);
Packit Service ae04f2
Packit Service ae04f2
	attr = pk11_attribute_bytype(dsa, CKA_PRIME);
Packit Service ae04f2
	INSIST(attr != NULL);
Packit Service ae04f2
	key->key_size = pk11_numbits(attr->pValue, attr->ulValueLen);
Packit Service ae04f2
Packit Service ae04f2
	return (ISC_R_SUCCESS);
Packit Service ae04f2
Packit Service ae04f2
 err:
Packit Service ae04f2
	pkcs11dsa_destroy(key);
Packit Service ae04f2
	dst__privstruct_free(&priv, mctx);
Packit Service ae04f2
	isc_safe_memwipe(&priv, sizeof(priv));
Packit Service ae04f2
	return (ret);
Packit Service ae04f2
}
Packit Service ae04f2
Packit Service ae04f2
static dst_func_t pkcs11dsa_functions = {
Packit Service ae04f2
	pkcs11dsa_createctx,
Packit Service ae04f2
	NULL, /*%< createctx2 */
Packit Service ae04f2
	pkcs11dsa_destroyctx,
Packit Service ae04f2
	pkcs11dsa_adddata,
Packit Service ae04f2
	pkcs11dsa_sign,
Packit Service ae04f2
	pkcs11dsa_verify,
Packit Service ae04f2
	NULL, /*%< verify2 */
Packit Service ae04f2
	NULL, /*%< computesecret */
Packit Service ae04f2
	pkcs11dsa_compare,
Packit Service ae04f2
	NULL, /*%< paramcompare */
Packit Service ae04f2
	pkcs11dsa_generate,
Packit Service ae04f2
	pkcs11dsa_isprivate,
Packit Service ae04f2
	pkcs11dsa_destroy,
Packit Service ae04f2
	pkcs11dsa_todns,
Packit Service ae04f2
	pkcs11dsa_fromdns,
Packit Service ae04f2
	pkcs11dsa_tofile,
Packit Service ae04f2
	pkcs11dsa_parse,
Packit Service ae04f2
	NULL, /*%< cleanup */
Packit Service ae04f2
	NULL, /*%< fromlabel */
Packit Service ae04f2
	NULL, /*%< dump */
Packit Service ae04f2
	NULL, /*%< restore */
Packit Service ae04f2
};
Packit Service ae04f2
Packit Service ae04f2
isc_result_t
Packit Service ae04f2
dst__pkcs11dsa_init(dst_func_t **funcp) {
Packit Service ae04f2
	REQUIRE(funcp != NULL);
Packit Service ae04f2
	if (*funcp == NULL)
Packit Service ae04f2
		*funcp = &pkcs11dsa_functions;
Packit Service ae04f2
	return (ISC_R_SUCCESS);
Packit Service ae04f2
}
Packit Service ae04f2
#endif /* !PK11_DSA_DISABLE */
Packit Service ae04f2
Packit Service ae04f2
#else /* PKCS11CRYPTO */
Packit Service ae04f2
Packit Service ae04f2
#include <isc/util.h>
Packit Service ae04f2
Packit Service ae04f2
EMPTY_TRANSLATION_UNIT
Packit Service ae04f2
Packit Service ae04f2
#endif /* PKCS11CRYPTO */
Packit Service ae04f2
/*! \file */