Commit graph

91 commits

Author SHA1 Message Date
Gilles Peskine
dcaefae849 Parametrize Diffie-Hellman keys by a group identifier
Parametrize finite-field Diffie-Hellman key types with a DH group
identifier, in the same way elliptic curve keys are parametrized with
an EC curve identifier.

Define the DH groups from the TLS registry (these are the groups from
RFC 7919).

Replicate the macro definitions and the metadata tests from elliptic
curve identifiers to DH group identifiers.

Define PSA_DH_GROUP_CUSTOM as an implementation-specific extension for
which domain parameters are used to specify the group.
2019-05-16 19:51:10 +02:00
Gilles Peskine
a99d3fbd05 Rename generator functions to psa_key_derivation_xxx
Generators are mostly about key derivation (currently: only about key
derivation). "Generator" is not a commonly used term in cryptography.
So favor "derivation" as terminology. Call a generator a key
derivation operation structure, since it behaves like other multipart
operation structures. Furthermore, the function names are not fully
consistent.

In this commit, I rename the functions to consistently have the prefix
"psa_key_derivation_". I used the following command:

    perl -i -pe '%t = (
        psa_crypto_generator_t => "psa_key_derivation_operation_t",
        psa_crypto_generator_init => "psa_key_derivation_init",
        psa_key_derivation_setup => "psa_key_derivation_setup",
        psa_key_derivation_input_key => "psa_key_derivation_input_key",
        psa_key_derivation_input_bytes => "psa_key_derivation_input_bytes",
        psa_key_agreement => "psa_key_derivation_key_agreement",
        psa_set_generator_capacity => "psa_key_derivation_set_capacity",
        psa_get_generator_capacity => "psa_key_derivation_get_capacity",
        psa_generator_read => "psa_key_derivation_output_bytes",
        psa_generate_derived_key => "psa_key_derivation_output_key",
        psa_generator_abort => "psa_key_derivation_abort",
        PSA_CRYPTO_GENERATOR_INIT => "PSA_KEY_DERIVATION_OPERATION_INIT",
        PSA_GENERATOR_UNBRIDLED_CAPACITY => "PSA_KEY_DERIVATION_UNLIMITED_CAPACITY",
        ); s/\b(@{[join("|", keys %t)]})\b/$t{$1}/ge' $(git ls-files)
2019-05-16 18:55:21 +02:00
Gilles Peskine
73676cbc50 Put handle parameter last: psa_import_key
In psa_import_key, change the order of parameters to pass
the pointer where the newly created handle will be stored last.
This is consistent with most other library functions that put inputs
before outputs.
2019-05-15 23:16:07 +02:00
Gilles Peskine
98dd779eb5 Put handle parameter last: psa_generate_derived_key
In psa_generate_derived_key, change the order of parameters to pass
the pointer where the newly created handle will be stored last.
This is consistent with most other library functions that put inputs
before outputs.
2019-05-15 20:15:31 +02:00
Adrian L. Shaw
5a5a79ae2a Rename psa_generate_key() and psa_generator_import_key() 2019-05-03 15:44:28 +01:00
Gilles Peskine
e56e878207 Remove extra parameter from psa_generate_key
Read extra data from the domain parameters in the attribute structure
instead of taking an argument on the function call.

Implement this for RSA key generation, where the public exponent can
be set as a domain parameter.

Add tests that generate RSA keys with various public exponents.
2019-04-26 17:37:50 +02:00
Gilles Peskine
3a4f1f8e46 Set the key size as an attribute
Instead of passing a separate parameter for the key size to
psa_generate_key and psa_generator_import_key, set it through the
attributes, like the key type and other metadata.
2019-04-26 13:49:28 +02:00
Jaeden Amero
986a15199d programs, tests: Depend only on libmbedcrypto
Update the tests and programs to depend only on libmbedcrypto, since
we'll soon only build libmbedcrypto.
2019-04-25 11:46:21 +01:00
Gilles Peskine
dfea0a2510 Use the attribute-based key creation interface in sample programs 2019-04-24 15:46:04 +02:00
Gilles Peskine
87a5e565f4 Rename functions that inject key material to an allocated handle
This commit starts a migration to a new interface for key creation.
Today, the application allocates a handle, then fills its metadata,
and finally injects key material. The new interface fills metadata
into a temporary structure, and a handle is allocated at the same time
it gets filled with both metadata and key material.

This commit was obtained by moving the declaration of the old-style
functions to crypto_extra.h and renaming them with the to_handle
suffix, adding declarations for the new-style functions in crypto.h
under their new name, and running

    perl -i -pe 's/\bpsa_(import|copy|generator_import|generate)_key\b/$&_to_handle/g' library/*.c tests/suites/*.function programs/psa/*.c
    perl -i -pe 's/\bpsa_get_key_lifetime\b/$&_from_handle/g' library/*.c tests/suites/*.function programs/psa/*.c

Many functions that are specific to the old interface, and which will
not remain under the same name with the new interface, are still in
crypto.h for now.

All functional tests should still pass. The documentation may have
some broken links.
2019-04-24 15:24:45 +02:00
Gilles Peskine
882e57ecba psa_constant_names: support key agreement algorithms 2019-04-18 09:42:21 +02:00
Jaeden Amero
fa30c3382d programs: psa: Remove dependency on platform.h
platform.h should only be used internally by the library implementation
itself, not the examples. Remove the dependency on platform.h from all
PSA programs.
2019-03-11 16:48:36 +00:00
Jaeden Amero
b281f74284 psa: example: Initialize operation contexts
Add missing initializers to PSA Crypto example. Operation contexts must
be initialized before calling psa_*_setup().
2019-02-20 10:51:42 +00:00
Jaeden Amero
0574e6a7bd
Merge pull request #51 from Patater/update-dev-tls-dev-crypto-merge
Merge mbedtls/development-psa, mbedtls/development into development
2019-02-15 15:07:37 +00:00
Jaeden Amero
db29ab528a psa: Fix builds without MBEDTLS_PLATFORM_C
When `MBEDTLS_PLATFORM_C` is not enabled, our PSA Crypto implementation
depends on the standard C library for functions like snprintf() and
exit(). However, our implementation was not including the proper header
files nor redefining all `mbedtls_*` symbols properly to ensure
successful builds without MBEDTLS_PLATFORM_C. Add the necessary header
files and macro definitions to our PSA Crypto implementation.
2019-02-14 16:01:14 +00:00
Jaeden Amero
44a59ab3f5 psa: Enable use of PSA examples with CHECK_PARAMS
When MBEDTLS_CHECK_PARAMS is enabled, it's required to have an
implementation of mbedtls_param_failed() present. Without it in the PSA
examples, building the PSA examples will result in linker errors like
the following.

  ../../library/libmbedcrypto.a(rsa.c.o): In function `mbedtls_rsa_import':
  rsa.c:(.text+0x9fd): undefined reference to `mbedtls_param_failed'
  ../../library/libmbedcrypto.a(rsa.c.o): In function `mbedtls_rsa_import_raw':
  rsa.c:(.text+0xb0b): undefined reference to `mbedtls_param_failed'
  ../../library/libmbedcrypto.a(rsa.c.o): In function `mbedtls_rsa_complete':
  rsa.c:(.text+0xe63): undefined reference to `mbedtls_param_failed'
  ../../library/libmbedcrypto.a(rsa.c.o): In function `mbedtls_rsa_export_raw':
  rsa.c:(.text+0xfee): undefined reference to `mbedtls_param_failed'
  ../../library/libmbedcrypto.a(rsa.c.o): In function `mbedtls_rsa_export':
  rsa.c:(.text+0x116f): undefined reference to `mbedtls_param_failed'
  ../../library/libmbedcrypto.a(rsa.c.o):rsa.c:(.text+0x1304): more undefined
  references to `mbedtls_param_failed' follow
  collect2: error: ld returned 1 exit status
  programs/psa/CMakeFiles/crypto_examples.dir/build.make:97: recipe for target
  'programs/psa/crypto_examples' failed
  make[2]: *** [programs/psa/crypto_examples] Error 1

Add an implementation of mbedtls_param_failed() to the PSA Crypto
examples to avoid getting this error on the PSA examples.
2019-02-14 16:01:14 +00:00
Gilles Peskine
3f775264d3 psa_constant_names: adding support for signed types
psa_constant_names now works correctly with signed values, such as
psa_status_t may have.
2019-02-13 18:46:51 +01:00
Gilles Peskine
1b879843d1 psa_constant_names: factor unsigned support into its own function
This is in preparation for adding support for signed types (namely,
psa_status_t).
2019-02-13 18:46:51 +01:00
Darryl Green
21b33b07df Run generate_psa_constants.py before building psa_constant_names with cmake 2019-02-07 13:08:34 +00:00
Darryl Green
d519583ae3 Run generate_psa_constants.py in cmake builds 2019-02-06 13:45:03 +00:00
Gilles Peskine
6a78573088 CMake: psa_constant_names and test_psa_constant_names
Build and install psa_constant_names.

Make sure that test_psa_constant_names passes in an out-of-tree build.
2019-01-29 16:08:46 +00:00
Gilles Peskine
f31dbb7bf1 CMake: build and install key_ladder_demo 2019-01-29 16:08:46 +00:00
Gilles Peskine
738f017c12 Fix the build of key_ladder_demo under Clang
Clang -Wall -Wincompatible-pointer-types-discards-qualifiers said:
thou shalt not put a string literal in a non-const char*.
2019-01-29 16:08:46 +00:00
Gilles Peskine
265a171c52 Error out if a value is out of range
psa_status_t is currently a signed type where only non-negative values
are used, which makes things a bit awkward. For now, non-negative
values trigger an error. This code will need to be revised if we
switch to using negative values as error codes.
2019-01-29 16:08:46 +00:00
Gilles Peskine
567840e335 Support multiple values on the command line 2019-01-29 16:07:45 +00:00
Gilles Peskine
d40c1fbd50 Don't require a type and size when creating a key slot
Remove the type and bits arguments to psa_allocate_key() and
psa_create_key(). They can be useful if the implementation wants to
know exactly how much space to allocate for the slot, but many
implementations (including ours) don't care, and it's possible to work
around their lack by deferring size-dependent actions to the time when
the key material is created. They are a burden to applications and
make the API more complex, and the benefits aren't worth it.

Change the API and adapt the implementation, the units test and the
sample code accordingly.
2019-01-19 12:20:52 +01:00
Jaeden Amero
70261c513a psa: Add initializers for key policies
Add new initializers for key policies and use them in our docs, example
programs, tests, and library code. Prefer using the macro initializers
due to their straightforwardness.
2019-01-08 14:28:04 +00:00
Gilles Peskine
5e09bc7eb5 Fix maybe-uninitialized warning
GCC 4.8 warns that some variables may be used without having been
initialized. They aren't, but determining that takes nontrivial
analysis, so initialize them at the point of definition.
2018-12-21 12:06:15 +01:00
Gilles Peskine
b0edfb513b Convert the PSA example programs to the new handle API
Switch from the direct use of slot numbers to handles allocated by
psa_allocate_key.
2018-12-11 16:48:13 +01:00
Darryl Green
608e091d9a Add pre Visual Studio 2015 support to psa_constant_names
snprintf was only added in Visual Studio 2015. This adds support
for building using Visual Studio versions prior to 2015.

This implementation of snprintf has been taken from platform.c
2018-10-23 12:02:37 +01:00
Darryl Green
1824696681 Fix integer conversion warnings in psa_constant_names 2018-10-22 09:05:33 +01:00
Gilles Peskine
38808fa094 psa_constant_names: fix some copypasta 2018-10-08 14:45:35 +02:00
Gilles Peskine
0deaf3d8d7 psa_constant_names: new function append_integer
Factor repeated code into a new function append_integer.
2018-10-08 14:45:35 +02:00
Gilles Peskine
daea26f70f Correct and simplify block-based cipher modes
OFB and CFB are streaming modes. XTS is a not a cipher mode but it
doesn't use a separate padding step. This leaves only CBC as a block
cipher mode that needs a padding step.

Since CBC is the only mode that uses a separate padding step, and is
likely to remain the only mode in the future, encode the padding mode
directly in the algorithm constant, rather than building up an
algorithm value from a chaining mode and a padding mode. This greatly
simplifies the interface as well as some parts of the implementation.
2018-09-20 11:58:22 +02:00
itayzafrir
18ac331e15 psa: programs: Add cipher example fallback main
When dependencies are missing, print an error message from the example
about missing dependencies at run-time.
2018-09-12 16:50:07 +03:00
itayzafrir
44b09d2a67 psa: programs: Add cipher AES CTR multipart 2018-09-12 16:50:07 +03:00
itayzafrir
a2d0804b33 psa: programs: Add cipher AES CBC PKCS7 multipart 2018-09-12 16:50:07 +03:00
itayzafrir
10366708d6 psa: programs: Add cipher AES CBC no padding 2018-09-12 16:50:07 +03:00
itayzafrir
a3ff8a6ed5 psa: programs: Add cipher example
Add `programs/psa/crypto_examples.c`. Update relevant Makefiles,
CMakeLists.txt, and .gitignore files.
2018-09-12 16:50:07 +03:00
Gilles Peskine
f0fa436b65 New sample program key_ladder_demo
Demo of a key derivation ladder.

Sample run in key_ladder_demo.sh.
2018-09-12 16:50:07 +03:00
Gilles Peskine
029b5d648d New utility program psa/psa_constant_names
Print the symbolic name corresponding to a numerical value.

Supported types: status values, algorithms, elliptic curves,
key types, key usage masks.

The program is partly generated from parsing psa/crypto.h with a few
hard-coded assumptions. This isn't ideal but it works and requires
little machinery.
2018-09-12 16:41:12 +03:00