MCPcopy Create free account
hub / github.com/cuberite/cuberite / Encrypt

Method Encrypt

src/Crypto.cpp:199–226  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

197
198
199int cRSAPrivateKey::Encrypt(const Byte * a_PlainData, size_t a_PlainLength, Byte * a_EncryptedData, size_t a_EncryptedMaxLength)
200{
201 if (a_EncryptedMaxLength < m_Rsa.len)
202 {
203 LOGD("%s: Invalid a_EncryptedMaxLength: got %u, exp at least %u",
204 __FUNCTION__, (unsigned)a_EncryptedMaxLength, (unsigned)(m_Rsa.len)
205 );
206 ASSERT(!"Invalid a_DecryptedMaxLength!");
207 return -1;
208 }
209 if (a_EncryptedMaxLength < m_Rsa.len)
210 {
211 LOGD("%s: Invalid a_PlainLength: got %u, exp at least %u",
212 __FUNCTION__, (unsigned)a_PlainLength, (unsigned)(m_Rsa.len)
213 );
214 ASSERT(!"Invalid a_PlainLength!");
215 return -1;
216 }
217 int res = rsa_pkcs1_encrypt(
218 &m_Rsa, ctr_drbg_random, &m_Ctr_drbg, RSA_PRIVATE,
219 a_PlainLength, a_PlainData, a_EncryptedData
220 );
221 if (res != 0)
222 {
223 return -1;
224 }
225 return (int)m_Rsa.len;
226}
227
228
229

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected