Repository navigation
Conversation
|
Errrr... I don't think it is ready yet :) |
What's wrong with my math? :( |
|
|
# Conflicts: # lib/std/crypto/bcrypt.zig
|
This is awesome work! Just one thing. Returning strings that have to be deallocated is not very common in Zig, especially when the length is a constant for a given set of parameters. In the current code, the same allocator is also used for two completely different things (allocating gigabytes of aligned memory for the duration of a computation vs returning a 64 byte string). So, maybe the functions can accept an existing array and return the corresponding slice? For the Unix crypt format, the size is constant. For the PHC format, the upper bound is known and the exact size can be computed from the parameters. |
|
Let's wait for base64 to be merged. |
|
Yep, this is going to remove a bit of code duplication. |
add VerifyOptions to strVerify refactor
|
Hi @x13a, CI may be acting up, but otherwise, the code looks really good! Once CI's happy, do you think this is ready to merge, or are there more changes you would like to do? |
|
Hi @jedisct1 , Suppose it's ready. Some things I have to mention..
pub const Error = @import("crypto/error.zig").Error || std.mem.Allocator.Error;Or we can transform it to some internal error. Another thing, besides I have added If I change it to It will be nice if you can check if |
No need to add |
|
Lol, really didn't think that we can merge errors on return :) Will update tomorrow. |
|
Is there any way to understand what is the reason for error in |
|
It may be an error happening at comptime. Or, in the case of your function, if may be that the instance is running out of memory. The way I usually deal with these is by having setup Azure Pipelines for a copy of the repository, with the CI scripts reduced to the bare minimum (only running the Linux tasks, running the relevant tests first, not running non-native environments). You may get more informative messages that way, but it also makes it faster to get feedback after having made a change. |
|
Hello @jedisct1 , Merging with master helped: "All checks have passed". |
|
Yay! This is great news! Everything looks really nice! Just one thing: with these changes, bcrypt now requires an allocator, even though the function itself has a constant-size state and always returns a constant-size string. It the allocator even used here? |
|
This is done for |
| kdf(derived_key[0..derived_key_length], password, salt[0..salt_length].*, params); | ||
| } | ||
|
|
||
| /// Apply BCRYPT to generate a key from a password. |
There was a problem hiding this comment.
Wait, what? bcrypt is not a KDF.
There was a problem hiding this comment.
Let's look..
wikipedia bcrypt tells us that: bcrypt is a password-hashing function designed by.., if we click on password-hashing function we get redirected to Key derivation function. Where we can read this:
In cryptography, a key derivation function (KDF) is a cryptographic hash function that derives one or more secret keys from a secret value such as a main key, a password, or a passphrase using a pseudorandom function.
...
The first[citation needed] deliberately slow (key stretching) password-based key derivation function was called "crypt" (or "crypt(3)" after its man page), and was invented by Robert Morris in 1978.
...
Various algorithms have been designed specifically for this purpose, including bcrypt, scrypt and, more recently, Lyra2 and Argon2 (the latter being the winner of the Password Hashing Competition).
There was a problem hiding this comment.
bcrypt is a little bit different: it was only made to be a password hashing function.
bcrypt as a KDF generally refers to the bcrypt-pbkdf function.
|
Got it. Requiring a "mock pointer" feels a little bit odd. How about including the allocator in the options set of functions requiring one? |
|
I though that allocator is always passed as first argument to functions that require allocations. Maybe do not save the same signature between |
Not necessarily. For example |
| password: []const u8, | ||
| options: HashOptions, | ||
| out: []u8, | ||
| ) (Error || mem.Allocator.Error)![]u8 { |
There was a problem hiding this comment.
You are using Error || mem.Allocator.Error 9 times.
Could you extract/name it?
|
30+ days old draft; closing |
|
@andrewrk Merged with upstream cause I wanted to complete it in few days. Could you reopen or I have to create new? upd: I will create a new one with reference to this. It will be better. |
This pull adds scrypt key derivation function and basic phc-string parser for kdf(s).
With much help of @jedisct1 .