aboutsummaryrefslogtreecommitdiff
path: root/rust/guts/src/riscv_rva23u64.rs
diff options
context:
space:
mode:
authorJack O'Connor <[email protected]>2024-01-21 22:16:02 -0800
committerJack O'Connor <[email protected]>2024-01-21 22:16:02 -0800
commitf4ffbbca2f35e8341760c70c51e49ae6dd53f2be (patch)
treebf247720c4d98063e8884f6f6ba4a7063067b533 /rust/guts/src/riscv_rva23u64.rs
parent5558fa46239742720d84c46edb0544732adf4db8 (diff)
factor out RISCV support from the guts_api branchguts_riscv
TODO: figure out what environment variable should enable this
Diffstat (limited to 'rust/guts/src/riscv_rva23u64.rs')
-rw-r--r--rust/guts/src/riscv_rva23u64.rs124
1 files changed, 124 insertions, 0 deletions
diff --git a/rust/guts/src/riscv_rva23u64.rs b/rust/guts/src/riscv_rva23u64.rs
new file mode 100644
index 0000000..7f2a7ab
--- /dev/null
+++ b/rust/guts/src/riscv_rva23u64.rs
@@ -0,0 +1,124 @@
+//! This implementation currently assumes riscv_rva23u64_zbb_zvbb. Zvbb in particular ("Vector
+//! Bit-manipulation used in Cryptography") is a bleeding-edge extension that was only frozen a few
+//! weeks ago at the time I'm writing this comment. Compiling and testing this code currently
+//! requires quite a lot of effort, including building Clang from master and building QEMU from a
+//! custom branch. Please don't expect this code to be usable on real hardware for some time.
+
+use crate::{BlockBytes, CVBytes, Implementation};
+
+// NOTE: Keep this in sync with the same constant in assembly.
+pub(crate) const MAX_SIMD_DEGREE: usize = 16;
+
+extern "C" {
+ fn blake3_guts_riscv_rva23u64_degree() -> usize;
+ fn blake3_guts_riscv_rva23u64_compress(
+ block: *const BlockBytes,
+ block_len: u32,
+ cv: *const CVBytes,
+ counter: u64,
+ flags: u32,
+ out: *mut CVBytes,
+ );
+ fn blake3_guts_riscv_rva23u64_hash_chunks(
+ input: *const u8,
+ input_len: usize,
+ key: *const CVBytes,
+ counter: u64,
+ flags: u32,
+ transposed_output: *mut u32,
+ );
+ fn blake3_guts_riscv_rva23u64_hash_parents(
+ transposed_input: *const u32,
+ num_parents: usize,
+ key: *const CVBytes,
+ flags: u32,
+ transposed_output: *mut u32,
+ );
+ fn blake3_guts_riscv_rva23u64_xof(
+ block: *const BlockBytes,
+ block_len: u32,
+ cv: *const CVBytes,
+ counter: u64,
+ flags: u32,
+ out: *mut u8,
+ out_len: usize,
+ );
+ fn blake3_guts_riscv_rva23u64_xof_xor(
+ block: *const BlockBytes,
+ block_len: u32,
+ cv: *const CVBytes,
+ counter: u64,
+ flags: u32,
+ out: *mut u8,
+ out_len: usize,
+ );
+ fn blake3_guts_riscv_rva23u64_universal_hash(
+ input: *const u8,
+ input_len: usize,
+ key: *const CVBytes,
+ counter: u64,
+ out: *mut [u8; 16],
+ );
+}
+
+pub fn implementation() -> Implementation {
+ Implementation::new(
+ blake3_guts_riscv_rva23u64_degree,
+ blake3_guts_riscv_rva23u64_compress,
+ blake3_guts_riscv_rva23u64_hash_chunks,
+ blake3_guts_riscv_rva23u64_hash_parents,
+ blake3_guts_riscv_rva23u64_xof,
+ blake3_guts_riscv_rva23u64_xof_xor,
+ blake3_guts_riscv_rva23u64_universal_hash,
+ )
+}
+
+#[cfg(test)]
+mod test {
+ use super::*;
+
+ #[test]
+ fn test_compress_vs_portable() {
+ crate::test::test_compress_vs_portable(&implementation());
+ }
+
+ #[test]
+ fn test_compress_vs_reference() {
+ crate::test::test_compress_vs_reference(&implementation());
+ }
+
+ #[test]
+ fn test_hash_chunks_vs_portable() {
+ crate::test::test_hash_chunks_vs_portable(&implementation());
+ }
+
+ #[test]
+ fn test_hash_parents_vs_portable() {
+ crate::test::test_hash_parents_vs_portable(&implementation());
+ }
+
+ #[test]
+ fn test_chunks_and_parents_vs_reference() {
+ crate::test::test_chunks_and_parents_vs_reference(&implementation());
+ }
+
+ #[test]
+ fn test_xof_vs_portable() {
+ crate::test::test_xof_vs_portable(&implementation());
+ }
+
+ #[test]
+ fn test_xof_vs_reference() {
+ crate::test::test_xof_vs_reference(&implementation());
+ }
+
+ #[test]
+ fn test_universal_hash_vs_portable() {
+ crate::test::test_universal_hash_vs_portable(&implementation());
+ }
+
+ #[test]
+ fn test_universal_hash_vs_reference() {
+ crate::test::test_universal_hash_vs_reference(&implementation());
+ }
+}