jets: boots without urcrypt

This commit is contained in:
Matthew LeVan 2023-12-20 21:14:00 -05:00
parent 38f9bd4e26
commit afbb5ea245
5 changed files with 37 additions and 146 deletions

1
rust/ares/Cargo.lock generated
View File

@ -77,7 +77,6 @@ dependencies = [
"num-traits",
"signal-hook",
"static_assertions",
"urcrypt-sys",
]
[[package]]

View File

@ -30,7 +30,6 @@ num-derive = "0.3"
num-traits = "0.2"
signal-hook = "0.3"
static_assertions = "1.1.0"
urcrypt-sys = "0.1.1"
[build-dependencies]
autotools = "0.2.6"

View File

@ -167,8 +167,8 @@ mod util {
let (mut atom, buffer) = IndirectAtom::new_raw_mut_bytes(stack, bytes.len());
buffer[0..len].copy_from_slice(&(bytes[0..len]));
item.length = bytes.len();
item.bytes = atom.data_pointer_mut() as *mut u8;
item.length = len;
ads = cell.tail();
}
@ -190,7 +190,6 @@ mod util {
ac_siv_data.as_mut_ptr() as *mut &mut [u8],
ac_siv_data.len(),
);
eprintln!("siv_data: {:?}", siv_data);
let txt_len = met(3, txt);
let txt_bytes = &mut (txt.as_mut_bytes()[0..txt_len]);
@ -244,12 +243,8 @@ mod util {
Ok(direct) => direct.data() as usize,
Err(_) => return Err(JetErr::Fail(Error::NonDeterministic(D(0)))),
};
// let (_, txt_bytes) = IndirectAtom::new_raw_mut_bytes(stack, txt_len);
// txt_bytes[0..txt_len].copy_from_slice(&(txt.as_bytes()[0..txt_len]));
let txt_bytes = &mut (txt.as_mut_bytes()[0..txt_len]);
// let (_iv_ida, iv_bytes) = IndirectAtom::new_raw_mut_bytes(stack, 16);
// iv_bytes[0..16].copy_from_slice(&(iv.as_bytes()[0..16]));
let iv_bytes = &mut (iv.as_mut_bytes()[0..16]);
let ac_siv_data = _allocate_ads(stack, ads)?;

View File

@ -72,7 +72,8 @@ pub fn jet_shal(context: &mut Context, subject: Noun) -> Result {
Err(_) => return Err(JetErr::Fail(Error::NonDeterministic(D(0)))),
};
let message = &mut (dat.as_mut_bytes())[0..width]; // drop trailing zeros
let msg_len = met(3, dat);
let message = &mut (dat.as_mut_bytes())[0..msg_len]; // drop trailing zeros
unsafe {
let (mut ida, mut out) = IndirectAtom::new_raw_mut_bytes(stack, 64);

View File

@ -20,6 +20,12 @@ pub fn _ac_aes_siv_en(
iv: &mut [u8],
out: &mut [u8],
) -> Result<(), Error> {
key.reverse();
message.reverse();
for i in 0..data.len() {
data[i].reverse();
}
let iv_tag;
if key.len() == 32 {
if let Ok(mut cipher) = Aes128Siv::new_from_slice(&key) {
@ -55,7 +61,7 @@ pub fn _ac_aes_siv_en(
iv_slice.reverse();
iv.copy_from_slice(&iv_slice);
message.reverse();
out.copy_from_slice(message);
out[0..message.len()].copy_from_slice(message);
Ok(())
}
@ -67,6 +73,13 @@ pub fn _ac_aes_siv_de(
iv: &mut [u8],
out: &mut [u8],
) -> Result<(), Error> {
key.reverse();
message.reverse();
iv.reverse();
for i in 0..data.len() {
data[i].reverse();
}
let iv_array = GenericArray::from_slice(iv);
if key.len() == 32 {
if let Ok(mut cipher) = Aes128Siv::new_from_slice(&key) {
@ -98,6 +111,7 @@ pub fn _ac_aes_siv_de(
} else {
return Err(Error::InvalidKeyLength);
}
message.reverse();
out.copy_from_slice(message);
Ok(())
}
@ -188,83 +202,44 @@ mod urcrypt_tests {
#[test]
fn test_aes_siva_de() {
let mut key: [u8; 32] = [42; 32];
let mut message: [u8; 32] = [
61, 88, 88, 36, 83, 232, 120, 45, 27, 159, 15, 145, 140, 231, 114, 229, 61, 243, 54,
183, 156, 53, 217, 103, 88, 36, 53, 37, 165, 240, 92, 133,
];
let mut iv: [u8; 16] = [
16, 90, 129, 170, 175, 145, 229, 78, 107, 253, 192, 138, 136, 52, 159, 219,
];
let mut uc_bytes = [42; 32];
let mut uc_bytes_two = [43; 32];
let mut uc_out: [u8; 32] = [0; 32];
let mut uc_data: [urcrypt_aes_siv_data; 2] = [
urcrypt_aes_siv_data {
bytes: uc_bytes.as_mut_ptr(),
length: uc_bytes.len(),
},
urcrypt_aes_siv_data {
bytes: uc_bytes_two.as_mut_ptr(),
length: uc_bytes_two.len(),
},
];
unsafe {
urcrypt_aes_siva_de(
message.as_mut_ptr(),
message.len(),
uc_data.as_mut_ptr(),
uc_data.len(),
key.as_mut_ptr(),
iv.as_mut_ptr(),
uc_out.as_mut_ptr(),
)
};
let mut ac_data: [&mut [u8]; 2] = [&mut uc_bytes, &mut uc_bytes_two];
let mut ac_out: [u8; 32] = [0; 32];
ac_aes_siva_de(&mut key, &mut message, &mut ac_data, &mut iv, &mut ac_out).unwrap();
assert_eq!(ac_out, uc_out);
todo!();
}
#[test]
fn test_aes_siva_en() {
let mut key: [u8; 32] = [42; 32];
let mut message: [u8; 32] = [42; 32];
let mut iv: [u8; 16] = [42; 16];
// https://datatracker.ietf.org/doc/html/rfc5297#section-4
let mut uc_key: [u8; 32] = [255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 245, 244, 243, 242, 241, 240, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255];
let mut uc_message: [u8; 14] = [238, 221, 204, 187, 170, 153, 136, 119, 102, 85, 68, 51, 34, 17];
let mut uc_iv = [0u8; 16];
let mut uc_bytes = [42; 32];
let mut uc_bytes_two = [43; 32];
let mut uc_bytes = [39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16];
let mut uc_out: [u8; 32] = [0; 32];
let mut uc_data: [urcrypt_aes_siv_data; 2] = [
let mut uc_data: [urcrypt_aes_siv_data; 1] = [
urcrypt_aes_siv_data {
bytes: uc_bytes.as_mut_ptr(),
length: uc_bytes.len(),
},
urcrypt_aes_siv_data {
bytes: uc_bytes_two.as_mut_ptr(),
length: uc_bytes_two.len(),
},
];
unsafe {
urcrypt_aes_siva_en(
message.as_mut_ptr(),
message.len(),
uc_message.as_mut_ptr(),
uc_message.len(),
uc_data.as_mut_ptr(),
uc_data.len(),
key.as_mut_ptr(),
iv.as_mut_ptr(),
uc_key.as_mut_ptr(),
uc_iv.as_mut_ptr(),
uc_out.as_mut_ptr(),
)
};
let mut ac_data: [&mut [u8]; 2] = [&mut uc_bytes, &mut uc_bytes_two];
let mut ac_key: [u8; 32] = [255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 245, 244, 243, 242, 241, 240, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255];
let mut ac_message: [u8; 14] = [238, 221, 204, 187, 170, 153, 136, 119, 102, 85, 68, 51, 34, 17];
let mut ac_iv = [0u8; 16];
let ac_data: &mut[&mut [u8]] = &mut[&mut [39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16]];
let mut ac_out: [u8; 32] = [0; 32];
ac_aes_siva_en(&mut key, &mut message, &mut ac_data, &mut iv, &mut ac_out).unwrap();
ac_aes_siva_en(&mut ac_key, &mut ac_message, ac_data, &mut ac_iv, &mut ac_out).unwrap();
assert_eq!(ac_out, uc_out);
}
@ -310,46 +285,7 @@ mod urcrypt_tests {
#[test]
fn test_aes_sivb_de() {
let mut key: [u8; 48] = [42; 48];
let mut message: [u8; 32] = [
20, 249, 192, 238, 22, 92, 186, 62, 26, 194, 51, 61, 88, 148, 89, 208, 114, 24, 67, 99,
35, 241, 247, 133, 64, 18, 144, 54, 126, 121, 100, 145,
];
let mut iv: [u8; 16] = [
9, 146, 75, 192, 45, 169, 211, 188, 36, 212, 236, 80, 49, 197, 78, 141,
];
let mut uc_bytes = [42; 32];
let mut uc_bytes_two = [43; 32];
let mut uc_out: [u8; 32] = [0; 32];
let mut uc_data: [urcrypt_aes_siv_data; 2] = [
urcrypt_aes_siv_data {
bytes: uc_bytes.as_mut_ptr(),
length: uc_bytes.len(),
},
urcrypt_aes_siv_data {
bytes: uc_bytes_two.as_mut_ptr(),
length: uc_bytes_two.len(),
},
];
unsafe {
urcrypt_aes_sivb_de(
message.as_mut_ptr(),
message.len(),
uc_data.as_mut_ptr(),
uc_data.len(),
key.as_mut_ptr(),
iv.as_mut_ptr(),
uc_out.as_mut_ptr(),
)
};
let mut ac_data: [&mut [u8]; 2] = [&mut uc_bytes, &mut uc_bytes_two];
let mut ac_out: [u8; 32] = [0; 32];
ac_aes_sivb_de(&mut key, &mut message, &mut ac_data, &mut iv, &mut ac_out).unwrap();
assert_eq!(ac_out, uc_out);
todo!();
}
#[test]
@ -393,45 +329,6 @@ mod urcrypt_tests {
#[test]
fn test_aes_sivc_de() {
let mut key: [u8; 64] = [42; 64];
let mut message: [u8; 32] = [
213, 96, 61, 200, 217, 8, 33, 147, 58, 213, 99, 8, 221, 23, 89, 206, 164, 237, 59, 231,
235, 50, 93, 122, 50, 202, 78, 248, 218, 41, 170, 175,
];
let mut iv: [u8; 16] = [
105, 123, 123, 122, 45, 244, 179, 136, 167, 164, 134, 30, 97, 14, 241, 223,
];
let mut uc_bytes = [42; 32];
let mut uc_bytes_two = [43; 32];
let mut uc_out: [u8; 32] = [0; 32];
let mut uc_data: [urcrypt_aes_siv_data; 2] = [
urcrypt_aes_siv_data {
bytes: uc_bytes.as_mut_ptr(),
length: uc_bytes.len(),
},
urcrypt_aes_siv_data {
bytes: uc_bytes_two.as_mut_ptr(),
length: uc_bytes_two.len(),
},
];
unsafe {
urcrypt_aes_sivc_de(
message.as_mut_ptr(),
message.len(),
uc_data.as_mut_ptr(),
uc_data.len(),
key.as_mut_ptr(),
iv.as_mut_ptr(),
uc_out.as_mut_ptr(),
)
};
let mut ac_data: [&mut [u8]; 2] = [&mut uc_bytes, &mut uc_bytes_two];
let mut ac_out: [u8; 32] = [0; 32];
ac_aes_sivc_de(&mut key, &mut message, &mut ac_data, &mut iv, &mut ac_out).unwrap();
assert_eq!(ac_out, uc_out);
todo!();
}
}