mirror of
https://github.com/ziglang/zig.git
synced 2026-02-21 16:54:52 +00:00
Fix compilation issues in crypto.bccrypt and poly1305 (#20756)
This commit is contained in:
parent
be1e1fa180
commit
2e8acdf6fa
@ -496,24 +496,24 @@ 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);
|
||||
@ -521,12 +521,12 @@ const pbkdf_prf = struct {
|
||||
|
||||
/// 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);
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user