Skip to content

Commit 9c99dc8

Browse files
authored
Merge pull request #2395 from ARMmbed/development-psa-merged-dev-8e76332
Merge updated development-psa into development
2 parents f352f75 + 064128c commit 9c99dc8

Some content is hidden

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

54 files changed

+8828
-518
lines changed

.gitmodules

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[submodule "crypto"]
2+
path = crypto
3+
url = https://github.com/ARMmbed/mbed-crypto
4+
branch = development

CMakeLists.txt

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ option(USE_PKCS11_HELPER_LIBRARY "Build mbed TLS with the pkcs11-helper library.
99
option(ENABLE_ZLIB_SUPPORT "Build mbed TLS with zlib library." OFF)
1010

1111
option(ENABLE_PROGRAMS "Build mbed TLS programs." ON)
12+
option(USE_CRYPTO_SUBMODULE "Build and use libmbedcrypto from the crypto submodule." OFF)
1213

1314
option(UNSAFE_BUILD "Allow unsafe builds. These builds ARE NOT SECURE." OFF)
1415

@@ -167,8 +168,6 @@ else()
167168
set(LIB_INSTALL_DIR lib)
168169
endif()
169170

170-
include_directories(include/)
171-
172171
if(ENABLE_ZLIB_SUPPORT)
173172
find_package(ZLIB)
174173

@@ -179,6 +178,10 @@ endif(ENABLE_ZLIB_SUPPORT)
179178

180179
add_subdirectory(library)
181180
add_subdirectory(include)
181+
if(USE_CRYPTO_SUBMODULE)
182+
add_subdirectory(crypto/library)
183+
add_subdirectory(crypto/include)
184+
endif()
182185

183186
if(ENABLE_PROGRAMS)
184187
add_subdirectory(programs)

ChangeLog

+18
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,24 @@ Bugfix
9393
* Clarify documentation of mbedtls_ssl_set_own_cert() regarding the absence
9494
of check for certificate/key matching. Reported by Attila Molnar, #507.
9595

96+
= mbed TLS 2.15.1 branch released 2018-11-30
97+
98+
Changes
99+
* Update the Mbed Crypto submodule to version 0.1.0b2.
100+
101+
= mbed TLS 2.15.0 branch released 2018-11-23
102+
103+
Features
104+
* Add an experimental build option, USE_CRYPTO_SUBMODULE, to enable use of
105+
Mbed Crypto as the source of the cryptography implementation.
106+
* Add an experimental configuration option, MBEDTLS_PSA_CRYPTO_C, to enable
107+
the PSA Crypto API from Mbed Crypto when additionally used with the
108+
USE_CRYPTO_SUBMODULE build option.
109+
110+
Changes
111+
* Add unit tests for AES-GCM when called through mbedtls_cipher_auth_xxx()
112+
from the cipher abstraction layer. Fixes #2198.
113+
96114
= mbed TLS 2.14.1 branch released 2018-11-30
97115

98116
Security

Makefile

+12
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ install: no_test
2828
mkdir -p $(DESTDIR)/lib
2929
cp -RP library/libmbedtls.* $(DESTDIR)/lib
3030
cp -RP library/libmbedx509.* $(DESTDIR)/lib
31+
ifdef USE_CRYPTO_SUBMODULE
32+
mkdir -p $(DESTDIR)/include/psa
33+
cp -rp crypto/include/psa $(DESTDIR)/include
34+
cp -RP crypto/library/libmbedcrypto.* $(DESTDIR)/lib
35+
else
3136
cp -RP library/libmbedcrypto.* $(DESTDIR)/lib
37+
endif
3238

3339
mkdir -p $(DESTDIR)/bin
3440
for p in programs/*/* ; do \
@@ -44,6 +50,9 @@ uninstall:
4450
rm -f $(DESTDIR)/lib/libmbedtls.*
4551
rm -f $(DESTDIR)/lib/libmbedx509.*
4652
rm -f $(DESTDIR)/lib/libmbedcrypto.*
53+
ifdef USE_CRYPTO_SUBMODULE
54+
$(MAKE) -C crypto uninstall
55+
endif
4756

4857
for p in programs/*/* ; do \
4958
if [ -x $$p ] && [ ! -d $$p ] ; \
@@ -85,6 +94,9 @@ clean:
8594
$(MAKE) -C library clean
8695
$(MAKE) -C programs clean
8796
$(MAKE) -C tests clean
97+
ifdef USE_CRYPTO_SUBMODULE
98+
$(MAKE) -C crypto clean
99+
endif
88100
ifndef WINDOWS
89101
find . \( -name \*.gcno -o -name \*.gcda -o -name \*.info \) -exec rm {} +
90102
endif

README.md

+37
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,43 @@ Configurations
158158

159159
We provide some non-standard configurations focused on specific use cases in the `configs/` directory. You can read more about those in `configs/README.txt`
160160

161+
Using Mbed Crypto as a submodule
162+
--------------------------------
163+
164+
As an experimental feature, you can use Mbed Crypto as the source of the cryptography implementation, with Mbed TLS providing the X.509 and TLS parts of the library. Mbed Crypto is currently provided for evaluation only and should not be used in production. At this point, you should only use this option if you want to try out the experimental PSA Crypto API.
165+
166+
To enable the use of Mbed Crypto as a submodule:
167+
168+
1. Check out the `crypto` submodule and update it.
169+
170+
git submodule init crypto
171+
git submodule update crypto
172+
173+
2. (Optional) TO enable the PSA Crypto API, set the build configuration option `MBEDTLS_PSA_CRYPTO_C`. You can either edit `include/mbedtls/config.h` directly or use the configuration script:
174+
175+
scripts/config.pl set MBEDTLS_PSA_CRYPTO_C
176+
177+
3. Activate the build option `USE_CRYPTO_SUBMODULE`. With GNU make, set `USE_CRYPTO_SUBMODULE=1` on each make invocation:
178+
179+
make USE_CRYPTO_SUBMODULE=1
180+
make USE_CRYPTO_SUBMODULE=1 test
181+
tests/ssl-opt.sh -f Default
182+
183+
Note that you need to pass `USE_CRYPTO_SUBMODULE=1` even to `make clean`. For example, if you change `config.h`, run this before rebuilding:
184+
185+
make USE_CRYPTO_SUBMODULE=1 clean
186+
187+
With CMake, create a build directory (recommended) and pass `-DUSE_CRYPTO_SUBMODULE=1` to `cmake`:
188+
189+
mkdir build
190+
cd build
191+
cmake -DUSE_CRYPTO_SUBMODULE=1 ..
192+
make
193+
make test
194+
tests/ssl-opt.sh -f Default
195+
196+
Note that this does not enable the PSA-specific tests and utility programs. To use these programs, use Mbed Crypto as a standalone project.
197+
161198
Porting Mbed TLS
162199
----------------
163200

crypto

Submodule crypto added at 0574e6a

include/mbedtls/check_config.h

+36
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,38 @@
506506
#error "MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO and MBEDTLS_PLATFORM_STD_NV_SEED_WRITE cannot be defined simultaneously"
507507
#endif
508508

509+
#if defined(MBEDTLS_PSA_CRYPTO_C) && \
510+
!( defined(MBEDTLS_CTR_DRBG_C) && \
511+
defined(MBEDTLS_ENTROPY_C) )
512+
#error "MBEDTLS_PSA_CRYPTO_C defined, but not all prerequisites"
513+
#endif
514+
515+
#if defined(MBEDTLS_PSA_CRYPTO_SPM) && !defined(MBEDTLS_PSA_CRYPTO_C)
516+
#error "MBEDTLS_PSA_CRYPTO_SPM defined, but not all prerequisites"
517+
#endif
518+
519+
#if defined(MBEDTLS_PSA_CRYPTO_STORAGE_FILE_C) && defined(MBEDTLS_PSA_CRYPTO_STORAGE_ITS_C)
520+
#error "Only one of MBEDTLS_PSA_CRYPTO_STORAGE_FILE_C or MBEDTLS_PSA_CRYPTO_STORAGE_ITS_C can be defined"
521+
#endif
522+
523+
#if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) && \
524+
!( defined(MBEDTLS_PSA_CRYPTO_C) && \
525+
( defined(MBEDTLS_PSA_CRYPTO_STORAGE_FILE_C) || \
526+
defined(MBEDTLS_PSA_CRYPTO_STORAGE_ITS_C) ) )
527+
#error "MBEDTLS_PSA_CRYPTO_STORAGE_C defined, but not all prerequisites"
528+
#endif
529+
530+
#if defined(MBEDTLS_PSA_CRYPTO_STORAGE_FILE_C) && \
531+
!( defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) && \
532+
defined(MBEDTLS_FS_IO) )
533+
#error "MBEDTLS_PSA_CRYPTO_STORAGE_FILE_C defined, but not all prerequisites"
534+
#endif
535+
536+
#if defined(MBEDTLS_PSA_CRYPTO_STORAGE_ITS_C) && \
537+
! defined(MBEDTLS_PSA_CRYPTO_STORAGE_C)
538+
#error "MBEDTLS_PSA_CRYPTO_STORAGE_ITS_C defined, but not all prerequisites"
539+
#endif
540+
509541
#if defined(MBEDTLS_RSA_C) && ( !defined(MBEDTLS_BIGNUM_C) || \
510542
!defined(MBEDTLS_OID_C) )
511543
#error "MBEDTLS_RSA_C defined, but not all prerequisites"
@@ -648,6 +680,10 @@
648680
#endif
649681
#undef MBEDTLS_THREADING_IMPL
650682

683+
#if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_PSA_CRYPTO_C)
684+
#error "MBEDTLS_USE_PSA_CRYPTO defined, but not all prerequisites"
685+
#endif
686+
651687
#if defined(MBEDTLS_VERSION_FEATURES) && !defined(MBEDTLS_VERSION_C)
652688
#error "MBEDTLS_VERSION_FEATURES defined, but not all prerequisites"
653689
#endif

include/mbedtls/cipher.h

+66-20
Original file line numberDiff line numberDiff line change
@@ -180,16 +180,16 @@ typedef enum {
180180

181181
/** Supported cipher modes. */
182182
typedef enum {
183-
MBEDTLS_MODE_NONE = 0, /**< None. */
184-
MBEDTLS_MODE_ECB, /**< The ECB cipher mode. */
185-
MBEDTLS_MODE_CBC, /**< The CBC cipher mode. */
186-
MBEDTLS_MODE_CFB, /**< The CFB cipher mode. */
187-
MBEDTLS_MODE_OFB, /**< The OFB cipher mode. */
188-
MBEDTLS_MODE_CTR, /**< The CTR cipher mode. */
189-
MBEDTLS_MODE_GCM, /**< The GCM cipher mode. */
190-
MBEDTLS_MODE_STREAM, /**< The stream cipher mode. */
191-
MBEDTLS_MODE_CCM, /**< The CCM cipher mode. */
192-
MBEDTLS_MODE_XTS, /**< The XTS cipher mode. */
183+
MBEDTLS_MODE_NONE = 0, /**< None. */
184+
MBEDTLS_MODE_ECB, /**< The ECB cipher mode. */
185+
MBEDTLS_MODE_CBC, /**< The CBC cipher mode. */
186+
MBEDTLS_MODE_CFB, /**< The CFB cipher mode. */
187+
MBEDTLS_MODE_OFB, /**< The OFB cipher mode. */
188+
MBEDTLS_MODE_CTR, /**< The CTR cipher mode. */
189+
MBEDTLS_MODE_GCM, /**< The GCM cipher mode. */
190+
MBEDTLS_MODE_STREAM, /**< The stream cipher mode. */
191+
MBEDTLS_MODE_CCM, /**< The CCM cipher mode. */
192+
MBEDTLS_MODE_XTS, /**< The XTS cipher mode. */
193193
MBEDTLS_MODE_CHACHAPOLY, /**< The ChaCha-Poly cipher mode. */
194194
} mbedtls_cipher_mode_t;
195195

@@ -322,14 +322,32 @@ typedef struct mbedtls_cipher_context_t
322322
/** CMAC-specific context. */
323323
mbedtls_cmac_context_t *cmac_ctx;
324324
#endif
325+
326+
#if defined(MBEDTLS_USE_PSA_CRYPTO)
327+
/** Indicates whether the cipher operations should be performed
328+
* by Mbed TLS' own crypto library or an external implementation
329+
* of the PSA Crypto API.
330+
* This is unset if the cipher context was established through
331+
* mbedtls_cipher_setup(), and set if it was established through
332+
* mbedtls_cipher_setup_psa().
333+
*/
334+
unsigned char psa_enabled;
335+
#endif /* MBEDTLS_USE_PSA_CRYPTO */
336+
325337
} mbedtls_cipher_context_t;
326338

327339
/**
328-
* \brief This function retrieves the list of ciphers supported by the generic
329-
* cipher module.
340+
* \brief This function retrieves the list of ciphers supported
341+
* by the generic cipher module.
342+
*
343+
* For any cipher identifier in the returned list, you can
344+
* obtain the corresponding generic cipher information structure
345+
* via mbedtls_cipher_info_from_type(), which can then be used
346+
* to prepare a cipher context via mbedtls_cipher_setup().
347+
*
330348
*
331-
* \return A statically-allocated array of ciphers. The last entry
332-
* is zero.
349+
* \return A statically-allocated array of cipher identifiers
350+
* of type cipher_type_t. The last entry is zero.
333351
*/
334352
const int *mbedtls_cipher_list( void );
335353

@@ -396,9 +414,8 @@ void mbedtls_cipher_free( mbedtls_cipher_context_t *ctx );
396414

397415

398416
/**
399-
* \brief This function initializes and fills the cipher-context
400-
* structure with the appropriate values. It also clears
401-
* the structure.
417+
* \brief This function initializes a cipher context for
418+
* use with the given cipher primitive.
402419
*
403420
* \param ctx The context to initialize. This must be initialized.
404421
* \param cipher_info The cipher to use.
@@ -416,6 +433,33 @@ void mbedtls_cipher_free( mbedtls_cipher_context_t *ctx );
416433
int mbedtls_cipher_setup( mbedtls_cipher_context_t *ctx,
417434
const mbedtls_cipher_info_t *cipher_info );
418435

436+
#if defined(MBEDTLS_USE_PSA_CRYPTO)
437+
/**
438+
* \brief This function initializes a cipher context for
439+
* PSA-based use with the given cipher primitive.
440+
*
441+
* \note See #MBEDTLS_USE_PSA_CRYPTO for information on PSA.
442+
*
443+
* \param ctx The context to initialize. May not be \c NULL.
444+
* \param cipher_info The cipher to use.
445+
* \param taglen For AEAD ciphers, the length in bytes of the
446+
* authentication tag to use. Subsequent uses of
447+
* mbedtls_cipher_auth_encrypt() or
448+
* mbedtls_cipher_auth_decrypt() must provide
449+
* the same tag length.
450+
* For non-AEAD ciphers, the value must be \c 0.
451+
*
452+
* \return \c 0 on success.
453+
* \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on
454+
* parameter-verification failure.
455+
* \return #MBEDTLS_ERR_CIPHER_ALLOC_FAILED if allocation of the
456+
* cipher-specific context fails.
457+
*/
458+
int mbedtls_cipher_setup_psa( mbedtls_cipher_context_t *ctx,
459+
const mbedtls_cipher_info_t *cipher_info,
460+
size_t taglen );
461+
#endif /* MBEDTLS_USE_PSA_CRYPTO */
462+
419463
/**
420464
* \brief This function returns the block size of the given cipher.
421465
*
@@ -638,7 +682,7 @@ int mbedtls_cipher_reset( mbedtls_cipher_context_t *ctx );
638682
* \param ctx The generic cipher context. This must be initialized.
639683
* \param ad The additional data to use. This must be a readable
640684
* buffer of at least \p ad_len Bytes.
641-
* \param ad_len the Length of \p ad Bytes.
685+
* \param ad_len The length of \p ad in Bytes.
642686
*
643687
* \return \c 0 on success.
644688
* \return A specific error code on failure.
@@ -681,8 +725,10 @@ int mbedtls_cipher_update_ad( mbedtls_cipher_context_t *ctx,
681725
* unsupported mode for a cipher.
682726
* \return A cipher-specific error code on failure.
683727
*/
684-
int mbedtls_cipher_update( mbedtls_cipher_context_t *ctx, const unsigned char *input,
685-
size_t ilen, unsigned char *output, size_t *olen );
728+
int mbedtls_cipher_update( mbedtls_cipher_context_t *ctx,
729+
const unsigned char *input,
730+
size_t ilen, unsigned char *output,
731+
size_t *olen );
686732

687733
/**
688734
* \brief The generic cipher finalization function. If data still

include/mbedtls/cipher_internal.h

+28
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434

3535
#include "cipher.h"
3636

37+
#if defined(MBEDTLS_USE_PSA_CRYPTO)
38+
#include "psa/crypto.h"
39+
#endif /* MBEDTLS_USE_PSA_CRYPTO */
40+
3741
#ifdef __cplusplus
3842
extern "C" {
3943
#endif
@@ -114,6 +118,30 @@ typedef struct
114118
const mbedtls_cipher_info_t *info;
115119
} mbedtls_cipher_definition_t;
116120

121+
#if defined(MBEDTLS_USE_PSA_CRYPTO)
122+
typedef enum
123+
{
124+
MBEDTLS_CIPHER_PSA_KEY_UNSET = 0,
125+
MBEDTLS_CIPHER_PSA_KEY_OWNED, /* Used for PSA-based cipher contexts which */
126+
/* use raw key material internally imported */
127+
/* into a allocated key slot, and which */
128+
/* hence need to destroy that key slot */
129+
/* when they are no longer needed. */
130+
MBEDTLS_CIPHER_PSA_KEY_NOT_OWNED, /* Used for PSA-based cipher contexts */
131+
/* which use a key from a key slot */
132+
/* provided by the user, and which */
133+
/* hence should not be destroyed when */
134+
/* the context is no longer needed. */
135+
} mbedtls_cipher_psa_key_ownership;
136+
137+
typedef struct
138+
{
139+
psa_algorithm_t alg;
140+
psa_key_handle_t slot;
141+
mbedtls_cipher_psa_key_ownership slot_state;
142+
} mbedtls_cipher_context_psa;
143+
#endif /* MBEDTLS_USE_PSA_CRYPTO */
144+
117145
extern const mbedtls_cipher_definition_t mbedtls_cipher_definitions[];
118146

119147
extern int mbedtls_cipher_supported[];

0 commit comments

Comments
 (0)