# SLIP-0016 : Format for password storage and its encryption
```
Number: SLIP-0016
Title: Format for password storage and its encryption
Type: Standard
Status: Draft
Authors: Peter Jensen <peteritsjustadream@gmail.com>
Created: 2016-18-02
```
## Abstract
------
SLIP-0016 describes simple encryption concept for hardware device for secure storage of passwords.
## General design
------
At first, we derive a master key from HW device itself, which is divided in two parts.
First part is hashed and used as a name of storage file.
Second part is used for primary storage encryption.
Storage file is encrypted JSON object, which contains configuration, tags and separate entries. Each entry has other two encrypted properties derivated from device to provide higher level of security with low risk of leaks.
## Design details
------
#### Deriving master key
We derive masterKey from hardware device by sending cipherKeyValue with following params:
- path: ```m/10016'/0``` (hardened path, see BIP32)
- ENC_VALUE: ```'2d650551248d792eabf628f451200d7f51cb63e46aadcbb1038aacb05e8c8aee2d650551248d792eabf628f451200d7f51cb63e46aadcbb1038aacb05e8c8aee'``` (in hexadecimal (128 /2), max length is 1024 bytes)
- ```title```: title is represented as string. If given string is matching URL, it will be shown on device as domain without protocol prefix.
- ```username```: string, will be passed to device, in encryption/decryption process
- ```nonce```: hidden generated string which is output of cipherKeyValue over Title + Username key and random values
- ```password```: is buffer array output of plain string and nonce (encryption process described later)
- ```safe_note```: is also buffer array output of plain string and nonce (also described later)
- ```note```: is plain UTF8 string
- ```tags```: is array of Tags key values
Step by step entry encryption:
1. Generate random 32 bytes buffer and convert to HEX string inadequately called ```nonce```
2. Set key as ```'Unlock ' + title + ' for user ' + username + '?'```
3. Ask device for ```cipherKeyValue```, where path is the same as in the deriving file name, key is described in second step and enc_value is our ```nonce``` from the first step. Do not forget to setup properly other three bool values!
false, //askOnEncrypt? is the same in encryption and decryption
true) // askOnDecrypt? we want this becuase otherwise somebody could rob us!
```
4. Then we use our famous ```nonce``` from the first step in ```AES-256-GCM``` algorithm encryption for ```password``` string and ```safe_note``` string. Process of encryption is the same as in the deriving encryption key and file level encryption. So basically we get some Buffer array output with 12 bytes of IV and 16 bytes of GCM authTag and the rest is cipherText.
5. Output of each encryption is stored to appropriate keys, just instead of generated ```nonce``` we store result from third step ( ```cipherKeyValue ```) which we later use for decryption process
Entry decryption:
1. We ask device for the same ```cipherKeyValue ``` as in encryption process, just instead of ```nonce```, we use our encrypted result and boolean value ```encrypt? ``` is **false**!
false, //askOnEncrypt? is the same in encryption and decryption
true) // askOnDecrypt? we want this becuase otherwise somebody could rob us!
```
2. Other steps are the same as in entry encryption, we just symetrically decrypt values of ```password``` and ```safe_note``` via ```AES-256-GCM``` algorithm. Size of IV and authTag for AES is the same as in encryption. Beware on cipher Key data type - it must be hex. Output is in JSON.