本文整理汇总了C++中EC_KEY_new_by_curve_name函数的典型用法代码示例。如果您正苦于以下问题:C++ EC_KEY_new_by_curve_name函数的具体用法?C++ EC_KEY_new_by_curve_name怎么用?C++ EC_KEY_new_by_curve_name使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了EC_KEY_new_by_curve_name函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: EC_KEY_free
bool CKey::SetSecret(const CSecret& vchSecret, bool fCompressed)
{
EC_KEY_free(pkey);
pkey = EC_KEY_new_by_curve_name(NID_secp256k1);
if (pkey == NULL)
throw key_error("CKey::SetSecret() : EC_KEY_new_by_curve_name failed");
if (vchSecret.size() != 32)
throw key_error("CKey::SetSecret() : secret must be 32 bytes");
BIGNUM *bn = BN_bin2bn(&vchSecret[0],32,BN_new());
if (bn == NULL)
throw key_error("CKey::SetSecret() : BN_bin2bn failed");
if (!EC_KEY_regenerate_key(pkey,bn))
{
BN_clear_free(bn);
throw key_error("CKey::SetSecret() : EC_KEY_regenerate_key failed");
}
BN_clear_free(bn);
fSet = true;
if (fCompressed || fCompressedPubKey)
SetCompressedPubKey();
return true;
}
开发者ID:shriishrii,项目名称:csap,代码行数:22,代码来源:key.cpp
示例2: cmd_ECDHParameters
/* ECDH temporary parameters */
static int cmd_ECDHParameters(SSL_CONF_CTX *cctx, const char *value)
{
int rv = 1;
EC_KEY *ecdh;
int nid;
nid = EC_curve_nist2nid(value);
if (nid == NID_undef)
nid = OBJ_sn2nid(value);
if (nid == 0)
return 0;
ecdh = EC_KEY_new_by_curve_name(nid);
if (!ecdh)
return 0;
if (cctx->ctx)
rv = SSL_CTX_set_tmp_ecdh(cctx->ctx, ecdh);
else if (cctx->ssl)
rv = SSL_set_tmp_ecdh(cctx->ssl, ecdh);
EC_KEY_free(ecdh);
return rv > 0;
}
开发者ID:AndreV84,项目名称:openssl,代码行数:23,代码来源:ssl_conf.c
示例3: initialize_ecdh
static void
initialize_ecdh(void)
{
#if (OPENSSL_VERSION_NUMBER >= 0x0090800fL) && !defined(OPENSSL_NO_ECDH)
EC_KEY *ecdh;
int nid;
nid = OBJ_sn2nid(SSLECDHCurve);
if (!nid)
ereport(FATAL,
(errmsg("ECDH: unrecognized curve name: %s", SSLECDHCurve)));
ecdh = EC_KEY_new_by_curve_name(nid);
if (!ecdh)
ereport(FATAL,
(errmsg("ECDH: could not create key")));
SSL_CTX_set_options(SSL_context, SSL_OP_SINGLE_ECDH_USE);
SSL_CTX_set_tmp_ecdh(SSL_context, ecdh);
EC_KEY_free(ecdh);
#endif
}
开发者ID:RelentlessMike,项目名称:postgres,代码行数:22,代码来源:be-secure-openssl.c
示例4: soter_asym_ka_init
SOTER_PRIVATE_API
soter_status_t soter_asym_ka_init(soter_asym_ka_t* asym_ka_ctx, soter_asym_ka_alg_t alg)
{
EVP_PKEY* pkey;
int nid = soter_alg_to_curve_nid(alg);
if ((!asym_ka_ctx) || (0 == nid)) {
return SOTER_INVALID_PARAMETER;
}
pkey = EVP_PKEY_new();
if (!pkey) {
return SOTER_NO_MEMORY;
}
if (!EVP_PKEY_set_type(pkey, EVP_PKEY_EC)) {
EVP_PKEY_free(pkey);
return SOTER_FAIL;
}
asym_ka_ctx->pkey_ctx = EVP_PKEY_CTX_new(pkey, NULL);
if (!(asym_ka_ctx->pkey_ctx)) {
EVP_PKEY_free(pkey);
return SOTER_FAIL;
}
EC_KEY* ec = EC_KEY_new_by_curve_name(nid);
if (!ec) {
EVP_PKEY_CTX_free(asym_ka_ctx->pkey_ctx);
return SOTER_FAIL;
}
if (1 != EVP_PKEY_set1_EC_KEY(pkey, ec)) {
EVP_PKEY_CTX_free(asym_ka_ctx->pkey_ctx);
EC_KEY_free(ec);
return SOTER_FAIL;
}
EC_KEY_free(ec);
return SOTER_SUCCESS;
}
开发者ID:cossacklabs,项目名称:themis,代码行数:39,代码来源:soter_asym_ka.c
示例5: opensslecdsa_generate
static isc_result_t
opensslecdsa_generate(dst_key_t *key, int unused, void (*callback)(int)) {
isc_result_t ret;
EVP_PKEY *pkey;
EC_KEY *eckey = NULL;
int group_nid;
REQUIRE(key->key_alg == DST_ALG_ECDSA256 ||
key->key_alg == DST_ALG_ECDSA384);
UNUSED(unused);
UNUSED(callback);
if (key->key_alg == DST_ALG_ECDSA256)
group_nid = NID_X9_62_prime256v1;
else
group_nid = NID_secp384r1;
eckey = EC_KEY_new_by_curve_name(group_nid);
if (eckey == NULL)
return (dst__openssl_toresult(DST_R_OPENSSLFAILURE));
if (EC_KEY_generate_key(eckey) != 1)
DST_RET (dst__openssl_toresult(DST_R_OPENSSLFAILURE));
pkey = EVP_PKEY_new();
if (pkey == NULL)
DST_RET (ISC_R_NOMEMORY);
if (!EVP_PKEY_set1_EC_KEY(pkey, eckey)) {
EVP_PKEY_free(pkey);
DST_RET (ISC_R_FAILURE);
}
key->keydata.pkey = pkey;
ret = ISC_R_SUCCESS;
err:
if (eckey != NULL)
EC_KEY_free(eckey);
return (ret);
}
开发者ID:phonehold,项目名称:bind-9,代码行数:39,代码来源:opensslecdsa_link.c
示例6: SSL_CTX_set_options
void SSLCommon::load_ecdh_params(SSL_CTX *ctx, Logger &logger)
{
SSL_CTX_set_options(ctx,
SSL_OP_SINGLE_DH_USE |
SSL_OP_SINGLE_ECDH_USE |
SSL_OP_NO_SSLv2);
/* Cheesily pick an elliptic curve to use with elliptic curve ciphersuites.
* We just hardcode a single curve which is reasonably decent.
* See http://www.mail-archive.com/[email protected]/msg30957.html */
EC_KEY *ecdh = EC_KEY_new_by_curve_name (NID_X9_62_prime256v1);
if (! ecdh)
{
logger << "Couldn't create elliptic curve" << endl;
exitSSL("EC_KEY_new_by_curve_name(ecdh)");
}
if (1 != SSL_CTX_set_tmp_ecdh (ctx, ecdh))
{
logger << "Couldn't set ecdh parameters" << endl;
exitSSL("SSL_CTX_set_tmp_ecdh(ecdh)");
}
}
开发者ID:OlegUA,项目名称:ffead-cpp,代码行数:22,代码来源:SSLCommon.cpp
示例7: pki_pubkey_build_ecdsa
int pki_pubkey_build_ecdsa(ssh_key key, int nid, ssh_string e)
{
EC_POINT *p;
const EC_GROUP *g;
int ok;
key->ecdsa_nid = nid;
key->type_c = pki_key_ecdsa_nid_to_name(nid);
key->ecdsa = EC_KEY_new_by_curve_name(key->ecdsa_nid);
if (key->ecdsa == NULL) {
return -1;
}
g = EC_KEY_get0_group(key->ecdsa);
p = EC_POINT_new(g);
if (p == NULL) {
return -1;
}
ok = EC_POINT_oct2point(g,
p,
ssh_string_data(e),
ssh_string_len(e),
NULL);
if (!ok) {
EC_POINT_free(p);
return -1;
}
ok = EC_KEY_set_public_key(key->ecdsa, p);
if (!ok) {
EC_POINT_free(p);
}
return 0;
}
开发者ID:AudriusButkevicius,项目名称:node-libssh,代码行数:38,代码来源:pki_crypto.c
示例8: ECDSA_SIG_new
// reconstruct public key from a compact signature
// This is only slightly more CPU intensive than just verifying it.
// If this function succeeds, the recovered public key is guaranteed to be valid
// (the signature is a valid signature of the given data for that key)
bool CKey::SetCompactSignature(uint256 hash, const std::vector<unsigned char>& vchSig)
{
if (vchSig.size() != 65)
return false;
int nV = vchSig[0];
if (nV<27 || nV>=35)
return false;
ECDSA_SIG *sig = ECDSA_SIG_new();
if (!sig) return false;
#if OPENSSL_VERSION_NUMBER > 0x1000ffffL
// sig_r and sig_s are deallocated by ECDSA_SIG_free(sig);
BIGNUM *sig_r = BN_bin2bn(&vchSig[1],32,BN_new());
BIGNUM *sig_s = BN_bin2bn(&vchSig[33],32,BN_new());
if (!sig_r || !sig_s) return false;
// copy and transfer ownership to sig
ECDSA_SIG_set0(sig, sig_r, sig_s);
#else
BN_bin2bn(&vchSig[1],32,sig->r);
BN_bin2bn(&vchSig[33],32,sig->s);
#endif
EC_KEY_free(pkey);
pkey = EC_KEY_new_by_curve_name(NID_secp256k1);
if (nV >= 31)
{
SetCompressedPubKey();
nV -= 4;
}
if (ECDSA_SIG_recover_key_GFp(pkey, sig, (unsigned char*)&hash, sizeof(hash), nV - 27, 0) == 1)
{
fSet = true;
ECDSA_SIG_free(sig);
return true;
}
ECDSA_SIG_free(sig);
return false;
}
开发者ID:mikaelh2,项目名称:primecoin,代码行数:42,代码来源:key.cpp
示例9: eckey_pub_decode
static int eckey_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey) {
const uint8_t *p = NULL;
void *pval;
int ptype, pklen;
EC_KEY *eckey = NULL;
X509_ALGOR *palg;
if (!X509_PUBKEY_get0_param(NULL, &p, &pklen, &palg, pubkey)) {
return 0;
}
X509_ALGOR_get0(NULL, &ptype, &pval, palg);
if (ptype != V_ASN1_OBJECT) {
OPENSSL_PUT_ERROR(EVP, EVP_R_DECODE_ERROR);
return 0;
}
eckey = EC_KEY_new_by_curve_name(OBJ_obj2nid((ASN1_OBJECT *)pval));
if (eckey == NULL) {
OPENSSL_PUT_ERROR(EVP, ERR_R_EC_LIB);
return 0;
}
/* We have parameters now set public key */
if (!o2i_ECPublicKey(&eckey, &p, pklen)) {
OPENSSL_PUT_ERROR(EVP, EVP_R_DECODE_ERROR);
goto err;
}
EVP_PKEY_assign_EC_KEY(pkey, eckey);
return 1;
err:
if (eckey) {
EC_KEY_free(eckey);
}
return 0;
}
开发者ID:bheesham,项目名称:boringssl,代码行数:37,代码来源:p_ec_asn1.c
示例10: attempt_parse_blob
static void
attempt_parse_blob(u_char *blob, size_t len)
{
struct sshbuf *p1;
BIGNUM *bn;
EC_KEY *eck;
u_char *s;
size_t l;
u_int8_t u8;
u_int16_t u16;
u_int32_t u32;
u_int64_t u64;
p1 = sshbuf_new();
ASSERT_PTR_NE(p1, NULL);
ASSERT_INT_EQ(sshbuf_put(p1, blob, len), 0);
sshbuf_get_u8(p1, &u8);
sshbuf_get_u16(p1, &u16);
sshbuf_get_u32(p1, &u32);
sshbuf_get_u64(p1, &u64);
if (sshbuf_get_string(p1, &s, &l) == 0) {
bzero(s, l);
free(s);
}
bn = BN_new();
if (sshbuf_get_bignum1(p1, bn) == 0)
BN_clear_free(bn);
bn = BN_new();
if (sshbuf_get_bignum2(p1, bn) == 0)
BN_clear_free(bn);
eck = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
ASSERT_PTR_NE(eck, NULL);
if (sshbuf_get_eckey(p1, eck) == 0)
EC_KEY_free(eck);
sshbuf_free(p1);
}
开发者ID:hshoexer,项目名称:libopenssh,代码行数:36,代码来源:test_sshbuf_getput_fuzz.c
示例11: BN_new
// Get the AlphaCrypt default PEER public Key
EC_POINT * CAlphaCrypt::GetAlphaCryptPublicKey() {
EC_KEY * lpPublicCurve = NULL; // Curve that contains the public key
EC_POINT * pubKey = NULL; // Public key generated from the 2 coordinates
const LPSTR XCoordHex = "46668077A4449322CA896BD64901DE333156B6FEAE75ABE5D4922A039B3CD013";
const LPSTR YCoordHex = "304AB8B3F15F498094F14058A1D1EBE823BEF512D44210CC50BBD94128D2CD05";
BIGNUM * pBnX = NULL, * pBnY = NULL;
int iRet = 0;
// Allocate the 2 points structures
pBnX = BN_new(); pBnY = BN_new();
// Get X and Y Coordinate
BN_hex2bn(&pBnX, XCoordHex);
BN_hex2bn(&pBnY, YCoordHex);
// Create the curve that contains the public key
lpPublicCurve = EC_KEY_new_by_curve_name(NID_secp256k1);
// Create the generator
pubKey = EC_POINT_new(lpPublicCurve->group);
// Generate the Public key and verify it
EC_POINT_set_affine_coordinates_GFp(lpPublicCurve->group, pubKey, pBnX, pBnY, NULL);
EC_KEY_set_public_key(lpPublicCurve, pubKey);
iRet = EC_KEY_check_key(lpPublicCurve);
// Cleanup
EC_KEY_free(lpPublicCurve);
BN_free(pBnX); BN_free(pBnY);
if (iRet)
return pubKey;
else
EC_POINT_free(pubKey);
return NULL;
}
开发者ID:Brainiarc7,项目名称:TeslaDecrypt,代码行数:37,代码来源:AlphaCrypt.cpp
示例12: test_ecdsa_sign
static void test_ecdsa_sign(void)
{
EVP_PKEY *pkey;
{ /* create pkey */
EC_KEY *eckey = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
EC_KEY_generate_key(eckey);
pkey = EVP_PKEY_new();
EVP_PKEY_set1_EC_KEY(pkey, eckey);
EC_KEY_free(eckey);
}
const char *message = "hello world";
ptls_buffer_t sigbuf;
uint8_t sigbuf_small[1024];
ptls_buffer_init(&sigbuf, sigbuf_small, sizeof(sigbuf_small));
ok(do_sign(pkey, &sigbuf, ptls_iovec_init(message, strlen(message)), EVP_sha256()) == 0);
EVP_PKEY_up_ref(pkey);
ok(verify_sign(pkey, ptls_iovec_init(message, strlen(message)), ptls_iovec_init(sigbuf.base, sigbuf.off)) == 0);
ptls_buffer_dispose(&sigbuf);
EVP_PKEY_free(pkey);
}
开发者ID:fetus-hina,项目名称:h2o,代码行数:24,代码来源:openssl.c
示例13: ssl_set_ecdh_curve
void
ssl_set_ecdh_curve(SSL_CTX *ctx, const char *curve)
{
int nid;
EC_KEY *ecdh;
if (curve == NULL)
curve = SSL_ECDH_CURVE;
if ((nid = OBJ_sn2nid(curve)) == 0) {
ssl_error("ssl_set_ecdh_curve");
fatal("ssl_set_ecdh_curve: unknown curve name "
SSL_ECDH_CURVE);
}
if ((ecdh = EC_KEY_new_by_curve_name(nid)) == NULL) {
ssl_error("ssl_set_ecdh_curve");
fatal("ssl_set_ecdh_curve: unable to create curve "
SSL_ECDH_CURVE);
}
SSL_CTX_set_tmp_ecdh(ctx, ecdh);
SSL_CTX_set_options(ctx, SSL_OP_SINGLE_ECDH_USE);
EC_KEY_free(ecdh);
}
开发者ID:lucasad,项目名称:OpenSMTPD,代码行数:24,代码来源:ssl.c
示例14: ECDSA_SIG_new
// reconstruct public key from a compact signature
// This is only slightly more CPU intensive than just verifying it.
// If this function succeeds, the recovered public key is guaranteed to be valid
// (the signature is a valid signature of the given data for that key)
bool CKey::SetCompactSignature(uint256 hash, const std::vector<unsigned char> &vchSig)
{
if (vchSig.size() != 65)
return false;
int nV = vchSig[0];
if (nV < 27 || nV >= 35)
return false;
ECDSA_SIG *sig = ECDSA_SIG_new();
BN_bin2bn(&vchSig[1], 32, sig->r);
BN_bin2bn(&vchSig[33], 32, sig->s);
EC_KEY_free(pkey);
pkey = EC_KEY_new_by_curve_name(NID_secp256k1);
if (nV >= 31) {
SetCompressedPubKey();
nV -= 4;
}
if (ECDSA_SIG_recover_key_GFp(pkey, sig, (unsigned char *)&hash, sizeof(hash), nV - 27, 0) == 1) {
fSet = true;
ECDSA_SIG_free(sig);
return true;
}
return false;
}
开发者ID:66maintainer,项目名称:66coin,代码行数:28,代码来源:key.cpp
示例15: lws_context_ssl_init_ecdh_curve
static int
lws_context_ssl_init_ecdh_curve(struct lws_context_creation_info *info,
struct lws_vhost *vhost)
{
#if defined(LWS_HAVE_OPENSSL_ECDH_H) && !defined(LWS_WITH_MBEDTLS)
EC_KEY *ecdh;
int ecdh_nid;
const char *ecdh_curve = "prime256v1";
if (info->ecdh_curve)
ecdh_curve = info->ecdh_curve;
ecdh_nid = OBJ_sn2nid(ecdh_curve);
if (NID_undef == ecdh_nid) {
lwsl_err("SSL: Unknown curve name '%s'", ecdh_curve);
return 1;
}
ecdh = EC_KEY_new_by_curve_name(ecdh_nid);
if (NULL == ecdh) {
lwsl_err("SSL: Unable to create curve '%s'", ecdh_curve);
return 1;
}
SSL_CTX_set_tmp_ecdh(vhost->ssl_ctx, ecdh);
EC_KEY_free(ecdh);
SSL_CTX_set_options(vhost->ssl_ctx, SSL_OP_SINGLE_ECDH_USE);
lwsl_notice(" SSL ECDH curve '%s'\n", ecdh_curve);
#else
#if !defined(LWS_WITH_MBEDTLS)
lwsl_notice(" OpenSSL doesn't support ECDH\n");
#endif
#endif
return 0;
}
开发者ID:kubecz3k,项目名称:godot,代码行数:36,代码来源:ssl-server.c
示例16: generate_ec_key
static EP_STAT
generate_ec_key(EP_CRYPTO_KEY *key, const char *curve)
{
if (curve == NULL)
curve = ep_adm_getstrparam("libep.crypto.key.ec.curve",
"sect283r1");
int nid = OBJ_txt2nid(curve);
if (nid == NID_undef)
{
_ep_crypto_error("unknown EC curve name %s", curve);
goto fail0;
}
EC_KEY *eckey = EC_KEY_new_by_curve_name(nid);
if (eckey == NULL)
{
_ep_crypto_error("cannot create EC key");
goto fail0;
}
if (!EC_KEY_generate_key(eckey))
{
_ep_crypto_error("cannot generate EC key");
goto fail1;
}
if (EVP_PKEY_assign_EC_KEY(key, eckey) != 1)
{
_ep_crypto_error("cannot assign EC key");
goto fail1;
}
return EP_STAT_OK;
fail1:
EC_KEY_free(eckey);
fail0:
return EP_STAT_CRYPTO_KEYCREATE;
}
开发者ID:jugador87,项目名称:gdp,代码行数:36,代码来源:ep_crypto_key.c
示例17: set_ec_params
/*
* Set elliptic curve.
*/
static int set_ec_params(SSL_CTX * ctx, const char* curve_name)
{
int curve = 0;
if (curve_name) {
curve = OBJ_txt2nid(curve_name);
}
if (curve > 0) {
EC_KEY *ecdh = EC_KEY_new_by_curve_name (curve);
if (! ecdh) {
LM_ERR("unable to create EC curve\n");
return -1;
}
if (1 != SSL_CTX_set_tmp_ecdh (ctx, ecdh)) {
LM_ERR("unable to set tmp_ecdh\n");
return -1;
}
EC_KEY_free (ecdh);
}
else {
LM_ERR("unable to find the EC curve\n");
return -1;
}
return 0;
}
开发者ID:abh-gitcs1989,项目名称:opensips,代码行数:27,代码来源:tls_init.c
示例18: ecdh_init
NOEXPORT int ecdh_init(SERVICE_OPTIONS *section) {
#ifdef WITH_WOLFSSL
/* wolfSSL automatically detects ecdh parameters from ECC key file.
* No need to load explicitly */
(void)section;
return 0;
#else
EC_KEY *ecdh;
s_log(LOG_DEBUG, "ECDH initialization");
ecdh=EC_KEY_new_by_curve_name(section->curve);
if(!ecdh) {
sslerror("EC_KEY_new_by_curve_name");
s_log(LOG_ERR, "Cannot create curve %s",
OBJ_nid2ln(section->curve));
return 1; /* FAILED */
}
SSL_CTX_set_tmp_ecdh(section->ctx, ecdh);
EC_KEY_free(ecdh);
s_log(LOG_DEBUG, "ECDH initialized with curve %s",
OBJ_nid2ln(section->curve));
return 0; /* OK */
#endif /* WITH_WOLFSSL */
}
开发者ID:NickolasLapp,项目名称:stunnel,代码行数:24,代码来源:ctx.c
示例19: main
int main (int argc, const char * argv[]) {
EC_KEY *eckey;
unsigned int curve;
size_t digest_len;
char name[1024], curve_name[200], pubkey[1024], privkey[1024];
if (!read_params(name, 1024, curve_name, 200, pubkey, 1024, privkey, 1024))
return ERR_STDIN_READ;
///*debug*/printf("%s\n%s\n%s\n%s\n", name, curve_name, pubkey, privkey);
// Get curve type and digest_len
if (strcmp(curve_name, "secp112r1") == 0) {
curve = NID_secp112r1;
digest_len = 14;
} else if (strcmp(curve_name, "secp128r1") == 0) {
curve = NID_secp128r1;
digest_len = 16;
} else if (strcmp(curve_name, "secp160r1") == 0) {
curve = NID_secp160r1;
digest_len = 20;
} else {
return ERR_CURVE_UNKNOWN;
}
eckey = EC_KEY_new_by_curve_name(curve);
if (eckey == NULL)
return ERR_INIT_KEY;
// set public key
unsigned char *bin = NULL;
size_t len = hex2bin(&bin, pubkey);
if (len == 0)
return ERR_PUBLIC_KEY_DECODING;
const unsigned char *bin_copy = bin;
eckey = o2i_ECPublicKey(&eckey, &bin_copy, len);
OPENSSL_free(bin);
// set private key
len = hex2bin(&bin, privkey);
if (len == 0)
return ERR_PUBLIC_KEY_DECODING;
bin_copy = bin;
eckey = d2i_ECPrivateKey(&eckey, &bin_copy, len);
OPENSSL_free(bin);
// check keys
if (!EC_KEY_check_key(eckey))
return ERR_WRONG_KEYS;
// calculate sha-1
unsigned char digest[digest_len];
el_compute_digest(name, digest, digest_len);
// sign
ECDSA_SIG *sig = ECDSA_do_sign(digest, digest_len, eckey);
if (sig == NULL)
return ERR_SIGNING;
size_t rlen = BN_num_bytes(sig->r);
size_t slen = BN_num_bytes(sig->s);
size_t binlen = rlen + slen;
bin = OPENSSL_malloc(binlen);
bzero(bin, binlen);
BN_bn2bin(sig->r, bin);
BN_bn2bin(sig->s, bin + rlen); // join two values into bin
ECDSA_SIG_free(sig);
size_t b32len = el_base32_encode_buffer_size(binlen);
char *base32 = OPENSSL_malloc(b32len);
bzero(base32, b32len);
el_base32_encode(bin, binlen, base32, b32len);
printf("%s", base32);
OPENSSL_free(bin);
OPENSSL_free(base32);
return 0;
}
开发者ID:nicroto,项目名称:ellipticlicense,代码行数:82,代码来源:main.c
示例20: buffer_get_string_msg
Key *key_private_deserialize(buffer_t *blob)
{
int success = 0;
char *type_name = NULL;
Key *k = NULL;
unsigned int pklen, sklen;
int type;
type_name = buffer_get_string_msg(blob, NULL);
if (type_name == NULL)
goto error;
type = get_keytype_from_name(type_name);
k = key_new_private(type);
switch (type) {
case KEY_RSA:
buffer_get_bignum2_msg(blob, k->rsa->n);
buffer_get_bignum2_msg(blob, k->rsa->e);
buffer_get_bignum2_msg(blob, k->rsa->d);
buffer_get_bignum2_msg(blob, k->rsa->iqmp);
buffer_get_bignum2_msg(blob, k->rsa->p);
buffer_get_bignum2_msg(blob, k->rsa->q);
/* Generate additional parameters */
rsa_generate_additional_parameters(k->rsa);
break;
case KEY_DSA:
buffer_get_bignum2_msg(blob, k->dsa->p);
buffer_get_bignum2_msg(blob, k->dsa->q);
buffer_get_bignum2_msg(blob, k->dsa->g);
buffer_get_bignum2_msg(blob, k->dsa->pub_key);
buffer_get_bignum2_msg(blob, k->dsa->priv_key);
break;
case KEY_ECDSA256:
case KEY_ECDSA384:
case KEY_ECDSA521:
{
int success = 0;
unsigned int nid;
char *curve = NULL;
ssh_keytype skt;
BIGNUM *exponent = NULL;
EC_POINT *q = NULL;
nid = keytype_to_cipher_nid(type);
curve = buffer_get_string_msg(blob, NULL);
skt = key_curve_name_to_keytype(curve);
if (nid != keytype_to_cipher_nid(skt))
goto ecdsa_error;
k->ecdsa = EC_KEY_new_by_curve_name(nid);
if (k->ecdsa == NULL)
goto ecdsa_error;
q = EC_POINT_new(EC_KEY_get0_group(k->ecdsa));
if (q == NULL)
goto ecdsa_error;
if ((exponent = BN_new()) == NULL)
goto ecdsa_error;
buffer_get_ecpoint_msg(blob,
EC_KEY_get0_group(k->ecdsa), q);
buffer_get_bignum2_msg(blob, exponent);
if (EC_KEY_set_public_key(k->ecdsa, q) != 1)
goto ecdsa_error;
if (EC_KEY_set_private_key(k->ecdsa, exponent) != 1)
goto ecdsa_error;
if (key_ec_validate_public(EC_KEY_get0_group(k->ecdsa),
EC_KEY_get0_public_key(k->ecdsa)) != 0)
goto ecdsa_error;
if (key_ec_validate_private(k->ecdsa) != 0)
goto ecdsa_error;
success = 1;
ecdsa_error:
free(curve);
if (exponent)
BN_clear_free(exponent);
if (q)
EC_POINT_free(q);
if (success == 0)
goto error;
}
break;
case KEY_ED25519:
k->ed25519_pk = buffer_get_string_msg(blob, &pklen);
k->ed25519_sk = buffer_get_string_msg(blob, &sklen);
if (pklen != ED25519_PK_SZ)
goto error;
if (sklen != ED25519_SK_SZ)
goto error;
break;
default:
goto error;
//.........这里部分代码省略.........
开发者ID:pakls,项目名称:teraterm-ttssh2,代码行数:101,代码来源:key.c
注:本文中的EC_KEY_new_by_curve_name函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论