Score:2

Storing length of encrypted data

bt flag

I need to encrypt some user's data. However to make it more apparent to the user what data is stored in each key, I was thinking to also store the length of the actual data along the cipher.

E.g.

user_1_secrets = [
  {
    "key": "mysecret"
    "encrypted_data": b"abf4c2",
    "length": "10",
  },
  {
    "key": "myothersecret"
    "encrypted_data": b"g3d532",
    "length": "24",
  },
]

Is this safe from a security prospective? Or is giving the length, too much information that someone can misuse?

The encrypted data is encrypted with a user password-derived key.

Score:2
ng flag

There are some cases where hiding the plaintext length is desirable (e.g. if the plaintext by destination is either "yes" or "no", or if that plaintext is a password).

However, hiding the length of the plaintext is not a standard goal for encryption. Many modern encryption methods make it trivial to find the exact plaintext length from the ciphertext (e.g. CTR, GCM), and about every other makes it possible to get an approximation of the length, e.g. recognize "Bob Lee" from "Emmanuella Wolfeschlegelsteinhausenbergerdorff".

Knowing the length will slightly help in some cryptographic attacks, but does not by itself give adversaries a padding oracle. That issue can only happen if [the receiving end checks that length] AND [the encryption system uses padding].

Therefore putting the length along the ciphertext is generally OK, as long as: [that length is not by itself secret] AND [[that length is ignored by the decryption code] OR [the encryption system does not use padding]].

Authenticated encryption that does not use padding include ChaCha20-Poly1305, AES-GCM, AES-GCM-SIV, AES-CCM, AES-OCB, AES-CWC, AES-EAX. Non-authenticated (thus less recommendable) encryption that does not use padding include AES-CTR, AES-OFB.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.