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

Undocumented alignment of secp256k1_context #1082

Closed
Kixunil opened this issue Mar 8, 2022 · 3 comments
Closed

Undocumented alignment of secp256k1_context #1082

Kixunil opened this issue Mar 8, 2022 · 3 comments

Comments

@Kixunil
Copy link

Kixunil commented Mar 8, 2022

secp256k1_context doesn't have alignment documented but looking at the code it's clearly bigger than 1 since it contains pointers and int. Possibly becuase of lacking documentation Rust bindings used array of bytes (u8 AKA uint8_t) which is very wrong.

@elichai
Copy link
Contributor

elichai commented Mar 8, 2022

I assume you mean the buffer to the preallocated context and not the context itself?
if so, the documentation says that it should be aligned to hold "suitably aligned to hold an object of any type.":

* of size at least secp256k1_context_preallocated_size(flags) bytes, suitably
* aligned to hold an object of any type.

Also, see this discussion: rust-bitcoin/rust-secp256k1#141 (comment)

@Kixunil
Copy link
Author

Kixunil commented Mar 8, 2022

Ah, OK, I expected to find this at type not a function. Thanks!

@Kixunil Kixunil closed this as completed Mar 8, 2022
@elichai
Copy link
Contributor

elichai commented Mar 8, 2022

Note that the secp256k1_context type is opaque and can only be created via function calls to libsecp (either context_create/clone or context_preallocated_create/clone), so either libsecp allocates the memory and takes care of the alignment or the user supplies a buffer to the preallocated API and then they need to make sure it has the alignment that the preallocated API requires.

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

No branches or pull requests

2 participants