You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: draft-RNCryptor-Spec-v4.0.md
+76-39Lines changed: 76 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,19 +18,26 @@
18
18
19
19
All data is in network order (big-endian).
20
20
21
-
Note that the version of the RNCryptor ObjC library is not directly related to the version of the RNCryptor file format. For example, v2.2 of the RNCryptor ObjC library writes v3 of the file format. The versioning of an implementation is related to its API, not the file formats it supports.
21
+
Note that the version of the RNCryptor ObjC library is not directly related to
22
+
the version of the RNCryptor file format. For example, v2.2 of the RNCryptor
23
+
ObjC library writes v3 of the file format. The versioning of an implementation
24
+
is related to its API, not the file formats it supports.
22
25
23
26
## Key Generation
24
27
25
-
RNCryptor uses either a 256-bit random key or a password. It extracts a 512-bit pseudorandom key (PRK) from this using HKDF-Extract or PBKDF2. It then uses HKDF-Expand to expand this key material into the IV, a validation token, the encryption key, and the HMAC key.
28
+
RNCryptor uses either a 256-bit random key or a password. It extracts a 512-bit
29
+
pseudorandom key (PRK) from this using HKDF-Extract or PBKDF2. It then uses
30
+
HKDF-Expand to expand this key material into the IV, a validation token, the
31
+
encryption key, and the HMAC key.
26
32
27
33
## Key Validation
28
34
29
35
Using the validation token, the encryption key can be tested without validating HMAC.
30
36
31
37
## Implementation Procedure
32
38
33
-
Unless otherwise noted, all example implementations are given in an abtract, idealized language. It includes the following constructs:
39
+
Unless otherwise noted, all example implementations are given in an abtract,
40
+
idealized language. It includes the following constructs:
34
41
35
42
*`||` - Operator that concatenates two octet strings.
36
43
*`RandomDataOfLength(n)` - Returns `n` random octets generated by a [CSPRNG](https://en.wikipedia.org/wiki/Cryptographically_secure_pseudorandom_number_generator).
@@ -46,76 +53,91 @@ Unless otherwise noted, all example implementations are given in an abtract, ide
46
53
*`SHA512` - Token indicating SHA-2 hash function with 512-bit length.
47
54
*`CBCMode` - Token indicating [cipher block chaining (CBC)](https://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher-block_chaining_.28CBC.29) block cipher mode. This implicitly includes PKCS#7 padding.
48
55
56
+
## Key HKDF-expansion
57
+
58
+
Expand PRK to 96 bytes for required material using HMAC-SHA-512 + HMAC-SHA-512-256.
When comparing the computed HMAC with the expected HMAC, it is important that your comparison be made in consistent time. Your comparison function should compare all of the bytes of the ExpectedHMAC, even if it finds a mismatch. Otherwise, your comparison can be subject to a timing attack, where the attacker sends you different HMACs and times how long it takes you to return that they are not equal. Using this, the attacker can progressively determine each byte of the HMAC.
218
+
When comparing the computed HMAC with the expected HMAC, it is important that
219
+
your comparison be made in consistent time. Your comparison function should
220
+
compare all of the bytes of the ExpectedHMAC, even if it finds a mismatch.
221
+
Otherwise, your comparison can be subject to a timing attack, where the
222
+
attacker sends you different HMACs and times how long it takes you to return
223
+
that they are not equal. Using this, the attacker can progressively determine
224
+
each byte of the HMAC.
197
225
198
226
Here is an example consistent-time equality function in ObjC:
// The point of this routine is XOR the bytes of each data and accumulate the results with OR.
@@ -219,18 +248,26 @@ Here is an example consistent-time equality function in ObjC:
219
248
220
249
## Approach and Notes
221
250
222
-
RNCryptor is very similar to [draft-mcgrew-aead-aes-cbc-hmac-sha2](https://tools.ietf.org/id/draft-mcgrew-aead-aes-cbc-hmac-sha2-02.html) AEAD_AES_256_CBC_HMAC_SHA_512 in how it produces authenticated encryption from AES-CBC and HMAC-SHA. It differs slightly in how it generates the keys (via HKDF rather than splitting the PRK), and it computes the IV via HKDF rather than passing a random IV.
AEAD_AES_256_CBC_HMAC_SHA_512 in how it produces authenticated encryption from
254
+
AES-CBC and HMAC-SHA. It differs slightly in how it generates the keys (via
255
+
HKDF rather than splitting the PRK), and it computes the IV via HKDF rather
256
+
than passing a random IV.
223
257
224
-
RNCryptor relies on HKDF ([RFC 5869](https://tools.ietf.org/html/rfc5869)) to generate random octet strings from a master 512-bit PRK.
258
+
RNCryptor relies on HKDF ([RFC 5869](https://tools.ietf.org/html/rfc5869)) to
259
+
generate random octet strings from a master 512-bit PRK.
225
260
226
-
RNCryptor makes an effort to minimize the number of cryptographic primitives required. In particular, SHA-512 is used in some places that SHA-256 could be sufficient.
261
+
The HMAC is are truncated according to [RFC 2104 Section
262
+
5](https://tools.ietf.org/html/rfc2104). Private HMACs are not truncated.
227
263
228
-
The HMAC is truncated to 256 bits in accordance with AEAD_AES_256_CBC_HMAC_SHA_512.
264
+
SHA-512 is used throughout to favor CPU rather than GPU performance.
229
265
230
-
## Changes since version 3.1
266
+
## Changes since version 3.0
231
267
232
268
* Employs draft-mcgrew-aead-aes-cbc-hmac-sha2 and HKDF.
0 commit comments