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