-
Notifications
You must be signed in to change notification settings - Fork 15
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
Python and JS wrappers #2
Comments
There is no standard API for XOFs in Python, so this would entail inventing one at the very minimum. |
@mumbleskates thanks for the response, what do you mean by "standard API"? We can simply copy the API standard of BLAKE2 where they allow the existence of digest size, key and salt. |
Cool, that's a fair observation! I forgot they added those in 3.6. The C api of libk12.so is pretty straightforward, so calling into it with |
Creating bindings of K12 for other languages would of course be of great interest for the community. See for instance the bindings for Rust written by Jack O'Connor. However, to be honest, I don't think I will work on this any time soon. For the time being, I stay focused on cryptography and core cryptographic implementations. Also, although I think (or hope) that I have the abilities to write such wrappers, I do not have any experience. So, if anyone wants to take on this task it would certainly be very useful. |
Yes, I believe this would definitely belong in a separate repository. |
It should be in a separate repo, I agree, but it should be good to know that it should be done. |
Regardless of a precedent for variable output length with blake2, Some immediate challenges i can see:
So from all of the above, there are still non-trivial amounts of work to be done to 1) figure out the desired python API, and either 2a) add a couple helpful bits to K12 or 2b) create a new library with its own .so to use. I would prefer adding public APIs to return the size and alignment of the struct, since managing a mutable buffer with a bytearray and ctypes is pretty doable and managing lifetimes of memory allocated by a C extension sounds pretty lame. Having these functions seems potentially useful for other language wrappers as well. |
The API for SHAKE128 and SHAKE256 in Python solves part of the problem. The method
A possible fallback solution would be to have a canonical struct to store the state (with fixed size and alignment) and functions that import/export from/to the |
We could, but this still punts on the idea of knowing how much space to allocate. However, looking at it a little more, I think it might be quite safe to choose the current 64B aligned struct sizeof() and always use that. I believe that currently the most-aligned layout has a sizeof() of 512, and looks like this:
This actually seems like ample overhead and it could be very reasonable to just assume that 512 bytes, 64-byte aligned, will probably always be enough. It seems kind of unlikely that we would need to support a build whose padding overhead is somehow even worse than this. |
Would be useful to have wrappers that makes such usage easy.
Standard formatting: https://docs.python.org/3/library/hashlib.html
x = k12(param="number")
x.update(b"binary data")
y = x.digest()
The text was updated successfully, but these errors were encountered: