-
Notifications
You must be signed in to change notification settings - Fork 93
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
serde library should have hash functions #105
Comments
Given several of these operate with 64 bit integers, it's non-trivial to implement them in pure Luau. It'd be easier and significantly faster to do on the Rust side. For reference, here's a SHA-512 implementation I made. It's likely a significant portion of people don't have the knowledge or quite frankly will power to implement these on their own just due to the sheer amount of bit math involved to treat two 32-bit integers as one 64-bit one. |
This would be fairly simple to implement in Rust, there's a bunch of well-vetted implementations for most most cryptographic algorithms. |
If hashing support does get added, here's a list of my recommendations, along with why:
Despite widespread use, including SHA-1 and MD5 as built-in hashes is irresponsible IMO since they're broken and easily implemented in Luau at acceptable speeds. In regards to stuff like HMAC, I am of two minds. HMAC is hilariously easy to implement (I have an old implementation that is 43 lines long) so it's probably fine to leave out. On the other hand, it's also a standard so expecting people to implement it themselves is maybe weird! I'd also like to comment on potential non-cryptographic functions. I think we should err on the side of caution and not touch them. Something like xxHash3 has its uses but it's really not secure, and including it is asking for people to just use it because it's fast. Blake3 is a great alternative for most use cases anyway. |
I think before we go further with this, incidentally, we should settle two questions:
|
I left some thoughts on the related PR (#122) and would like to leave a couple extra ones here.
All in all, I'm currently leaning towards an API that looks something like: type Hasher = "hash" | "algorithm" | "names"
serde.hash(algo: Hasher, message: string): string
serde.hmac(algo: Hasher, secret: string, message: string): string where if necessary for some specific hashing algorithm we could add additional arguments to the end after This does leave out the use case of updating a hasher multiple times for performance when there are several inputs. I don't think we should prioritize this use case, since it changes our entire API surface, and makes it much less friendly for every other use case. If we support the new Luau |
I have a rough implementation that uses basically the format above. It's straight forward, but still uses a macro to erase some boilerplate (quite frankly, nobody needs to see the same 3 lines repeated for every single hashing algorithm). I'm not sure if |
Buffer is actually supported by mlua, and lune 0.8.0 ships with buffer support. |
I'm not seeing references to it in the docs. The |
Disappointing, but not surprising. Never mind then, thank you. |
@Dekkonot thought I'd chime in with a small update here - you can accept buffers as rust function args very easily now in the latest |
I'd greatly appreciate support for this my use case is caching raw binary file data with hashes, i have an automatic image compression program and i'd like to cache whatever images already compressed as a Hash |
The
serde
library should include some general hashing functions.Some possible hash functions that could be implemented are
Ideally, there'd probably be more. This is just what I came up with. I'd imagine that all of these have Rust implementations available?
The text was updated successfully, but these errors were encountered: