I saw posts tangentially related to this, but not this one specifically.
I'm building a content-addressable storage layer where I'd like to store the contents encrypted. The question is what is a safe 'content address'/lookup identifier that would not weaken the encryption.
In an unencrypted store, I would have some data data
, and the key would be sha256(data)
and the value would be data
.
In a naive encrypted store, I would have some data
, and the key would remain sha256(data)
and the data would be, say, aes-gcm(data)
. But is this safe? Does knowledge of the sha256 of the cleartext data aid an attacker in figuring out how to decrypt data
?
I suppose I could do a content-addressable store where key::value was sha256(aes-gcm(data))
:: aes-gcm(data)
, but ideally I'd like to avoid inefficiency on the client, having to encrypt a file to get a hash to determine whether the value already exists on the server would be slow with a large number of files. Simply using the hash of the cleartext data would be much more efficient.
As a followup question, should I make sure data
always has some minimum length? Padded with randomness? Is it insecure to store very small values that are easily guessed?