Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide linkable functions of PSA getters and setters #3230

Open
gilles-peskine-arm opened this issue Apr 22, 2020 · 4 comments
Open

Provide linkable functions of PSA getters and setters #3230

gilles-peskine-arm opened this issue Apr 22, 2020 · 4 comments

Comments

@gilles-peskine-arm
Copy link
Contributor

Getters and setters in the PSA API are declared as static inline. That's great if you're programming in C or C++, but if you're writing a wrapper for a high-level language, you may well need a linkable function. This has come up with Rust wrappers for example.

Mbed TLS, and possibly the PSA Crypto API, should be able to provide a linkable version of these functions.

Initializers are also static inline, but these might not be necessary since they can officially be replaced by all-bits-zero initialization.

@gilles-peskine-arm gilles-peskine-arm changed the title Provide linkable functions of getters and setters Provide linkable functions of PSA getters and setters Apr 22, 2020
@egrimley-arm
Copy link

It is possible to use the static inline functions from Rust by having a shim library. I'm playing with that approach now. It means maintaining a separate list of those functions, of course.

There's a related problem with preprocessor symbols. With Rust, if the C header contains #define X (123) then bindgen turns that into a pub const u32. But if the C header contains #define X ((int)123) then bindgen just ignores it. I don't know about other high-level languages accessing preprocessor symbols, but the C preprocessor is such a bizarre thing that I can't imagine it's straightforward in all cases.

@gilles-peskine-arm
Copy link
Contributor Author

It would be good for bindgen to support such constants. The cast is necessary to get constants that work reliably with bitwise operations, especially involving negation. It also sometimes helps with static analyzers to detect when you're putting a numerical constant of one type where the context expects a different type. This may be complicated to implement, I don't know how sophisticated bindgen is.

@daverodgman
Copy link
Contributor

There is more discussion on this topic in #6400

@daverodgman
Copy link
Contributor

It looks like bindgen is working to support this kind of thing - see recent activity in rust-lang/rust-bindgen#1090

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

No branches or pull requests

3 participants