SLIP-0016 describes simple encryption concept for hardware device for secure storage of passwords.
SLIP-0016 describes simple encryption concept for hardware device for secure storage of passwords.
## General design
## General design
At first, we derive a master key from HW device itself, which is divided in two parts.
At first, we derive a master key from HW device itself, which is divided in two parts.
...
@@ -22,55 +21,51 @@ Second part is used for primary storage encryption.
...
@@ -22,55 +21,51 @@ 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.
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
## Design details
#### Deriving master key
### Deriving master key
We derive masterKey from hardware device by sending cipherKeyValue with following params:
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)
- ENC_VALUE: `'2d650551248d792eabf628f451200d7f51cb63e46aadcbb1038aacb05e8c8aee2d650551248d792eabf628f451200d7f51cb63e46aadcbb1038aacb05e8c8aee'` (in hexadecimal (128 /2), max length is 1024 bytes)
CipherKeyValue will be defined in SLIP-0011; right now you can check the source code in trezor source code_.
CipherKeyValue will be defined in SLIP-0011; right now you can check the source code in [trezor source code](https://github.com/trezor/trezor-mcu/blob/master/firmware/fsm.c#L451-L483).
@@ -108,24 +103,27 @@ for more: https://nodejs.org/api/crypto.html#crypto_crypto_createdecipheriv_algo
...
@@ -108,24 +103,27 @@ for more: https://nodejs.org/api/crypto.html#crypto_crypto_createdecipheriv_algo
}
}
```
```
#### Entry level encryption
### Entry level encryption
Every entry contains keys from upper example.
Every entry contains keys from upper example.
- ```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
-`title`: title is represented as string. If given string is matching URL, it will be shown on device as domain without protocol prefix.
- ```nonce```: hidden generated string which is output of cipherKeyValue over Title + Username key and random values
-`username`: string, will be passed to device, in encryption/decryption process
- ```password```: is buffer array output of plain string and nonce (encryption process described later)
-`nonce`: hidden generated string which is output of cipherKeyValue over Title + Username key and random values
- ```safe_note```: is also buffer array output of plain string and nonce (also described later)
-`password`: is buffer array output of plain string and nonce (encryption process described later)
- ```note```: is plain UTF8 string
-`safe_note`: is also buffer array output of plain string and nonce (also described later)
- ```tags```: is array of Tags key values
-`note`: is plain UTF8 string
-`tags`: is array of Tags key values
Step by step entry encryption:
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!
EXAMPLE:
1. Generate random 32 bytes buffer and convert to HEX string inadequately called `nonce`
```javascript
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!
EXAMPLE:
``` javascript
session.cipherKeyValue(
session.cipherKeyValue(
[(10016|0x80000000)>>>0,0],// same path
[(10016|0x80000000)>>>0,0],// same path
'Unlock github.com for user Satoshi Nakamoto?',
'Unlock github.com for user Satoshi Nakamoto?',
...
@@ -135,14 +133,16 @@ false, //askOnEncrypt? is the same in encryption and decryption
...
@@ -135,14 +133,16 @@ false, //askOnEncrypt? is the same in encryption and decryption
true)// askOnDecrypt? we want this becuase otherwise somebody could rob us!
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.
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
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
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**!
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**!
EXAMPLE:
EXAMPLE:
```javascript
``` javascript
session.cipherKeyValue(
session.cipherKeyValue(
[(10016|0x80000000)>>>0,0],// same path
[(10016|0x80000000)>>>0,0],// same path
'Unlock github.com for user Satoshi Nakamoto?',
'Unlock github.com for user Satoshi Nakamoto?',
...
@@ -151,8 +151,5 @@ false, //encrypt? - has to be FALSE in decryption
...
@@ -151,8 +151,5 @@ false, //encrypt? - has to be FALSE in decryption
false,//askOnEncrypt? is the same in encryption and decryption
false,//askOnEncrypt? is the same in encryption and decryption
true)// askOnDecrypt? we want this becuase otherwise somebody could rob us!
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.
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.