# What information should I send along with an AES ciphertext and is there any standard to do that?

While using some crypto implementations I got to see that many times a comment is added to the ciphertext.

For example:

-----BEGIN PGP MESSAGE-----
Version: OpenPGP.js v1.5.0
Comment: http://openpgpjs.org

wcBMAyJd6d8o7Y2pAQf/WZM1LV/iq3R8QGK7fUiQoUVzR8nEow+RJcBh6ujH
MBGWKcm4Y//a76hOL4r/Htbt7lwnfGe2HLrznRQip1TaONW897zrD7amsOp3
xlbZZep/HQNHNgtOGHx4peqDjrPQk9Y7HvRxrPFQWM2jMFTFlvJsw3kBWiNn
FI0jn+8RZalxCXloAE2OSWTkzInf+RfAefrFRCSiQW536UZ0h89u560TgA10
u7N0b+iGzRAB+4AFBZjkWpO5/KpYRzlUng+BMw4TmrlHJlLxiW7s3R3V74/J
ZNu1IIZ0S16A0r3XuWGbccO59igNY8qzi3FyMiQgCbYCReccm6M59no7M0gK
0tJFAe9BC5GJuS0oTrnoH9Wf6/tftw5booEaNU67HDnU0qI9blUK2rFVFoR/
ZCNlDy2HxpQZFgrnGPBMsvV6wZSj/LgLF+wi
=jLQU
-----END PGP MESSAGE-----


Where:

-----BEGIN PGP MESSAGE-----


… identifies the beginning of the data.

Version: OpenPGP.js v1.5.0


… identifies which implementation of the protocol was used to encrypt the text.

Comment: http://openpgpjs.org


… provides a generic comment.

-----END PGP MESSAGE-----


identifies the end of the data.

The first thing I am wondering if it's some standard out there for this comments, and if so some links or informations about it. Would've asked to Google but don't know what to search.

Then, I would like to use a comment like the one showed above to store my ciphered messages as plaintext.

Assuming I want to do that for a message ciphered using AES, which informations should I store?

1. Should I store the AES mode used for encryption ?
2. Should I store the AES implementation I used ?
3. Should I store the initialization vector ?
4. Should I try to be compliant to some standards while storing these informations ?
• The implementation should be irrelevant, as all AES implementations do the same (if they're compliant to the standard). – SEJPM Jan 30 '16 at 13:27
• @SEJPM Yes, "irrelevant" is probably a better word then "inconsequential" :) – Maarten Bodewes Jan 30 '16 at 13:30
• If you use PGP format for symmetric-under-pubkey, which is far from the only standard for "AES ciphertext", the symmetric cipher algorithm is transmitted in the encrypted key value and the mode and IV are defined by the PGP standard and don't need to be represented explicitly. If you use some other format, standard or not, it depends on that format. – dave_thompson_085 Jan 31 '16 at 1:09

## 2 Answers

What you are looking for is a definition of PEM, privacy enhanced mail. Obviously PEM is not just used for mail anymore. The definition of the header lines seems to be best described by section 4.6: "Summary of Encapsulated Header Fields" of RFC 1421: "Privacy Enhancement for Internet Electronic Mail: Part I: Message Encryption and Authentication Procedures". Obviously for PGP specific header fields you'll have to take a look at the OpenPGP format, specifically the section about ASCII armor.

Then, i would like to use a comment like the one showed above to store my ciphered messages as plaintext. Assuming i want to do that for a message ciphered using AES, which informations should i store ?

That depends on the scheme you've chosen. For transport security the minimum would be the IV, the ciphertext and an authentication tag over both.

Should i store the AES mode used for encryption ?

That depends. You could store a protocol version instead which determines which mode is used. You should not just store the mode without authentication and then proceed to process the message based on the header fields. That would give an attacker to decide which operation is performed on the receiving side. You need to keep control over what is performed on the receiving side.

Should i store the AES implementation i used ?

No, the implementation of the block cipher should be irrelevant if you've decided upon a well defined protocol.

You could store a version of the software implementation of a protocol. In that case you may be able to work around possible bugs within the implementation. I've seen quite a few instances where the implementation of PGP did matter.

Should i store the initialization vector ?

Yes, unless you've got ways of establishing the IV out-of-band (e.g. an operation over a message counter included in a message counter, or a counter kept in sync at both sides). If unsure include a random IV of sufficient size.

Should i try to be compliant to some standards while storing these informations ?

It's strongly advisable to keep to well known container formats such as CMS or the already named OpenPGP yes.

You may need to answer some preliminary questions first:

1 - do you want to exchange encrypted data or just store it for your own use?

2 - do you want/need to interoperate with existing protocols or applications?

3 - how "stealth" do you want to be (PGP "armor" is just a red rag to a bull)?

This older thread may help: https://stackoverflow.com/questions/1306865/what-are-the-standard-encryption-file-formats

A few ideas:

1 - If you are the only user or in a small/closed community, make it simple but have a look at some of the standards to check them for good practises. Possibly pay attention to 3.

2 - Check the relevant standard(s), RFC or others, and select appropriate modes (standards may be overly complex in order to ensure interoperability with old versions)

3 - Detecting encrypted data in transfer is not difficult but you don't need to make everything obvious to an attacker with respect to your parameters/settings

Finally (or first of all!), make sure your key exchange/storage mechanism is secure if you need one.