Fixed naming inconsietencies across crypto submodules
This commit is contained in:
parent
891727d959
commit
fc71c1a65b
2 changed files with 40 additions and 39 deletions
|
|
@ -15,7 +15,7 @@ const RANDOM = @import("crypto/random.zig");
|
|||
//
|
||||
|
||||
pub const PartialEngine = struct {
|
||||
aes_cbc256: ? AES.CBC256_Implementation = null,
|
||||
aes_cbc256: ? AES.CBC256.Implementation = null,
|
||||
ed25519: ? ED25519.Implementation = null,
|
||||
hkdf: ? HKDF.Implementation = null,
|
||||
hmac: ? HMAC.Implementation = null,
|
||||
|
|
@ -26,7 +26,7 @@ pub const PartialEngine = struct {
|
|||
};
|
||||
|
||||
pub const Engine = struct {
|
||||
aes_cbc256: AES.CBC256_Implementation,
|
||||
aes_cbc256: AES.CBC256.Implementation,
|
||||
ed25519: ED25519.Implementation,
|
||||
hkdf: HKDF.Implementation,
|
||||
hmac: HMAC.Implementation,
|
||||
|
|
@ -45,18 +45,15 @@ pub const Engine = struct {
|
|||
// function and its sub-structs.
|
||||
pub fn resolveEngine(comptime provider: PartialEngine) Engine {
|
||||
|
||||
// Used by other engine components
|
||||
const randomImpl = provider.random orelse RANDOM.defaultImplementation;
|
||||
|
||||
return .{
|
||||
.aes_cbc256 = provider.aes_cbc256 orelse AES.CBC256_DefaultImplementation,
|
||||
.ed25519 = provider.ed25519 orelse ED25519.defaultImplementation(randomImpl),
|
||||
.hkdf = provider.hkdf orelse HKDF.DefaultImplementation,
|
||||
.hmac = provider.hmac orelse HMAC.DefaultImplementation,
|
||||
.sha256 = provider.sha256 orelse SHA256.DefaultImplementation,
|
||||
.sha512 = provider.sha512 orelse SHA512.DefaultImplementation,
|
||||
.x25519 = provider.x25519 orelse X25519.DefaultImplementation,
|
||||
.random = randomImpl,
|
||||
.aes_cbc256 = provider.aes_cbc256 orelse AES.CBC256.defaultImplementation,
|
||||
.ed25519 = provider.ed25519 orelse ED25519.defaultImplementation,
|
||||
.hkdf = provider.hkdf orelse HKDF.defaultImplementation,
|
||||
.hmac = provider.hmac orelse HMAC.defaultImplementation,
|
||||
.sha256 = provider.sha256 orelse SHA256.defaultImplementation,
|
||||
.sha512 = provider.sha512 orelse SHA512.defaultImplementation,
|
||||
.x25519 = provider.x25519 orelse X25519.defaultImplementation,
|
||||
.random = provider.random orelse RANDOM.defaultImplementation,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,30 +1,34 @@
|
|||
pub const block_size = 16;
|
||||
pub const key_size = 32;
|
||||
pub const CBC256 = struct {
|
||||
|
||||
pub const block_size = 16;
|
||||
pub const key_size = 32;
|
||||
|
||||
pub const CBC256_Implementation = struct {
|
||||
pub const Implementation = struct {
|
||||
|
||||
// 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,
|
||||
decrypt: *const fn (key: *const [key_size]u8, iv: *const [block_size]u8, data: *const []u8) void,
|
||||
// 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,
|
||||
decrypt: *const fn (key: *const [key_size]u8, iv: *const [block_size]u8, data: *const []u8) void,
|
||||
};
|
||||
|
||||
// TODO
|
||||
|
||||
// Zig stdlib seems to provide no support for AES CBC265
|
||||
// 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 {
|
||||
_ = key;
|
||||
_ = iv;
|
||||
_ = data;
|
||||
}
|
||||
fn decrypt(key: *const [key_size]u8, iv: *const [block_size]u8, data: *const []u8) void {
|
||||
_ = key;
|
||||
_ = iv;
|
||||
_ = data;
|
||||
}
|
||||
|
||||
pub const defaultImplementation: Implementation = .{
|
||||
.decrypt = decrypt,
|
||||
.encrypt = encrypt,
|
||||
};
|
||||
};
|
||||
|
||||
// TODO
|
||||
|
||||
// Zig stdlib seems to provide no support for AES CBC265
|
||||
// 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 {
|
||||
_ = key;
|
||||
_ = iv;
|
||||
_ = data;
|
||||
}
|
||||
fn decrypt(key: *const [key_size]u8, iv: *const [block_size]u8, data: *const []u8) void {
|
||||
_ = key;
|
||||
_ = iv;
|
||||
_ = data;
|
||||
}
|
||||
|
||||
pub const CBC256_DefaultImplementation: CBC256_Implementation = .{
|
||||
.decrypt = decrypt,
|
||||
.encrypt = encrypt,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue