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

Fix compilation issues in crypto.bcrypt and poly1305 #20756

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/std/crypto/bcrypt.zig
Original file line number Diff line number Diff line change
Expand Up @@ -496,37 +496,37 @@ const pbkdf_prf = struct {
hasher: Sha512,
sha2pass: [Sha512.digest_length]u8,

fn create(out: *[mac_length]u8, msg: []const u8, key: []const u8) void {
pub fn create(out: *[mac_length]u8, msg: []const u8, key: []const u8) void {
var ctx = Self.init(key);
ctx.update(msg);
ctx.final(out);
}

fn init(key: []const u8) Self {
pub fn init(key: []const u8) Self {
var self: Self = undefined;
self.hasher = Sha512.init(.{});
Sha512.hash(key, &self.sha2pass, .{});
return self;
}

fn update(self: *Self, msg: []const u8) void {
pub fn update(self: *Self, msg: []const u8) void {
self.hasher.update(msg);
}

fn final(self: *Self, out: *[mac_length]u8) void {
pub fn final(self: *Self, out: *[mac_length]u8) void {
var sha2salt: [Sha512.digest_length]u8 = undefined;
self.hasher.final(&sha2salt);
out.* = hash(self.sha2pass, sha2salt);
}

/// Matches OpenBSD function
/// https://github.com/openbsd/src/blob/6df1256b7792691e66c2ed9d86a8c103069f9e34/lib/libutil/bcrypt_pbkdf.c#L98
fn hash(sha2pass: [Sha512.digest_length]u8, sha2salt: [Sha512.digest_length]u8) [32]u8 {
pub fn hash(sha2pass: [Sha512.digest_length]u8, sha2salt: [Sha512.digest_length]u8) [32]u8 {
var cdata: [8]u32 = undefined;
{
const ciphertext = "OxychromaticBlowfishSwatDynamite";
var j: usize = 0;
for (cdata) |*v| {
for (&cdata) |*v| {
v.* = State.toWord(ciphertext, &j);
}
}
Expand Down Expand Up @@ -557,7 +557,7 @@ const pbkdf_prf = struct {

// zap
crypto.utils.secureZero(u32, &cdata);
crypto.utils.secureZero(State, @as(*[1]State, &state));
crypto.utils.secureZero(u32, &state.subkeys);

return out;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/std/crypto/poly1305.zig
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ pub const Poly1305 = struct {
return;
}
@memset(st.buf[st.leftover..], 0);
st.blocks(&st.buf);
st.blocks(&st.buf, false);
st.leftover = 0;
}

Expand Down