Compare commits
No commits in common. "150c5b2e38dd2f085165f95679e86caf0c8ca000" and "ff60995aaa771b20ddd331ef0d742e6bc6d88b4f" have entirely different histories.
150c5b2e38
...
ff60995aaa
5 changed files with 19 additions and 39 deletions
|
|
@ -1,3 +1,7 @@
|
||||||
|
// WARNING NOT FUNCTIONAL !!!
|
||||||
|
// This is just a draft
|
||||||
|
// TODO
|
||||||
|
|
||||||
///////////////// Imports
|
///////////////// Imports
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
@ -69,5 +73,5 @@ test "AES encryption defaults" {
|
||||||
var data = [_]u8{ 1, 2, 3, 4 };
|
var data = [_]u8{ 1, 2, 3, 4 };
|
||||||
const key = [_]u8{ 1, 2, 3, 4 };
|
const key = [_]u8{ 1, 2, 3, 4 };
|
||||||
const iv = [_]u8{ 1, 2, 3, 4 };
|
const iv = [_]u8{ 1, 2, 3, 4 };
|
||||||
crypto.aes_cbc256.encrypt(&data, &key, &iv);
|
crypto.Aes.CBC_265.encrypt(&data, &key, &iv);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ pub const CBC256_Implementation = struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
pub const CBC256_DefaultImplementation = struct {
|
pub const CBC265_DefaultImplementation = struct {
|
||||||
|
|
||||||
// Zig stdlib seems to provide no support for AES CBC265
|
// Zig stdlib seems to provide no support for AES CBC265
|
||||||
// It may need some custom implementation or another library
|
// It may need some custom implementation or another library
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,9 @@
|
||||||
pub const Implementation = struct {
|
pub const Implementation = struct {
|
||||||
|
|
||||||
prk_length: comptime_int,
|
|
||||||
|
|
||||||
expand: *const fn (out: []u8, ctx: []const u8, prk: *[Implementation.prk_length]u8) void,
|
|
||||||
extract: *const fn (out: *[Implementation.prk_length]u8, salt: []const u8, ikm: []const u8) void,
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const defaultImplementation = struct {
|
pub const defaultImplementation = struct {
|
||||||
|
|
||||||
const Sha256 = @import("std").crypto.hash.sha2.Sha256;
|
const Hkdf = @import("std").crypto.kdf.hkdf.Hkdf;
|
||||||
|
|
||||||
const HashImpl = Sha256;
|
|
||||||
const HmacImpl = @import("std").crypto.auth.hmac.Hmac(HashImpl);
|
|
||||||
|
|
||||||
const Hkdf = @import("std").crypto.kdf.hkdf.Hkdf(HmacImpl);
|
|
||||||
|
|
||||||
pub const prk_length = Hkdf.prk_length;
|
|
||||||
|
|
||||||
pub fn expand(out: []u8, ctx: []const u8, prk: *[prk_length]u8) void {
|
|
||||||
Hkdf.expand(out, ctx, prk);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn extract(out: *[prk_length]u8, salt: []const u8, ikm: []const u8) void {
|
|
||||||
out *= Hkdf.extract(salt, ikm);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,15 @@
|
||||||
pub const Implementation = struct {
|
pub const Implementation = struct {
|
||||||
|
|
||||||
mac_length: comptime_int,
|
|
||||||
|
|
||||||
create: *const fn (out: *[Implementation.mac_length]u8, msg: []const u8, key: []const u8) void,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const defaultImplementation = struct {
|
pub const defaultImplementation = struct {
|
||||||
|
|
||||||
const Sha256 = @import("std").crypto.hash.sha2.Sha256;
|
const Hmac = @import("std").crypto.auth.hmac.Hmac;
|
||||||
|
|
||||||
const HashImpl = Sha256;
|
pub fn create(out: []u8, msg: []const u8, key: []const u8) !void {
|
||||||
const Hmac = @import("std").crypto.auth.hmac.Hmac(Sha256);
|
_ = out;
|
||||||
|
_ = msg;
|
||||||
pub const mac_length = Hmac.mac_length;
|
_ = key;
|
||||||
|
return error.NotImplemented;
|
||||||
pub fn create(out: *[mac_length]u8, msg: []const u8, key: []const u8) void {
|
|
||||||
Hmac.create(out, msg, key);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,18 @@
|
||||||
pub const Implementation = struct {
|
pub const Implementation = struct {
|
||||||
|
|
||||||
hash_length: comptime_int,
|
hash: *const fn (buffer: []const u8, out: []u8) void,
|
||||||
|
|
||||||
hash: *const fn (buffer: []const u8, out: *[Implementation.hash_length]u8) void,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const defaultImplementation = struct {
|
pub const defaultImplementation = struct {
|
||||||
|
|
||||||
const Sha256 = @import("std").crypto.hash.sha2.Sha256;
|
const Sha256 = @import("std").crypto.hash.sha2.Sha256;
|
||||||
|
|
||||||
pub const hash_len = Sha256.digest_length;
|
const HASH_LEN = 32; // In bytes
|
||||||
|
|
||||||
pub fn hash(buffer: []const u8, out: *[hash_len]u8) !void {
|
pub fn hash(buffer: []const u8, out: []u8) !void {
|
||||||
|
if (out.len < HASH_LEN) {
|
||||||
|
return error.BufferTooShort;
|
||||||
|
}
|
||||||
Sha256.hash(buffer, out, .{});
|
Sha256.hash(buffer, out, .{});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue