Skip to content

Commit 5285b39

Browse files
committed
Update Mbed TLS to the latest development version
This updates Mbed TLS to the latest development version, commit 535ee4a35b9c in the Mbed TLS repo.
1 parent 86825a6 commit 5285b39

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+8099
-3045
lines changed

features/mbedtls/VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
mbedtls-2.15.1
1+
development

features/mbedtls/inc/mbedtls/aes.h

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,16 @@ typedef struct mbedtls_aes_xts_context
121121
* It must be the first API called before using
122122
* the context.
123123
*
124-
* \param ctx The AES context to initialize.
124+
* \param ctx The AES context to initialize. This must not be \c NULL.
125125
*/
126126
void mbedtls_aes_init( mbedtls_aes_context *ctx );
127127

128128
/**
129129
* \brief This function releases and clears the specified AES context.
130130
*
131131
* \param ctx The AES context to clear.
132+
* If this is \c NULL, this function does nothing.
133+
* Otherwise, the context must have been at least initialized.
132134
*/
133135
void mbedtls_aes_free( mbedtls_aes_context *ctx );
134136

@@ -139,14 +141,16 @@ void mbedtls_aes_free( mbedtls_aes_context *ctx );
139141
* It must be the first API called before using
140142
* the context.
141143
*
142-
* \param ctx The AES XTS context to initialize.
144+
* \param ctx The AES XTS context to initialize. This must not be \c NULL.
143145
*/
144146
void mbedtls_aes_xts_init( mbedtls_aes_xts_context *ctx );
145147

146148
/**
147149
* \brief This function releases and clears the specified AES XTS context.
148150
*
149151
* \param ctx The AES XTS context to clear.
152+
* If this is \c NULL, this function does nothing.
153+
* Otherwise, the context must have been at least initialized.
150154
*/
151155
void mbedtls_aes_xts_free( mbedtls_aes_xts_context *ctx );
152156
#endif /* MBEDTLS_CIPHER_MODE_XTS */
@@ -155,7 +159,9 @@ void mbedtls_aes_xts_free( mbedtls_aes_xts_context *ctx );
155159
* \brief This function sets the encryption key.
156160
*
157161
* \param ctx The AES context to which the key should be bound.
162+
* It must be initialized.
158163
* \param key The encryption key.
164+
* This must be a readable buffer of size \p keybits bits.
159165
* \param keybits The size of data passed in bits. Valid options are:
160166
* <ul><li>128 bits</li>
161167
* <li>192 bits</li>
@@ -171,7 +177,9 @@ int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
171177
* \brief This function sets the decryption key.
172178
*
173179
* \param ctx The AES context to which the key should be bound.
180+
* It must be initialized.
174181
* \param key The decryption key.
182+
* This must be a readable buffer of size \p keybits bits.
175183
* \param keybits The size of data passed. Valid options are:
176184
* <ul><li>128 bits</li>
177185
* <li>192 bits</li>
@@ -189,8 +197,10 @@ int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
189197
* sets the encryption key.
190198
*
191199
* \param ctx The AES XTS context to which the key should be bound.
200+
* It must be initialized.
192201
* \param key The encryption key. This is comprised of the XTS key1
193202
* concatenated with the XTS key2.
203+
* This must be a readable buffer of size \p keybits bits.
194204
* \param keybits The size of \p key passed in bits. Valid options are:
195205
* <ul><li>256 bits (each of key1 and key2 is a 128-bit key)</li>
196206
* <li>512 bits (each of key1 and key2 is a 256-bit key)</li></ul>
@@ -207,8 +217,10 @@ int mbedtls_aes_xts_setkey_enc( mbedtls_aes_xts_context *ctx,
207217
* sets the decryption key.
208218
*
209219
* \param ctx The AES XTS context to which the key should be bound.
220+
* It must be initialized.
210221
* \param key The decryption key. This is comprised of the XTS key1
211222
* concatenated with the XTS key2.
223+
* This must be a readable buffer of size \p keybits bits.
212224
* \param keybits The size of \p key passed in bits. Valid options are:
213225
* <ul><li>256 bits (each of key1 and key2 is a 128-bit key)</li>
214226
* <li>512 bits (each of key1 and key2 is a 256-bit key)</li></ul>
@@ -234,10 +246,13 @@ int mbedtls_aes_xts_setkey_dec( mbedtls_aes_xts_context *ctx,
234246
* call to this API with the same context.
235247
*
236248
* \param ctx The AES context to use for encryption or decryption.
249+
* It must be initialized and bound to a key.
237250
* \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
238251
* #MBEDTLS_AES_DECRYPT.
239-
* \param input The 16-Byte buffer holding the input data.
240-
* \param output The 16-Byte buffer holding the output data.
252+
* \param input The buffer holding the input data.
253+
* It must be readable and at least \c 16 Bytes long.
254+
* \param output The buffer where the output data will be written.
255+
* It must be writeable and at least \c 16 Bytes long.
241256
242257
* \return \c 0 on success.
243258
*/
@@ -260,8 +275,8 @@ int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx,
260275
* mbedtls_aes_setkey_enc() or mbedtls_aes_setkey_dec() must be called
261276
* before the first call to this API with the same context.
262277
*
263-
* \note This function operates on aligned blocks, that is, the input size
264-
* must be a multiple of the AES block size of 16 Bytes.
278+
* \note This function operates on full blocks, that is, the input size
279+
* must be a multiple of the AES block size of \c 16 Bytes.
265280
*
266281
* \note Upon exit, the content of the IV is updated so that you can
267282
* call the same function again on the next
@@ -272,13 +287,17 @@ int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx,
272287
*
273288
*
274289
* \param ctx The AES context to use for encryption or decryption.
290+
* It must be initialized and bound to a key.
275291
* \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
276292
* #MBEDTLS_AES_DECRYPT.
277293
* \param length The length of the input data in Bytes. This must be a
278-
* multiple of the block size (16 Bytes).
294+
* multiple of the block size (\c 16 Bytes).
279295
* \param iv Initialization vector (updated after use).
296+
* It must be a readable and writeable buffer of \c 16 Bytes.
280297
* \param input The buffer holding the input data.
298+
* It must be readable and of size \p length Bytes.
281299
* \param output The buffer holding the output data.
300+
* It must be writeable and of size \p length Bytes.
282301
*
283302
* \return \c 0 on success.
284303
* \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH
@@ -306,25 +325,26 @@ int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
306325
* returns #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH.
307326
*
308327
* \param ctx The AES XTS context to use for AES XTS operations.
328+
* It must be initialized and bound to a key.
309329
* \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
310330
* #MBEDTLS_AES_DECRYPT.
311-
* \param length The length of a data unit in bytes. This can be any
331+
* \param length The length of a data unit in Bytes. This can be any
312332
* length between 16 bytes and 2^24 bytes inclusive
313333
* (between 1 and 2^20 block cipher blocks).
314334
* \param data_unit The address of the data unit encoded as an array of 16
315335
* bytes in little-endian format. For disk encryption, this
316336
* is typically the index of the block device sector that
317337
* contains the data.
318338
* \param input The buffer holding the input data (which is an entire
319-
* data unit). This function reads \p length bytes from \p
339+
* data unit). This function reads \p length Bytes from \p
320340
* input.
321341
* \param output The buffer holding the output data (which is an entire
322-
* data unit). This function writes \p length bytes to \p
342+
* data unit). This function writes \p length Bytes to \p
323343
* output.
324344
*
325345
* \return \c 0 on success.
326346
* \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH if \p length is
327-
* smaller than an AES block in size (16 bytes) or if \p
347+
* smaller than an AES block in size (16 Bytes) or if \p
328348
* length is larger than 2^20 blocks (16 MiB).
329349
*/
330350
int mbedtls_aes_crypt_xts( mbedtls_aes_xts_context *ctx,
@@ -360,13 +380,18 @@ int mbedtls_aes_crypt_xts( mbedtls_aes_xts_context *ctx,
360380
*
361381
*
362382
* \param ctx The AES context to use for encryption or decryption.
383+
* It must be initialized and bound to a key.
363384
* \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
364385
* #MBEDTLS_AES_DECRYPT.
365-
* \param length The length of the input data.
386+
* \param length The length of the input data in Bytes.
366387
* \param iv_off The offset in IV (updated after use).
388+
* It must point to a valid \c size_t.
367389
* \param iv The initialization vector (updated after use).
390+
* It must be a readable and writeable buffer of \c 16 Bytes.
368391
* \param input The buffer holding the input data.
392+
* It must be readable and of size \p length Bytes.
369393
* \param output The buffer holding the output data.
394+
* It must be writeable and of size \p length Bytes.
370395
*
371396
* \return \c 0 on success.
372397
*/
@@ -401,12 +426,16 @@ int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx,
401426
*
402427
*
403428
* \param ctx The AES context to use for encryption or decryption.
429+
* It must be initialized and bound to a key.
404430
* \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
405431
* #MBEDTLS_AES_DECRYPT
406432
* \param length The length of the input data.
407433
* \param iv The initialization vector (updated after use).
434+
* It must be a readable and writeable buffer of \c 16 Bytes.
408435
* \param input The buffer holding the input data.
436+
* It must be readable and of size \p length Bytes.
409437
* \param output The buffer holding the output data.
438+
* It must be writeable and of size \p length Bytes.
410439
*
411440
* \return \c 0 on success.
412441
*/
@@ -451,11 +480,16 @@ int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx,
451480
* will compromise security.
452481
*
453482
* \param ctx The AES context to use for encryption or decryption.
483+
* It must be initialized and bound to a key.
454484
* \param length The length of the input data.
455485
* \param iv_off The offset in IV (updated after use).
486+
* It must point to a valid \c size_t.
456487
* \param iv The initialization vector (updated after use).
488+
* It must be a readable and writeable buffer of \c 16 Bytes.
457489
* \param input The buffer holding the input data.
490+
* It must be readable and of size \p length Bytes.
458491
* \param output The buffer holding the output data.
492+
* It must be writeable and of size \p length Bytes.
459493
*
460494
* \return \c 0 on success.
461495
*/
@@ -527,15 +561,21 @@ int mbedtls_aes_crypt_ofb( mbedtls_aes_context *ctx,
527561
* securely discarded as soon as it's no longer needed.
528562
*
529563
* \param ctx The AES context to use for encryption or decryption.
564+
* It must be initialized and bound to a key.
530565
* \param length The length of the input data.
531566
* \param nc_off The offset in the current \p stream_block, for
532567
* resuming within the current cipher stream. The
533568
* offset pointer should be 0 at the start of a stream.
569+
* It must point to a valid \c size_t.
534570
* \param nonce_counter The 128-bit nonce and counter.
571+
* It must be a readable-writeable buffer of \c 16 Bytes.
535572
* \param stream_block The saved stream block for resuming. This is
536573
* overwritten by the function.
574+
* It must be a readable-writeable buffer of \c 16 Bytes.
537575
* \param input The buffer holding the input data.
576+
* It must be readable and of size \p length Bytes.
538577
* \param output The buffer holding the output data.
578+
* It must be writeable and of size \p length Bytes.
539579
*
540580
* \return \c 0 on success.
541581
*/
@@ -588,7 +628,7 @@ int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx,
588628
* \brief Deprecated internal AES block encryption function
589629
* without return value.
590630
*
591-
* \deprecated Superseded by mbedtls_aes_encrypt_ext() in 2.5.0.
631+
* \deprecated Superseded by mbedtls_internal_aes_encrypt()
592632
*
593633
* \param ctx The AES context to use for encryption.
594634
* \param input Plaintext block.
@@ -602,7 +642,7 @@ MBEDTLS_DEPRECATED void mbedtls_aes_encrypt( mbedtls_aes_context *ctx,
602642
* \brief Deprecated internal AES block decryption function
603643
* without return value.
604644
*
605-
* \deprecated Superseded by mbedtls_aes_decrypt_ext() in 2.5.0.
645+
* \deprecated Superseded by mbedtls_internal_aes_decrypt()
606646
*
607647
* \param ctx The AES context to use for decryption.
608648
* \param input Ciphertext block.
@@ -615,6 +655,8 @@ MBEDTLS_DEPRECATED void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
615655
#undef MBEDTLS_DEPRECATED
616656
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
617657

658+
659+
#if defined(MBEDTLS_SELF_TEST)
618660
/**
619661
* \brief Checkup routine.
620662
*
@@ -623,6 +665,8 @@ MBEDTLS_DEPRECATED void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
623665
*/
624666
int mbedtls_aes_self_test( int verbose );
625667

668+
#endif /* MBEDTLS_SELF_TEST */
669+
626670
#ifdef __cplusplus
627671
}
628672
#endif

features/mbedtls/inc/mbedtls/aesni.h

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
* \file aesni.h
33
*
44
* \brief AES-NI for hardware AES acceleration on some Intel processors
5+
*
6+
* \warning These functions are only for internal use by other library
7+
* functions; you must not call them directly.
58
*/
69
/*
710
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
@@ -24,6 +27,12 @@
2427
#ifndef MBEDTLS_AESNI_H
2528
#define MBEDTLS_AESNI_H
2629

30+
#if !defined(MBEDTLS_CONFIG_FILE)
31+
#include "config.h"
32+
#else
33+
#include MBEDTLS_CONFIG_FILE
34+
#endif
35+
2736
#include "aes.h"
2837

2938
#define MBEDTLS_AESNI_AES 0x02000000u
@@ -42,7 +51,10 @@ extern "C" {
4251
#endif
4352

4453
/**
45-
* \brief AES-NI features detection routine
54+
* \brief Internal function to detect the AES-NI feature in CPUs.
55+
*
56+
* \note This function is only for internal use by other library
57+
* functions; you must not call it directly.
4658
*
4759
* \param what The feature to detect
4860
* (MBEDTLS_AESNI_AES or MBEDTLS_AESNI_CLMUL)
@@ -52,7 +64,10 @@ extern "C" {
5264
int mbedtls_aesni_has_support( unsigned int what );
5365

5466
/**
55-
* \brief AES-NI AES-ECB block en(de)cryption
67+
* \brief Internal AES-NI AES-ECB block encryption and decryption
68+
*
69+
* \note This function is only for internal use by other library
70+
* functions; you must not call it directly.
5671
*
5772
* \param ctx AES context
5873
* \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
@@ -62,12 +77,15 @@ int mbedtls_aesni_has_support( unsigned int what );
6277
* \return 0 on success (cannot fail)
6378
*/
6479
int mbedtls_aesni_crypt_ecb( mbedtls_aes_context *ctx,
65-
int mode,
66-
const unsigned char input[16],
67-
unsigned char output[16] );
80+
int mode,
81+
const unsigned char input[16],
82+
unsigned char output[16] );
6883

6984
/**
70-
* \brief GCM multiplication: c = a * b in GF(2^128)
85+
* \brief Internal GCM multiplication: c = a * b in GF(2^128)
86+
*
87+
* \note This function is only for internal use by other library
88+
* functions; you must not call it directly.
7189
*
7290
* \param c Result
7391
* \param a First operand
@@ -77,21 +95,29 @@ int mbedtls_aesni_crypt_ecb( mbedtls_aes_context *ctx,
7795
* elements of GF(2^128) as per the GCM spec.
7896
*/
7997
void mbedtls_aesni_gcm_mult( unsigned char c[16],
80-
const unsigned char a[16],
81-
const unsigned char b[16] );
98+
const unsigned char a[16],
99+
const unsigned char b[16] );
82100

83101
/**
84-
* \brief Compute decryption round keys from encryption round keys
102+
* \brief Internal round key inversion. This function computes
103+
* decryption round keys from the encryption round keys.
104+
*
105+
* \note This function is only for internal use by other library
106+
* functions; you must not call it directly.
85107
*
86108
* \param invkey Round keys for the equivalent inverse cipher
87109
* \param fwdkey Original round keys (for encryption)
88110
* \param nr Number of rounds (that is, number of round keys minus one)
89111
*/
90112
void mbedtls_aesni_inverse_key( unsigned char *invkey,
91-
const unsigned char *fwdkey, int nr );
113+
const unsigned char *fwdkey,
114+
int nr );
92115

93116
/**
94-
* \brief Perform key expansion (for encryption)
117+
* \brief Internal key expansion for encryption
118+
*
119+
* \note This function is only for internal use by other library
120+
* functions; you must not call it directly.
95121
*
96122
* \param rk Destination buffer where the round keys are written
97123
* \param key Encryption key
@@ -100,8 +126,8 @@ void mbedtls_aesni_inverse_key( unsigned char *invkey,
100126
* \return 0 if successful, or MBEDTLS_ERR_AES_INVALID_KEY_LENGTH
101127
*/
102128
int mbedtls_aesni_setkey_enc( unsigned char *rk,
103-
const unsigned char *key,
104-
size_t bits );
129+
const unsigned char *key,
130+
size_t bits );
105131

106132
#ifdef __cplusplus
107133
}

0 commit comments

Comments
 (0)