1999-09-27 16:55:45 +00:00
|
|
|
/*
|
|
|
|
* Portions Copyright (c) 1995-1998 by Network Associates, Inc.
|
2000-05-08 14:38:29 +00:00
|
|
|
* Portions Copyright (C) 1999, 2000 Internet Software Consortium.
|
1999-09-27 16:55:45 +00:00
|
|
|
*
|
2000-05-08 14:38:29 +00:00
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
1999-09-27 16:55:45 +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-05-08 14:38:29 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM AND
|
|
|
|
* NETWORK ASSOCIATES DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
|
|
|
|
* SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
* FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE CONSORTIUM OR 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 THIS SOFTWARE.
|
1999-09-27 16:55:45 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Principal Author: Brian Wellington
|
2000-05-24 05:10:00 +00:00
|
|
|
* $Id: openssldh_link.c,v 1.17 2000/05/24 05:09:37 tale Exp $
|
1999-09-27 16:55:45 +00:00
|
|
|
*/
|
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
#if defined(OPENSSL)
|
|
|
|
|
1999-09-27 16:55:45 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
1999-10-27 20:46:33 +00:00
|
|
|
#include <ctype.h>
|
1999-09-27 16:55:45 +00:00
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
#include <isc/string.h>
|
2000-04-28 01:12:23 +00:00
|
|
|
#include <isc/util.h>
|
1999-09-27 16:55:45 +00:00
|
|
|
|
2000-05-02 03:54:17 +00:00
|
|
|
#include <dst/result.h>
|
|
|
|
|
1999-09-27 16:55:45 +00:00
|
|
|
#include "dst_internal.h"
|
|
|
|
#include "dst_parse.h"
|
|
|
|
|
|
|
|
#include <openssl/dh.h>
|
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
#define PRIME768 "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088" \
|
|
|
|
"A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25" \
|
|
|
|
"F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A63A3620FFFFFFFFFFFFFFFF"
|
1999-09-27 16:55:45 +00:00
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
#define PRIME1024 "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E08" \
|
|
|
|
"8A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF2" \
|
|
|
|
"5F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406" \
|
|
|
|
"B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF"
|
1999-09-27 16:55:45 +00:00
|
|
|
|
|
|
|
static struct dst_func openssldh_functions;
|
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
static isc_result_t
|
|
|
|
dst_openssldh_computesecret(const dst_key_t *pub, const dst_key_t *priv,
|
|
|
|
isc_buffer_t *secret);
|
|
|
|
|
|
|
|
static isc_boolean_t
|
|
|
|
dst_openssldh_compare(const dst_key_t *key1, const dst_key_t *key2);
|
|
|
|
|
|
|
|
static isc_boolean_t
|
|
|
|
dst_openssldh_paramcompare(const dst_key_t *key1, const dst_key_t *key2);
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
dst_openssldh_generate(dst_key_t *key, int generator, isc_mem_t *mctx);
|
|
|
|
|
|
|
|
static isc_boolean_t
|
|
|
|
dst_openssldh_isprivate(const dst_key_t *key);
|
|
|
|
|
|
|
|
static void
|
|
|
|
dst_openssldh_destroy(void *key, isc_mem_t *mctx);
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
dst_openssldh_to_dns(const dst_key_t *in_key, isc_buffer_t *data);
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
dst_openssldh_from_dns(dst_key_t *key, isc_buffer_t *data, isc_mem_t *mctx);
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
dst_openssldh_to_file(const dst_key_t *key);
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
dst_openssldh_from_file(dst_key_t *key, const isc_uint16_t id,
|
|
|
|
isc_mem_t *mctx);
|
|
|
|
|
|
|
|
static void
|
|
|
|
uint16_toregion(isc_uint16_t val, isc_region_t *region);
|
|
|
|
|
|
|
|
static isc_uint16_t
|
|
|
|
uint16_fromregion(isc_region_t *region);
|
|
|
|
|
|
|
|
static void
|
|
|
|
BN_fromhex(BIGNUM *b, const char *str);
|
1999-09-27 16:55:45 +00:00
|
|
|
|
1999-10-27 20:46:33 +00:00
|
|
|
static BIGNUM bn2, bn768, bn1024;
|
1999-09-27 16:55:45 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* dst_s_openssldh_init()
|
|
|
|
* Sets up function pointers for OpenSSL related functions
|
|
|
|
*/
|
|
|
|
void
|
2000-05-08 14:38:29 +00:00
|
|
|
dst_s_openssldh_init(void) {
|
1999-09-27 16:55:45 +00:00
|
|
|
REQUIRE(dst_t_func[DST_ALG_DH] == NULL);
|
|
|
|
dst_t_func[DST_ALG_DH] = &openssldh_functions;
|
|
|
|
memset(&openssldh_functions, 0, sizeof(struct dst_func));
|
|
|
|
openssldh_functions.sign = NULL;
|
|
|
|
openssldh_functions.verify = NULL;
|
|
|
|
openssldh_functions.computesecret = dst_openssldh_computesecret;
|
|
|
|
openssldh_functions.compare = dst_openssldh_compare;
|
|
|
|
openssldh_functions.paramcompare = dst_openssldh_paramcompare;
|
|
|
|
openssldh_functions.generate = dst_openssldh_generate;
|
|
|
|
openssldh_functions.isprivate = dst_openssldh_isprivate;
|
|
|
|
openssldh_functions.destroy = dst_openssldh_destroy;
|
|
|
|
openssldh_functions.to_dns = dst_openssldh_to_dns;
|
|
|
|
openssldh_functions.from_dns = dst_openssldh_from_dns;
|
|
|
|
openssldh_functions.to_file = dst_openssldh_to_file;
|
|
|
|
openssldh_functions.from_file = dst_openssldh_from_file;
|
|
|
|
CRYPTO_set_mem_functions(dst_mem_alloc, dst_mem_realloc, dst_mem_free);
|
|
|
|
|
1999-10-27 20:46:33 +00:00
|
|
|
BN_init(&bn2);
|
|
|
|
BN_init(&bn768);
|
|
|
|
BN_init(&bn1024);
|
|
|
|
BN_set_word(&bn2, 2);
|
|
|
|
BN_fromhex(&bn768, PRIME768);
|
|
|
|
BN_fromhex(&bn1024, PRIME1024);
|
1999-09-27 16:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
1999-10-20 22:14:15 +00:00
|
|
|
* ISC_R_SUCCESS Success
|
|
|
|
* !ISC_R_SUCCESS Failure
|
1999-09-27 16:55:45 +00:00
|
|
|
*/
|
2000-03-06 20:06:01 +00:00
|
|
|
static isc_result_t
|
1999-09-27 16:55:45 +00:00
|
|
|
dst_openssldh_computesecret(const dst_key_t *pub, const dst_key_t *priv,
|
|
|
|
isc_buffer_t *secret)
|
|
|
|
{
|
|
|
|
DH *dhpub, *dhpriv;
|
|
|
|
int ret;
|
|
|
|
isc_region_t r;
|
|
|
|
unsigned int len;
|
|
|
|
|
|
|
|
REQUIRE(pub->opaque != NULL);
|
|
|
|
REQUIRE(priv->opaque != NULL);
|
|
|
|
|
|
|
|
dhpub = (DH *) pub->opaque;
|
|
|
|
dhpriv = (DH *) priv->opaque;
|
|
|
|
|
|
|
|
len = DH_size(dhpriv);
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_availableregion(secret, &r);
|
1999-09-27 16:55:45 +00:00
|
|
|
if (r.length < len)
|
1999-10-20 22:14:15 +00:00
|
|
|
return (ISC_R_NOSPACE);
|
1999-09-27 16:55:45 +00:00
|
|
|
ret = DH_compute_key(r.base, dhpub->pub_key, dhpriv);
|
|
|
|
if (ret == 0)
|
1999-10-20 22:14:15 +00:00
|
|
|
return (DST_R_COMPUTESECRETFAILURE);
|
1999-09-27 16:55:45 +00:00
|
|
|
isc_buffer_add(secret, len);
|
1999-10-20 22:14:15 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-09-27 16:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* dst_openssldh_isprivate
|
|
|
|
* Is this a private key?
|
|
|
|
* Parameters
|
|
|
|
* key DST KEY structure
|
|
|
|
* Returns
|
|
|
|
* ISC_TRUE
|
|
|
|
* ISC_FALSE
|
|
|
|
*/
|
|
|
|
static isc_boolean_t
|
|
|
|
dst_openssldh_isprivate(const dst_key_t *key) {
|
|
|
|
DH *dh = (DH *) key->opaque;
|
1999-10-29 12:56:58 +00:00
|
|
|
return (ISC_TF(dh != NULL && dh->priv_key != NULL));
|
1999-09-27 16:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* dst_openssldh_to_dns
|
|
|
|
* Converts key from DH to DNS distribution format
|
|
|
|
* Parameters
|
|
|
|
* key DST KEY structure
|
|
|
|
* data output data
|
|
|
|
* Returns
|
1999-10-20 22:14:15 +00:00
|
|
|
* ISC_R_SUCCESS Success
|
|
|
|
* !ISC_R_SUCCESS Failure
|
1999-09-27 16:55:45 +00:00
|
|
|
*/
|
|
|
|
|
2000-03-06 20:06:01 +00:00
|
|
|
static isc_result_t
|
1999-09-27 16:55:45 +00:00
|
|
|
dst_openssldh_to_dns(const dst_key_t *key, isc_buffer_t *data) {
|
|
|
|
DH *dh;
|
|
|
|
isc_region_t r;
|
|
|
|
isc_uint16_t dnslen, plen, glen, publen;
|
|
|
|
|
|
|
|
REQUIRE(key->opaque != NULL);
|
|
|
|
|
|
|
|
dh = (DH *) key->opaque;
|
|
|
|
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_availableregion(data, &r);
|
1999-09-27 16:55:45 +00:00
|
|
|
|
1999-10-27 20:46:33 +00:00
|
|
|
if (dh->g == &bn2 && (dh->p == &bn768 || dh->p == &bn1024)) {
|
1999-09-27 16:55:45 +00:00
|
|
|
plen = 1;
|
|
|
|
glen = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
plen = BN_num_bytes(dh->p);
|
|
|
|
glen = BN_num_bytes(dh->g);
|
|
|
|
}
|
|
|
|
publen = BN_num_bytes(dh->pub_key);
|
|
|
|
dnslen = plen + glen + publen + 6;
|
|
|
|
if (r.length < (unsigned int) dnslen)
|
1999-10-20 22:14:15 +00:00
|
|
|
return (ISC_R_NOSPACE);
|
1999-09-27 16:55:45 +00:00
|
|
|
|
|
|
|
uint16_toregion(plen, &r);
|
|
|
|
if (plen == 1) {
|
1999-10-27 20:46:33 +00:00
|
|
|
if (dh->p == &bn768)
|
1999-09-27 16:55:45 +00:00
|
|
|
*r.base = 1;
|
|
|
|
else
|
|
|
|
*r.base = 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
BN_bn2bin(dh->p, r.base);
|
|
|
|
r.base += plen;
|
|
|
|
|
|
|
|
uint16_toregion(glen, &r);
|
|
|
|
if (glen > 0)
|
|
|
|
BN_bn2bin(dh->g, r.base);
|
|
|
|
r.base += glen;
|
|
|
|
|
|
|
|
uint16_toregion(publen, &r);
|
|
|
|
BN_bn2bin(dh->pub_key, r.base);
|
|
|
|
r.base += publen;
|
|
|
|
|
|
|
|
isc_buffer_add(data, dnslen);
|
|
|
|
|
1999-10-20 22:14:15 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-09-27 16:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
1999-10-20 22:14:15 +00:00
|
|
|
* ISC_R_SUCCESS Success
|
|
|
|
* !ISC_R_SUCCESS Failure
|
1999-09-27 16:55:45 +00:00
|
|
|
*/
|
2000-03-06 20:06:01 +00:00
|
|
|
static isc_result_t
|
1999-09-27 16:55:45 +00:00
|
|
|
dst_openssldh_from_dns(dst_key_t *key, isc_buffer_t *data, isc_mem_t *mctx) {
|
|
|
|
DH *dh;
|
|
|
|
isc_region_t r;
|
|
|
|
isc_uint16_t plen, glen, publen;
|
|
|
|
int special = 0;
|
|
|
|
|
2000-05-11 22:48:12 +00:00
|
|
|
UNUSED(mctx);
|
1999-09-27 16:55:45 +00:00
|
|
|
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_remainingregion(data, &r);
|
1999-09-27 16:55:45 +00:00
|
|
|
if (r.length == 0)
|
1999-10-20 22:14:15 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-09-27 16:55:45 +00:00
|
|
|
|
|
|
|
dh = DH_new();
|
|
|
|
if (dh == NULL)
|
1999-10-20 22:14:15 +00:00
|
|
|
return (ISC_R_NOMEMORY);
|
1999-09-27 16:55:45 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Read the prime length. 1 & 2 are table entries, > 16 means a
|
|
|
|
* prime follows, otherwise an error.
|
|
|
|
*/
|
|
|
|
if (r.length < 2) {
|
|
|
|
DH_free(dh);
|
|
|
|
return (DST_R_INVALIDPUBLICKEY);
|
|
|
|
}
|
|
|
|
plen = uint16_fromregion(&r);
|
|
|
|
if (plen < 16 && plen != 1 && plen != 2) {
|
|
|
|
DH_free(dh);
|
|
|
|
return (DST_R_INVALIDPUBLICKEY);
|
|
|
|
}
|
|
|
|
if (r.length < plen) {
|
|
|
|
DH_free(dh);
|
|
|
|
return (DST_R_INVALIDPUBLICKEY);
|
|
|
|
}
|
|
|
|
if (plen == 1 || plen == 2) {
|
|
|
|
if (plen == 1)
|
|
|
|
special = *r.base++;
|
|
|
|
else
|
|
|
|
special = uint16_fromregion(&r);
|
|
|
|
switch (special) {
|
|
|
|
case 1:
|
1999-10-27 20:46:33 +00:00
|
|
|
dh->p = &bn768;
|
1999-09-27 16:55:45 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
1999-10-27 20:46:33 +00:00
|
|
|
dh->p = &bn1024;
|
1999-09-27 16:55:45 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DH_free(dh);
|
|
|
|
return (DST_R_INVALIDPUBLICKEY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dh->p = BN_bin2bn(r.base, plen, NULL);
|
|
|
|
r.base += plen;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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) {
|
|
|
|
DH_free(dh);
|
|
|
|
return (DST_R_INVALIDPUBLICKEY);
|
|
|
|
}
|
|
|
|
glen = uint16_fromregion(&r);
|
|
|
|
if (r.length < glen) {
|
|
|
|
DH_free(dh);
|
|
|
|
return (DST_R_INVALIDPUBLICKEY);
|
|
|
|
}
|
|
|
|
if (special != 0) {
|
|
|
|
if (glen == 0)
|
1999-10-27 20:46:33 +00:00
|
|
|
dh->g = &bn2;
|
1999-09-27 16:55:45 +00:00
|
|
|
else {
|
|
|
|
dh->g = BN_bin2bn(r.base, glen, NULL);
|
1999-10-27 20:46:33 +00:00
|
|
|
if (BN_cmp(dh->g, &bn2) == 0) {
|
1999-09-27 16:55:45 +00:00
|
|
|
BN_free(dh->g);
|
1999-10-27 20:46:33 +00:00
|
|
|
dh->g = &bn2;
|
1999-09-27 16:55:45 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
DH_free(dh);
|
|
|
|
return (DST_R_INVALIDPUBLICKEY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (glen == 0) {
|
|
|
|
DH_free(dh);
|
|
|
|
return (DST_R_INVALIDPUBLICKEY);
|
|
|
|
}
|
|
|
|
dh->g = BN_bin2bn(r.base, glen, NULL);
|
|
|
|
}
|
|
|
|
r.base += glen;
|
|
|
|
|
|
|
|
if (r.length < 2) {
|
|
|
|
DH_free(dh);
|
|
|
|
return (DST_R_INVALIDPUBLICKEY);
|
|
|
|
}
|
|
|
|
publen = uint16_fromregion(&r);
|
|
|
|
if (r.length < publen) {
|
|
|
|
DH_free(dh);
|
|
|
|
return (DST_R_INVALIDPUBLICKEY);
|
|
|
|
}
|
|
|
|
dh->pub_key = BN_bin2bn(r.base, publen, NULL);
|
|
|
|
r.base += publen;
|
|
|
|
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_remainingregion(data, &r);
|
1999-09-27 16:55:45 +00:00
|
|
|
key->key_id = dst_s_id_calc(r.base, plen + glen + publen + 6);
|
|
|
|
key->key_size = BN_num_bits(dh->p);
|
|
|
|
|
|
|
|
isc_buffer_forward(data, plen + glen + publen + 6);
|
|
|
|
|
|
|
|
key->opaque = (void *) dh;
|
|
|
|
|
1999-10-20 22:14:15 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-09-27 16:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* dst_openssldh_to_file
|
|
|
|
* Encodes a DH Key into the portable file format.
|
|
|
|
* Parameters
|
|
|
|
* key DST KEY structure
|
|
|
|
* Returns
|
1999-10-20 22:14:15 +00:00
|
|
|
* ISC_R_SUCCESS Success
|
|
|
|
* !ISC_R_SUCCESS Failure
|
1999-09-27 16:55:45 +00:00
|
|
|
*/
|
2000-03-06 20:06:01 +00:00
|
|
|
static isc_result_t
|
1999-09-27 16:55:45 +00:00
|
|
|
dst_openssldh_to_file(const dst_key_t *key) {
|
|
|
|
int cnt = 0;
|
|
|
|
DH *dh;
|
|
|
|
dst_private_t priv;
|
|
|
|
unsigned char bufs[4][128];
|
|
|
|
|
|
|
|
if (key->opaque == NULL)
|
|
|
|
return (DST_R_NULLKEY);
|
|
|
|
|
|
|
|
dh = (DH *) key->opaque;
|
|
|
|
|
|
|
|
priv.elements[cnt].tag = TAG_DH_PRIME;
|
|
|
|
priv.elements[cnt].length = BN_num_bytes(dh->p);
|
|
|
|
BN_bn2bin(dh->p, bufs[cnt]);
|
|
|
|
priv.elements[cnt].data = bufs[cnt];
|
|
|
|
cnt++;
|
|
|
|
|
|
|
|
priv.elements[cnt].tag = TAG_DH_GENERATOR;
|
|
|
|
priv.elements[cnt].length = BN_num_bytes(dh->g);
|
|
|
|
BN_bn2bin(dh->g, bufs[cnt]);
|
|
|
|
priv.elements[cnt].data = bufs[cnt];
|
|
|
|
cnt++;
|
|
|
|
|
|
|
|
priv.elements[cnt].tag = TAG_DH_PRIVATE;
|
|
|
|
priv.elements[cnt].length = BN_num_bytes(dh->priv_key);
|
|
|
|
BN_bn2bin(dh->priv_key, bufs[cnt]);
|
|
|
|
priv.elements[cnt].data = bufs[cnt];
|
|
|
|
cnt++;
|
|
|
|
|
|
|
|
priv.elements[cnt].tag = TAG_DH_PUBLIC;
|
|
|
|
priv.elements[cnt].length = BN_num_bytes(dh->pub_key);
|
|
|
|
BN_bn2bin(dh->pub_key, bufs[cnt]);
|
|
|
|
priv.elements[cnt].data = bufs[cnt];
|
|
|
|
cnt++;
|
|
|
|
|
|
|
|
priv.nelements = cnt;
|
2000-05-15 21:02:39 +00:00
|
|
|
return (dst_s_write_private_key_file(key, &priv));
|
1999-09-27 16:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
1999-10-20 22:14:15 +00:00
|
|
|
* ISC_R_SUCCESS Success
|
|
|
|
* !ISC_R_SUCCESS Failure
|
1999-09-27 16:55:45 +00:00
|
|
|
*/
|
|
|
|
|
2000-03-06 20:06:01 +00:00
|
|
|
static isc_result_t
|
2000-05-08 14:38:29 +00:00
|
|
|
dst_openssldh_from_file(dst_key_t *key, const isc_uint16_t id,
|
|
|
|
isc_mem_t *mctx) {
|
1999-09-27 16:55:45 +00:00
|
|
|
dst_private_t priv;
|
2000-03-06 20:06:01 +00:00
|
|
|
isc_result_t ret;
|
1999-09-27 16:55:45 +00:00
|
|
|
isc_buffer_t dns;
|
|
|
|
isc_region_t r;
|
|
|
|
unsigned char dns_array[1024];
|
|
|
|
int i;
|
|
|
|
DH *dh = NULL;
|
|
|
|
#define DST_RET(a) {ret = a; goto err;}
|
|
|
|
|
|
|
|
/* read private key file */
|
2000-05-15 21:30:45 +00:00
|
|
|
ret = dst_s_parse_private_key_file(key, id, &priv, mctx);
|
1999-10-20 22:14:15 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
1999-09-27 16:55:45 +00:00
|
|
|
return (ret);
|
|
|
|
|
|
|
|
dh = DH_new();
|
|
|
|
if (dh == NULL)
|
1999-10-20 22:14:15 +00:00
|
|
|
DST_RET(ISC_R_NOMEMORY);
|
1999-09-27 16:55:45 +00:00
|
|
|
key->opaque = dh;
|
|
|
|
|
|
|
|
for (i=0; i < priv.nelements; i++) {
|
|
|
|
BIGNUM *bn;
|
|
|
|
bn = BN_bin2bn(priv.elements[i].data,
|
|
|
|
priv.elements[i].length, NULL);
|
|
|
|
if (bn == NULL)
|
1999-10-20 22:14:15 +00:00
|
|
|
DST_RET(ISC_R_NOMEMORY);
|
1999-09-27 16:55:45 +00:00
|
|
|
|
|
|
|
switch (priv.elements[i].tag) {
|
|
|
|
case TAG_DH_PRIME:
|
|
|
|
dh->p = bn;
|
|
|
|
break;
|
|
|
|
case TAG_DH_GENERATOR:
|
|
|
|
dh->g = bn;
|
|
|
|
break;
|
|
|
|
case TAG_DH_PRIVATE:
|
|
|
|
dh->priv_key = bn;
|
|
|
|
break;
|
|
|
|
case TAG_DH_PUBLIC:
|
|
|
|
dh->pub_key = bn;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dst_s_free_private_structure_fields(&priv, mctx);
|
|
|
|
|
|
|
|
key->key_size = BN_num_bits(dh->p);
|
|
|
|
|
|
|
|
if ((key->key_size == 768 || key->key_size == 1024) &&
|
1999-10-27 20:46:33 +00:00
|
|
|
BN_cmp(dh->g, &bn2) == 0)
|
1999-09-27 16:55:45 +00:00
|
|
|
{
|
1999-10-27 20:46:33 +00:00
|
|
|
if (key->key_size == 768 && BN_cmp(dh->p, &bn768) == 0) {
|
1999-09-27 16:55:45 +00:00
|
|
|
BN_free(dh->p);
|
|
|
|
BN_free(dh->g);
|
1999-10-27 20:46:33 +00:00
|
|
|
dh->p = &bn768;
|
|
|
|
dh->g = &bn2;
|
2000-05-24 05:10:00 +00:00
|
|
|
} else if (key->key_size == 1024 &&
|
|
|
|
BN_cmp(dh->p, &bn1024) == 0) {
|
1999-09-27 16:55:45 +00:00
|
|
|
BN_free(dh->p);
|
|
|
|
BN_free(dh->g);
|
1999-10-27 20:46:33 +00:00
|
|
|
dh->p = &bn1024;
|
|
|
|
dh->g = &bn2;
|
1999-09-27 16:55:45 +00:00
|
|
|
}
|
|
|
|
}
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_init(&dns, dns_array, sizeof(dns_array));
|
1999-09-27 16:55:45 +00:00
|
|
|
ret = dst_openssldh_to_dns(key, &dns);
|
1999-10-20 22:14:15 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
1999-09-27 16:55:45 +00:00
|
|
|
DST_RET(ret);
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_usedregion(&dns, &r);
|
1999-09-27 16:55:45 +00:00
|
|
|
key->key_id = dst_s_id_calc(r.base, r.length);
|
|
|
|
|
|
|
|
if (key->key_id != id)
|
|
|
|
DST_RET(DST_R_INVALIDPRIVATEKEY);
|
|
|
|
|
1999-10-20 22:14:15 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-09-27 16:55:45 +00:00
|
|
|
|
|
|
|
err:
|
|
|
|
key->opaque = NULL;
|
|
|
|
dst_openssldh_destroy(dh, mctx);
|
|
|
|
dst_s_free_private_structure_fields(&priv, mctx);
|
|
|
|
memset(&priv, 0, sizeof(priv));
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* dst_openssldh_destroy
|
|
|
|
* Frees all dynamically allocated structures in key.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
dst_openssldh_destroy(void *key, isc_mem_t *mctx) {
|
|
|
|
DH *dh = (DH *) key;
|
2000-05-11 22:48:12 +00:00
|
|
|
|
|
|
|
UNUSED(mctx);
|
|
|
|
|
1999-09-27 16:55:45 +00:00
|
|
|
if (dh == NULL)
|
|
|
|
return;
|
|
|
|
|
1999-10-27 20:46:33 +00:00
|
|
|
if (dh->p == &bn768 || dh->p == &bn1024)
|
1999-09-27 16:55:45 +00:00
|
|
|
dh->p = NULL;
|
1999-10-27 20:46:33 +00:00
|
|
|
if (dh->g == &bn2)
|
1999-09-27 16:55:45 +00:00
|
|
|
dh->g = NULL;
|
|
|
|
DH_free(dh);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
1999-10-20 22:14:15 +00:00
|
|
|
* ISC_R_SUCCESS Success
|
|
|
|
* !ISC_R_SUCCESS Failure
|
1999-09-27 16:55:45 +00:00
|
|
|
*/
|
|
|
|
|
2000-03-06 20:06:01 +00:00
|
|
|
static isc_result_t
|
1999-09-27 16:55:45 +00:00
|
|
|
dst_openssldh_generate(dst_key_t *key, int generator, isc_mem_t *mctx) {
|
|
|
|
DH *dh = NULL;
|
|
|
|
unsigned char dns_array[1024];
|
|
|
|
isc_buffer_t dns;
|
|
|
|
isc_region_t r;
|
|
|
|
|
2000-05-11 22:48:12 +00:00
|
|
|
UNUSED(mctx);
|
1999-09-27 16:55:45 +00:00
|
|
|
|
|
|
|
if (generator == 0) {
|
|
|
|
if (key->key_size == 768 || key->key_size == 1024) {
|
|
|
|
dh = DH_new();
|
|
|
|
if (dh == NULL)
|
1999-10-20 22:14:15 +00:00
|
|
|
return (ISC_R_NOMEMORY);
|
1999-09-27 16:55:45 +00:00
|
|
|
if (key->key_size == 768)
|
1999-10-27 20:46:33 +00:00
|
|
|
dh->p = &bn768;
|
1999-09-27 16:55:45 +00:00
|
|
|
else
|
1999-10-27 20:46:33 +00:00
|
|
|
dh->p = &bn1024;
|
|
|
|
dh->g = &bn2;
|
1999-09-27 16:55:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
generator = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (generator != 0)
|
|
|
|
dh = DH_generate_parameters(key->key_size, generator,
|
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
if (dh == NULL)
|
|
|
|
return (DST_R_INVALIDPARAM);
|
|
|
|
|
|
|
|
if (DH_generate_key(dh) == 0) {
|
|
|
|
DH_free(dh);
|
1999-10-20 22:14:15 +00:00
|
|
|
return (ISC_R_NOMEMORY);
|
1999-09-27 16:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
key->opaque = dh;
|
|
|
|
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_init(&dns, dns_array, sizeof(dns_array));
|
1999-09-27 16:55:45 +00:00
|
|
|
dst_openssldh_to_dns(key, &dns);
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_usedregion(&dns, &r);
|
1999-09-27 16:55:45 +00:00
|
|
|
key->key_id = dst_s_id_calc(r.base, r.length);
|
|
|
|
|
1999-10-20 22:14:15 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-09-27 16:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* 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
|
|
|
|
dst_openssldh_compare(const dst_key_t *key1, const dst_key_t *key2) {
|
|
|
|
int status;
|
|
|
|
DH *dh1, *dh2;
|
|
|
|
|
|
|
|
dh1 = (DH *) key1->opaque;
|
|
|
|
dh2 = (DH *) key2->opaque;
|
|
|
|
|
|
|
|
if (dh1 == NULL && dh2 == NULL)
|
1999-10-20 22:14:15 +00:00
|
|
|
return (ISC_TRUE);
|
1999-09-27 16:55:45 +00:00
|
|
|
else if (dh1 == NULL || dh2 == NULL)
|
|
|
|
return (ISC_FALSE);
|
|
|
|
|
|
|
|
status = BN_cmp(dh1->p, dh2->p) ||
|
|
|
|
BN_cmp(dh1->g, dh2->g) ||
|
|
|
|
BN_cmp(dh1->pub_key, dh2->pub_key);
|
|
|
|
|
|
|
|
if (status != 0)
|
|
|
|
return (ISC_FALSE);
|
|
|
|
|
|
|
|
if (dh1->priv_key != NULL || dh2->priv_key != NULL) {
|
|
|
|
if (dh1->priv_key == NULL || dh2->priv_key == NULL)
|
|
|
|
return (ISC_FALSE);
|
1999-10-05 15:06:37 +00:00
|
|
|
if (BN_cmp(dh1->priv_key, dh2->priv_key) != 0)
|
1999-09-27 16:55:45 +00:00
|
|
|
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
|
|
|
|
dst_openssldh_paramcompare(const dst_key_t *key1, const dst_key_t *key2) {
|
|
|
|
int status;
|
|
|
|
DH *dh1, *dh2;
|
|
|
|
|
|
|
|
dh1 = (DH *) key1->opaque;
|
|
|
|
dh2 = (DH *) key2->opaque;
|
|
|
|
|
|
|
|
if (dh1 == NULL && dh2 == NULL)
|
1999-10-20 22:14:15 +00:00
|
|
|
return (ISC_TRUE);
|
1999-09-27 16:55:45 +00:00
|
|
|
else if (dh1 == NULL || dh2 == NULL)
|
|
|
|
return (ISC_FALSE);
|
|
|
|
|
|
|
|
status = BN_cmp(dh1->p, dh2->p) ||
|
|
|
|
BN_cmp(dh1->g, dh2->g);
|
|
|
|
|
|
|
|
if (status != 0)
|
|
|
|
return (ISC_FALSE);
|
|
|
|
return (ISC_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
uint16_toregion(isc_uint16_t val, isc_region_t *region) {
|
|
|
|
*region->base++ = (val & 0xff00) >> 8;
|
|
|
|
*region->base++ = (val & 0x00ff);
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_uint16_t
|
|
|
|
uint16_fromregion(isc_region_t *region) {
|
|
|
|
isc_uint16_t val;
|
|
|
|
unsigned char *cp = region->base;
|
|
|
|
|
|
|
|
val = ((unsigned int)(cp[0])) << 8;
|
|
|
|
val |= ((unsigned int)(cp[1]));
|
|
|
|
|
|
|
|
region->base += 2;
|
1999-10-20 22:14:15 +00:00
|
|
|
return (val);
|
1999-09-27 16:55:45 +00:00
|
|
|
}
|
|
|
|
|
1999-10-27 20:46:33 +00:00
|
|
|
static void
|
|
|
|
BN_fromhex(BIGNUM *b, const char *str) {
|
|
|
|
static const char hexdigits[] = "0123456789abcdef";
|
|
|
|
unsigned char data[512];
|
|
|
|
unsigned int i;
|
|
|
|
BIGNUM *out;
|
|
|
|
|
|
|
|
RUNTIME_CHECK(strlen(str) < 1024 && strlen(str) % 2 == 0);
|
|
|
|
for (i = 0; i < strlen(str); i += 2) {
|
|
|
|
char *s;
|
|
|
|
unsigned int high, low;
|
|
|
|
|
2000-05-09 22:22:25 +00:00
|
|
|
s = strchr(hexdigits, tolower((unsigned char)str[i]));
|
1999-10-27 20:46:33 +00:00
|
|
|
RUNTIME_CHECK(s != NULL);
|
|
|
|
high = s - hexdigits;
|
|
|
|
|
2000-05-09 22:22:25 +00:00
|
|
|
s = strchr(hexdigits, tolower((unsigned char)str[i + 1]));
|
1999-10-27 20:46:33 +00:00
|
|
|
RUNTIME_CHECK(s != NULL);
|
|
|
|
low = s - hexdigits;
|
|
|
|
|
|
|
|
data[i/2] = (unsigned char)((high << 4) + low);
|
|
|
|
}
|
|
|
|
out = BN_bin2bn(data, strlen(str)/2, b);
|
|
|
|
RUNTIME_CHECK(out != NULL);
|
|
|
|
}
|
1999-09-27 16:55:45 +00:00
|
|
|
|
2000-05-02 03:54:17 +00:00
|
|
|
#endif /* OPENSSL */
|