1*3d3b0591SJens WiklanderREADME for Mbed TLS 2817466cbSJens Wiklander=================== 3817466cbSJens Wiklander 4817466cbSJens WiklanderConfiguration 5817466cbSJens Wiklander------------- 6817466cbSJens Wiklander 7*3d3b0591SJens WiklanderMbed TLS should build out of the box on most systems. Some platform specific options are available in the fully documented configuration file `include/mbedtls/config.h`, which is also the place where features can be selected. This file can be edited manually, or in a more programmatic way using the Perl script `scripts/config.pl` (use `--help` for usage instructions). 8817466cbSJens Wiklander 9817466cbSJens WiklanderCompiler options can be set using conventional environment variables such as `CC` and `CFLAGS` when using the Make and CMake build system (see below). 10817466cbSJens Wiklander 11817466cbSJens WiklanderCompiling 12817466cbSJens Wiklander--------- 13817466cbSJens Wiklander 14*3d3b0591SJens WiklanderThere are currently three active build systems used within Mbed TLS releases: 15817466cbSJens Wiklander 16*3d3b0591SJens Wiklander- GNU Make 17817466cbSJens Wiklander- CMake 18*3d3b0591SJens Wiklander- Microsoft Visual Studio (Microsoft Visual Studio 2010 or later) 19817466cbSJens Wiklander 20*3d3b0591SJens WiklanderThe main systems used for development are CMake and GNU Make. Those systems are always complete and up-to-date. The others should reflect all changes present in the CMake and Make build system, although features may not be ported there automatically. 21817466cbSJens Wiklander 22817466cbSJens WiklanderThe Make and CMake build systems create three libraries: libmbedcrypto, libmbedx509, and libmbedtls. Note that libmbedtls depends on libmbedx509 and libmbedcrypto, and libmbedx509 depends on libmbedcrypto. As a result, some linkers will expect flags to be in a specific order, for example the GNU linker wants `-lmbedtls -lmbedx509 -lmbedcrypto`. Also, when loading shared libraries using dlopen(), you'll need to load libmbedcrypto first, then libmbedx509, before you can load libmbedtls. 23817466cbSJens Wiklander 24817466cbSJens Wiklander### Make 25817466cbSJens Wiklander 26*3d3b0591SJens WiklanderWe require GNU Make. To build the library and the sample programs, GNU Make and a C compiler are sufficient. Some of the more advanced build targets require some Unix/Linux tools. 27817466cbSJens Wiklander 28*3d3b0591SJens WiklanderWe intentionally only use a minimum of functionality in the makefiles in order to keep them as simple and independent of different toolchains as possible, to allow users to more easily move between different platforms. Users who need more features are recommended to use CMake. 29*3d3b0591SJens Wiklander 30*3d3b0591SJens WiklanderIn order to build from the source code using GNU Make, just enter at the command line: 31817466cbSJens Wiklander 32817466cbSJens Wiklander make 33817466cbSJens Wiklander 34817466cbSJens WiklanderIn order to run the tests, enter: 35817466cbSJens Wiklander 36817466cbSJens Wiklander make check 37817466cbSJens Wiklander 38817466cbSJens WiklanderThe tests need Perl to be built and run. If you don't have Perl installed, you can skip building the tests with: 39817466cbSJens Wiklander 40817466cbSJens Wiklander make no_test 41817466cbSJens Wiklander 42817466cbSJens WiklanderYou'll still be able to run a much smaller set of tests with: 43817466cbSJens Wiklander 44817466cbSJens Wiklander programs/test/selftest 45817466cbSJens Wiklander 46817466cbSJens WiklanderIn order to build for a Windows platform, you should use `WINDOWS_BUILD=1` if the target is Windows but the build environment is Unix-like (for instance when cross-compiling, or compiling from an MSYS shell), and `WINDOWS=1` if the build environment is a Windows shell (for instance using mingw32-make) (in that case some targets will not be available). 47817466cbSJens Wiklander 48*3d3b0591SJens WiklanderSetting the variable `SHARED` in your environment will build shared libraries in addition to the static libraries. Setting `DEBUG` gives you a debug build. You can override `CFLAGS` and `LDFLAGS` by setting them in your environment or on the make command line; compiler warning options may be overridden separately using `WARNING_CFLAGS`. Some directory-specific options (for example, `-I` directives) are still preserved. 49817466cbSJens Wiklander 50*3d3b0591SJens WiklanderPlease note that setting `CFLAGS` overrides its default value of `-O2` and setting `WARNING_CFLAGS` overrides its default value (starting with `-Wall -W`), so if you just want to add some warning options to the default ones, you can do so by setting `CFLAGS=-O2 -Werror` for example. Setting `WARNING_CFLAGS` is useful when you want to get rid of its default content (for example because your compiler doesn't accept `-Wall` as an option). Directory-specific options cannot be overriden from the command line. 51817466cbSJens Wiklander 52*3d3b0591SJens WiklanderDepending on your platform, you might run into some issues. Please check the Makefiles in `library/`, `programs/` and `tests/` for options to manually add or remove for specific platforms. You can also check [the Mbed TLS Knowledge Base](https://tls.mbed.org/kb) for articles on your platform or issue. 53*3d3b0591SJens Wiklander 54*3d3b0591SJens WiklanderIn case you find that you need to do something else as well, please let us know what, so we can add it to the [Mbed TLS Knowledge Base](https://tls.mbed.org/kb). 55817466cbSJens Wiklander 56817466cbSJens Wiklander### CMake 57817466cbSJens Wiklander 58*3d3b0591SJens WiklanderIn order to build the source using CMake in a separate directory (recommended), just enter at the command line: 59817466cbSJens Wiklander 60*3d3b0591SJens Wiklander mkdir /path/to/build_dir && cd /path/to/build_dir 61*3d3b0591SJens Wiklander cmake /path/to/mbedtls_source 62817466cbSJens Wiklander make 63817466cbSJens Wiklander 64817466cbSJens WiklanderIn order to run the tests, enter: 65817466cbSJens Wiklander 66817466cbSJens Wiklander make test 67817466cbSJens Wiklander 68817466cbSJens WiklanderThe test suites need Perl to be built. If you don't have Perl installed, you'll want to disable the test suites with: 69817466cbSJens Wiklander 70*3d3b0591SJens Wiklander cmake -DENABLE_TESTING=Off /path/to/mbedtls_source 71817466cbSJens Wiklander 72817466cbSJens WiklanderIf you disabled the test suites, but kept the programs enabled, you can still run a much smaller set of tests with: 73817466cbSJens Wiklander 74817466cbSJens Wiklander programs/test/selftest 75817466cbSJens Wiklander 76817466cbSJens WiklanderTo configure CMake for building shared libraries, use: 77817466cbSJens Wiklander 78*3d3b0591SJens Wiklander cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On /path/to/mbedtls_source 79817466cbSJens Wiklander 80817466cbSJens WiklanderThere are many different build modes available within the CMake buildsystem. Most of them are available for gcc and clang, though some are compiler-specific: 81817466cbSJens Wiklander 82*3d3b0591SJens Wiklander- `Release`. This generates the default code without any unnecessary information in the binary files. 83*3d3b0591SJens Wiklander- `Debug`. This generates debug information and disables optimization of the code. 84*3d3b0591SJens Wiklander- `Coverage`. This generates code coverage information in addition to debug information. 85*3d3b0591SJens Wiklander- `ASan`. This instruments the code with AddressSanitizer to check for memory errors. (This includes LeakSanitizer, with recent version of gcc and clang.) (With recent version of clang, this mode also instruments the code with UndefinedSanitizer to check for undefined behaviour.) 86*3d3b0591SJens Wiklander- `ASanDbg`. Same as ASan but slower, with debug information and better stack traces. 87*3d3b0591SJens Wiklander- `MemSan`. This instruments the code with MemorySanitizer to check for uninitialised memory reads. Experimental, needs recent clang on Linux/x86\_64. 88*3d3b0591SJens Wiklander- `MemSanDbg`. Same as MemSan but slower, with debug information, better stack traces and origin tracking. 89*3d3b0591SJens Wiklander- `Check`. This activates the compiler warnings that depend on optimization and treats all warnings as errors. 90817466cbSJens Wiklander 91817466cbSJens WiklanderSwitching build modes in CMake is simple. For debug mode, enter at the command line: 92817466cbSJens Wiklander 93*3d3b0591SJens Wiklander cmake -D CMAKE_BUILD_TYPE=Debug /path/to/mbedtls_source 94817466cbSJens Wiklander 95817466cbSJens WiklanderTo list other available CMake options, use: 96817466cbSJens Wiklander 97817466cbSJens Wiklander cmake -LH 98817466cbSJens Wiklander 99*3d3b0591SJens WiklanderNote that, with CMake, you can't adjust the compiler or its flags after the 100*3d3b0591SJens Wiklanderinitial invocation of cmake. This means that `CC=your_cc make` and `make 101*3d3b0591SJens WiklanderCC=your_cc` will *not* work (similarly with `CFLAGS` and other variables). 102*3d3b0591SJens WiklanderThese variables need to be adjusted when invoking cmake for the first time, 103*3d3b0591SJens Wiklanderfor example: 104*3d3b0591SJens Wiklander 105*3d3b0591SJens Wiklander CC=your_cc cmake /path/to/mbedtls_source 106*3d3b0591SJens Wiklander 107*3d3b0591SJens WiklanderIf you already invoked cmake and want to change those settings, you need to 108*3d3b0591SJens Wiklanderremove the build directory and create it again. 109*3d3b0591SJens Wiklander 110*3d3b0591SJens WiklanderNote that it is possible to build in-place; this will however overwrite the 111*3d3b0591SJens Wiklanderprovided Makefiles (see `scripts/tmp_ignore_makefiles.sh` if you want to 112*3d3b0591SJens Wiklanderprevent `git status` from showing them as modified). In order to do so, from 113*3d3b0591SJens Wiklanderthe Mbed TLS source directory, use: 114*3d3b0591SJens Wiklander 115*3d3b0591SJens Wiklander cmake . 116*3d3b0591SJens Wiklander make 117*3d3b0591SJens Wiklander 118*3d3b0591SJens WiklanderIf you want to change `CC` or `CFLAGS` afterwards, you will need to remove the 119*3d3b0591SJens WiklanderCMake cache. This can be done with the following command using GNU find: 120817466cbSJens Wiklander 121817466cbSJens Wiklander find . -iname '*cmake*' -not -name CMakeLists.txt -exec rm -rf {} + 122*3d3b0591SJens Wiklander 123*3d3b0591SJens WiklanderYou can now make the desired change: 124*3d3b0591SJens Wiklander 125*3d3b0591SJens Wiklander CC=your_cc cmake . 126*3d3b0591SJens Wiklander make 127*3d3b0591SJens Wiklander 128*3d3b0591SJens WiklanderRegarding variables, also note that if you set CFLAGS when invoking cmake, 129*3d3b0591SJens Wiklanderyour value of CFLAGS doesn't override the content provided by cmake (depending 130*3d3b0591SJens Wiklanderon the build mode as seen above), it's merely prepended to it. 131817466cbSJens Wiklander 132817466cbSJens Wiklander### Microsoft Visual Studio 133817466cbSJens Wiklander 134817466cbSJens WiklanderThe build files for Microsoft Visual Studio are generated for Visual Studio 2010. 135817466cbSJens Wiklander 136817466cbSJens WiklanderThe solution file `mbedTLS.sln` contains all the basic projects needed to build the library and all the programs. The files in tests are not generated and compiled, as these need a perl environment as well. However, the selftest program in `programs/test/` is still available. 137817466cbSJens Wiklander 138817466cbSJens WiklanderExample programs 139817466cbSJens Wiklander---------------- 140817466cbSJens Wiklander 141*3d3b0591SJens WiklanderWe've included example programs for a lot of different features and uses in [`programs/`](programs/README.md). Most programs only focus on a single feature or usage scenario, so keep that in mind when copying parts of the code. 142817466cbSJens Wiklander 143817466cbSJens WiklanderTests 144817466cbSJens Wiklander----- 145817466cbSJens Wiklander 146*3d3b0591SJens WiklanderMbed TLS includes an elaborate test suite in `tests/` that initially requires Perl to generate the tests files (e.g. `test\_suite\_mpi.c`). These files are generated from a `function file` (e.g. `suites/test\_suite\_mpi.function`) and a `data file` (e.g. `suites/test\_suite\_mpi.data`). The `function file` contains the test functions. The `data file` contains the test cases, specified as parameters that will be passed to the test function. 147817466cbSJens Wiklander 148817466cbSJens WiklanderFor machines with a Unix shell and OpenSSL (and optionally GnuTLS) installed, additional test scripts are available: 149817466cbSJens Wiklander 150817466cbSJens Wiklander- `tests/ssl-opt.sh` runs integration tests for various TLS options (renegotiation, resumption, etc.) and tests interoperability of these options with other implementations. 151817466cbSJens Wiklander- `tests/compat.sh` tests interoperability of every ciphersuite with other implementations. 152817466cbSJens Wiklander- `tests/scripts/test-ref-configs.pl` test builds in various reduced configurations. 153817466cbSJens Wiklander- `tests/scripts/key-exchanges.pl` test builds in configurations with a single key exchange enabled 154817466cbSJens Wiklander- `tests/scripts/all.sh` runs a combination of the above tests, plus some more, with various build options (such as ASan, full `config.h`, etc). 155817466cbSJens Wiklander 156817466cbSJens WiklanderConfigurations 157817466cbSJens Wiklander-------------- 158817466cbSJens Wiklander 159817466cbSJens WiklanderWe provide some non-standard configurations focused on specific use cases in the `configs/` directory. You can read more about those in `configs/README.txt` 160817466cbSJens Wiklander 161*3d3b0591SJens WiklanderPorting Mbed TLS 162817466cbSJens Wiklander---------------- 163817466cbSJens Wiklander 164*3d3b0591SJens WiklanderMbed TLS can be ported to many different architectures, OS's and platforms. Before starting a port, you may find the following Knowledge Base articles useful: 165817466cbSJens Wiklander 166*3d3b0591SJens Wiklander- [Porting Mbed TLS to a new environment or OS](https://tls.mbed.org/kb/how-to/how-do-i-port-mbed-tls-to-a-new-environment-OS) 167*3d3b0591SJens Wiklander- [What external dependencies does Mbed TLS rely on?](https://tls.mbed.org/kb/development/what-external-dependencies-does-mbedtls-rely-on) 168*3d3b0591SJens Wiklander- [How do I configure Mbed TLS](https://tls.mbed.org/kb/compiling-and-building/how-do-i-configure-mbedtls) 169817466cbSJens Wiklander 170817466cbSJens WiklanderContributing 171817466cbSJens Wiklander------------ 172817466cbSJens Wiklander 173817466cbSJens WiklanderWe gratefully accept bug reports and contributions from the community. There are some requirements we need to fulfill in order to be able to integrate contributions: 174817466cbSJens Wiklander 175817466cbSJens Wiklander- All contributions, whether large or small require a Contributor's License Agreement (CLA) to be accepted. This is because source code can possibly fall under copyright law and we need your consent to share in the ownership of the copyright. 176817466cbSJens Wiklander- We would ask that contributions conform to [our coding standards](https://tls.mbed.org/kb/development/mbedtls-coding-standards), and that contributions should be fully tested before submission. 177817466cbSJens Wiklander- As with any open source project, contributions will be reviewed by the project team and community and may need some modifications to be accepted. 178817466cbSJens Wiklander 179*3d3b0591SJens WiklanderTo accept the Contributor’s Licence Agreement (CLA), individual contributors can do this by creating an Mbed account and [accepting the online agreement here with a click through](https://os.mbed.com/contributor_agreement/). Alternatively, for contributions from corporations, or those that do not wish to create an Mbed account, a slightly different agreement can be found [here](https://www.mbed.com/en/about-mbed/contributor-license-agreements/). This agreement should be signed and returned to Arm as described in the instructions given. 180817466cbSJens Wiklander 181817466cbSJens Wiklander### Making a Contribution 182817466cbSJens Wiklander 183*3d3b0591SJens Wiklander1. [Check for open issues](https://github.com/ARMmbed/mbedtls/issues) or [start a discussion](https://forums.mbed.com/c/mbed-tls) around a feature idea or a bug. 184*3d3b0591SJens Wiklander2. Fork the [Mbed TLS repository on GitHub](https://github.com/ARMmbed/mbedtls) to start making your changes. As a general rule, you should use the "development" branch as a basis. 185817466cbSJens Wiklander3. Write a test which shows that the bug was fixed or that the feature works as expected. 186817466cbSJens Wiklander4. Send a pull request and bug us until it gets merged and published. Contributions may need some modifications, so work with us to get your change accepted. We will include your name in the ChangeLog :) 187817466cbSJens Wiklander 188