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

Method Decrypt

src/Crypto.cpp:165–193  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

163
164
165int cRSAPrivateKey::Decrypt(const Byte * a_EncryptedData, size_t a_EncryptedLength, Byte * a_DecryptedData, size_t a_DecryptedMaxLength)
166{
167 if (a_EncryptedLength < m_Rsa.len)
168 {
169 LOGD("%s: Invalid a_EncryptedLength: got %u, exp at least %u",
170 __FUNCTION__, (unsigned)a_EncryptedLength, (unsigned)(m_Rsa.len)
171 );
172 ASSERT(!"Invalid a_DecryptedMaxLength!");
173 return -1;
174 }
175 if (a_DecryptedMaxLength < m_Rsa.len)
176 {
177 LOGD("%s: Invalid a_DecryptedMaxLength: got %u, exp at least %u",
178 __FUNCTION__, (unsigned)a_EncryptedLength, (unsigned)(m_Rsa.len)
179 );
180 ASSERT(!"Invalid a_DecryptedMaxLength!");
181 return -1;
182 }
183 size_t DecryptedLength;
184 int res = rsa_pkcs1_decrypt(
185 &m_Rsa, ctr_drbg_random, &m_Ctr_drbg, RSA_PRIVATE, &DecryptedLength,
186 a_EncryptedData, a_DecryptedData, a_DecryptedMaxLength
187 );
188 if (res != 0)
189 {
190 return -1;
191 }
192 return (int)DecryptedLength;
193}
194
195
196

Calls

no outgoing calls

Tested by

no test coverage detected