Change internal iop generate key error variable to int
instead of psa_status_t since the error variable get
passed to mbedtls_to_psa_error() when being returned
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
Add ecp prefix to internal iop generate key function names
to emphasize that the functions are doing eliptic curves
keys only and not any other types.
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
Remove MBEDTLS_ECP_MAX_MPI_BYTES macro as
it's not needed anymore.It was added when
memcpy was being used but now that
mbedtls_mpi_write_binary() is being used
it can handle copying a large buffer filled
with leading zeros into a smaller buffer.
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
- Move the checks on the size to the start of the
function to avaoid costly calls to mbedtls_ecp_gen_privkey()
in case of invalid size.
- Improve the readability of error checking
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
Add MBEDTLS_ECP_MAX_MPI define to determine the maximum
number of bytes for the biggest Elliptic curve in bignum
representation.
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
* Used bignum helper API instead of memcpy
* changed the key length output to the size of the curve because:
- using the bignum produces a bigger size than the curve size
due to the limb size being 8 bytes and import key rejects
the key if it's not exactly curve size.
- we know that the generated key is filled with leading
zeros becuase the generated key is bounded by the modulas.
* skipped leading zeros when passing the buffer to import_key()
due to the intermediate buffer allocated to the maximum size
possible and import_key() needs the exact size.
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
Ecp key data length should not be measured by mbedtls_mpi_size(), as
this does not count leading zeros, which are still part of the key. This
resulted intermittently in the code attempting to import a wrongly sized
key as the first byte was all zero.
Signed-off-by: Paul Elliott <paul.elliott@arm.com>
Remove generate key brainpool160r1 & SECP224K1 test cases
as they are scheduled to be removed in 4.0 .
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
This fixes accesses to uninitialized memory in test code if
`psa_crypto_init()` fails.
A lot of those were pointed out by Coverity. I quickly reviewed all calls to
`MD_PSA_INIT()` manually, rather than follow any particular list.
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
generate_test_code.py doesn't support UTF-8 in .function files (but does
in .data files) when run in a non-UTF-8 locale with Python <=3.6.
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
mbedtls_ecp_gen_key() generates a private key and calculates the public key.
Calculating the public key takes most of the CPU time. But the PSA key store
doesn't store the key, in order to simplify the plumbing when drivers are
involved. So the time spent calculating the public key is a waste.
Instead, call mbedtls_ecp_gen_privkey(), which does not calculate the public
key.
This also saves 8 instructions in a sample arm thumb build.
Resolves#9732.
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Run the function on a few different curves with shorter, just-right and
larger buffer sizes. Perform some basic sanity checks on the output (which
is random).
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit improves the makefile error message when using make, it no
longer incorrectly reports that CMakeLists.txt cannot be found instead
of exported.make.
Signed-off-by: Harry Ramsey <harry.ramsey@arm.com>
Skip 6144-bit and 8192-bit FFDH tests in MSan or Valgrind test
configurations. These test cases are slow and sometimes trigger GnuTLS's
built-in timeout (which cannot be configured until more recent versions).
Resolves#9742.
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Now that it's always on, this is no longer necessary.
Also this is a step towards no longer being able to set it, because it soon
won't be a selectable configuration option anymore.
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>