opensslgost_link.c revision 0c27b3fe77ac1d5094ba3521e8142d9e7973133f
/*
* Copyright (C) 2010-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/.
*/
#include <config.h>
#if defined(OPENSSL) && defined(HAVE_OPENSSL_GOST)
#include "dst_internal.h"
#include "dst_openssl.h"
#include "dst_parse.h"
#include "dst_gost.h"
static const EVP_MD *opensslgost_digest;
return (opensslgost_digest);
}
/* ISC methods */
int ret;
return (DST_R_CRYPTOFAILURE);
if (ret != 1)
return (DST_R_CRYPTOFAILURE);
return (ISC_R_SUCCESS);
}
void
}
unsigned int len)
{
int ret;
if (ret != 1)
return (DST_R_CRYPTOFAILURE);
return (ISC_R_SUCCESS);
}
int ret;
if (ret != 1)
return (DST_R_CRYPTOFAILURE);
return (ISC_R_SUCCESS);
}
/* DST methods */
isc_buffer_t *data);
static isc_result_t
return (DST_R_OPENSSLFAILURE);
if (evp_md_ctx == NULL)
return (ISC_R_NOMEMORY);
return (ISC_R_FAILURE);
}
return (ISC_R_SUCCESS);
}
static void
if (evp_md_ctx != NULL) {
}
}
static isc_result_t
return (ISC_R_FAILURE);
return (ISC_R_SUCCESS);
}
static isc_result_t
isc_region_t r;
unsigned int siglen = 0;
return (ISC_R_NOSPACE);
return (ISC_R_FAILURE);
return (ISC_R_SUCCESS);
}
static isc_result_t
int status = 0;
switch (status) {
case 1:
return (ISC_R_SUCCESS);
case 0:
return (dst__openssl_toresult(DST_R_VERIFYFAILURE));
default:
"EVP_VerifyFinal",
}
}
static isc_boolean_t
return (ISC_TRUE);
return (ISC_FALSE);
return (ISC_FALSE);
return (ISC_TRUE);
}
static int
{
union {
void *dptr;
void (*fptr)(int);
} u;
int p;
p = EVP_PKEY_CTX_get_keygen_info(ctx, 0);
u.fptr(p);
return (1);
}
static isc_result_t
union {
void *dptr;
void (*fptr)(int);
} u;
}
if (EVP_PKEY_keygen_init(ctx) <= 0)
return (ISC_R_SUCCESS);
err:
return (ret);
}
static isc_boolean_t
}
static void
}
unsigned char gost_prefix[37] = {
0x30, 0x63, 0x30, 0x1c, 0x06, 0x06, 0x2a, 0x85,
0x03, 0x02, 0x02, 0x13, 0x30, 0x12, 0x06, 0x07,
0x2a, 0x85, 0x03, 0x02, 0x02, 0x23, 0x01, 0x06,
0x07, 0x2a, 0x85, 0x03, 0x02, 0x02, 0x1e, 0x01,
0x03, 0x43, 0x00, 0x04, 0x40
};
static isc_result_t
isc_region_t r;
int len;
if (r.length < 64)
return (ISC_R_NOSPACE);
p = der;
return (ISC_R_SUCCESS);
}
static isc_result_t
isc_region_t r;
const unsigned char *p;
if (r.length == 0)
return (ISC_R_SUCCESS);
if (r.length != 64)
return (DST_R_INVALIDPUBLICKEY);
p = der;
return (dst__openssl_toresult2("d2i_PUBKEY",
return (ISC_R_SUCCESS);
}
#ifdef PREFER_GOSTASN1
static isc_result_t
unsigned char *der, *p;
int len;
return (DST_R_NULLKEY);
}
return (ISC_R_NOMEMORY);
p = der;
goto fail;
}
fail:
return (result);
}
#else
static isc_result_t
return (DST_R_NULLKEY);
}
return (dst__openssl_toresult(DST_R_OPENSSLFAILURE));
return (ISC_R_FAILURE);
return (ISC_R_NOMEMORY);
return (ret);
}
#endif
static unsigned char gost_dummy_key[71] = {
0x30, 0x45, 0x02, 0x01, 0x00, 0x30, 0x1c, 0x06,
0x06, 0x2a, 0x85, 0x03, 0x02, 0x02, 0x13, 0x30,
0x12, 0x06, 0x07, 0x2a, 0x85, 0x03, 0x02, 0x02,
0x23, 0x01, 0x06, 0x07, 0x2a, 0x85, 0x03, 0x02,
0x02, 0x1e, 0x01, 0x04, 0x22, 0x02, 0x20, 0x1b,
0x3f, 0x94, 0xf7, 0x1a, 0x5f, 0x2f, 0xe7, 0xe5,
0x74, 0x0b, 0x8c, 0xd4, 0xb7, 0x18, 0xdd, 0x65,
0x68, 0x26, 0xd1, 0x54, 0xfb, 0x77, 0xba, 0x63,
0x72, 0xd9, 0xf0, 0x63, 0x87, 0xe0, 0xd6
};
static isc_result_t
const unsigned char *p;
/* read private key file */
if (ret != ISC_R_SUCCESS)
return (ret);
return (ISC_R_SUCCESS);
}
"d2i_PrivateKey",
} else {
}
/* can't create directly the whole key */
p = gost_dummy_key;
(long) sizeof(gost_dummy_key)) == NULL)
"d2i_PrivateKey",
return (dst__openssl_toresult(DST_R_OPENSSLFAILURE));
/* have to (re)set the public key */
#ifdef notyet
(void) gost2001_compute_public(eckey);
#else
#endif
}
return (ISC_R_SUCCESS);
err:
return (ret);
}
static void
opensslgost_cleanup(void) {
if (e != NULL) {
ENGINE_finish(e);
ENGINE_free(e);
e = NULL;
}
}
static dst_func_t opensslgost_functions = {
NULL, /*%< createctx2 */
NULL, /*%< verify2 */
NULL, /*%< computesecret */
NULL, /*%< paramcompare */
NULL, /*%< fromlabel */
NULL, /*%< dump */
NULL /*%< restore */
};
/* check if the gost engine works properly */
e = ENGINE_by_id("gost");
if (e == NULL)
return (dst__openssl_toresult2("ENGINE_by_id",
if (ENGINE_init(e) <= 0) {
ENGINE_free(e);
e = NULL;
return (dst__openssl_toresult2("ENGINE_init",
}
/* better than to rely on digest_gost symbol */
if (opensslgost_digest == NULL)
/* from openssl.cnf */
if (ENGINE_register_pkey_asn1_meths(e) <= 0)
"ENGINE_register_pkey_asn1_meths",
if (ENGINE_ctrl_cmd_string(e,
"CRYPT_PARAMS",
"id-Gost28147-89-CryptoPro-A-ParamSet",
0) <= 0)
return (ISC_R_SUCCESS);
err:
ENGINE_finish(e);
ENGINE_free(e);
e = NULL;
return (ret);
}
#else /* HAVE_OPENSSL_GOST */
#endif /* HAVE_OPENSSL_GOST */
/*! \file */