本文整理匯總了C++中EC_KEY_set_conv_form函數的典型用法代碼示例。如果您正苦於以下問題:C++ EC_KEY_set_conv_form函數的具體用法?C++ EC_KEY_set_conv_form怎麽用?C++ EC_KEY_set_conv_form使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了EC_KEY_set_conv_form函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: EC_KEY_set_conv_form
void elliptic_curve_key::set_compressed(bool compressed)
{
if (compressed)
EC_KEY_set_conv_form(key_, POINT_CONVERSION_COMPRESSED);
else
EC_KEY_set_conv_form(key_, POINT_CONVERSION_UNCOMPRESSED);
}
示例2: main
int main(int argc, const char **argv)
{
EC_KEY *pub;
char workbuf[BUFSIZE];
const unsigned char *workbuf_p;
size_t len, i;
if (argv[1] == NULL)
{
fprintf(stderr, "usage: %s [base64key]\n", argv[0]);
return EXIT_FAILURE;
}
memset(workbuf, '\0', sizeof workbuf);
pub = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
EC_KEY_set_conv_form(pub, POINT_CONVERSION_COMPRESSED);
len = base64_decode(argv[1], workbuf, BUFSIZE);
workbuf_p = (unsigned char *) workbuf;
o2i_ECPublicKey(&pub, &workbuf_p, len);
if (!EC_KEY_check_key(pub))
{
fprintf(stderr, "Key data provided on commandline is inconsistent.\n");
return EXIT_FAILURE;
}
printf("Public key (reassembled):\n");
EC_KEY_print_fp(stdout, pub, 4);
return EXIT_SUCCESS;
}
示例3: ec_key_new_from_group
/*
* Creates a new EC_KEY on the EC group obj. arg can be an EC::Group or a String
* representing an OID.
*/
static EC_KEY *
ec_key_new_from_group(VALUE arg)
{
EC_KEY *ec;
if (rb_obj_is_kind_of(arg, cEC_GROUP)) {
EC_GROUP *group;
SafeRequire_EC_GROUP(arg, group);
if (!(ec = EC_KEY_new()))
ossl_raise(eECError, NULL);
if (!EC_KEY_set_group(ec, group)) {
EC_KEY_free(ec);
ossl_raise(eECError, NULL);
}
} else {
int nid = OBJ_sn2nid(StringValueCStr(arg));
if (nid == NID_undef)
ossl_raise(eECError, "invalid curve name");
if (!(ec = EC_KEY_new_by_curve_name(nid)))
ossl_raise(eECError, NULL);
EC_KEY_set_asn1_flag(ec, OPENSSL_EC_NAMED_CURVE);
EC_KEY_set_conv_form(ec, POINT_CONVERSION_UNCOMPRESSED);
}
return ec;
}
示例4: key_set_privkey
bool key_set_privkey(struct key *k, const void *privkey, size_t len) {
BIGNUM *res;
BIGNUM bn;
int s;
/*
* Cf bitcoin/src/base58.h
* bitcoin/src/key.h
*
* If len == 33 and privkey[32] == 1, then:
* "the public key corresponding to this private key is (to be)
* compressed."
*/
ASSERT(len == 32 || len == 33);
BN_init(&bn);
res = BN_bin2bn(privkey, 32, &bn);
ASSERT(res);
s = key_regenerate(k, &bn);
ASSERT(s);
ASSERT(EC_KEY_check_key(k->key));
EC_KEY_set_conv_form(k->key, POINT_CONVERSION_COMPRESSED);
ASSERT(k->pub_key == NULL);
ASSERT(k->pub_len == 0);
key_get_pubkey_int(k, &k->pub_key, &k->pub_len);
BN_clear_free(&bn);
ASSERT(EC_KEY_check_key(k->key));
return 1;
}
示例5: key_alloc
struct key *key_generate_new(void) {
struct key *k;
int s;
k = key_alloc();
s = EC_KEY_generate_key(k->key);
if (s == 0) {
Log(LGPFX " EC_KEY_generate_key failed.\n");
goto exit;
}
s = EC_KEY_check_key(k->key);
if (s == 0) {
Log(LGPFX " EC_KEY_check_key failed.\n");
goto exit;
}
EC_KEY_set_conv_form(k->key, POINT_CONVERSION_COMPRESSED);
ASSERT(k->pub_key == NULL);
ASSERT(k->pub_len == 0);
key_get_pubkey_int(k, &k->pub_key, &k->pub_len);
return k;
exit:
key_free(k);
return NULL;
}
示例6: FC_THROW_EXCEPTION
public_key::public_key( const compact_signature& c, const fc::sha256& digest, bool check_canonical )
{
int nV = c.data[0];
if (nV<27 || nV>=35)
FC_THROW_EXCEPTION( exception, "unable to reconstruct public key from signature" );
ECDSA_SIG *sig = ECDSA_SIG_new();
BN_bin2bn(&c.data[1],32,sig->r);
BN_bin2bn(&c.data[33],32,sig->s);
if( check_canonical )
{
FC_ASSERT( is_canonical( c ), "signature is not canonical" );
}
my->_key = EC_KEY_new_by_curve_name(NID_secp256k1);
if (nV >= 31)
{
EC_KEY_set_conv_form( my->_key, POINT_CONVERSION_COMPRESSED );
nV -= 4;
// fprintf( stderr, "compressed\n" );
}
if (detail::public_key_impl::ECDSA_SIG_recover_key_GFp(my->_key, sig, (unsigned char*)&digest, sizeof(digest), nV - 27, 0) == 1)
{
ECDSA_SIG_free(sig);
return;
}
ECDSA_SIG_free(sig);
FC_THROW_EXCEPTION( exception, "unable to reconstruct public key from signature" );
}
示例7: bp_key_secret_set
bool bp_key_secret_set(struct bp_key *key, const void *privkey_, size_t pk_len)
{
bp_key_free(key);
if (!privkey_ || pk_len != 32)
return false;
const unsigned char *privkey = privkey_;
BIGNUM *bn = BN_bin2bn(privkey, 32, BN_new());
if (!bn)
return false;
key->k = EC_KEY_new_by_curve_name(NID_secp256k1);
if (!key->k)
goto err_out;
if (!EC_KEY_regenerate_key(key->k, bn))
goto err_out;
if (!EC_KEY_check_key(key->k))
return false;
EC_KEY_set_conv_form(key->k, POINT_CONVERSION_COMPRESSED);
BN_clear_free(bn);
return true;
err_out:
bp_key_free(key);
BN_clear_free(bn);
return false;
}
示例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: EC_KEY_set_conv_form
void CECKey::GetPrivKey(CPrivKey &privkey, bool fCompressed) {
EC_KEY_set_conv_form(pkey, fCompressed ? POINT_CONVERSION_COMPRESSED : POINT_CONVERSION_UNCOMPRESSED);
int nSize = i2d_ECPrivateKey(pkey, NULL);
assert(nSize);
privkey.resize(nSize);
unsigned char* pbegin = &privkey[0];
int nSize2 = i2d_ECPrivateKey(pkey, &pbegin);
assert(nSize == nSize2);
}
示例10: bp_pubkey_set
bool bp_pubkey_set(struct bp_key *key, const void *pubkey_, size_t pk_len)
{
const unsigned char *pubkey = pubkey_;
if (!o2i_ECPublicKey(&key->k, &pubkey, pk_len))
return false;
if (pk_len == 33)
EC_KEY_set_conv_form(key->k, POINT_CONVERSION_COMPRESSED);
return true;
}
示例11: ec_key_new_secp256k1_compressed
static ec_key ec_key_new_secp256k1_compressed()
{
EC_KEY* key = EC_KEY_new_by_curve_name (NID_secp256k1);
if (key == nullptr) throw std::runtime_error ("EC_KEY_new_by_curve_name() failed");
EC_KEY_set_conv_form (key, POINT_CONVERSION_COMPRESSED);
return ec_key((ec_key::pointer_t) key);
}
示例12: 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);
}
示例13: bp_privkey_set
bool bp_privkey_set(struct bp_key *key, const void *privkey_, size_t pk_len)
{
const unsigned char *privkey = privkey_;
if (!d2i_ECPrivateKey(&key->k, &privkey, pk_len))
return false;
if (!EC_KEY_check_key(key->k))
return false;
EC_KEY_set_conv_form(key->k, POINT_CONVERSION_COMPRESSED);
return true;
}
示例14: mech_start
static int mech_start(sasl_session_t *p, char **out, size_t *out_len)
{
ecdsa_session_t *s = mowgli_alloc(sizeof(ecdsa_session_t));
p->mechdata = s;
s->pubkey = EC_KEY_new_by_curve_name(CURVE_IDENTIFIER);
s->step = ECDSA_ST_ACCNAME;
EC_KEY_set_conv_form(s->pubkey, POINT_CONVERSION_COMPRESSED);
return ASASL_MORE;
}
示例15: bp_key_generate
bool bp_key_generate(struct bp_key *key)
{
if (!key->k)
return false;
if (!EC_KEY_generate_key(key->k))
return false;
if (!EC_KEY_check_key(key->k))
return false;
EC_KEY_set_conv_form(key->k, POINT_CONVERSION_COMPRESSED);
return true;
}