diff options
author | madmaxoft <github@xoft.cz> | 2014-01-25 19:19:17 +0100 |
---|---|---|
committer | madmaxoft <github@xoft.cz> | 2014-01-25 19:19:17 +0100 |
commit | ca0e51d89c5b3979f38918b3df7e0f9137f251ce (patch) | |
tree | 065d0a7a84fe04b91113893f95b67064d64ec58f /src/Crypto.cpp | |
parent | Merged branch 'master' into ChangeToPolarSSL. (diff) | |
download | cuberite-ca0e51d89c5b3979f38918b3df7e0f9137f251ce.tar cuberite-ca0e51d89c5b3979f38918b3df7e0f9137f251ce.tar.gz cuberite-ca0e51d89c5b3979f38918b3df7e0f9137f251ce.tar.bz2 cuberite-ca0e51d89c5b3979f38918b3df7e0f9137f251ce.tar.lz cuberite-ca0e51d89c5b3979f38918b3df7e0f9137f251ce.tar.xz cuberite-ca0e51d89c5b3979f38918b3df7e0f9137f251ce.tar.zst cuberite-ca0e51d89c5b3979f38918b3df7e0f9137f251ce.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Crypto.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/Crypto.cpp b/src/Crypto.cpp index 5ad866f34..2045d0385 100644 --- a/src/Crypto.cpp +++ b/src/Crypto.cpp @@ -196,6 +196,40 @@ int cRSAPrivateKey::Decrypt(const Byte * a_EncryptedData, size_t a_EncryptedLeng +int cRSAPrivateKey::Encrypt(const Byte * a_PlainData, size_t a_PlainLength, Byte * a_EncryptedData, size_t a_EncryptedMaxLength) +{ + if (a_EncryptedMaxLength < m_Rsa.len) + { + LOGD("%s: Invalid a_EncryptedMaxLength: got %u, exp at least %u", + __FUNCTION__, (unsigned)a_EncryptedMaxLength, (unsigned)(m_Rsa.len) + ); + ASSERT(!"Invalid a_DecryptedMaxLength!"); + return -1; + } + if (a_PlainLength < m_Rsa.len) + { + LOGD("%s: Invalid a_PlainLength: got %u, exp at least %u", + __FUNCTION__, (unsigned)a_PlainLength, (unsigned)(m_Rsa.len) + ); + ASSERT(!"Invalid a_PlainLength!"); + return -1; + } + size_t DecryptedLength; + int res = rsa_pkcs1_encrypt( + &m_Rsa, ctr_drbg_random, &m_Ctr_drbg, RSA_PUBLIC, + a_PlainLength, a_PlainData, a_EncryptedData + ); + if (res != 0) + { + return -1; + } + return (int)DecryptedLength; +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cAESCFBDecryptor: |