cardano-foundation / cardano-wallet

HTTP server & command-line for managing UTxOs and HD wallets in Cardano.
Apache License 2.0
758 stars 213 forks source link

Enable salt in aes cipher #4524

Closed paweljakubas closed 3 months ago

paweljakubas commented 3 months ago

Comments

It is important to note that when we use salt encrypted message is appended with salt prefix and salt. Here is demonstration:

$ echo CXH8t8dSqro-n 000000000000000 | openssl enc -e -aes-256-cbc -pbkdf2 -iter 10000 -a -k "password" -S 3030303030303030 -v
bufsize=8192
U2FsdGVkX18wMDAwMDAwMPCoW2E+adl2BLopcz8iftA=
bytes read   :       15
bytes written:       45

$ echo U2FsdGVkX18wMDAwMDAwMPCoW2E+adl2BLopcz8iftA= | base64 -d | xxd
00000000: 5361 6c74 6564 5f5f 3030 3030 3030 3030  Salted__00000000
00000010: f0a8 5b61 3e69 d976 04ba 2973 3f22 7ed0  ..[a>i.v..)s?"~.

$ echo -n 000000000000000 | openssl enc -e -aes-256-cbc -pbkdf2 -iter 10000 -a -k "password" -S 3232323230303030 -v
bufsize=8192
U2FsdGVkX18yMjIyMDAwMNMkzD3e6bZFrwKXyj5GWi8=
bytes read   :       15
bytes written:       45

$ echo U2FsdGVkX18yMjIyMDAwMNMkzD3e6bZFrwKXyj5GWi8= | base64 -d | xxd
00000000: 5361 6c74 6564 5f5f 3232 3232 3030 3030  Salted__22220000
00000010: d324 cc3d dee9 b645 af02 97ca 3e46 5a2f  .$.=...E....>FZ/

Conclusions:

  1. 16 bytes are prepended when salt is used.
  2. First 8 bytes are always constant, ie. irrespective of salt value, and is Salted__, the next 8 bytes is salt
  3. Salt MUST be 8 bytes.

Issue Number

adp-3327