base::byte_vector decrypt(base::const_byte_span data) const { Expects(isValid()); constexpr auto kDecryptSize = 256; auto result = base::byte_vector(kDecryptSize, gsl::byte {}); auto res = RSA_public_decrypt(kDecryptSize, reinterpret_cast<const unsigned char*>(data.data()), reinterpret_cast<unsigned char*>(result.data()), _rsa, RSA_NO_PADDING); if (res < 0 || res > kDecryptSize) { ERR_load_crypto_strings(); LOG(("RSA Error: RSA_public_encrypt failed, key fp: %1, result: %2, error: %3").arg(getFingerPrint()).arg(res).arg(ERR_error_string(ERR_get_error(), 0))); return base::byte_vector(); } else if (auto zeroBytes = kDecryptSize - res) { auto resultBytes = gsl::make_span(result); base::move_bytes(resultBytes.subspan(zeroBytes - res, res), resultBytes.subspan(0, res)); base::set_bytes(resultBytes.subspan(0, zeroBytes - res), gsl::byte {}); } return result; }
DroidMemory& DroidMemory::operator<<(DroidMemory const& other) { setExp(getExp() + other.getExp()); setFingerPrint(getFingerPrint() ^ other.getFingerPrint()); return *this; }
bool RSAPublicKey::encrypt(const void *data, std::string &result) const { Expects(isValid()); result.resize(256); int res = RSA_public_encrypt(256, reinterpret_cast<const unsigned char*>(data), reinterpret_cast<uchar*>(&result[0]), impl_->rsa, RSA_NO_PADDING); if (res != 256) { ERR_load_crypto_strings(); LOG(("RSA Error: RSA_public_encrypt failed, key fp: %1, result: %2, error: %3").arg(getFingerPrint()).arg(res).arg(ERR_error_string(ERR_get_error(), 0))); return false; } return true; }
void DroidMemory::setExp(size_t const value) { _exp = value; } DroidMemory& DroidMemory::operator<<(DroidMemory const& other) { setExp(getExp() + other.getExp()); setFingerPrint(getFingerPrint() ^ other.getFingerPrint()); return *this; } DroidMemory& DroidMemory::operator>>(DroidMemory& other) const { other.setExp(getExp() + other.getExp()); other.setFingerPrint(getFingerPrint() ^ other.getFingerPrint()); return other; } DroidMemory& DroidMemory::operator+=(DroidMemory const& other) { setExp(getExp() + other.getExp()); setFingerPrint(getFingerPrint() ^ other.getFingerPrint()); return *this; } DroidMemory& DroidMemory::operator+=(size_t const& val) { setExp(getExp() + val); setFingerPrint(getFingerPrint() ^ val); return *this;