openssldh_link.c revision 90adbb5f1cfeac900fecf654c9000d7f26c06b98
#if defined(OPENSSL)
/*
* Portions Copyright (c) 1995-1998 by Network Associates, Inc.
*
* Permission to use, copy modify, and 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 NETWORK ASSOCIATES
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
* NETWORK ASSOCIATES 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 THE SOFTWARE.
*/
/*
* Principal Author: Brian Wellington
* $Id: openssldh_link.c,v 1.6 1999/10/29 12:56:57 marka Exp $
*/
#include <config.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <ctype.h>
#include <isc/assertions.h>
#include "dst_internal.h"
#include "dst_parse.h"
#define PRIME768 "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A63A3620FFFFFFFFFFFFFFFF"
#define PRIME1024 "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF"
static struct dst_func openssldh_functions;
isc_buffer_t *data);
const isc_uint16_t id,
/*
* dst_s_openssldh_init()
* Sets up function pointers for OpenSSL related functions
*/
void
{
}
/*
* dst_openssldh_computesecret
* Compute a shared secret from this public and private key
* Parameters
* pub The public key
* priv The private key
* secret A buffer into which the secret is written
* Returns
* ISC_R_SUCCESS Success
* !ISC_R_SUCCESS Failure
*/
static dst_result_t
{
int ret;
isc_region_t r;
unsigned int len;
isc_buffer_available(secret, &r);
return (ISC_R_NOSPACE);
if (ret == 0)
return (DST_R_COMPUTESECRETFAILURE);
return (ISC_R_SUCCESS);
}
/*
* dst_openssldh_isprivate
* Is this a private key?
* Parameters
* key DST KEY structure
* Returns
* ISC_TRUE
* ISC_FALSE
*/
static isc_boolean_t
}
/*
* dst_openssldh_to_dns
* Converts key from DH to DNS distribution format
* Parameters
* key DST KEY structure
* data output data
* Returns
* ISC_R_SUCCESS Success
* !ISC_R_SUCCESS Failure
*/
static dst_result_t
isc_region_t r;
isc_buffer_available(data, &r);
plen = 1;
glen = 0;
}
else {
}
return (ISC_R_NOSPACE);
uint16_toregion(plen, &r);
if (plen == 1) {
*r.base = 1;
else
*r.base = 2;
}
else
uint16_toregion(glen, &r);
if (glen > 0)
uint16_toregion(publen, &r);
return (ISC_R_SUCCESS);
}
/*
* dst_openssldh_from_dns
* Converts from a DNS KEY RR format to a DH KEY.
* Parameters
* key Partially filled key structure
* data Buffer containing key in DNS format
* Return
* ISC_R_SUCCESS Success
* !ISC_R_SUCCESS Failure
*/
static dst_result_t
isc_region_t r;
int special = 0;
isc_buffer_remaining(data, &r);
if (r.length == 0)
return (ISC_R_SUCCESS);
return (ISC_R_NOMEMORY);
/*
* Read the prime length. 1 & 2 are table entries, > 16 means a
* prime follows, otherwise an error.
*/
if (r.length < 2) {
return (DST_R_INVALIDPUBLICKEY);
}
plen = uint16_fromregion(&r);
return (DST_R_INVALIDPUBLICKEY);
}
return (DST_R_INVALIDPUBLICKEY);
}
if (plen == 1)
else
special = uint16_fromregion(&r);
switch (special) {
case 1:
break;
case 2:
break;
default:
return (DST_R_INVALIDPUBLICKEY);
}
}
else {
}
/*
* Read the generator length. This should be 0 if the prime was
* special, but it might not be. If it's 0 and the prime is not
* special, we have a problem.
*/
if (r.length < 2) {
return (DST_R_INVALIDPUBLICKEY);
}
glen = uint16_fromregion(&r);
return (DST_R_INVALIDPUBLICKEY);
}
if (special != 0) {
if (glen == 0)
else {
}
else {
return (DST_R_INVALIDPUBLICKEY);
}
}
}
else {
if (glen == 0) {
return (DST_R_INVALIDPUBLICKEY);
}
}
if (r.length < 2) {
return (DST_R_INVALIDPUBLICKEY);
}
publen = uint16_fromregion(&r);
return (DST_R_INVALIDPUBLICKEY);
}
isc_buffer_remaining(data, &r);
return (ISC_R_SUCCESS);
}
/*
* dst_openssldh_to_file
* Encodes a DH Key into the portable file format.
* Parameters
* key DST KEY structure
* Returns
* ISC_R_SUCCESS Success
* !ISC_R_SUCCESS Failure
*/
static dst_result_t
int cnt = 0;
return (DST_R_NULLKEY);
cnt++;
cnt++;
cnt++;
cnt++;
}
/*
* dst_openssldh_from_file
* Converts contents of a private key file into a private DH key.
* Parameters
* key Partially filled DH KEY structure
* id The key id
* path The directory that the file will be read from
* Return
* ISC_R_SUCCESS Success
* !ISC_R_SUCCESS Failure
*/
static dst_result_t
isc_region_t r;
unsigned char dns_array[1024];
int i;
/* read private key file */
if (ret != ISC_R_SUCCESS)
return (ret);
case TAG_DH_PRIME:
break;
case TAG_DH_GENERATOR:
break;
case TAG_DH_PRIVATE:
break;
case TAG_DH_PUBLIC:
break;
}
}
{
}
}
}
if (ret != ISC_R_SUCCESS)
isc_buffer_used(&dns, &r);
return (ISC_R_SUCCESS);
err:
return (ret);
}
/*
* dst_openssldh_destroy
* Frees all dynamically allocated structures in key.
*/
static void
return;
}
/*
* dst_openssldh_generate
* Generates unique keys that are hard to predict.
* Parameters
* key DST Key structure
* generator generator
* mctx memory context to allocate key
* Return
* ISC_R_SUCCESS Success
* !ISC_R_SUCCESS Failure
*/
static dst_result_t
unsigned char dns_array[1024];
isc_region_t r;
if (generator == 0) {
return (ISC_R_NOMEMORY);
else
}
else
generator = 2;
}
if (generator != 0)
return (DST_R_INVALIDPARAM);
if (DH_generate_key(dh) == 0) {
return (ISC_R_NOMEMORY);
}
isc_buffer_used(&dns, &r);
return (ISC_R_SUCCESS);
}
/**************************************************************************
* dst_openssldh_compare
* Compare two keys for equality.
* Return
* ISC_TRUE The keys are equal
* ISC_FALSE The keys are not equal
*/
static isc_boolean_t
int status;
return (ISC_TRUE);
return (ISC_FALSE);
if (status != 0)
return (ISC_FALSE);
return (ISC_FALSE);
return (ISC_FALSE);
}
return (ISC_TRUE);
}
/**************************************************************************
* dst_openssldh_paramcompare
* Compare two keys' parameters for equality.
* Return
* ISC_TRUE The keys are equal
* ISC_FALSE The keys are not equal
*/
static isc_boolean_t
int status;
return (ISC_TRUE);
return (ISC_FALSE);
if (status != 0)
return (ISC_FALSE);
return (ISC_TRUE);
}
static void
}
static isc_uint16_t
return (val);
}
static void
static const char hexdigits[] = "0123456789abcdef";
unsigned char data[512];
unsigned int i;
char *s;
RUNTIME_CHECK(s != NULL);
RUNTIME_CHECK(s != NULL);
}
}
#endif