#include <openssl/ecdsa.h>
#include <openssl/obj_mac.h>
-#include <openssl/ssl.h>
-#include <openssl/ecdh.h>
#include "key.h"
#include "base58.h"
-#include "ies.h"
// Generate a private key from just the secret parameter
int EC_KEY_regenerate_key(EC_KEY *eckey, BIGNUM *priv_key)
return true;
}
+// Initialize from octets stream
+bool CPoint::setPubKey(const CPubKey &vchPubKey)
+{
+ return setBytes(vchPubKey.Raw());
+}
+
// Serialize to octets stream
bool CPoint::getBytes(std::vector<unsigned char> &vchBytes)
{
EC_KEY_free(eckey);
CPoint point;
- if (!point.setBytes(pubKeyL.Raw())) {
+ if (!point.setPubKey(pubKeyL)) {
throw key_error("CMalleablePubKey::GetVariant() : Unable to decode L value");
}
bnHash.setuint160(Hash160(vchLr));
CPoint pointH;
- pointH.setBytes(pubKeyH.Raw());
+ pointH.setPubKey(pubKeyH);
CPoint P;
// Calculate P = Hash(L*r)*G + H
vchPubKeyVariant = CPubKey(vchResult);
}
-std::string CMalleablePubKey::ToString()
+std::string CMalleablePubKey::ToString() const
{
CDataStream ssKey(SER_NETWORK, PROTOCOL_VERSION);
ssKey << *this;
return EncodeBase58Check(vch);
}
+std::vector<unsigned char> CMalleablePubKey::Raw() const
+{
+ CDataStream ssKey(SER_NETWORK, PROTOCOL_VERSION);
+ ssKey << *this;
+ std::vector<unsigned char> vch(ssKey.begin(), ssKey.end());
+
+ return vch;
+}
+
bool CMalleablePubKey::SetString(const std::string& strMalleablePubKey)
{
std::vector<unsigned char> vchTemp;
SetSecrets(L, H);
}
+/*
CMalleableKey& CMalleableKey::operator=(const CMalleableKey &b)
{
SetSecrets(b.vchSecretL, b.vchSecretH);
return (*this);
}
+*/
CMalleableKey::~CMalleableKey()
{
Reset();
CKey L, H;
- if (!L.SetSecret(pvchSecretL, true) || !H.SetSecret(pvchSecretH, true))
+ if (pvchSecretL.size() != 32 || pvchSecretH.size() != 32 || !L.SetSecret(pvchSecretL, true) || !H.SetSecret(pvchSecretH, true))
{
nVersion = 0;
return false;
}
// Check ownership
-bool CMalleableKey::CheckKeyVariant(const CPubKey &R, const CPubKey &vchPubKeyVariant)
+bool CMalleableKey::CheckKeyVariant(const CPubKey &R, const CPubKey &vchPubKeyVariant) const
{
if (IsNull()) {
throw key_error("CMalleableKey::CheckKeyVariant() : Attempting to run on NULL key object.");
}
CPoint point_R;
- if (!point_R.setBytes(R.Raw())) {
+ if (!point_R.setPubKey(R)) {
throw key_error("CMalleableKey::CheckKeyVariant() : Unable to decode R value");
}
std::vector<unsigned char> vchPubKeyH = H.GetPubKey().Raw();
CPoint point_H;
- if (!point_H.setBytes(vchPubKeyH)) {
+ if (!point_H.setPubKey(vchPubKeyH)) {
throw key_error("CMalleableKey::CheckKeyVariant() : Unable to decode H value");
}
CPoint point_P;
- if (!point_P.setBytes(vchPubKeyVariant.Raw())) {
+ if (!point_P.setPubKey(vchPubKeyVariant)) {
throw key_error("CMalleableKey::CheckKeyVariant() : Unable to decode P value");
}
}
// Check ownership and restore private key
-bool CMalleableKey::CheckKeyVariant(const CPubKey &R, const CPubKey &vchPubKeyVariant, CKey &privKeyVariant)
+bool CMalleableKey::CheckKeyVariant(const CPubKey &R, const CPubKey &vchPubKeyVariant, CKey &privKeyVariant) const
{
if (IsNull()) {
throw key_error("CMalleableKey::CheckKeyVariant() : Attempting to run on NULL key object.");
}
CPoint point_R;
- if (!point_R.setBytes(R.Raw())) {
+ if (!point_R.setPubKey(R)) {
throw key_error("CMalleableKey::CheckKeyVariant() : Unable to decode R value");
}
std::vector<unsigned char> vchPubKeyH = H.GetPubKey().Raw();
CPoint point_H;
- if (!point_H.setBytes(vchPubKeyH)) {
+ if (!point_H.setPubKey(vchPubKeyH)) {
throw key_error("CMalleableKey::CheckKeyVariant() : Unable to decode H value");
}
CPoint point_P;
- if (!point_P.setBytes(vchPubKeyVariant.Raw())) {
+ if (!point_P.setPubKey(vchPubKeyVariant)) {
throw key_error("CMalleableKey::CheckKeyVariant() : Unable to decode P value");
}
return true;
}
-std::string CMalleableKey::ToString()
+std::string CMalleableKey::ToString() const
{
CDataStream ssKey(SER_NETWORK, PROTOCOL_VERSION);
ssKey << *this;
return EncodeBase58Check(vch);
}
+std::vector<unsigned char> CMalleableKey::Raw() const
+{
+ CDataStream ssKey(SER_NETWORK, PROTOCOL_VERSION);
+ ssKey << *this;
+ std::vector<unsigned char> vch(ssKey.begin(), ssKey.end());
+
+ return vch;
+}
+
bool CMalleableKey::SetString(const std::string& strMutableKey)
{
std::vector<unsigned char> vchTemp;
CMalleableKeyView::CMalleableKeyView(const CMalleableKey &b)
{
+ if (b.vchSecretL.size() != 32)
+ throw key_error("CMalleableKeyView::CMalleableKeyView() : L size must be 32 bytes");
+
+ if (b.vchSecretH.size() != 32)
+ throw key_error("CMalleableKeyView::CMalleableKeyView() : L size must be 32 bytes");
+
vchSecretL = b.vchSecretL;
CKey H;
H.SetSecret(b.vchSecretH, true);
+
vchPubKeyH = H.GetPubKey().Raw();
nVersion = b.nVersion;
}
}
// Check ownership
-bool CMalleableKeyView::CheckKeyVariant(const CPubKey &R, const CPubKey &vchPubKeyVariant)
+bool CMalleableKeyView::CheckKeyVariant(const CPubKey &R, const CPubKey &vchPubKeyVariant) const
{
if (!R.IsValid()) {
throw key_error("CMalleableKeyView::CheckKeyVariant() : R is invalid");
}
CPoint point_R;
- if (!point_R.setBytes(R.Raw())) {
+ if (!point_R.setPubKey(R)) {
throw key_error("CMalleableKeyView::CheckKeyVariant() : Unable to decode R value");
}
CPoint point_H;
- if (!point_H.setBytes(vchPubKeyH)) {
+ if (!point_H.setPubKey(vchPubKeyH)) {
throw key_error("CMalleableKeyView::CheckKeyVariant() : Unable to decode H value");
}
CPoint point_P;
- if (!point_P.setBytes(vchPubKeyVariant.Raw())) {
+ if (!point_P.setPubKey(vchPubKeyVariant)) {
throw key_error("CMalleableKeyView::CheckKeyVariant() : Unable to decode P value");
}
return true;
}
-std::string CMalleableKeyView::ToString()
+std::string CMalleableKeyView::ToString() const
{
CDataStream ssKey(SER_NETWORK, PROTOCOL_VERSION);
ssKey << *this;
return IsNull();
}
+std::vector<unsigned char> CMalleableKeyView::Raw() const
+{
+ CDataStream ssKey(SER_NETWORK, PROTOCOL_VERSION);
+ ssKey << *this;
+ std::vector<unsigned char> vch(ssKey.begin(), ssKey.end());
+
+ return vch;
+}
+
+
bool CMalleableKeyView::IsNull() const
{
return nVersion != CURRENT_VERSION;