openssldsa_link.c revision 76af83c9adb772f7b045c62cf8b411165bfaa5ef
/*
* Portions Copyright (C) 1999-2002, 2004-2009, 2011-2016 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Portions Copyright (C) 1995-2000 by Network Associates, Inc.
*
* 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.
*/
#ifdef OPENSSL
#ifndef USE_EVP
#define USE_EVP 1
#endif
#include <config.h>
#ifndef PK11_DSA_DISABLE
#include <string.h>
#include "dst_internal.h"
#include "dst_openssl.h"
#include "dst_parse.h"
static void
const BIGNUM **g)
{
if (p != NULL)
*p = d->p;
if (q != NULL)
*q = d->q;
if (g != NULL)
*g = d->g;
}
static int
return 0;
BN_free(d->p);
BN_free(d->q);
BN_free(d->g);
d->p = p;
d->q = q;
d->g = g;
return 1;
}
static void
}
static int
/* Note that it is valid for priv_key to be NULL */
return 0;
return 1;
}
static void
}
static int
return 0;
BN_clear_free(sig->r);
BN_clear_free(sig->s);
sig->r = r;
sig->s = s;
return 1;
}
#define DSA_clear_flags(d, x) (d)->flags &= ~(x)
#endif
static isc_result_t
#if USE_EVP
if (evp_md_ctx == NULL)
return (ISC_R_NOMEMORY);
return (ISC_R_FAILURE);
}
return (ISC_R_SUCCESS);
#else
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
#endif
}
static void
#if USE_EVP
if (evp_md_ctx != NULL) {
}
#else
}
#endif
}
static isc_result_t
#if USE_EVP
return (ISC_R_FAILURE);
}
#else
#endif
return (ISC_R_SUCCESS);
}
static int
while (bytes-- > 0)
*buf++ = 0;
return (size);
}
static isc_result_t
unsigned int klen;
#if USE_EVP
unsigned char *sigbuf;
const unsigned char *sb;
unsigned int siglen;
#else
unsigned char digest[ISC_SHA1_DIGESTLENGTH];
#endif
return (ISC_R_NOSPACE);
#if USE_EVP
pkey = EVP_PKEY_new();
return (ISC_R_NOMEMORY);
return (ISC_R_FAILURE);
}
return (ISC_R_NOMEMORY);
}
"EVP_SignFinal",
}
/* Convert from Dss-Sig-Value (RFC2459). */
dsasig = DSA_SIG_new();
return (ISC_R_NOMEMORY);
}
"d2i_DSA_SIG",
}
#elif 0
/* Only use EVP for the Digest */
"EVP_DigestFinal_ex",
}
"DSA_do_sign",
#else
"DSA_do_sign",
#endif
if (klen > 255)
return (ISC_R_FAILURE);
DSA_SIG_get0(dsasig, &r, &s);
return (ISC_R_SUCCESS);
}
static isc_result_t
int status = 0;
#if USE_EVP
#if 0
unsigned char *sigbuf;
#endif
unsigned int siglen;
#else
#endif
unsigned char digest[ISC_SHA1_DIGESTLENGTH];
#if USE_EVP
#if 1
/* Only use EVP for the digest */
return (ISC_R_FAILURE);
}
#endif
#else
#endif
return (DST_R_VERIFYFAILURE);
}
cp++; /*%< Skip T */
dsasig = DSA_SIG_new();
return (ISC_R_NOMEMORY);
DSA_SIG_set0(dsasig, r, s);
#if 0
pkey = EVP_PKEY_new();
return (ISC_R_NOMEMORY);
return (ISC_R_FAILURE);
}
/* Convert to Dss-Sig-Value (RFC2459). */
return (ISC_R_NOMEMORY);
}
#else
#endif
switch (status) {
case 1:
return (ISC_R_SUCCESS);
case 0:
return (dst__openssl_toresult(DST_R_VERIFYFAILURE));
default:
"DSA_do_verify",
}
}
static isc_boolean_t
return (ISC_TRUE);
return (ISC_FALSE);
return (ISC_FALSE);
return (ISC_FALSE);
return (ISC_FALSE);
}
return (ISC_TRUE);
}
#if OPENSSL_VERSION_NUMBER > 0x00908000L
static int
{
union {
void *dptr;
void (*fptr)(int);
} u;
UNUSED(n);
u.fptr(p);
return (1);
}
#endif
static isc_result_t
unsigned char rand_array[ISC_SHA1_DIGESTLENGTH];
#if OPENSSL_VERSION_NUMBER > 0x00908000L
#endif
union {
void *dptr;
void (*fptr)(int);
} u;
#else
#endif
if (result != ISC_R_SUCCESS)
return (result);
#if OPENSSL_VERSION_NUMBER > 0x00908000L
return (dst__openssl_toresult(DST_R_OPENSSLFAILURE));
cb = BN_GENCB_new();
return (dst__openssl_toresult(DST_R_OPENSSLFAILURE));
}
#endif
} else {
}
cb))
{
return (dst__openssl_toresult2("DSA_generate_parameters_ex",
}
#else
return (dst__openssl_toresult2("DSA_generate_parameters",
#endif
if (DSA_generate_key(dsa) == 0) {
return (dst__openssl_toresult2("DSA_generate_key",
}
return (ISC_R_SUCCESS);
}
static isc_boolean_t
}
static void
}
static isc_result_t
isc_region_t r;
int dnslen;
unsigned int t, p_bytes;
DSA_get0_pqg(dsa, &p, &q, &g);
if (t > 8)
return (DST_R_INVALIDPUBLICKEY);
return (ISC_R_NOSPACE);
*r.base = t;
isc_region_consume(&r, 1);
isc_region_consume(&r, p_bytes);
isc_region_consume(&r, p_bytes);
isc_region_consume(&r, p_bytes);
return (ISC_R_SUCCESS);
}
static isc_result_t
isc_region_t r;
unsigned int t, p_bytes;
if (r.length == 0)
return (ISC_R_SUCCESS);
return (ISC_R_NOMEMORY);
t = (unsigned int) *r.base;
isc_region_consume(&r, 1);
if (t > 8) {
return (DST_R_INVALIDPUBLICKEY);
}
return (DST_R_INVALIDPUBLICKEY);
}
isc_region_consume(&r, p_bytes);
isc_region_consume(&r, p_bytes);
isc_region_consume(&r, p_bytes);
return (ISC_R_NOMEMORY);
}
DSA_set0_pqg(dsa, p, q, g);
return (ISC_R_SUCCESS);
}
static isc_result_t
int cnt = 0;
return (DST_R_NULLKEY);
}
DSA_get0_pqg(dsa, &p, &q, &g);
cnt++;
cnt++;
cnt++;
cnt++;
cnt++;
}
static isc_result_t
int i;
/* read private key file */
if (ret != ISC_R_SUCCESS)
return (ret);
return (ISC_R_SUCCESS);
}
case TAG_DSA_PRIME:
p = bn;
break;
case TAG_DSA_SUBPRIME:
q = bn;
break;
case TAG_DSA_BASE:
g = bn;
break;
case TAG_DSA_PRIVATE:
break;
case TAG_DSA_PUBLIC:
break;
}
}
DSA_set0_pqg(dsa, p, q, g);
return (ISC_R_SUCCESS);
err:
if (p != NULL)
BN_free(p);
if (q != NULL)
BN_free(q);
if (g != NULL)
BN_free(g);
return (ret);
}
static dst_func_t openssldsa_functions = {
NULL, /*%< createctx2 */
NULL, /*%< verify2 */
NULL, /*%< computesecret */
NULL, /*%< paramcompare */
NULL, /*%< cleanup */
NULL, /*%< fromlabel */
NULL, /*%< dump */
NULL, /*%< restore */
};
return (ISC_R_SUCCESS);
}
#endif /* !PK11_DSA_DISABLE */
#else /* OPENSSL */
#endif /* OPENSSL */
/*! \file */