Skip to content

Conversation

@silabs-ArchanaM
Copy link
Contributor

Description

This is rev 1.1 of the Codegen that fixes #5137

Status

IN DEVELOPMENT

Requires Backporting

NO
Which branch?

Migrations

If there is any API change, what's the incentive and logic for it.

YES | NO

Additional comments

Any additional information that could be of interest

Todos

  • Tests
  • Documentation
  • Changelog updated
  • Backported

Steps to test or reproduce

NA

@silabs-ArchanaM
Copy link
Contributor Author

@gilles-peskine-arm, This PR has pretty much what I had in mind for rev 1.1. It covers, JSON addition, header generation and key management templating.

I expect CI to fail as-is, since the following two seem to be problems
(1) CodeGen now requires jsonschema, would be the sensible thing to run validation against.
(2) With the codegen templating some new constant are generated for driver ID. The way its setup this maps to MBEDTLS_* for the test drivers keeping in mind the nomenclature for the functions, but looks like the scripts are calling the new macros as errors (these are autogen and could ideally be ignored). Do we want to migrate all function names to have a PSA_CRYPTO prefix (that seems like a cleanup task), any thoughts on what the mbedTLS project is aligned towards ?

@silabs-ArchanaM silabs-ArchanaM force-pushed the codegen_1.1 branch 2 times, most recently from 86cc89a to da77e04 Compare January 10, 2022 11:21
@yanesca yanesca added Community component-psa PSA keystore/dispatch layer (storage, drivers, …) labels Jan 10, 2022
@silabs-ArchanaM silabs-ArchanaM force-pushed the codegen_1.1 branch 2 times, most recently from 6dc91cf to 2585023 Compare January 11, 2022 11:32
# The version of Pylint is set to 2.4.4 to match CI.
RUN python3 -m pip install \
packaging mypy pylint==2.4.4

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes #5412 .

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that this change is no longer required

Relevant discussion

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't removed these changes as yet. Do we want to ?. As I understand it from my discussion with @gilles-peskine-arm this docker is not being used and will at some point be completely removed. I've been running my trial tests on this docker. So if it doesn't hurt, I would like to keep these changes. It's a stand alone commit, so can be knocked off.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with having these changes. But please be aware that Arm will not make any effort to maintain this Dockerfile, and we're likely to remove it soon. We maintain and use https://github.com/ARMmbed/mbedtls-test/tree/master/resources/docker_files .

@silabs-ArchanaM
Copy link
Contributor Author

Changelog and Migration guide will be updated towards the end of review.

@gilles-peskine-arm gilles-peskine-arm added needs-review Every commit must be reviewed by at least two team members, needs-reviewer This PR needs someone to pick it up for review size-s Estimated task size: small (~2d) labels Jan 12, 2022
@febdoctor febdoctor mentioned this pull request Jan 17, 2022
3 tasks
@minosgalanakis minosgalanakis self-requested a review February 3, 2022 09:10
.travis.yml Outdated
language: c
before_install:
- choco install python --version=3.5.4
- pip install jsonschema==3.2.0 types-jsonschema
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason we are not using the scripts/min_requirements.py script from the install section?

install:
  - $PYTHON scripts/min_requirements.py

If it has be provided in the before_install enviroment could we have a comment as to why so?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would assume min_requirements.py anyway gets triggered by .travis.yml, but on the Windows server, unless I explicitly request for this install, jsonschema is not installed and the CI cries in pain. @gilles-peskine-arm, I think we saw this in the past as well. Am I missing some thing here ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've lost track of all the attempts we made in the early draft of this PR, but I think it should be ok to remove this line. On Windows, first the before_install block installs Python, then the global install block installs the Python packages.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, this kind of just fixed itself and am very wary when that happens. @gilles-peskine-arm did we somehow force the Python version on the Windows server to not invoke the alternate system python. Any fixes that went in there ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked past versions and couldn't find attempts to do it differently here. Just this patch vs nothing. Failing attempts must have been due to not yet having the modules listed in a requirements file.

If it was necessary to install Python modules this way on Windows, that would also apply to Jinja2.

On the Travis Windows images, there's no system Python. Confusion between the system python and the Travis python are an issue on Linux.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for checking ! But it did fail at some point and was hence added. Maybe something else tripped me then.

@silabs-ArchanaM
Copy link
Contributor Author

@minosgalanakis, @gilles-peskine-arm any further comments on this PR ?

- pip install jsonschema==3.2.0 types-jsonschema
env:
# Add the directory where the Choco packages go
- PATH=/c/Python35:/c/Python35/Scripts:$PATH
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To my knowledge in latest Windows, Python can also be installed to:

C:\Users\username\AppData\Local\Programs\Python\Python35\

Should that also be included in the path?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python can be installed in any number of places on Windows. Here it only matters where we're installing it (with choco on the line above).

'scripts/data_files/driver_jsons/driver_transparent_schema.json'), 'r') as file:
transparent_driver_schema = json.load(file)
with open(os.path.join(mbedtls_root, \
'scripts/data_files/driver_jsons/driver_opaque_schema.json'), 'r') as file:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed above

@minosgalanakis
Copy link
Contributor

I have added few comments, which can be addressed when reworking the changes that @gilles-peskine-arm requested.

@silabs-ArchanaM silabs-ArchanaM force-pushed the codegen_1.1 branch 3 times, most recently from 3dc6d21 to cc1122a Compare February 28, 2022 01:26
@silabs-ArchanaM silabs-ArchanaM force-pushed the codegen_1.1 branch 2 times, most recently from b489a1a to 2ae9376 Compare March 14, 2022 10:42
@gilles-peskine-arm gilles-peskine-arm self-requested a review March 14, 2022 10:52
Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a sentence in the documentation that needs updating. Other than that, looks good to me.

In terms of design, I think there's too much intelligence in the template files, where the meta-logic is mixed with the C code. I'd prefer to have this intelligence in a single place, in the Python script. But this can be improved incrementally in the future.

Signed-off-by: Asfandyar Orakzai <[email protected]>
Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update, LGTM

minosgalanakis
minosgalanakis previously approved these changes Nov 2, 2022
Copy link
Contributor

@minosgalanakis minosgalanakis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall it looks good, and is fit for purpose.

Should we have a changelog entry before merging though?

Signed-off-by: Asfandyar Orakzai <[email protected]>
@asfand-silabs
Copy link
Contributor

Overall it looks good, and is fit for purpose.

Should we have a changelog entry before merging though?

Overall it looks good, and is fit for purpose.

Should we have a changelog entry before merging though?

Updated change log

ChangeLog Outdated
and hmac_demo.c, which use PSA and the md/cipher interfaces side
by side in order to illustrate how the operation is performed in PSA.
Addresses #5208.
* Brought in PSA code gen driver list JSON,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plz no txtspk in chglog

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also you need to add a file to Changelog.d, don't edit ChangeLog directly (if we edit ChangeLog directly we get conflicts between all the pull requests that do it).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gilles-peskine-arm Changelog issue is addressed, if there is anything please let me.

Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@asfand-silabs
Copy link
Contributor

LGTM

Thanks, What is merging strategy?

@gilles-peskine-arm
Copy link
Contributor

@asfand-silabs Waiting for Minos to approve the latest version, then one of us will push the merge button. Thanks for the updates!

Copy link
Contributor

@minosgalanakis minosgalanakis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gilles-peskine-arm gilles-peskine-arm added approved Design and code approved - may be waiting for CI or backports and removed needs-review Every commit must be reviewed by at least two team members, labels Nov 7, 2022
@gilles-peskine-arm gilles-peskine-arm merged commit 34c0946 into Mbed-TLS:development Nov 7, 2022
@asfand-silabs asfand-silabs deleted the codegen_1.1 branch November 9, 2022 09:44
@gstrauss
Copy link
Contributor

FYI: #5396 or #6577 broke my build environment due to a new dependency for the build.

I had to install the python3-jsonschema package on my system.

@gilles-peskine-arm
Copy link
Contributor

@gstrauss Sorry about that. We didn't announce it in the changelog because it only affects people who use the development branch, not people who use a release (the generated file is included in the release). We should probably have a place where we can communicate this. Maybe add a changelog section for people who use development? Or just a small number of entries that are not applicable to people who use releases? (Noting that you need to consult ChangeLog.d/* between releases, not just ChangeLog.)

For future reference, Python dependencies are listed in scripts/*.requirements.txt. If you just want to build the library (and the tests), the official source of truth is basic.requirements.txt (following any included files). We should make this information more visible, any suggestion how?

@gilles-peskine-arm
Copy link
Contributor

(Note that this information is in README.md. But for long-time users, there's a bootstrap problem that while users might be expected to read README.md, it's too much to ask for existing users to re-read it every time.)

@gstrauss
Copy link
Contributor

@gilles-peskine-arm as you can see, I was able to figure it out. README.md did not change for this added dependency, and it probably should not have changed. As you point out, README.md already points to python -m pip install -r scripts/basic.requirements.txt.

The reason I posted is that the requirements changed underneath me and it was not immediately obvious. I do not frequently rebuild my test environment from scratch.

When things broke for me, I did check for differences in ChangeLog.d/*, so perhaps that might be a place to note development changes which might impact others, though doing so is not necessary for all development changes. Just a suggestion since you asked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Design and code approved - may be waiting for CI or backports component-psa PSA keystore/dispatch layer (storage, drivers, …) priority-medium Medium priority - this can be reviewed as time permits size-m Estimated task size: medium (~1w)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Driver dispatch code auto gen

7 participants