blob: 977e26c41a226a8b0a2b6b02ca459cae37633c83 [file] [log] [blame] [view]
Gilles Peskineceb7b122018-01-18 23:27:47 +01001Mbed TLS sample programs
2========================
3
4This subdirectory mostly contains sample programs that illustrate specific features of the library, as well as a few test and support programs.
5
6## Symmetric cryptography (AES) examples
7
Gilles Peskinec2e5cdd2018-07-30 20:11:05 +02008* [`aes/aescrypt2.c`](aes/aescrypt2.c): file encryption and authentication with a key derived from a low-entropy secret, demonstrating the low-level AES interface, the digest interface and HMAC.
9 Warning: this program illustrates how to use low-level functions in the library. It should not be taken as an example of how to build a secure encryption mechanism. To derive a key from a low-entropy secret such as a password, use a standard key stretching mechanism such as PBKDF2 (provided by the `pkcs5` module). To encrypt and authenticate data, use a standard mode such as GCM or CCM (both available as library module).
Gilles Peskineceb7b122018-01-18 23:27:47 +010010
11* [`aes/crypt_and_hash.c`](aes/crypt_and_hash.c): file encryption and authentication, demonstrating the generic cipher interface and the generic hash interface.
12
13## Hash (digest) examples
14
15* [`hash/generic_sum.c`](hash/generic_sum.c): file hash calculator and verifier, demonstrating the message digest (`md`) interface.
16
17* [`hash/hello.c`](hash/hello.c): hello-world program for MD5.
18
19## Public-key cryptography examples
20
21### Generic public-key cryptography (`pk`) examples
22
Gilles Peskine6b9cbb82018-07-30 20:06:19 +020023* [`pkey/gen_key.c`](pkey/gen_key.c): generates a key for any of the supported public-key algorithms (RSA or ECC) and writes it to a file that can be used by the other pk sample programs.
Gilles Peskineceb7b122018-01-18 23:27:47 +010024
Gilles Peskine6b9cbb82018-07-30 20:06:19 +020025* [`pkey/key_app.c`](pkey/key_app.c): loads a PEM or DER public key or private key file and dumps its content.
Gilles Peskineceb7b122018-01-18 23:27:47 +010026
Gilles Peskine6b9cbb82018-07-30 20:06:19 +020027* [`pkey/key_app_writer.c`](pkey/key_app_writer.c): loads a PEM or DER public key or private key file and writes it to a new PEM or DER file.
Gilles Peskineceb7b122018-01-18 23:27:47 +010028
Gilles Peskine27a04602018-08-06 20:09:16 +020029* [`pkey/pk_encrypt.c`](pkey/pk_encrypt.c), [`pkey/pk_decrypt.c`](pkey/pk_decrypt.c): loads a PEM or DER public/private key file and uses the key to encrypt/decrypt a short string through the generic public-key interface.
Gilles Peskineceb7b122018-01-18 23:27:47 +010030
Gilles Peskine27a04602018-08-06 20:09:16 +020031* [`pkey/pk_sign.c`](pkey/pk_sign.c), [`pkey/pk_verify.c`](pkey/pk_verify.c): loads a PEM or DER private/public key file and uses the key to sign/verify a short string.
Gilles Peskineceb7b122018-01-18 23:27:47 +010032
33### ECDSA and RSA signature examples
34
Gilles Peskine0b544192018-08-10 11:32:11 +020035* [`pkey/ecdsa.c`](pkey/ecdsa.c): generates an ECDSA key, signs a fixed message and verifies the signature.
Gilles Peskineceb7b122018-01-18 23:27:47 +010036
Gilles Peskine27a04602018-08-06 20:09:16 +020037* [`pkey/rsa_encrypt.c`](pkey/rsa_encrypt.c), [`pkey/rsa_decrypt.c`](pkey/rsa_decrypt.c): loads an RSA public/private key and uses it to encrypt/decrypt a short string through the low-level RSA interface.
Gilles Peskineceb7b122018-01-18 23:27:47 +010038
Gilles Peskine27a04602018-08-06 20:09:16 +020039* [`pkey/rsa_genkey.c`](pkey/rsa_genkey.c): generates an RSA key and writes it to a file that can be used with the other RSA sample programs.
Gilles Peskineceb7b122018-01-18 23:27:47 +010040
Gilles Peskine27a04602018-08-06 20:09:16 +020041* [`pkey/rsa_sign.c`](pkey/rsa_sign.c), [`pkey/rsa_verify.c`](pkey/rsa_verify.c): loads an RSA private/public key and uses it to sign/verify a short string with the RSA PKCS#1 v1.5 algorithm.
Gilles Peskineceb7b122018-01-18 23:27:47 +010042
Gilles Peskine0b544192018-08-10 11:32:11 +020043* [`pkey/rsa_sign_pss.c`](pkey/rsa_sign_pss.c), [`pkey/rsa_verify_pss.c`](pkey/rsa_verify_pss.c): loads an RSA private/public key and uses it to sign/verify a short string with the RSASSA-PSS algorithm.
Gilles Peskineceb7b122018-01-18 23:27:47 +010044
45### Diffie-Hellman key exchange examples
46
Gilles Peskineceb7b122018-01-18 23:27:47 +010047* [`pkey/ecdh_curve25519.c`](pkey/ecdh_curve25519.c): demonstration of a elliptic curve Diffie-Hellman (ECDH) key agreement.
48
49### Bignum (`mpi`) usage examples
50
Gilles Peskine6b9cbb82018-07-30 20:06:19 +020051* [`pkey/dh_genprime.c`](pkey/dh_genprime.c): shows how to use the bignum (`mpi`) interface to generate Diffie-Hellman parameters.
Gilles Peskineceb7b122018-01-18 23:27:47 +010052
53* [`pkey/mpi_demo.c`](pkey/mpi_demo.c): demonstrates operations on big integers.
54
55## Random number generator (RNG) examples
56
Gilles Peskine6b9cbb82018-07-30 20:06:19 +020057* [`random/gen_entropy.c`](random/gen_entropy.c): shows how to use the default entropy sources to generate random data.
58 Note: most applications should only use the entropy generator to seed a cryptographic pseudorandom generator, as illustrated by `random/gen_random_ctr_drbg.c`.
Gilles Peskineceb7b122018-01-18 23:27:47 +010059
Gilles Peskineaa220302018-08-06 20:19:50 +020060* [`random/gen_random_ctr_drbg.c`](random/gen_random_ctr_drbg.c): shows how to use the default entropy sources to seed a pseudorandom generator, and how to use the resulting random generator to generate random data.
Gilles Peskineceb7b122018-01-18 23:27:47 +010061
Gilles Peskine6b9cbb82018-07-30 20:06:19 +020062* [`random/gen_random_havege.c`](random/gen_random_havege.c): demonstrates the HAVEGE entropy collector.
Gilles Peskineceb7b122018-01-18 23:27:47 +010063
Gilles Peskineceb7b122018-01-18 23:27:47 +010064## Test utilities
65
66* [`test/benchmark.c`](test/benchmark.c): benchmark for cryptographic algorithms.
67
Gilles Peskine6b9cbb82018-07-30 20:06:19 +020068* [`test/selftest.c`](test/selftest.c): runs the self-test function in each library module.
Gilles Peskineceb7b122018-01-18 23:27:47 +010069
Gilles Peskine6b9cbb82018-07-30 20:06:19 +020070* [`test/udp_proxy.c`](test/udp_proxy.c): a UDP proxy that can inject certain failures (delay, duplicate, drop). Useful for testing DTLS.
Gilles Peskineceb7b122018-01-18 23:27:47 +010071
Gilles Peskineffbdc612018-08-10 11:48:52 +020072* [`test/zeroize.c`](test/zeroize.c): a test program for `mbedtls_platform_zeroize`, used by [`tests/scripts/test_zeroize.gdb`](tests/scripts/test_zeroize.gdb).
73
Gilles Peskineceb7b122018-01-18 23:27:47 +010074## Development utilities
75
Gilles Peskine6b9cbb82018-07-30 20:06:19 +020076* [`util/pem2der.c`](util/pem2der.c): a PEM to DER converter. Mbed TLS can read PEM files directly, but this utility can be useful for interacting with other tools or with minimal Mbed TLS builds that lack PEM support.
Gilles Peskineceb7b122018-01-18 23:27:47 +010077
Gilles Peskine6b9cbb82018-07-30 20:06:19 +020078* [`util/strerror.c`](util/strerror.c): prints the error description corresponding to an integer status returned by an Mbed TLS function.