本文整理汇总了C++中i2o_ECPublicKey函数的典型用法代码示例。如果您正苦于以下问题:C++ i2o_ECPublicKey函数的具体用法?C++ i2o_ECPublicKey怎么用?C++ i2o_ECPublicKey使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了i2o_ECPublicKey函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: eckey_pub_encode
static int eckey_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
{
EC_KEY *ec_key = pkey->pkey.ec;
void *pval = NULL;
int ptype;
unsigned char *penc = NULL, *p;
int penclen;
if (!eckey_param2type(&ptype, &pval, ec_key))
{
ECerr(EC_F_ECKEY_PUB_ENCODE, ERR_R_EC_LIB);
return 0;
}
penclen = i2o_ECPublicKey(ec_key, NULL);
if (penclen <= 0)
goto err;
penc = OPENSSL_malloc(penclen);
if (!penc)
goto err;
p = penc;
penclen = i2o_ECPublicKey(ec_key, &p);
if (penclen <= 0)
goto err;
if (X509_PUBKEY_set0_param(pk, OBJ_nid2obj(EVP_PKEY_EC),
ptype, pval, penc, penclen))
return 1;
err:
if (ptype == V_ASN1_OBJECT)
ASN1_OBJECT_free(pval);
else
ASN1_STRING_free(pval);
if (penc)
OPENSSL_free(penc);
return 0;
}
示例2: opensslecdsa_todns
static isc_result_t
opensslecdsa_todns(const dst_key_t *key, isc_buffer_t *data) {
isc_result_t ret;
EVP_PKEY *pkey;
EC_KEY *eckey = NULL;
isc_region_t r;
int len;
unsigned char *cp;
unsigned char buf[DNS_KEY_ECDSA384SIZE + 1];
REQUIRE(key->keydata.pkey != NULL);
pkey = key->keydata.pkey;
eckey = EVP_PKEY_get1_EC_KEY(pkey);
if (eckey == NULL)
return (dst__openssl_toresult(ISC_R_FAILURE));
len = i2o_ECPublicKey(eckey, NULL);
/* skip form */
len--;
isc_buffer_availableregion(data, &r);
if (r.length < (unsigned int) len)
DST_RET (ISC_R_NOSPACE);
cp = buf;
if (!i2o_ECPublicKey(eckey, &cp))
DST_RET (dst__openssl_toresult(ISC_R_FAILURE));
memmove(r.base, buf + 1, len);
isc_buffer_add(data, len);
ret = ISC_R_SUCCESS;
err:
if (eckey != NULL)
EC_KEY_free(eckey);
return (ret);
}
示例3: i2o_ECPublicKey
CPubKey CKey::GetPubKey() const
{
int nSize = i2o_ECPublicKey(pkey, NULL);
if (!nSize)
throw key_error("CKey::GetPubKey() : i2o_ECPublicKey failed");
std::vector<unsigned char> vchPubKey(nSize, 0);
unsigned char* pbegin = &vchPubKey[0];
if (i2o_ECPublicKey(pkey, &pbegin) != nSize)
throw key_error("CKey::GetPubKey() : i2o_ECPublicKey returned unexpected size");
return CPubKey(vchPubKey);
}
示例4: EC_KEY_set_conv_form
void CECKey::GetPubKey(CPubKey &pubkey, bool fCompressed) {
EC_KEY_set_conv_form(pkey, fCompressed ? POINT_CONVERSION_COMPRESSED : POINT_CONVERSION_UNCOMPRESSED);
int nSize = i2o_ECPublicKey(pkey, NULL);
assert(nSize);
assert(nSize <= 65);
unsigned char c[65];
unsigned char *pbegin = c;
int nSize2 = i2o_ECPublicKey(pkey, &pbegin);
assert(nSize == nSize2);
pubkey.Set(&c[0], &c[nSize]);
}
示例5: EC_KEY_set_conv_form
void CECKey::GetPubKey(std::vector<unsigned char> &pubkey, bool fCompressed) {
EC_KEY_set_conv_form(pkey, fCompressed ? POINT_CONVERSION_COMPRESSED : POINT_CONVERSION_UNCOMPRESSED);
int nSize = i2o_ECPublicKey(pkey, NULL);
assert(nSize);
assert(nSize <= 65);
pubkey.clear();
pubkey.resize(nSize);
unsigned char *pbegin(begin_ptr(pubkey));
int nSize2 = i2o_ECPublicKey(pkey, &pbegin);
assert(nSize == nSize2);
}
示例6: i2o_ECPublicKey
data_chunk elliptic_curve_key::public_key() const
{
// same as get_private_key
int length = i2o_ECPublicKey(key_, NULL);
if (!length)
return data_chunk();
data_chunk pubkey(length, 0);
uint8_t* pubkey_begin = pubkey.data();
if (i2o_ECPublicKey(key_, &pubkey_begin) != length)
return data_chunk();
return pubkey;
}
示例7: bp_pubkey_get
bool bp_pubkey_get(struct bp_key *key, void **pubkey, size_t *pk_len)
{
if (!EC_KEY_check_key(key->k))
return false;
size_t sz = i2o_ECPublicKey(key->k, 0);
unsigned char *orig_mem, *mem = malloc(sz);
orig_mem = mem;
i2o_ECPublicKey(key->k, &mem);
*pubkey = orig_mem;
*pk_len = sz;
return true;
}
示例8: EC_KEY_set_conv_form
public_key_point_data public_key::serialize_ecc_point()const
{
public_key_point_data dat;
if( !my->_key ) return dat;
EC_KEY_set_conv_form( my->_key, POINT_CONVERSION_UNCOMPRESSED );
char* front = &dat.data[0];
i2o_ECPublicKey( my->_key, (unsigned char**)&front ); // FIXME: questionable memory handling
return dat;
}
示例9: main
int
main(int argc, const char **argv)
{
if (! libathemecore_early_init())
return EXIT_FAILURE;
BIO *out;
EC_KEY *prv;
unsigned char *workbuf, *workbuf_p;
char encbuf[BUFSIZE];
size_t len;
memset(encbuf, '\0', sizeof encbuf);
prv = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
EC_KEY_set_conv_form(prv, POINT_CONVERSION_COMPRESSED);
EC_KEY_generate_key(prv);
len = i2o_ECPublicKey(prv, NULL);
workbuf = mowgli_alloc(len);
workbuf_p = workbuf;
i2o_ECPublicKey(prv, &workbuf_p);
workbuf_p = workbuf;
if (base64_encode(workbuf_p, len, encbuf, sizeof encbuf) == (size_t) -1)
{
fprintf(stderr, "Failed to encode public key!\n");
return EXIT_FAILURE;
}
printf("Keypair:\n");
EC_KEY_print_fp(stdout, prv, 4);
printf("Private key:\n");
out = BIO_new_fp(stdout, 0);
PEM_write_bio_ECPrivateKey(out, prv, NULL, NULL, 0, NULL, NULL);
printf("Public key (atheme format):\n");
printf("%s\n", encbuf);
return EXIT_SUCCESS;
}
示例10: key_get_pubkey_int
static bool key_get_pubkey_int(struct key *k, uint8 **pub, size_t *len) {
uint8 *data;
ASSERT(pub);
*pub = NULL;
*len = 0;
if (!EC_KEY_check_key(k->key)) {
NOT_TESTED();
return 0;
}
*len = i2o_ECPublicKey(k->key, 0);
ASSERT(*len <= 65);
data = safe_malloc(*len);
*pub = data;
i2o_ECPublicKey(k->key, &data);
return 1;
}
示例11: get_PublicKey
STDMETHODIMP CBECC::get_PublicKey(VARIANT *pVal)
{
if (m_pECC == NULL)
return E_NOTIMPL;
if (!EC_KEY_check_key((EC_KEY*)m_pECC))
return E_NOTIMPL;
int nSize;
if((nSize = i2o_ECPublicKey((EC_KEY*)m_pECC, NULL)) < 0)
return E_NOTIMPL;
CBVarPtr varPtr;
varPtr.Create(nSize);
if (!i2o_ECPublicKey((EC_KEY*)m_pECC, (unsigned char **)&varPtr.m_pData))
return E_INVALIDARG;
return varPtr.GetVariant(pVal);
}
示例12: eckey_pub_encode
static int eckey_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey) {
EC_KEY *ec_key = pkey->pkey.ec;
void *pval = NULL;
int ptype;
uint8_t *penc = NULL, *p;
int penclen;
if (!eckey_param2type(&ptype, &pval, ec_key)) {
OPENSSL_PUT_ERROR(EVP, ERR_R_EC_LIB);
return 0;
}
penclen = i2o_ECPublicKey(ec_key, NULL);
if (penclen <= 0) {
goto err;
}
penc = OPENSSL_malloc(penclen);
if (!penc) {
goto err;
}
p = penc;
penclen = i2o_ECPublicKey(ec_key, &p);
if (penclen <= 0) {
goto err;
}
if (X509_PUBKEY_set0_param(pk, OBJ_nid2obj(EVP_PKEY_EC), ptype, pval, penc,
penclen)) {
return 1;
}
err:
if (ptype == V_ASN1_OBJECT) {
ASN1_OBJECT_free(pval);
} else {
ASN1_STRING_free(pval);
}
if (penc) {
OPENSSL_free(penc);
}
return 0;
}
示例13: i2d_PublicKey
int i2d_PublicKey(EVP_PKEY *key, uint8_t **outp) {
switch (key->type) {
case EVP_PKEY_RSA:
return i2d_RSAPublicKey(key->pkey.rsa, outp);
case EVP_PKEY_DSA:
return i2d_DSAPublicKey(key->pkey.dsa, outp);
case EVP_PKEY_EC:
return i2o_ECPublicKey(key->pkey.ec, outp);
default:
OPENSSL_PUT_ERROR(EVP, EVP_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
return -1;
}
}
示例14: serialize_ec_point
void serialize_ec_point (ec_point const& point, std::uint8_t* ptr)
{
ec_key key = ec_key_new_secp256k1_compressed();
if (EC_KEY_set_public_key((EC_KEY*) key.get(), point.get()) <= 0)
{
throw std::runtime_error ("EC_KEY_set_public_key() failed");
}
int const size = i2o_ECPublicKey ((EC_KEY*) key.get(), &ptr);
assert (size <= 33);
(void) size;
}
示例15: ucrypto_ec_get_public_key_nif
ERL_NIF_TERM ucrypto_ec_get_public_key_nif(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
int length;
struct ec_key_handle *handle = NULL;
ErlNifBinary public_key;
if (! enif_get_resource(env, argv[0], ec_key_resource, (void **)&handle))
return enif_make_badarg(env);
if (! handle->key)
return enif_make_tuple2(env, ATOM_ERROR, ATOM_UNINITIALIZED_KEY);
length = i2o_ECPublicKey(handle->key, NULL);
if (! length)
return ATOM_ERROR;
enif_alloc_binary(length, &public_key);
if (i2o_ECPublicKey(handle->key, &public_key.data) != length)
return ATOM_ERROR;
return enif_make_binary(env, &public_key);
}