Skip to content

Commit 9835706

Browse files
committed
cleanup markdown formatting
1 parent f2ffb28 commit 9835706

File tree

2 files changed

+56
-59
lines changed

2 files changed

+56
-59
lines changed

slip-0013.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ The index is used so one can generate more keys corresponding to the same URI.
3939

4040
##HD Structure
4141

42-
1. First concatenate `index` with the URI (`uri`). Use little endian for `index`.
42+
1. First concatenate `index` with the URI (`uri`). Use little endian for `index`.
4343

4444
2. Compute the SHA256 hash of the result (`hash`).
4545

@@ -52,7 +52,7 @@ The index is used so one can generate more keys corresponding to the same URI.
5252
6. Derive the HD node `m/13'/A'/B'/C'/D'` according to BIP32.
5353

5454
###Worked example
55-
1. `index + uri`=`0` + `https://[email protected]/login`
55+
1. `index + uri`=`0` + `https://[email protected]/login`
5656

5757
2. `sha256(index + uri)` = `d0e2389d4c8394a9f3e32de01104bf6e8db2d9e2bb0905d60fffa5a18fd696db`
5858

@@ -62,7 +62,7 @@ The index is used so one can generate more keys corresponding to the same URI.
6262

6363
5. `A'` = 2637750992, `B'` = 2845082444, `C'` = 3761103859, `D'` = 4005495825
6464

65-
6. `bip32 node path` = `m/2147483661/2637750992/2845082444/3761103859/4005495825`
65+
6. `bip32 node path` = `m/2147483661/2637750992/2845082444/3761103859/4005495825`
6666

6767
See a [Python example](https://github.com/trezor/python-trezor/blob/ca45019918bc4c54f1ace899a9acf397c8f4d92f/tests/test_msg_signidentity.py#L27).
6868

slip-0016.md

+53-56
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ Created: 2016-18-02
1313

1414
SLIP-0016 describes simple encryption concept for hardware device for secure storage of passwords.
1515

16-
1716
## General design
1817

1918
At first, we derive a master key from HW device itself, which is divided in two parts.
@@ -22,110 +21,109 @@ Second part is used for primary storage encryption.
2221

2322
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.
2423

25-
2624
## Design details
2725

28-
#### Deriving master key
26+
### Deriving master key
2927

3028
We derive masterKey from hardware device by sending cipherKeyValue with following params:
31-
- path: ```m/10016'/0``` (hardened path, see BIP32)
32-
- ENC_KEY: ```'Unlock encrypted storage?'``` (max length message is 256 bytes)
33-
- ENC_VALUE: ```'2d650551248d792eabf628f451200d7f51cb63e46aadcbb1038aacb05e8c8aee2d650551248d792eabf628f451200d7f51cb63e46aadcbb1038aacb05e8c8aee'``` (in hexadecimal (128 /2), max length is 1024 bytes)
34-
- encrypt: ```true```
35-
- ask_on_encrypt: ```true```
36-
- ask_on_decrypt: ```true```
29+
- path: `m/10016'/0` (hardened path, see BIP32)
30+
- ENC_KEY: `'Unlock encrypted storage?'` (max length message is 256 bytes)
31+
- ENC_VALUE: `'2d650551248d792eabf628f451200d7f51cb63e46aadcbb1038aacb05e8c8aee2d650551248d792eabf628f451200d7f51cb63e46aadcbb1038aacb05e8c8aee'` (in hexadecimal (128 /2), max length is 1024 bytes)
32+
- encrypt: `true`
33+
- ask_on_encrypt: `true`
34+
- ask_on_decrypt: `true`
3735
- iv: unset
3836

3937
JS EXAMPLE:
40-
```javascript
38+
39+
``` javascript
4140
session.cipherKeyValue(
4241
[(10016 | 0x80000000) >>> 0, 0],
4342
'Unlock encrypted storage?',
4443
'2d650551248d792eabf628f451200d7f51cb63e46aadcbb1038aacb05e8c8aee2d650551248d792eabf628f451200d7f51cb63e46aadcbb1038aacb05e8c8aee',
4544
true, true, true)
4645
```
47-
CipherKeyValue will be defined in SLIP-0011; right now you can check the source code in trezor source code_.
48-
49-
.. _trezor source code: https://github.com/trezor/trezor-mcu/blob/master/firmware/fsm.c#L451-L483
46+
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).
5047

51-
52-
#### Deriving file name
48+
### Deriving file name
5349

5450
From the first half of master key, we derive the file name for every user/device in the following way:
5551
First, we use the HMAC function:
5652

57-
```HMAC-SHA256(fileKey, FILENAME_MESS)```
53+
`HMAC-SHA256(fileKey, FILENAME_MESS)`
5854

5955
where:
60-
- fileKey is the first half of masterKey
61-
(```masterKey.substring(0, masterKey.length / 2)```)
62-
- FILENAME_MESS is a constant string ```'5f91add3fa1c3c76e90c90a3bd0999e2bd7833d06a483fe884ee60397aca277a'```
6356

64-
The output result is digested to HEX string. After, we append extension ```'.pswd'```
57+
- fileKey is the first half of masterKey (`masterKey.substring(0, masterKey.length / 2)`)
58+
- FILENAME_MESS is a constant string `'5f91add3fa1c3c76e90c90a3bd0999e2bd7833d06a483fe884ee60397aca277a'`
6559

66-
EXAMPLE RESULT: ```a80387a2222f4360f71fd2165368c6ed91b26287d9bc1ce8be71e64e6b216a4f.pswd```
60+
The output result is digested to HEX string. After, we append extension `'.pswd'`
6761

62+
EXAMPLE RESULT: `a80387a2222f4360f71fd2165368c6ed91b26287d9bc1ce8be71e64e6b216a4f.pswd`
6863

69-
#### Deriving encryption key and file level encryption
64+
### Deriving encryption key and file level encryption
7065

7166
As an encryption key is used the SECOND half (32 bytes) of master key for the first level of data file encryption. Encrpytion key is in HEX string.
7267

73-
For encrypt/decrypt we are using ```AES-256-GCM``` algorithm.
68+
For encrypt/decrypt we are using `AES-256-GCM` algorithm.
7469

7570
- Input Vector (IV) is 12 randomly generated bytes
7671
- GCM is used with full 128-bit autentication tag (authTag)
7772

7873
for more: https://nodejs.org/api/crypto.html#crypto_crypto_createcipheriv_algorithm_key_iv
7974

8075
The result output stored in file is:
76+
8177
- first 12 bytes of the file is randomly generated IV
8278
- next 16 bytes is the GCM authTag
8379
- the rest is output ciphertext
8480

8581
for more: https://nodejs.org/api/crypto.html#crypto_crypto_createdecipheriv_algorithm_key_iv
8682

87-
88-
#### Data format
83+
### Data format
8984

9085
(Decrypted) data file is serialized JSON object with the following keys:
9186

92-
- ```version```: for future backwards compatibility and data storage manipualtion
93-
- ```config```: for remembering personal setup of application
94-
- ```tags```: contain set of labels with their icons (from icomoon set). Default tag is **All** and it is only tag, unable to edit or delete.
95-
```javascript
87+
- `version`: for future backwards compatibility and data storage manipualtion
88+
- `config`: for remembering personal setup of application
89+
- `tags`: contain set of labels with their icons (from icomoon set). Default tag is **All** and it is only tag, unable to edit or delete.
90+
``` javascript
9691
{title:"My social networks", icon:"person", active:"active"}
9792
```
98-
- ```entries```: is object of all password entries encrypted second time
99-
```javascript
93+
- `entries`: is object of all password entries encrypted second time
94+
``` javascript
10095
{
10196
"title": "http://wwww.github.com",
10297
"username": "Satoshi Nakamoto",
103-
"nonce": "8688105887642a3cbb61889d8762432ef864df107e097d2b19e93c8d808c2e21",
98+
"nonce": "8688105887642a3cbb61889d8762432ef864df107e097d2b19e93c8d808c2e21",
10499
"note": "public note",
105100
"password": {},
106101
"safe_note": {},
107102
"tags": [1]
108103
}
109104
```
110105

111-
#### Entry level encryption
106+
### Entry level encryption
112107

113108
Every entry contains keys from upper example.
114-
- ```title```: title is represented as string. If given string is matching URL, it will be shown on device as domain without protocol prefix.
115-
- ```username```: string, will be passed to device, in encryption/decryption process
116-
- ```nonce```: hidden generated string which is output of cipherKeyValue over Title + Username key and random values
117-
- ```password```: is buffer array output of plain string and nonce (encryption process described later)
118-
- ```safe_note```: is also buffer array output of plain string and nonce (also described later)
119-
- ```note```: is plain UTF8 string
120-
- ```tags```: is array of Tags key values
121-
109+
110+
- `title`: title is represented as string. If given string is matching URL, it will be shown on device as domain without protocol prefix.
111+
- `username`: string, will be passed to device, in encryption/decryption process
112+
- `nonce`: hidden generated string which is output of cipherKeyValue over Title + Username key and random values
113+
- `password`: is buffer array output of plain string and nonce (encryption process described later)
114+
- `safe_note`: is also buffer array output of plain string and nonce (also described later)
115+
- `note`: is plain UTF8 string
116+
- `tags`: is array of Tags key values
117+
122118
Step by step entry encryption:
123-
1. Generate random 32 bytes buffer and convert to HEX string inadequately called ```nonce```
124-
2. Set key as ```'Unlock ' + title + ' for user ' + username + '?'```
125-
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!
126119

127-
EXAMPLE:
128-
```javascript
120+
1. Generate random 32 bytes buffer and convert to HEX string inadequately called `nonce`
121+
2. Set key as `'Unlock ' + title + ' for user ' + username + '?'`
122+
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!
123+
124+
EXAMPLE:
125+
126+
``` javascript
129127
session.cipherKeyValue(
130128
[(10016 | 0x80000000) >>> 0, 0], // same path
131129
'Unlock github.com for user Satoshi Nakamoto?',
@@ -135,14 +133,16 @@ false, //askOnEncrypt? is the same in encryption and decryption
135133
true) // askOnDecrypt? we want this becuase otherwise somebody could rob us!
136134
```
137135

138-
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.
139-
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
136+
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.
137+
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
138+
139+
### Entry decryption
140140

141-
Entry decryption:
142-
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**!
141+
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**!
143142

144-
EXAMPLE:
145-
```javascript
143+
EXAMPLE:
144+
145+
``` javascript
146146
session.cipherKeyValue(
147147
[(10016 | 0x80000000) >>> 0, 0], // same path
148148
'Unlock github.com for user Satoshi Nakamoto?',
@@ -151,8 +151,5 @@ false, //encrypt? - has to be FALSE in decryption
151151
false, //askOnEncrypt? is the same in encryption and decryption
152152
true) // askOnDecrypt? we want this becuase otherwise somebody could rob us!
153153
```
154-
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.
155-
156-
157-
158154

155+
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.

0 commit comments

Comments
 (0)