Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
147 commits
Select commit Hold shift + click to select a range
c57eaf2
psa-client-server: move psasim from framework repo to the mbedtls one
valeriosetti May 3, 2024
3da878a
crypto-client test: add mechanism to build crypto library for client …
valeriosetti May 7, 2024
7238f3d
crypto-client test: ensure that client/server are linked against prop…
valeriosetti May 9, 2024
306d9e6
crypto-client test: implement the first IPC call for psa_crypto_init()
valeriosetti May 9, 2024
2dd4788
crypto-client: reorganize source files/folders
valeriosetti May 10, 2024
e1f5632
crypto-client: simplify build of mbedtls static libraries
valeriosetti May 10, 2024
9ce8193
crypto-client: fix the SID
valeriosetti May 10, 2024
977ba09
crypto-client: remove log files on "make clean"
valeriosetti May 10, 2024
e8c8fc6
crypto-client: allow debug build of libraries and test binaries
valeriosetti May 10, 2024
f917802
psa_ff_client: fix typos and useless blank lines
valeriosetti May 14, 2024
3ccf2b8
psasim: create a seedfile to be used for the crypto server
valeriosetti May 14, 2024
f048bb7
psa_autogen.py: improve management of output files
valeriosetti May 15, 2024
1bd3e3b
Replace final sprintf() with snprintf() in psa_ff_server.c
tom-cosgrove-arm May 27, 2024
2f29f27
Fix psa_ff_server.c to calculate the amount of data from client corre…
tom-cosgrove-arm May 27, 2024
e0d0940
Fix PSA sim test awk script by removing extra $
tom-cosgrove-arm May 27, 2024
c4cc08d
Fix sending a response of more than 184 bytes in psa_ff_server.c:psa_…
tom-cosgrove-arm May 28, 2024
1bb0751
Only print PSA crypto sim server messages when DEBUG defined
tom-cosgrove-arm May 28, 2024
04a8773
Remove unnecessary blank lines at top of functions in psa_ff_server.c
tom-cosgrove-arm May 28, 2024
10e0b2d
Fix code style in psa_ff_server.c
tom-cosgrove-arm May 29, 2024
161e759
Add PSA crypto sim serialisation functions for basic types
tom-cosgrove-arm May 29, 2024
386add5
Add PSA crypto sim serialisation functions for rest of types needed f…
tom-cosgrove-arm May 29, 2024
d726062
Add PSA crypto sim client and server implementations of psa_hash_comp…
tom-cosgrove-arm May 29, 2024
f2d96a7
The PSA sim logs aren't very many lines, so show them during tests
tom-cosgrove-arm May 29, 2024
c6bc912
Hook the new psa_sim_crypto_{client,server} into the build and tests
tom-cosgrove-arm May 29, 2024
b4adef8
Add PSA crypto sim serialisation functions needed for the remaining P…
tom-cosgrove-arm May 29, 2024
f37a6f4
Add the rest of the psa_hash_xxx() functions to the simulator
tom-cosgrove-arm May 29, 2024
f5ad224
Extend PSA crypto simulator tests to run psa_hash.c under the simulator
tom-cosgrove-arm May 29, 2024
70ea0c3
Mark temporary PSA crypto sim Perl scripts as executable
tom-cosgrove-arm May 29, 2024
ad00107
PSA crypto sim's server wrappers need to free deseraliased buffers wh…
tom-cosgrove-arm May 29, 2024
88ec6fe
Add missing licences
tom-cosgrove-arm May 30, 2024
0190ef0
Correctly build client-side code that's to be run under the PSA crypt…
tom-cosgrove-arm Jun 10, 2024
5972faa
We want the PSA hash code if MBEDTLS_PSA_CRYPTO_CLIENT && !MBEDTLS_PS…
tom-cosgrove-arm Jun 10, 2024
01b8304
Store operation_ts on PSA sim server side; only send handle to client
tom-cosgrove-arm Jun 10, 2024
566c7a6
Make psa_sim_generate.pl output the new type of server wrapper we want
tom-cosgrove-arm Jun 10, 2024
a84398b
Move the comment block in psa_sim_serialise.c back to where it belongs
tom-cosgrove-arm Jun 10, 2024
7774c5f
psa_sim_serialise.pl now creates the updated .h file
tom-cosgrove-arm Jun 10, 2024
c360f6c
psa_sim_serialise.pl now creates the updated .c file
tom-cosgrove-arm Jun 10, 2024
540913b
Revert "Correctly build client-side code that's to be run under the P…
tom-cosgrove-arm Jun 11, 2024
9dc22c5
Use our own copy of programs/psa/psa_hash.c in the PSA simulator tests
tom-cosgrove-arm Jun 11, 2024
eb7ef78
psa_sim_crypto_[client/server]: check if CRYPTO_C is enabled
valeriosetti Jun 10, 2024
5096a3e
psasim: build server library and binary before client's ones
valeriosetti Jun 10, 2024
0ad7940
Have PSA sim client wrappers say which call fails, if one does
tom-cosgrove-arm Jun 11, 2024
8377744
Make it possible to pass arguments to PSA sim psa_client
tom-cosgrove-arm Jun 11, 2024
6b96183
Add support for and run (a copy of) the PSA aead_demo program under P…
tom-cosgrove-arm Jun 11, 2024
016a246
Adjust build systems
ronald-cron-arm Jun 10, 2024
1ee5e04
psa_sim: make server ping time much faster
valeriosetti Jun 17, 2024
598e10e
psasim-server: add function to reset operations slots
valeriosetti Jun 17, 2024
d64ba42
Have psa_sim_generate.pl add psa_crypto_close() to psa_sim_crypto_ser…
tom-cosgrove-arm Jun 18, 2024
ac9043a
Have psa_sim_serialise.pl generate psa_sim_serialize_reset()
tom-cosgrove-arm Jun 18, 2024
b776a09
psa_sim: improve log prints
valeriosetti Jun 17, 2024
55b71e6
Update psa_sim_generate.pl to create the psa_sim_crypto_client.c we want
tom-cosgrove-arm Jun 18, 2024
53dfdf3
Update psa_sim_serialise.pl to create the psa_sim_serialise.c we want
tom-cosgrove-arm Jun 18, 2024
ee1b17a
Merge pull request #9279 from valeriosetti/reduce-psasim-ping-interval
minosgalanakis Jun 18, 2024
4bcd780
Merge pull request #9247 from ronald-cron-arm/move-psa-headers
ronald-cron-arm Jun 18, 2024
1a2537e
Merge pull request #9278 from valeriosetti/fix-psasim-logs
tom-cosgrove-arm Jun 19, 2024
964cd89
Merge pull request #9280 from valeriosetti/psasim-reset-slots-on-disc…
tom-cosgrove-arm Jun 19, 2024
8f81e20
psasim: add support for psa_generate_random()
tom-cosgrove-arm Jun 21, 2024
a5d11af
psasim: add support for psa_mac_xxx() functions
tom-cosgrove-arm Jun 21, 2024
099679c
psasim: add support for psa_cipher_xxx() functions
tom-cosgrove-arm Jun 21, 2024
c506151
psasim: skip some functions; see _SKIP_FUNCTIONS in generate_psa_wrap…
tom-cosgrove-arm Jun 21, 2024
b078983
psasim: use ser_params and ser_result variable names in client; 'para…
tom-cosgrove-arm Jun 21, 2024
66a1a0f
psasim: psa_key_derivation_verify_bytes() doesn't follow the naming c…
tom-cosgrove-arm Jun 21, 2024
b17abbc
psasim: add the ability to serialise psa_key_production_parameters_t
tom-cosgrove-arm Jun 21, 2024
0d3c4c7
psasim: add support for psa_key_derivation_xxx() and psa_raw_key_agre…
tom-cosgrove-arm Jun 21, 2024
fb61ab5
psasim: add support for psa_generate_key*() to the simulator
tom-cosgrove-arm Jun 21, 2024
079c654
psasim: add support for psa_{sign,verify}_{message,hash}() to the sim…
tom-cosgrove-arm Jun 21, 2024
2bd6bfa
psasim: add support for psa_asymmetric_{encrypt,decrypt}() to the sim…
tom-cosgrove-arm Jun 21, 2024
1c1005b
psasim: add support for key functions that don't need psa_key_attribu…
tom-cosgrove-arm Jun 21, 2024
3e689c8
psasim: add support for PSA functions that return uint32_t or void
tom-cosgrove-arm Jun 21, 2024
b0b20ea
psasim: add support for psa_{sign,verify}_hash_xxx() and get/set max ops
tom-cosgrove-arm Jun 21, 2024
5c66a73
psasim: add support for psa_copy_key()
tom-cosgrove-arm Jun 21, 2024
7f751a9
psasim: add support for psa_reset_key_attributes()
tom-cosgrove-arm Jun 21, 2024
c819e53
psasim: have the generator script check for type = "void" rather than…
tom-cosgrove-arm Jun 21, 2024
874e820
psasim: merge all AUT programs into a single executable
valeriosetti Jun 24, 2024
2ea5fdd
psasim: add AUT for psa_generate_random()
valeriosetti Jun 24, 2024
fb89b18
psasim: add AUT for MAC
valeriosetti Jun 24, 2024
6aff2a2
psasim: add AUT for key generation and raw key agreement
valeriosetti Jun 24, 2024
7f27ef7
psasim: add AUT for PSA sign and verify
valeriosetti Jun 24, 2024
a334b50
psasim: add AUT for symmetric encryption/decryption
valeriosetti Jun 24, 2024
d521ec5
psasim: add AUT for key derivation
valeriosetti Jun 24, 2024
5d50746
psasim: add AUT for cipher encryption/decryption
valeriosetti Jun 24, 2024
0bd5bac
psasim: add AUT for asymmetric encryption/decryption
valeriosetti Jun 24, 2024
39865e3
psasim: fix max line length in generated files
valeriosetti Jun 25, 2024
9d7302a
Adjust build systems
ronald-cron-arm Jun 14, 2024
2553e34
Merge pull request #9299 from ronald-cron-arm/move-mbedtls-crypto-hea…
ronald-cron-arm Jul 1, 2024
0185147
psasim: minor fixes to the core
valeriosetti Jun 27, 2024
4312abc
psasim: invalidate operations on abort+finish
tom-cosgrove-arm Jun 29, 2024
251370c
psasim: remove sleep on server side to make test as fast as possible
valeriosetti Jul 1, 2024
c255f2c
Merge pull request #9328 from valeriosetti/psasim-improvements
tom-cosgrove-arm Jul 2, 2024
1b39c5c
makefile: allow to build and link test suites against psasim
valeriosetti Jun 27, 2024
ecce17c
psasim: update bash scripts
valeriosetti Jun 27, 2024
f1a13b9
psasim: add a bit of white-box testing to hash operations
tom-cosgrove-arm Jun 29, 2024
397e482
Merge pull request #9237 from valeriosetti/issue8968
tom-cosgrove-arm Jul 2, 2024
0cc439f
Adapt psasim
ronald-cron-arm Jul 18, 2024
f35d900
Revert "Adapt psasim"
ronald-cron-arm Jul 22, 2024
733fcf6
psasim: Fix doorbell file path
ronald-cron-arm Jul 22, 2024
b465b5b
psasim: Fix IPCs removal
ronald-cron-arm Jul 22, 2024
1170ada
psasim: Move file clean-up to all.sh
ronald-cron-arm Jul 22, 2024
5811e35
psasim: Rename kill_server.sh to kill_servers.sh
ronald-cron-arm Jul 22, 2024
0e62b0f
all.sh: psasim: Start server in tf-psa-crypto/tests
ronald-cron-arm Jul 22, 2024
fb5e94d
Merge pull request #9394 from ronald-cron-arm/move-crypto-test-suites
ronald-cron-arm Jul 24, 2024
de419d1
Write output files to the expected directory
gilles-peskine-arm Jul 31, 2024
1e8bc61
Parse the actual headers
gilles-peskine-arm Jul 31, 2024
1b495c6
Enhance existing skip mechanism instead of duplicating it
gilles-peskine-arm Aug 1, 2024
889f31a
Remove cruft and update documentation
gilles-peskine-arm Aug 2, 2024
b4698a7
Migrate psasim wrappers to psa_custom_key_parameters_t
gilles-peskine-arm Jul 31, 2024
6cc552f
Update generated PSA wrappers
gilles-peskine-arm Jul 31, 2024
8c613fe
psasim: small fixes to all.sh and test bash scripts
valeriosetti Aug 5, 2024
41b7a2b
Merge pull request #9446 from gilles-peskine-arm/psa_generate_key_cus…
gilles-peskine-arm Aug 6, 2024
38a7f7d
Merge pull request #9427 from valeriosetti/psasim-small-fixes
tom-cosgrove-arm Aug 7, 2024
d121bf1
Merge pull request #1264 from Mbed-TLS/pre3.6.1_test_merge_upstream_dev
gilles-peskine-arm Aug 12, 2024
1a9a6c6
Merge pull request #9525 from mpg/dev-mergeback
gilles-peskine-arm Sep 2, 2024
e909991
Fix failing psasim tests
Harry-Ramsey Oct 7, 2024
2fd8bc7
Merge pull request #9653 from Harry-Ramsey/revert-version-features-de…
ronald-cron-arm Oct 9, 2024
cbf407f
Fix linking error for mbedtls_test_hook_error_add
Harry-Ramsey Oct 21, 2024
3426182
Fix formatting issue
Harry-Ramsey Oct 21, 2024
578ce8d
Add PSA interuptable key agreement APIs
waleed-elmelegy-arm Aug 6, 2024
c64ae58
Add required code to psa_sim_generate.pl
paul-elliott-arm Nov 15, 2024
a3f92e0
Regenerate PSA Sim headers
paul-elliott-arm Nov 14, 2024
3beb173
Fix paths for programs/psa
Harry-Ramsey Oct 22, 2024
262f91c
Refactor tests and programs comment
Harry-Ramsey Nov 4, 2024
014e84a
psasim: add support for psa_export_public_key_iop
valeriosetti Mar 3, 2025
5c2687a
psasim: add support for psa_can_do_hash()
valeriosetti Mar 3, 2025
e76014d
Merge pull request #10027 from valeriosetti/md-psa-dispatch-development
gilles-peskine-arm Mar 4, 2025
efbb0f4
psasim: update README file
valeriosetti Mar 4, 2025
b5d675a
tests: psasim: remove references to mbedtls_psa_register_se_key()
valeriosetti Mar 21, 2025
1005bec
Merge pull request #10050 from valeriosetti/issue8151-development
ronald-cron-arm Mar 26, 2025
5e1cd71
[development] Remove code relating to MBEDTLS_PSA_INJECT_ENTROPY
felixc-arm Mar 19, 2025
a1dfb4d
Merge pull request #10032 from valeriosetti/psasim-doc-update
mpg Mar 28, 2025
cdad5a2
Merge pull request #10073 from felixc-arm/remove-inject-entropy
ronald-cron-arm Mar 28, 2025
21fb240
psasim: add timeout while waiting for psa_server to start
valeriosetti Apr 8, 2025
5378540
Add __attribute__ ((nonstring)) to remove unterminated-string-initial…
felixc-arm Jun 11, 2025
4d73e5e
Replace __attribute__((nonstring)) with macro MBEDTLS_ATTRIBUTE_UNTER…
felixc-arm Jun 12, 2025
c5e4828
Add include so psasim files can find new macro
felixc-arm Jun 14, 2025
5453522
Add explanatory comment above #include "../tf-psa-crypto/core/common.h"
Jun 19, 2025
ceaf614
Remove trailing whitespace
Jun 19, 2025
085b69e
Merge pull request #10216 from felixc-arm/gcc-15-warning-dev
mpg Jun 20, 2025
9a7c021
Update references to tf-psa-crypto/core/common.h
bensze01 Jul 18, 2025
b5e68da
Merge pull request #10309 from bensze01/rename-tf-psa-crypto-common.h
bensze01 Jul 23, 2025
8aa61ae
Update PSASim tests to new call signature
bensze01 Aug 18, 2025
831a70a
Include fixups (headers moves to private directory)
amtkarm1 Jun 16, 2025
48da814
Merge pull request #1426 from gilles-peskine-arm/restricted-mbedtls-m…
gilles-peskine-arm Sep 17, 2025
bb25443
Add missing include of stdio.h
davidhorstmann-arm Sep 26, 2025
7139295
Merge remote-tracking branch 'restricted/development-restricted' into…
minosgalanakis Oct 11, 2025
cf7fa68
psasim: Preparation for importing the Mbedtls:psasim
minosgalanakis Dec 3, 2025
8d6a124
Import psasim history from Mbed TLS
minosgalanakis Dec 3, 2025
2583436
psasim: Update location in Makefile and all-core.sh
minosgalanakis Dec 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 75 additions & 58 deletions psasim/Makefile
Original file line number Diff line number Diff line change
@@ -1,64 +1,81 @@
CFLAGS ?= -Wall -std=c99
INCLUDE := -I./include/
DESTDIR ?= /usr/local
PREFIX := libpsaff
BUILDDIR ?= bin
CFLAGS += -Wall -Werror -std=c99 -D_XOPEN_SOURCE=1 -D_POSIX_C_SOURCE=200809L

.PHONY: all install test uninstall run docker ci
ifeq ($(DEBUG),1)
override CFLAGS += -DDEBUG -O0 -g
endif

all: libpsaff.so
CLIENT_LIBS := -Lclient_libs -lpsaclient -lmbedtls -lmbedx509 -lmbedcrypto
SERVER_LIBS := -Lserver_libs -lmbedcrypto

libpsaff.so:
$(CC) $(INCLUDE) $(CFLAGS) -c -fpic src/common.c -o common.o
$(CC) $(INCLUDE) $(CFLAGS) -c -fpic src/client.c -o client.o
$(CC) $(INCLUDE) $(CFLAGS) -c -fpic src/service.c -o server.o
$(CC) -shared -o libpsaff.so common.o client.o server.o
MBEDTLS_ROOT_PATH = ../..
COMMON_INCLUDE := -I./include -I$(MBEDTLS_ROOT_PATH)/include \
-I$(MBEDTLS_ROOT_PATH)/tf-psa-crypto/include \
-I$(MBEDTLS_ROOT_PATH)/tf-psa-crypto/drivers/builtin/include

ifeq ($(DEBUG),1)
CFLAGS += -DDEBUG -g
endif
GENERATED_H_FILES = include/psa_manifest/manifest.h \
include/psa_manifest/pid.h \
include/psa_manifest/sid.h

LIBPSACLIENT_SRC = src/psa_ff_client.c \
src/psa_sim_crypto_client.c \
src/psa_sim_serialise.c
LIBPSACLIENT_OBJS=$(LIBPSACLIENT_SRC:.c=.o)

PSA_CLIENT_BASE_SRC = $(LIBPSACLIENT_SRC) src/client.c

PSA_CLIENT_FULL_SRC = $(LIBPSACLIENT_SRC) \
$(wildcard src/aut_*.c)

PARTITION_SERVER_BOOTSTRAP = src/psa_ff_bootstrap_TEST_PARTITION.c

PSA_SERVER_SRC = $(PARTITION_SERVER_BOOTSTRAP) \
src/psa_ff_server.c \
src/psa_sim_crypto_server.c \
src/psa_sim_serialise.c

.PHONY: all clean client_libs server_libs

all:

test/seedfile:
dd if=/dev/urandom of=./test/seedfile bs=64 count=1

src/%.o: src/%.c $(GENERATED_H_FILES)
$(CC) $(COMMON_INCLUDE) $(CFLAGS) -c $< $(LDFLAGS) -o $@

client_libs/libpsaclient: $(LIBPSACLIENT_OBJS)
mkdir -p client_libs
$(AR) -src client_libs/libpsaclient.a $(LIBPSACLIENT_OBJS)

test/psa_client_base: $(PSA_CLIENT_BASE_SRC) $(GENERATED_H_FILES) test/seedfile
$(CC) $(COMMON_INCLUDE) $(CFLAGS) $(PSA_CLIENT_BASE_SRC) $(CLIENT_LIBS) $(LDFLAGS) -o $@

test/psa_client_full: $(PSA_CLIENT_FULL_SRC) $(GENERATED_H_FILES) test/seedfile
$(CC) $(COMMON_INCLUDE) $(CFLAGS) $(PSA_CLIENT_FULL_SRC) $(CLIENT_LIBS) $(LDFLAGS) -o $@

test/psa_server: $(PSA_SERVER_SRC) $(GENERATED_H_FILES)
$(CC) $(COMMON_INCLUDE) $(CFLAGS) $(PSA_SERVER_SRC) $(SERVER_LIBS) $(LDFLAGS) -o $@

$(PARTITION_SERVER_BOOTSTRAP) $(GENERATED_H_FILES): src/manifest.json src/server.c
tools/psa_autogen.py src/manifest.json

# Build MbedTLS libraries (crypto, x509 and tls) and copy them locally to
# build client/server applications.
#
# Note: these rules assume that mbedtls_config.h is already configured by all.sh.
# If not using all.sh then the user must do it manually.
client_libs: client_libs/libpsaclient
client_libs server_libs:
$(MAKE) -C $(MBEDTLS_ROOT_PATH)/library CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" libmbedcrypto.a libmbedx509.a libmbedtls.a
mkdir -p $@
cp $(MBEDTLS_ROOT_PATH)/library/libmbed*.a $@/

clean:
rm -rf $(BUILDDIR)
rm -f *.so *.o
rm -rf test/*dSYM
cd test && make clean

test:
cd test && make

test/partition:
cd test && make

run: test/partition
pkill partition || true
pkill client || true
ipcs | grep q | awk '{ printf " -q " $$2 }' | xargs ipcrm > /dev/null 2>&1 || true
(sleep 3 && ./test/client)&
./test/partition

ci:
pkill client || true
ipcs | grep q | awk '{ printf " -q " $$2 }' | xargs ipcrm > /dev/null 2>&1 || true
./test/partition 2>&1 &
sleep 3 && ./test/client
pkill partition || true

docker:
@docker run --rm -ti -v $$PWD:/opt --entrypoint /bin/bash ubuntu \
-c "cd /opt && ls && apt-get update -qq && apt install \
-y gcc make gdb python -qq && make clean && make install && make test && ldconfig && make run"

install: libpsaff.so
mkdir -p $(DESTDIR)/lib
mkdir -p $(DESTDIR)/include
cp libpsaff.so $(DESTDIR)/lib/
cp -r include/* $(DESTDIR)/include/
cp tools/psa_autogen /usr/local/bin/

uninstall:
rm $(DESTDIR)/lib/libpsaff.so
rm -rf $(DESTDIR)/include/psa
rm -rf $(DESTDIR)/include/psasim
rm -f /usr/local/bin/psa_autogen
clean_server_intermediate_files:
rm -f $(PARTITION_SERVER_BOOTSTRAP)
rm -rf include/psa_manifest

clean: clean_server_intermediate_files
rm -f test/psa_client_base test/psa_client_full test/psa_server
rm -rf client_libs server_libs
rm -f test/psa_service_* test/psa_notify_* test/*.log
rm -f test/seedfile
76 changes: 29 additions & 47 deletions psasim/README.md
Original file line number Diff line number Diff line change
@@ -1,60 +1,42 @@
# psasim

This tool simulates a PSA Firmware Framework implementation.
It allows you to develop secure partitions and their clients on a desktop computer.
It should be able to run on all systems that support POSIX and System V IPC:
e.g. macOS, Linux, FreeBSD, and perhaps Windows 10 WSL2.
PSASIM holds necessary C source and header files which allows to test Mbed TLS in a "pure crypto client" scenario, i.e `MBEDTLS_PSA_CRYPTO_CLIENT && !MBEDTLS_PSA_CRYPTO_C`.
In practical terms it means that this allow to build PSASIM with Mbed TLS sources and get 2 Linux applications, a client and a server, which are connected through Linux's shared memeory, and in which the client relies on the server to perform all PSA Crypto operations.

Please note that the code in this directory is maintained by the Mbed TLS / PSA Crypto project solely for the purpose of testing the use of Mbed TLS with client/service separation. We do not recommend using this code for any other purpose. In particular:
The goal of PSASIM is _not_ to provide a ready-to-use solution for anyone looking to implement the pure crypto client structure (see [Limitations](#limitations) for details), but to provide an example of TF-PSA-Crypto RPC (Remote Procedure Call) implementation using Mbed TLS.
## Limitations

* This simulator is not intended to pass or demonstrate compliance.
* This code is only intended for simulation and does not have any security goals. It does not isolate services from clients.
In the current implementation:

## Building
- Only Linux PC is supported.
- There can be only 1 client connected to 1 server.
- Shared memory is the only communication medium allowed. Others can be implemented (ex: net sockets), but in terms of simulation speed shared memory proved to be the fastest.
- Server is not secure at all: keys and operation structs are stored on the RAM, so they can easily be dumped.

To build and run the test program make sure you have `make`, `python` and a
C compiler installed and then enter the following commands:
## Testing

```sh
make install
make run
```
Please refer to `tests/scripts/components-psasim.sh` for guidance on how to build & test PSASIM:

On Linux you may need to run `ldconfig` to ensure the library is properly installed.
- `component_test_psasim()`: builds the server and a couple of test clients which are used to evaluate some basic PSA Crypto API commands.
- `component_test_suite_with_psasim()`: builds the server and _all_ the usual test suites (those found under the `<mbedtls-root>/tests/suites/*` folder) which are used by the CI and runs them. A small subset of test suites (`test_suite_constant_time_hmac`,`test_suite_lmots`,`test_suite_lms`) are being skipped, for CI turnover time optimization. They can be run locally if required.

An example pair of programs is included in the `test` directory.
## How to update automatically generated files

## Features
A significant portion of the intermediate code of PSASIM is auto-generated using Perl. In particular:

The implemented API is intended to be compliant with PSA-FF 1.0.0 with the exception of a couple of things that are a work in progress:
- `psa_sim_serialise.[c|h]`:
- Generated by `psa_sim_serialise.pl`.
- These files provide the serialisation/deserialisation support that is required to pass functions' parameters between client and server.
- `psa_sim_crypto_[client|server].c` and `psa_functions_codes.h`:
- Generated by `psa_sim_generate.pl`.
- `psa_sim_crypto_[client|server].c` provide interfaces for PSA Crypto APIs on client and server sides, while `psa_functions_codes.h` simply enumerates all PSA Crypto APIs.

* `psa_notify` support
* "strict" policy in manifest
These files need to be regenerated whenever some PSA Crypto API is added/deleted/modified. The procedure is as follows:

The only supported "interrupts" are POSIX signals, which act
as a "virtual interrupt".

The standard PSA RoT APIs are not included (e.g. cryptography, attestation, lifecycle etc).

## Design

The code is designed to be readable rather than fast or secure.
In this implementation only one message is delivered to a
RoT service at a time.
The code is not thread-safe.

To debug the simulator enable the debug flag:

```sh
make DEBUG=1 install
```

## Unsupported features

Because this is a simulator there are a few things that
can't be reasonably emulated:

* Manifest MMIO regions are unsupported
* Manifest priority field is ignored
* Partition IDs are in fact POSIX `pid_t`, which are only assigned at runtime,
making it infeasible to populate pid.h with correct values.
- `psa_sim_serialise.[c|h]`:
- go to `<mbedtls-root>/tests/psa-client-server/psasim/src/`
- run `./psa_sim_serialise.pl h > psa_sim_serialise.h`
- run `./psa_sim_serialise.pl c > psa_sim_serialise.c`
- `psa_sim_crypto_[client|server].c` and `psa_functions_codes.h`:
- go to Mbed TLS' root folder
- run `./tests/psa-client-server/psasim/src/psa_sim_generate.pl`
11 changes: 4 additions & 7 deletions psasim/include/psa/client.h → psasim/include/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ extern "C" {

#include <stdint.h>
#include <stddef.h>
#include <psa/error.h>

#include "psa/crypto.h"

#include "error_ext.h"
/*********************** PSA Client Macros and Types *************************/

#define PSA_FRAMEWORK_VERSION (0x0100)
Expand All @@ -32,12 +35,6 @@ extern "C" {
#define PSA_HANDLE_IS_VALID(handle) ((psa_handle_t) (handle) > 0)
#define PSA_HANDLE_TO_ERROR(handle) ((psa_status_t) (handle))

#define PSA_MAX_IOVEC (4u)

#define PSA_IPC_CALL (0)

typedef int32_t psa_handle_t;

/**
* A read-only input memory region provided to an RoT Service.
*/
Expand Down
52 changes: 52 additions & 0 deletions psasim/include/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* Common definitions used for clients and services */

/*
* Copyright The Mbed TLS Contributors
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
*/

#ifndef _COMMON_H_
#define _COMMON_H_

#include <stdint.h>
#include <stddef.h>

/* Increasing this might break on some platforms */
#define MAX_FRAGMENT_SIZE 200

#define CONNECT_REQUEST 1
#define CALL_REQUEST 2
#define CLOSE_REQUEST 3
#define VERSION_REQUEST 4
#define READ_REQUEST 5
#define READ_RESPONSE 6
#define WRITE_REQUEST 7
#define WRITE_RESPONSE 8
#define SKIP_REQUEST 9
#define PSA_REPLY 10

#define NON_SECURE (1 << 30)

typedef int32_t psa_handle_t;

#define PSA_MAX_IOVEC (4u)

#define PSA_IPC_CALL (0)

struct message_text {
int qid;
int32_t psa_type;
char buf[MAX_FRAGMENT_SIZE];
};

struct message {
long message_type;
struct message_text message_text;
};

typedef struct vector_sizes {
size_t invec_sizes[PSA_MAX_IOVEC];
size_t outvec_sizes[PSA_MAX_IOVEC];
} vector_sizes_t;

#endif /* _COMMON_H_ */
19 changes: 19 additions & 0 deletions psasim/include/error_ext.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* PSA status codes used by psasim. */

/*
* Copyright The Mbed TLS Contributors
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
*/

#ifndef PSA_ERROR_H
#define PSA_ERROR_H

#include <stdint.h>

#include "common.h"

#define PSA_ERROR_PROGRAMMER_ERROR ((psa_status_t) -129)
#define PSA_ERROR_CONNECTION_REFUSED ((psa_status_t) -130)
#define PSA_ERROR_CONNECTION_BUSY ((psa_status_t) -131)

#endif
2 changes: 1 addition & 1 deletion psasim/include/psasim/init.h → psasim/include/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

#include <stdint.h>
#include <psa/service.h>
#include <service.h>
void raise_signal(psa_signal_t signal);
void __init_psasim(const char **array,
int size,
Expand Down
File renamed without changes.
36 changes: 0 additions & 36 deletions psasim/include/psa/error.h

This file was deleted.

6 changes: 5 additions & 1 deletion psasim/include/psa/service.h → psasim/include/service.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ extern "C" {
#include <stdlib.h>
#include <stdint.h>
#include <stddef.h>
#include <psa/client.h>

#include "common.h"

#include "psa/crypto.h"

/********************** PSA Secure Partition Macros and Types ****************/

/* PSA wait timeouts */
Expand Down
Loading