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