Commit graph

169 commits

Author SHA1 Message Date
Gilles Peskine
0ea1b8fe8c
Merge pull request #7982 from gilles-peskine-arm/sample_program_demo_scripts-3.4
Run sample program demo scripts in all.sh
2023-10-18 10:03:52 +00:00
Thomas Daubney
2e67781e93 Alter program layout for better clarity
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2023-10-12 10:46:43 +01:00
Thomas Daubney
a21c972941 Remove extra blank line
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2023-10-11 17:17:32 +01:00
Thomas Daubney
d8453bb184 Remove superfluous comment
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2023-10-11 15:29:02 +01:00
Thomas Daubney
cd79f77439 Add missing newline
Newline character was missing from end of print
statement.

Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2023-10-11 15:28:13 +01:00
Thomas Daubney
1c2378b8b1 Add variable for message length
Add variable to store message length to increase
clarity in what the program is doing.

Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2023-10-11 15:19:38 +01:00
Thomas Daubney
34500874ce Remove trailing white space in documentation
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2023-10-11 10:04:54 +01:00
Thomas Daubney
760538885a Inform user when unknown hash algorithm supplied
Excplictly inform the user that their hash algorithm
selection is invalid.

Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2023-10-10 17:38:53 +01:00
Thomas Daubney
86f9795b00 Update documentation
Add further information about PSA hashing to the
comment at the beginning of the code.

Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2023-10-10 16:50:49 +01:00
Thomas Daubney
a68ef95394 Check length before calling memcmp
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2023-08-07 11:09:51 +01:00
Thomas Daubney
102033c38d Add new line at end of file to satisfy code style
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2023-08-03 16:20:09 +01:00
Thomas Daubney
5c2dcbd250 Implement cleanup label
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2023-08-03 16:03:30 +01:00
Thomas Daubney
21fbe4c90e Remove further superfluous call to psa_hash_abort
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2023-08-03 15:39:42 +01:00
Thomas Daubney
1ba9744afb Correct code style
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2023-07-28 17:25:16 +01:00
Thomas Daubney
c918c32cc0 Stop hashing the null byte
Change the hash data to not include the null byte used to terminate
the string. Pass sizeof() - 1 to the hash operation API functions
so that the null byte can be ignored.

Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2023-07-28 17:15:03 +01:00
Thomas Daubney
fbe742b2d0 Add extra check to one-shot operation results
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2023-07-28 16:17:38 +01:00
Thomas Daubney
ce14124f7c Check result of multipart operation
Check that the multi-part operation has produced
the correct result.

Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2023-07-28 16:14:20 +01:00
Thomas Daubney
606110fc19 Restructure start of program
Restructure the start of the program to make it
clear to a user exactly what this program is for.
Add a comment for additional clarity.

Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2023-07-28 15:57:10 +01:00
Thomas Daubney
1f98736e71 Add clarifying comment to new program section
Mark the beginning of the section that prints
the result with a comment.

Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2023-07-28 15:23:06 +01:00
Thomas Daubney
a2b7519d63 Use memcmp instead of reinventing it
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2023-07-28 15:21:46 +01:00
Thomas Daubney
9730cb1274 Change hash output formatting
Change the formatting of the hash output
to remove line breaks and spaces.

Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2023-07-28 15:07:19 +01:00
Thomas Daubney
c07fa29b58 Change wording in error message
Change wording from "failed" since this implied the
function had returned an error status instead of
producing the wrong result.

Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2023-07-28 14:58:55 +01:00
Thomas Daubney
3071c85835 Clarify comments
Clarify comments when moving into one-shot part
of demo.

Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2023-07-28 14:47:47 +01:00
Thomas Daubney
c050037c08 Remove mbedtls_ and psa_ prefix from var names
Remove the mbedtls and psa prefixes from variable
names in order to make clearer what is part of
the API and what is just part of the demo program.

Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2023-07-28 14:44:25 +01:00
Thomas Daubney
a79f806225 Remove superfluous calls to psa_hash_abort
Calls were not required since psa_hash_setup was yet
to be called.

Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2023-07-28 14:33:20 +01:00
Thomas Daubney
6fc4ca2d85 Replace hash_size with hash_length
This is to make the variable naming covnention align
with the PSA API documentation.

Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2023-07-28 14:31:06 +01:00
Thomas Daubney
2c872340e8 Fix erroneous macro guards
Replace MBEDTLS_SHA256_C for PSA_WANT_ALG_SHA_256
everywhere, including comments and print statements.

Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2023-07-28 14:21:38 +01:00
Gilles Peskine
086f85f055 Fix some mistakes in descriptive messages
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-07-25 19:40:35 +02:00
Gilles Peskine
03be234c7f Declare the dependencies of key_ladder_demo.sh
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-07-25 19:36:39 +02:00
Gilles Peskine
d1b5f6f609 Move common code of demo scripts into a library
The new file programs/demo_common.sh contains initialization code,
utility functions and cleanup code meant to be used by all demo
scripts written in sh.

Initial features:

* msg: Display a message.
* run, run_bad: Run a command, visibly.
* $root_dir, $programs_dir: location of the mbedtls source tree.
* $files_to_clean: files that are cleaned up on exit.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-07-25 19:36:13 +02:00
Thomas Daubney
1fd916a1a3 Address review comments
- make operation name more generic
- make use of psa_hash_abort

Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2023-07-25 16:10:48 +01:00
Thomas Daubney
9520df7580 Fix code style
Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2023-07-25 10:56:54 +01:00
Thomas Daubney
1db78fa32a Demonstrate algorithm agility
Define HALH_ALG to the desired PSA algorithm
to demostrate the ease of swapping algorithms
with the PSA API.

Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2023-07-24 16:49:14 +01:00
Thomas Daubney
f7348ae1fc Improve program from first round review comments
Following an initial review:
- Swap printf for mbedtls_printf
- Remove MBEDTLS_xxx dependencies
- Demonstrate correct buffer sizing

Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2023-07-24 12:18:40 +01:00
Thomas Daubney
209c9c9492 Bring code-style up-to-date
This PR was originally created before the code
style was changed. This commit updates the style.

Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2023-07-18 14:59:45 +01:00
Hannes Tschofenig
f8b9ebf297 Add example program for PSA hash
This commit adds the example program for PSA
hash as well as the relevant changes to
CMakeLists.txt and the Makefile.

Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
2023-07-18 13:55:36 +01:00
David Horstmann
4dfa368681 Fix demo scripts for out-of-tree builds
Allow demo scripts to be run from the build directory for out-of-tree
builds.

If the executable is not found in the source tree then search in the
current directory in case the script is being run from a build
directory.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2023-05-09 18:30:05 +01:00
Manuel Pégourié-Gonnard
33783b4646 Manually fix two remaining instances of old macros
Unless I missed something, all remaining instance of all macros are in
files where it makes sense to use these. I went over the output of:

    git grep -c -E 'MBEDTLS_(MD5|RIPEMD160|SHA[0-9]*)_C'

and I think all the files listed fall into one of the following
acceptable categories:

- documentation and historical documents: Changelog, docs/**/*.md
- config files and related: mbedtls_config.h, configs/*.h,
  check_config.h, config_psa.h, etc.
- scripts that build/modify configs: all.sh, depends.py,
  set_psa_test_dependencies.py, etc.
- implementation of MD or PSA or related: md.h, psa_util.h, etc. and
  corresponding test suites
- implementation of hashes: md5.c, sha256.h, etc. and corresponding test
  suites
- two example programs using a low-level hash API: hash/hello.c,
  pkey/ecdsa.c
- test/benchmark.c, test/selftest.c: actually want our built-in
  implementations
- a function in test_suite_psa_crypto_storage_format that is
  specifically for checking if the hash is built in.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2023-03-24 10:43:40 +01:00
Gilles Peskine
449bd8303e Switch to the new code style
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-01-11 14:50:10 +01:00
Manuel Pégourié-Gonnard
1a100b69a4
Merge pull request #6705 from davidhorstmann-arm/code-style-script-non-corrected
Add code style correction script
2022-12-09 09:41:14 +01:00
Tom Cosgrove
1797b05602 Fix typos prior to release
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2022-12-04 17:19:59 +00:00
David Horstmann
5b98d73864 Linewrap for the benefit of Uncrustify
The last line of programs/psa/key_ladder_demo.c is of the following
form:

 #endif /* Very long comment ... */

Uncrustify tries to reduce the length:

 #endif \
     /* Very long comment ... */

and causes a compiler error as there is a continuation line with no
actual code in it. Work around this by linewrapping the comment
in advance.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2022-11-14 12:10:37 +00:00
Paul Elliott
7adb8cbc0e Revert "Add generated files for 3.2.0 release"
This reverts commit cb21f2eab3.

Signed-off-by: Paul Elliott <paul.elliott@arm.com>
2022-07-11 18:18:30 +01:00
Paul Elliott
cb21f2eab3 Add generated files for 3.2.0 release
Signed-off-by: Paul Elliott <paul.elliott@arm.com>
2022-07-11 13:56:01 +01:00
Paul Elliott
41aa808a56
Merge pull request #952 from gilles-peskine-arm/stdio_buffering-setbuf
Turn off stdio buffering with setbuf()
2022-07-04 10:12:22 +01:00
Gilles Peskine
6d576c9646 Call setbuf when reading or writing files: programs
After opening a file containing sensitive data, call mbedtls_setbuf() to
disable buffering. This way, we don't expose sensitive data to a memory
disclosure vulnerability in a buffer outside our control.

This commit adds a call to mbedtls_setbuf() after each call to fopen(),
but only in sample programs that were calling mbedtls_platform_zeroize().
Don't bother protecting stdio buffers in programs where application buffers
weren't protected.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-06-30 17:06:11 +02:00
Andrzej Kurek
5c65c5781f Fix additional misspellings found by codespell
Remaining hits seem to be hex data, certificates,
and other miscellaneous exceptions.
List generated by running codespell -w -L 
keypair,Keypair,KeyPair,keyPair,ciph,nd

Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2022-05-11 21:25:54 +01:00
Dave Rodgman
017a19997a Update references to old Github organisation
Replace references to ARMmbed organisation with the new
org, Mbed-TLS, following project migration.

Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2022-03-31 14:43:16 +01:00
Manuel Pégourié-Gonnard
64754e1b8d Wrap long lines
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2022-02-08 11:21:14 +01:00
Manuel Pégourié-Gonnard
340808ca67 Add comments on error codes
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2022-02-08 11:15:26 +01:00