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

Argon2 outputs uninitialized memory with keysize > 64 #14912

Closed
guidovranken opened this issue Mar 14, 2023 · 3 comments · Fixed by #14914
Closed

Argon2 outputs uninitialized memory with keysize > 64 #14912

guidovranken opened this issue Mar 14, 2023 · 3 comments · Fixed by #14914
Labels
bug Observed behavior contradicts documented or intended behavior standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@guidovranken
Copy link

Zig Version

zig-linux-x86_64-0.11.0-dev.1969+d525ecb52

Steps to Reproduce and Observed Behavior

const std = @import("std");
const argon2 = std.crypto.pwhash.argon2;

pub fn main() !void {
    var pw: [32]u8 = [32]u8{
        0x01, 0x09, 0xb4, 0xd9, 0xce, 0xb9, 0x0b, 0xbf, 0xd8, 0xae, 0x53, 0xfc, 0x48, 0xcb, 0x37, 0xf0, 
        0x47, 0xf3, 0x5c, 0x08, 0xfb, 0x0f, 0x65, 0xa7, 0x84, 0x0b, 0xf9, 0x32, 0x0f, 0xc1, 0xbf, 0x0e};
    var salt: [32]u8 = [32]u8{
        0xbc, 0x22, 0x5f, 0xa8, 0xb1, 0x0d, 0x77, 0x5d, 0x1c, 0x66, 0xb9, 0x99, 0x1b, 0x1e, 0xc0, 0xc4, 
        0xd8, 0x0e, 0x3a, 0x3b, 0x75, 0x29, 0xc9, 0x6b, 0x1d, 0x4b, 0x12, 0xb7, 0xf5, 0x59, 0xbf, 0x89};
    const mode = argon2.Mode.argon2id;
    const params = argon2.Params{ .t = 2, .m = 20801, .p = 1 };
    const allocator = std.heap.page_allocator;
    var out: [65]u8 = undefined;
    argon2.kdf(
            allocator,
            out[0..65],
            pw[0..32],
            salt[0..32],
            params,
            mode) catch {
        return;
    };
    const stdout = std.io.getStdOut().writer();
    for (out) |elem| {
        std.fmt.format(stdout, "0x{x}, ", .{elem}) catch { };
    }
    std.fmt.format(stdout, "\n", .{}) catch { };
}

Prints:

0x82, 0xa1, 0x10, 0xa4, 0x28, 0xc8, 0xbb, 0x83, 0xa9, 0xdd, 0xac, 0x94, 0x25, 0x5b, 0x8a, 0x9a, 0x54, 0xcc, 0xb2, 0xa, 0xfb, 0x95, 0x8a, 0x6f, 0xda, 0x38, 0x97, 0x9b, 0x83, 0x89, 0x30, 0xa5, 0x4, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,

Expected Behavior

Should print:

0x82, 0xa1, 0x10, 0xa4, 0x28, 0xc8, 0xbb, 0x83, 0xa9, 0xdd, 0xac, 0x94, 0x25, 0x5b, 0x8a, 0x9a, 0x54, 0xcc, 0xb2, 0x0a, 0xfb, 0x95, 0x8a, 0x6f, 0xda, 0x38, 0x97, 0x9b, 0x83, 0x89, 0x30, 0xa5, 0xdf, 0xec, 0xde, 0xa8, 0x23, 0xb4, 0x19, 0x16, 0x80, 0x98, 0x3f, 0x8f, 0xca, 0x9d, 0x2f, 0xc2, 0x8f, 0x4d, 0xa8, 0x6d, 0x8e, 0x73, 0xec, 0xe5, 0x7c, 0xac, 0x31, 0xc3, 0xf4, 0x08, 0x26, 0xc4, 0x4a
@guidovranken guidovranken added the bug Observed behavior contradicts documented or intended behavior label Mar 14, 2023
@guidovranken
Copy link
Author

@jedisct1

@Vexu Vexu added the standard library This issue involves writing Zig code for the standard library. label Mar 14, 2023
@Vexu Vexu added this to the 0.11.0 milestone Mar 14, 2023
@jedisct1
Copy link
Contributor

@x13a

@jedisct1
Copy link
Contributor

Thank you @guidovranken !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants