| 837 | mac.Final(ciphertext + plaintextLength); |
| 838 | } |
| 839 | DecodingResult SymmetricDecrypt(const byte *key, const byte *ciphertext, size_t ciphertextLength, byte *plaintext, const NameValuePairs ¶meters) const |
| 840 | { |
| 841 | size_t plaintextLength = GetMaxSymmetricPlaintextLength(ciphertextLength); |
| 842 | const byte *cipherKey, *macKey; |
| 843 | if (DHAES_MODE) |
| 844 | { |
| 845 | macKey = key; |
| 846 | cipherKey = key + MAC::DEFAULT_KEYLENGTH; |
| 847 | } |
| 848 | else |
| 849 | { |
| 850 | cipherKey = key; |
| 851 | macKey = key + plaintextLength; |
| 852 | } |
| 853 | |
| 854 | ConstByteArrayParameter encodingParameters; |
| 855 | parameters.GetValue(Name::EncodingParameters(), encodingParameters); |
| 856 | |
| 857 | MAC mac(macKey); |
| 858 | mac.Update(ciphertext, plaintextLength); |
| 859 | mac.Update(encodingParameters.begin(), encodingParameters.size()); |
| 860 | if (DHAES_MODE) |
| 861 | { |
| 862 | byte L[8]; |
| 863 | PutWord(false, BIG_ENDIAN_ORDER, L, (LABEL_OCTETS ? word64(encodingParameters.size()) : 8 * word64(encodingParameters.size()))); |
| 864 | mac.Update(L, 8); |
| 865 | } |
| 866 | if (!mac.Verify(ciphertext + plaintextLength)) |
| 867 | return DecodingResult(); |
| 868 | |
| 869 | if (plaintextLength) // Coverity finding |
| 870 | xorbuf(plaintext, ciphertext, cipherKey, plaintextLength); |
| 871 | |
| 872 | return DecodingResult(plaintextLength); |
| 873 | } |
| 874 | }; |
| 875 | |
| 876 | //! _ |