コード例 #1
0
// Set from Botan representation
void BotanECDHPrivateKey::setFromBotan(const Botan::ECDH_PrivateKey* eckey)
{
	ByteString ec = BotanUtil::ecGroup2ByteString(eckey->domain());
	setEC(ec);
	ByteString d = BotanUtil::bigInt2ByteString(eckey->private_value());
	setD(d);
}
コード例 #2
0
// Set from Botan representation
void BotanECDHPrivateKey::setFromBotan(const Botan::ECDH_PrivateKey* inECKEY)
{
	ByteString inEC = BotanUtil::ecGroup2ByteString(inECKEY->domain());
	setEC(inEC);
	ByteString inD = BotanUtil::bigInt2ByteString(inECKEY->private_value());
	setD(inD);
}
コード例 #3
0
// Set from Botan representation
void BotanGOSTPrivateKey::setFromBotan(const Botan::GOST_3410_PrivateKey* inECKEY)
{
	ByteString inEC = BotanUtil::ecGroup2ByteString(inECKEY->domain());
	setEC(inEC);
	ByteString inD = BotanUtil::bigInt2ByteStringPrefix(inECKEY->private_value(), 32);
	setD(inD);
}
コード例 #4
0
// Set from Botan representation
void BotanEDPublicKey::setFromBotan(const Botan::Public_Key* inEDKEY)
{
	Botan::OID oid;
	std::vector<uint8_t> pub;

	for (;;)
	{
		const Botan::Curve25519_PublicKey* x25519 = dynamic_cast<const Botan::Curve25519_PublicKey*>(inEDKEY);
		if (x25519) {
			oid = x25519_oid;
			pub = x25519->public_value();
			break;
		}
		const Botan::Ed25519_PublicKey* ed25519 = dynamic_cast<const Botan::Ed25519_PublicKey*>(inEDKEY);
		if (ed25519) {
			oid = ed25519_oid;
			pub = ed25519->get_public_key();
			break;
		}
		return;
	}
	ByteString inEC = BotanUtil::oid2ByteString(oid);
	setEC(inEC);
	ByteString inA;
	inA.resize(pub.size());
	memcpy(&inA[0], &pub[0], pub.size());
	setA(DERUTIL::raw2Octet(inA));
}
コード例 #5
0
// Set from OpenSSL representation
void OSSLGOSTPrivateKey::setFromOSSL(const EVP_PKEY* pkey)
{
	const EC_KEY* eckey = (const EC_KEY*) EVP_PKEY_get0((EVP_PKEY*) pkey);
	const BIGNUM* priv = EC_KEY_get0_private_key(eckey);
	setD(OSSL::bn2ByteString(priv));

	ByteString inEC;
	int nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(eckey));
	inEC.resize(i2d_ASN1_OBJECT(OBJ_nid2obj(nid), NULL));
	unsigned char *p = &inEC[0];
	i2d_ASN1_OBJECT(OBJ_nid2obj(nid), &p);
	setEC(inEC);
}
コード例 #6
0
bool ECParameters::deserialise(ByteString& serialised)
{
	ByteString dEC = ByteString::chainDeserialise(serialised);

	if (dEC.size() == 0)
	{
		return false;
	}

	setEC(dEC);

	return true;
}
コード例 #7
0
// Set from OpenSSL representation
void OSSLECPublicKey::setFromOSSL(const EC_KEY* eckey)
{
	const EC_GROUP* grp = EC_KEY_get0_group(eckey);
	if (grp != NULL)
	{
		ByteString ec = OSSL::grp2ByteString(grp);
		setEC(ec);
	}
	const EC_POINT* pub = EC_KEY_get0_public_key(eckey);
	if (pub != NULL && grp != NULL)
	{
		ByteString q = OSSL::pt2ByteString(pub, grp);
		setQ(q);
	}
}
コード例 #8
0
// Set from OpenSSL representation
void OSSLECPrivateKey::setFromOSSL(const EC_KEY* inECKEY)
{
	const EC_GROUP* grp = EC_KEY_get0_group(inECKEY);
	if (grp != NULL)
	{
		ByteString inEC = OSSL::grp2ByteString(grp);
		setEC(inEC);
	}
	const BIGNUM* pk = EC_KEY_get0_private_key(inECKEY);
	if (pk != NULL)
	{
		ByteString inD = OSSL::bn2ByteString(pk);
		setD(inD);
	}
}
コード例 #9
0
bool OSSLGOSTPrivateKey::deserialise(ByteString& serialised)
{
	ByteString dEC = ByteString::chainDeserialise(serialised);
	ByteString dD = ByteString::chainDeserialise(serialised);

	if ((dEC.size() == 0) ||
	    (dD.size() == 0))
	{
		return false;
	}

	setEC(dEC);
	setD(dD);

	return true;
}
コード例 #10
0
bool ECPublicKey::deserialise(ByteString& serialised)
{
	ByteString dEC = ByteString::chainDeserialise(serialised);
	ByteString dQ = ByteString::chainDeserialise(serialised);

	if ((dEC.size() == 0) ||
	    (dQ.size() == 0))
	{
		return false;
	}

	setEC(dEC);
	setQ(dQ);

	return true;
}
コード例 #11
0
// Set from Botan representation
void BotanGOSTPublicKey::setFromBotan(const Botan::GOST_3410_PublicKey* inECKEY)
{
	ByteString inEC = BotanUtil::ecGroup2ByteString(inECKEY->domain());
	setEC(inEC);

	ByteString inQ = BotanUtil::ecPoint2ByteString(inECKEY->public_point()).substr(3);

	/* The points must be stored in little endian */
	const size_t length = inQ.size() / 2;
	for (size_t i = 0; i < (length / 2); i++)
	{
		std::swap(inQ[i], inQ[length-1-i]);
		std::swap(inQ[length+i], inQ[2*length-1-i]);
	}

	setQ(inQ);
}
コード例 #12
0
// Set from OpenSSL representation
void OSSLGOSTPublicKey::setFromOSSL(const EVP_PKEY* pkey)
{
	ByteString der;
	int len = i2d_PUBKEY((EVP_PKEY*) pkey, NULL);
	if (len != 37 + 64)
	{
		ERROR_MSG("bad GOST public key encoding length %d", len);
		return;
	}
	der.resize(len);
	unsigned char *p = &der[0];
	i2d_PUBKEY((EVP_PKEY*) pkey, &p);
	// can check: der is prefix + 64 bytes
	setQ(der.substr(37));

	ByteString inEC;
	const EC_KEY* eckey = (const EC_KEY*) EVP_PKEY_get0((EVP_PKEY*) pkey);
	int nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(eckey));
	inEC.resize(i2d_ASN1_OBJECT(OBJ_nid2obj(nid), NULL));
	p = &inEC[0];
	i2d_ASN1_OBJECT(OBJ_nid2obj(nid), &p);
	setEC(inEC);
}