| 74 | } |
| 75 | |
| 76 | bool CCrypter::Decrypt(const vector<unsigned char>& vchCiphertext, CKeyingMaterial& vchPlaintext) { |
| 77 | if (!fKeySet) |
| 78 | return false; |
| 79 | |
| 80 | // plaintext will always be equal to or lesser than length of ciphertext |
| 81 | int32_t nLen = vchCiphertext.size(); |
| 82 | int32_t nPLen = nLen, nFLen = 0; |
| 83 | |
| 84 | vchPlaintext = CKeyingMaterial(nPLen); |
| 85 | |
| 86 | evp_cipher_ctx ctx(EVP_CIPHER_CTX_new()); |
| 87 | if (!ctx) { |
| 88 | return false; |
| 89 | } |
| 90 | |
| 91 | bool fOk = true; |
| 92 | |
| 93 | if (fOk) |
| 94 | fOk = EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, chKey, chIV); |
| 95 | if (fOk) |
| 96 | fOk = EVP_DecryptUpdate(ctx, &vchPlaintext[0], &nPLen, &vchCiphertext[0], nLen); |
| 97 | if (fOk) |
| 98 | fOk = EVP_DecryptFinal_ex(ctx, (&vchPlaintext[0]) + nPLen, &nFLen); |
| 99 | |
| 100 | if (!fOk) |
| 101 | return false; |
| 102 | |
| 103 | vchPlaintext.resize(nPLen + nFLen); |
| 104 | return true; |
| 105 | } |
| 106 | |
| 107 | bool EncryptSecret(const CKeyingMaterial& vMasterKey, const CKeyingMaterial& vchPlaintext, const uint256& nIV, |
| 108 | vector<unsigned char>& vchCiphertext) { |
no test coverage detected