blob: 2f55d73f65767a926a69b65d8fc2717772e00a69 [file] [log] [blame]
David Brownfecda2d2017-09-07 10:20:34 -06001
2TinyCrypt Cryptographic Library
3###############################
4Copyright (C) 2015 by Intel Corporation, All Rights Reserved.
5
6Overview
7********
8The TinyCrypt Library provides an implementation for targeting constrained devices
9with a minimal set of standard cryptography primitives, as listed below. To better
10serve applications targeting constrained devices, TinyCrypt implementations differ
11from the standard specifications (see the Important Remarks section for some
12important differences). Certain cryptographic primitives depend on other
13primitives, as mentioned in the list below.
14
15Aside from the Important Remarks section below, valuable information on the usage,
16security and technicalities of each cryptographic primitive are found in the
17corresponding header file.
18
19* SHA-256:
20
21 * Type of primitive: Hash function.
22 * Standard Specification: NIST FIPS PUB 180-4.
23 * Requires: --
24
25* HMAC-SHA256:
26
27 * Type of primitive: Message authentication code.
28 * Standard Specification: RFC 2104.
29 * Requires: SHA-256
30
31* HMAC-PRNG:
32
33 * Type of primitive: Pseudo-random number generator (256-bit strength).
34 * Standard Specification: NIST SP 800-90A.
35 * Requires: SHA-256 and HMAC-SHA256.
36
37* AES-128:
38
39 * Type of primitive: Block cipher.
40 * Standard Specification: NIST FIPS PUB 197.
41 * Requires: --
42
43* AES-CBC mode:
44
45 * Type of primitive: Encryption mode of operation.
46 * Standard Specification: NIST SP 800-38A.
47 * Requires: AES-128.
48
49* AES-CTR mode:
50
51 * Type of primitive: Encryption mode of operation.
52 * Standard Specification: NIST SP 800-38A.
53 * Requires: AES-128.
54
55* AES-CMAC mode:
56
57 * Type of primitive: Message authentication code.
58 * Standard Specification: NIST SP 800-38B.
59 * Requires: AES-128.
60
61* AES-CCM mode:
62
63 * Type of primitive: Authenticated encryption.
64 * Standard Specification: NIST SP 800-38C.
65 * Requires: AES-128.
66
67* CTR-PRNG:
68
69 * Type of primitive: Pseudo-random number generator (128-bit strength).
70 * Standard Specification: NIST SP 800-90A.
71 * Requires: AES-128.
72
73* ECC-DH:
74
75 * Type of primitive: Key exchange.
76 * Standard Specification: RFC 6090.
77 * Requires: ECC auxiliary functions (ecc.h/c).
78
79* ECC-DSA:
80
81 * Type of primitive: Digital signature.
82 * Standard Specification: RFC 6090.
83 * Requires: ECC auxiliary functions (ecc.h/c).
84
85Design Goals
86************
87
88* Minimize the code size of each cryptographic primitive. This means minimize
89 the size of a platform-independent implementation, as presented in TinyCrypt.
90 Note that various applications may require further features, optimizations with
91 respect to other metrics and countermeasures for particular threats. These
92 peculiarities would increase the code size and thus are not considered here.
93
94* Minimize the dependencies among the cryptographic primitives. This means
95 that it is unnecessary to build and allocate object code for more primitives
96 than the ones strictly required by the intended application. In other words,
97 one can select and compile only the primitives required by the application.
98
99
100Important Remarks
101*****************
102
103The cryptographic implementations in TinyCrypt library have some limitations.
104Some of these limitations are inherent to the cryptographic primitives
105themselves, while others are specific to TinyCrypt. Some of these limitations
106are discussed in-depth below.
107
108General Remarks
109***************
110
111* TinyCrypt does **not** intend to be fully side-channel resistant. Due to the
112 variety of side-channel attacks, many of them making certain platforms
113 vulnerable. In this sense, instead of penalizing all library users with
114 side-channel countermeasures such as increasing the overall code size,
115 TinyCrypt only implements certain generic timing-attack countermeasures.
116
117Specific Remarks
118****************
119
120* SHA-256:
121
122 * The number of bits_hashed in the state is not checked for overflow. Note
123 however that this will only be a problem if you intend to hash more than
124 2^64 bits, which is an extremely large window.
125
126* HMAC:
127
128 * The HMAC verification process is assumed to be performed by the application.
129 This compares the computed tag with some given tag.
130 Note that conventional memory-comparison methods (such as memcmp function)
131 might be vulnerable to timing attacks; thus be sure to use a constant-time
132 memory comparison function (such as compare_constant_time
133 function provided in lib/utils.c).
134
135 * The tc_hmac_final function, responsible for computing the message tag,
136 cleans the state context before exiting. Thus, applications do not need to
137 clean the TCHmacState_t ctx after calling tc_hmac_final.
138
139* HMAC-PRNG:
140
141 * Before using HMAC-PRNG, you *must* find an entropy source to produce a seed.
142 PRNGs only stretch the seed into a seemingly random output of arbitrary
143 length. The security of the output is exactly equal to the
144 unpredictability of the seed.
145
146 * NIST SP 800-90A requires three items as seed material in the initialization
147 step: entropy seed, personalization and a nonce (which is not implemented).
148 TinyCrypt requires the personalization byte array and automatically creates
149 the entropy seed using a mandatory call to the re-seed function.
150
151* AES-128:
152
153 * The current implementation does not support other key-lengths (such as 256
154 bits). Note that if you need AES-256, it doesn't sound as though your
155 application is running in a constrained environment. AES-256 requires keys
156 twice the size as for AES-128, and the key schedule is 40% larger.
157
158* CTR mode:
159
160 * The AES-CTR mode limits the size of a data message they encrypt to 2^32
161 blocks. If you need to encrypt larger data sets, your application would
162 need to replace the key after 2^32 block encryptions.
163
164* CTR-PRNG:
165
166 * Before using CTR-PRNG, you *must* find an entropy source to produce a seed.
167 PRNGs only stretch the seed into a seemingly random output of arbitrary
168 length. The security of the output is exactly equal to the
169 unpredictability of the seed.
170
171* CBC mode:
172
173 * TinyCrypt CBC decryption assumes that the iv and the ciphertext are
174 contiguous (as produced by TinyCrypt CBC encryption). This allows for a
175 very efficient decryption algorithm that would not otherwise be possible.
176
177* CMAC mode:
178
179 * AES128-CMAC mode of operation offers 64 bits of security against collision
180 attacks. Note however that an external attacker cannot generate the tags
181 him/herself without knowing the MAC key. In this sense, to attack the
182 collision property of AES128-CMAC, an external attacker would need the
183 cooperation of the legal user to produce an exponentially high number of
184 tags (e.g. 2^64) to finally be able to look for collisions and benefit
185 from them. As an extra precaution, the current implementation allows to at
186 most 2^48 calls to tc_cmac_update function before re-calling tc_cmac_setup
187 (allowing a new key to be set), as suggested in Appendix B of SP 800-38B.
188
189* CCM mode:
190
191 * There are a few tradeoffs for the selection of the parameters of CCM mode.
192 In special, there is a tradeoff between the maximum number of invocations
193 of CCM under a given key and the maximum payload length for those
194 invocations. Both things are related to the parameter 'q' of CCM mode. The
195 maximum number of invocations of CCM under a given key is determined by
196 the nonce size, which is: 15-q bytes. The maximum payload length for those
197 invocations is defined as 2^(8q) bytes.
198
199 To achieve minimal code size, TinyCrypt CCM implementation fixes q = 2,
200 which is a quite reasonable choice for constrained applications. The
201 implications of this choice are:
202
203 The nonce size is: 13 bytes.
204
205 The maximum payload length is: 2^16 bytes = 65 KB.
206
207 The mac size parameter is an important parameter to estimate the security
208 against collision attacks (that aim at finding different messages that
209 produce the same authentication tag). TinyCrypt CCM implementation
210 accepts any even integer between 4 and 16, as suggested in SP 800-38C.
211
212 * TinyCrypt CCM implementation accepts associated data of any length between
213 0 and (2^16 - 2^8) = 65280 bytes.
214
215 * TinyCrypt CCM implementation accepts:
216
217 * Both non-empty payload and associated data (it encrypts and
218 authenticates the payload and only authenticates the associated data);
219
220 * Non-empty payload and empty associated data (it encrypts and
221 authenticates the payload);
222
223 * Non-empty associated data and empty payload (it degenerates to an
224 authentication-only mode on the associated data).
225
226 * RFC-3610, which also specifies CCM, presents a few relevant security
227 suggestions, such as: it is recommended for most applications to use a
228 mac size greater than 8. Besides, it is emphasized that the usage of the
229 same nonce for two different messages which are encrypted with the same
230 key obviously destroys the security properties of CCM mode.
231
232* ECC-DH and ECC-DSA:
233
234 * TinyCrypt ECC implementation is based on nano-ecc (see
235 https://github.com/iSECPartners/nano-ecc) which in turn is based on
236 mciro-ecc (see https://github.com/kmackay/micro-ecc). In the original
237 nano and micro-ecc documentation, there is an important remark about the
238 way integers are represented:
239
240 "Integer representation: To reduce code size, all large integers are
241 represented using little-endian words - so the least significant word is
242 first. You can use the 'ecc_bytes2native()' and 'ecc_native2bytes()'
243 functions to convert between the native integer representation and the
244 standardized octet representation."
245
246Examples of Applications
247************************
248It is possible to do useful cryptography with only the given small set of
249primitives. With this list of primitives it becomes feasible to support a range
250of cryptography usages:
251
252 * Measurement of code, data structures, and other digital artifacts (SHA256);
253
254 * Generate commitments (SHA256);
255
256 * Construct keys (HMAC-SHA256);
257
258 * Extract entropy from strings containing some randomness (HMAC-SHA256);
259
260 * Construct random mappings (HMAC-SHA256);
261
262 * Construct nonces and challenges (HMAC-PRNG, CTR-PRNG);
263
264 * Authenticate using a shared secret (HMAC-SHA256);
265
266 * Create an authenticated, replay-protected session (HMAC-SHA256 + HMAC-PRNG);
267
268 * Authenticated encryption (AES-128 + AES-CCM);
269
270 * Key-exchange (EC-DH);
271
272 * Digital signature (EC-DSA);
273
274Test Vectors
275************
276
277The library provides a test program for each cryptographic primitive (see 'test'
278folder). Besides illustrating how to use the primitives, these tests evaluate
279the correctness of the implementations by checking the results against
280well-known publicly validated test vectors.
281
282For the case of the HMAC-PRNG, due to the necessity of performing an extensive
283battery test to produce meaningful conclusions, we suggest the user to evaluate
284the unpredictability of the implementation by using the NIST Statistical Test
285Suite (see References).
286
287For the case of the EC-DH and EC-DSA implementations, most of the test vectors
288were obtained from the site of the NIST Cryptographic Algorithm Validation
289Program (CAVP), see References.
290
291References
292**********
293
294* `NIST FIPS PUB 180-4 (SHA-256)`_
295
296.. _NIST FIPS PUB 180-4 (SHA-256):
297 http://csrc.nist.gov/publications/fips/fips180-4/fips-180-4.pdf
298
299* `NIST FIPS PUB 197 (AES-128)`_
300
301.. _NIST FIPS PUB 197 (AES-128):
302 http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf
303
304* `NIST SP800-90A (HMAC-PRNG)`_
305
306.. _NIST SP800-90A (HMAC-PRNG):
307 http://csrc.nist.gov/publications/nistpubs/800-90A/SP800-90A.pdf
308
309* `NIST SP 800-38A (AES-CBC and AES-CTR)`_
310
311.. _NIST SP 800-38A (AES-CBC and AES-CTR):
312 http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf
313
314* `NIST SP 800-38B (AES-CMAC)`_
315
316.. _NIST SP 800-38B (AES-CMAC):
317 http://csrc.nist.gov/publications/nistpubs/800-38B/SP_800-38B.pdf
318
319* `NIST SP 800-38C (AES-CCM)`_
320
321.. _NIST SP 800-38C (AES-CCM):
322 http://csrc.nist.gov/publications/nistpubs/800-38C/SP800-38C_updated-July20_2007.pdf
323
324* `NIST Statistical Test Suite`_
325
326.. _NIST Statistical Test Suite:
327 http://csrc.nist.gov/groups/ST/toolkit/rng/documentation_software.html
328
329* `NIST Cryptographic Algorithm Validation Program (CAVP) site`_
330
331.. _NIST Cryptographic Algorithm Validation Program (CAVP) site:
332 http://csrc.nist.gov/groups/STM/cavp/
333
334* `RFC 2104 (HMAC-SHA256)`_
335
336.. _RFC 2104 (HMAC-SHA256):
337 https://www.ietf.org/rfc/rfc2104.txt
338
339* `RFC 6090 (ECC-DH and ECC-DSA)`_
340
341.. _RFC 6090 (ECC-DH and ECC-DSA):
342 https://www.ietf.org/rfc/rfc6090.txt