Fixed naming inconsietencies across crypto submodules

This commit is contained in:
Gu://em_ 2026-07-09 23:49:37 +02:00
parent 891727d959
commit fc71c1a65b
2 changed files with 40 additions and 39 deletions

View file

@ -15,7 +15,7 @@ const RANDOM = @import("crypto/random.zig");
// //
pub const PartialEngine = struct { pub const PartialEngine = struct {
aes_cbc256: ? AES.CBC256_Implementation = null, aes_cbc256: ? AES.CBC256.Implementation = null,
ed25519: ? ED25519.Implementation = null, ed25519: ? ED25519.Implementation = null,
hkdf: ? HKDF.Implementation = null, hkdf: ? HKDF.Implementation = null,
hmac: ? HMAC.Implementation = null, hmac: ? HMAC.Implementation = null,
@ -26,7 +26,7 @@ pub const PartialEngine = struct {
}; };
pub const Engine = struct { pub const Engine = struct {
aes_cbc256: AES.CBC256_Implementation, aes_cbc256: AES.CBC256.Implementation,
ed25519: ED25519.Implementation, ed25519: ED25519.Implementation,
hkdf: HKDF.Implementation, hkdf: HKDF.Implementation,
hmac: HMAC.Implementation, hmac: HMAC.Implementation,
@ -45,18 +45,15 @@ pub const Engine = struct {
// function and its sub-structs. // function and its sub-structs.
pub fn resolveEngine(comptime provider: PartialEngine) Engine { pub fn resolveEngine(comptime provider: PartialEngine) Engine {
// Used by other engine components
const randomImpl = provider.random orelse RANDOM.defaultImplementation;
return .{ return .{
.aes_cbc256 = provider.aes_cbc256 orelse AES.CBC256_DefaultImplementation, .aes_cbc256 = provider.aes_cbc256 orelse AES.CBC256.defaultImplementation,
.ed25519 = provider.ed25519 orelse ED25519.defaultImplementation(randomImpl), .ed25519 = provider.ed25519 orelse ED25519.defaultImplementation,
.hkdf = provider.hkdf orelse HKDF.DefaultImplementation, .hkdf = provider.hkdf orelse HKDF.defaultImplementation,
.hmac = provider.hmac orelse HMAC.DefaultImplementation, .hmac = provider.hmac orelse HMAC.defaultImplementation,
.sha256 = provider.sha256 orelse SHA256.DefaultImplementation, .sha256 = provider.sha256 orelse SHA256.defaultImplementation,
.sha512 = provider.sha512 orelse SHA512.DefaultImplementation, .sha512 = provider.sha512 orelse SHA512.defaultImplementation,
.x25519 = provider.x25519 orelse X25519.DefaultImplementation, .x25519 = provider.x25519 orelse X25519.defaultImplementation,
.random = randomImpl, .random = provider.random orelse RANDOM.defaultImplementation,
}; };
} }

View file

@ -1,30 +1,34 @@
pub const block_size = 16; pub const CBC256 = struct {
pub const key_size = 32;
pub const CBC256_Implementation = struct { pub const block_size = 16;
pub const key_size = 32;
pub const Implementation = struct {
// NOTE: data should be padded to make its length be a multiple of BLOCK_SIZE // NOTE: data should be padded to make its length be a multiple of BLOCK_SIZE
encrypt: *const fn (key: *const [key_size]u8, iv: *const [block_size]u8, data: *const []u8) void, encrypt: *const fn (key: *const [key_size]u8, iv: *const [block_size]u8, data: *const []u8) void,
decrypt: *const fn (key: *const [key_size]u8, iv: *const [block_size]u8, data: *const []u8) void, decrypt: *const fn (key: *const [key_size]u8, iv: *const [block_size]u8, data: *const []u8) void,
}; };
// TODO // TODO
// 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
fn encrypt(key: *const [key_size]u8, iv: *const [block_size]u8, data: *const []u8) void { fn encrypt(key: *const [key_size]u8, iv: *const [block_size]u8, data: *const []u8) void {
_ = key; _ = key;
_ = iv; _ = iv;
_ = data; _ = data;
} }
fn decrypt(key: *const [key_size]u8, iv: *const [block_size]u8, data: *const []u8) void { fn decrypt(key: *const [key_size]u8, iv: *const [block_size]u8, data: *const []u8) void {
_ = key; _ = key;
_ = iv; _ = iv;
_ = data; _ = data;
} }
pub const CBC256_DefaultImplementation: CBC256_Implementation = .{ pub const defaultImplementation: Implementation = .{
.decrypt = decrypt, .decrypt = decrypt,
.encrypt = encrypt, .encrypt = encrypt,
};
}; };