|
|
|
@ -68,6 +68,30 @@ namespace data
|
|
|
|
|
memcpy (excessBuf, signingKey + 128, excessLen);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SIGNING_KEY_TYPE_RSA_SHA256_2048:
|
|
|
|
|
{
|
|
|
|
|
memcpy (m_StandardIdentity.signingKey, signingKey, 128);
|
|
|
|
|
excessLen = i2p::crypto::RSASHA2562048_KEY_LENGTH - 128; // 128 = 256 - 128
|
|
|
|
|
excessBuf = new uint8_t[excessLen];
|
|
|
|
|
memcpy (excessBuf, signingKey + 128, excessLen);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SIGNING_KEY_TYPE_RSA_SHA384_3072:
|
|
|
|
|
{
|
|
|
|
|
memcpy (m_StandardIdentity.signingKey, signingKey, 128);
|
|
|
|
|
excessLen = i2p::crypto::RSASHA3843072_KEY_LENGTH - 128; // 256 = 384 - 128
|
|
|
|
|
excessBuf = new uint8_t[excessLen];
|
|
|
|
|
memcpy (excessBuf, signingKey + 128, excessLen);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SIGNING_KEY_TYPE_RSA_SHA512_4096:
|
|
|
|
|
{
|
|
|
|
|
memcpy (m_StandardIdentity.signingKey, signingKey, 128);
|
|
|
|
|
excessLen = i2p::crypto::RSASHA5124096_KEY_LENGTH - 128; // 384 = 512 - 128
|
|
|
|
|
excessBuf = new uint8_t[excessLen];
|
|
|
|
|
memcpy (excessBuf, signingKey + 128, excessLen);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
LogPrint ("Signing key type ", (int)type, " is not supported");
|
|
|
|
|
}
|
|
|
|
@ -225,6 +249,14 @@ namespace data
|
|
|
|
|
return 128;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t IdentityEx::GetSigningPrivateKeyLen () const
|
|
|
|
|
{
|
|
|
|
|
if (!m_Verifier) CreateVerifier ();
|
|
|
|
|
if (m_Verifier)
|
|
|
|
|
return m_Verifier->GetPrivateKeyLen ();
|
|
|
|
|
return GetSignatureLen ()/2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t IdentityEx::GetSignatureLen () const
|
|
|
|
|
{
|
|
|
|
|
if (!m_Verifier) CreateVerifier ();
|
|
|
|
@ -283,6 +315,33 @@ namespace data
|
|
|
|
|
m_Verifier = new i2p::crypto::ECDSAP521Verifier (signingKey);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SIGNING_KEY_TYPE_RSA_SHA256_2048:
|
|
|
|
|
{
|
|
|
|
|
uint8_t signingKey[i2p::crypto::RSASHA2562048_KEY_LENGTH];
|
|
|
|
|
memcpy (signingKey, m_StandardIdentity.signingKey, 128);
|
|
|
|
|
size_t excessLen = i2p::crypto::RSASHA2562048_KEY_LENGTH - 128; // 128 = 256- 128
|
|
|
|
|
memcpy (signingKey + 128, m_ExtendedBuffer + 4, excessLen); // right after signing and crypto key types
|
|
|
|
|
m_Verifier = new i2p::crypto:: RSASHA2562048Verifier (signingKey);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SIGNING_KEY_TYPE_RSA_SHA384_3072:
|
|
|
|
|
{
|
|
|
|
|
uint8_t signingKey[i2p::crypto::RSASHA3843072_KEY_LENGTH];
|
|
|
|
|
memcpy (signingKey, m_StandardIdentity.signingKey, 128);
|
|
|
|
|
size_t excessLen = i2p::crypto::RSASHA3843072_KEY_LENGTH - 128; // 256 = 384- 128
|
|
|
|
|
memcpy (signingKey + 128, m_ExtendedBuffer + 4, excessLen); // right after signing and crypto key types
|
|
|
|
|
m_Verifier = new i2p::crypto:: RSASHA3843072Verifier (signingKey);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SIGNING_KEY_TYPE_RSA_SHA512_4096:
|
|
|
|
|
{
|
|
|
|
|
uint8_t signingKey[i2p::crypto::RSASHA5124096_KEY_LENGTH];
|
|
|
|
|
memcpy (signingKey, m_StandardIdentity.signingKey, 128);
|
|
|
|
|
size_t excessLen = i2p::crypto::RSASHA5124096_KEY_LENGTH - 128; // 384 = 512- 128
|
|
|
|
|
memcpy (signingKey + 128, m_ExtendedBuffer + 4, excessLen); // right after signing and crypto key types
|
|
|
|
|
m_Verifier = new i2p::crypto:: RSASHA5124096Verifier (signingKey);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
LogPrint ("Signing key type ", (int)keyType, " is not supported");
|
|
|
|
|
}
|
|
|
|
@ -322,7 +381,7 @@ namespace data
|
|
|
|
|
size_t ret = m_Public.FromBuffer (buf, len);
|
|
|
|
|
memcpy (m_PrivateKey, buf + ret, 256); // private key always 256
|
|
|
|
|
ret += 256;
|
|
|
|
|
size_t signingPrivateKeySize = m_Public.GetSignatureLen ()/2; // 20 for DSA
|
|
|
|
|
size_t signingPrivateKeySize = m_Public.GetSigningPrivateKeyLen ();
|
|
|
|
|
memcpy (m_SigningPrivateKey, buf + ret, signingPrivateKeySize);
|
|
|
|
|
ret += signingPrivateKeySize;
|
|
|
|
|
delete m_Signer;
|
|
|
|
@ -336,7 +395,7 @@ namespace data
|
|
|
|
|
size_t ret = m_Public.ToBuffer (buf, len);
|
|
|
|
|
memcpy (buf + ret, m_PrivateKey, 256); // private key always 256
|
|
|
|
|
ret += 256;
|
|
|
|
|
size_t signingPrivateKeySize = m_Public.GetSignatureLen ()/2; // 20 for DSA
|
|
|
|
|
size_t signingPrivateKeySize = m_Public.GetSigningPrivateKeyLen ();
|
|
|
|
|
memcpy (buf + ret, m_SigningPrivateKey, signingPrivateKeySize);
|
|
|
|
|
ret += signingPrivateKeySize;
|
|
|
|
|
return ret;
|
|
|
|
@ -386,6 +445,15 @@ namespace data
|
|
|
|
|
case SIGNING_KEY_TYPE_ECDSA_SHA512_P521:
|
|
|
|
|
m_Signer = new i2p::crypto::ECDSAP521Signer (m_SigningPrivateKey);
|
|
|
|
|
break;
|
|
|
|
|
case SIGNING_KEY_TYPE_RSA_SHA256_2048:
|
|
|
|
|
m_Signer = new i2p::crypto::RSASHA2562048Signer (m_SigningPrivateKey);
|
|
|
|
|
break;
|
|
|
|
|
case SIGNING_KEY_TYPE_RSA_SHA384_3072:
|
|
|
|
|
m_Signer = new i2p::crypto::RSASHA3843072Signer (m_SigningPrivateKey);
|
|
|
|
|
break;
|
|
|
|
|
case SIGNING_KEY_TYPE_RSA_SHA512_4096:
|
|
|
|
|
m_Signer = new i2p::crypto::RSASHA5124096Signer (m_SigningPrivateKey);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
LogPrint ("Signing key type ", (int)m_Public.GetSigningKeyType (), " is not supported");
|
|
|
|
|
}
|
|
|
|
@ -398,7 +466,7 @@ namespace data
|
|
|
|
|
PrivateKeys keys;
|
|
|
|
|
auto& rnd = i2p::context.GetRandomNumberGenerator ();
|
|
|
|
|
// signature
|
|
|
|
|
uint8_t signingPublicKey[i2p::crypto::ECDSAP521_KEY_LENGTH]; // 132 bytes is max key size now
|
|
|
|
|
uint8_t signingPublicKey[512]; // signing public key is 512 bytes max
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case SIGNING_KEY_TYPE_ECDSA_SHA256_P256:
|
|
|
|
@ -410,6 +478,15 @@ namespace data
|
|
|
|
|
case SIGNING_KEY_TYPE_ECDSA_SHA512_P521:
|
|
|
|
|
i2p::crypto::CreateECDSAP521RandomKeys (rnd, keys.m_SigningPrivateKey, signingPublicKey);
|
|
|
|
|
break;
|
|
|
|
|
case SIGNING_KEY_TYPE_RSA_SHA256_2048:
|
|
|
|
|
i2p::crypto::CreateRSARandomKeys (rnd, i2p::crypto::RSASHA2562048_KEY_LENGTH, keys.m_SigningPrivateKey, signingPublicKey);
|
|
|
|
|
break;
|
|
|
|
|
case SIGNING_KEY_TYPE_RSA_SHA384_3072:
|
|
|
|
|
i2p::crypto::CreateRSARandomKeys (rnd, i2p::crypto::RSASHA3843072_KEY_LENGTH, keys.m_SigningPrivateKey, signingPublicKey);
|
|
|
|
|
break;
|
|
|
|
|
case SIGNING_KEY_TYPE_RSA_SHA512_4096:
|
|
|
|
|
i2p::crypto::CreateRSARandomKeys (rnd, i2p::crypto::RSASHA5124096_KEY_LENGTH, keys.m_SigningPrivateKey, signingPublicKey);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
LogPrint ("Signing key type ", (int)type, " is not supported. Create DSA-SHA1");
|
|
|
|
|
return PrivateKeys (i2p::data::CreateRandomKeys ()); // DSA-SHA1
|
|
|
|
|