I'm creating a password management application and I'm considering using the following procedure to keep passwords safe:
Asking the user for
raw_password
, for example "MyLongMasterKeyPassword"Generating
master_key
fromraw_password
with Scrypt and a randomsalt
Storing the
salt
(kept public)Asking for
raw_message
(the password to store)Generating
cipher
using AEAD-ChaCha20Poly1305IETF and generating a randomnonce
, and then asking forAD
(Additional authentication)Storing the
nonce
Encrypting
raw_message
withcipher
,nonce
, andAD
, then using thenonce
once for encryption, that returningcipher_text
Storing the
cipher_text
Decrypting
cipher_text
with storedsalt
andnonce
, then asking forAD
andraw_password
to regenerate themaster_key
with the storedsalt
, and then generating acipher
with themaster_key
and storednonce
, which returns thedecrypted_message
(a password, probably)
Now, the question is, is this procedure safe? Specifically, is it safe to re-use the same nonce for decryption an indefinite amount of times, if you only use it once for encryption?