Skip to content

Commit

Permalink
Fix compilation issues in crypto.bccrypt and poly1305 (#20756)
Browse files Browse the repository at this point in the history
  • Loading branch information
jedisct1 authored Jul 23, 2024
1 parent be1e1fa commit 2e8acdf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
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

0 comments on commit 2e8acdf

Please sign in to comment.