MCPcopy Create free account
hub / github.com/BitVM/BitVM / compress

Function compress

bitvm/src/hash/blake3_utils.rs:472–517  ·  view source on GitHub ↗
(
    stack: &mut StackTracker,
    chaining: bool,
    counter: u32,
    block_len: u32,
    flags: u32,
    mut message: HashMap<u8, StackVariable>,
    tables: &TablesVars,
    final_rounds: u8,
  

Source from the content-addressed store, hash-verified

470/// Applies the blake3 compression function to the given 512 bit message, consumes everything and leaves only the final value
471#[allow(clippy::too_many_arguments)]
472pub(crate) fn compress(
473 stack: &mut StackTracker,
474 chaining: bool,
475 counter: u32,
476 block_len: u32,
477 flags: u32,
478 mut message: HashMap<u8, StackVariable>,
479 tables: &TablesVars,
480 final_rounds: u8,
481 last_round: bool,
482) {
483 //chaining value needs to be copied for multiple blocks
484 //every time that is provided
485
486 // final_rounds must be 8, if you need more than 32 output bytes, you need to change this
487 assert_eq!(final_rounds, 8);
488
489 let mut state = init_state(stack, chaining, counter, block_len, flags);
490
491 for _ in 0..6 {
492 round(stack, &mut state, &message, tables, false);
493 message = permutate(&message);
494 }
495 round(stack, &mut state, &message, tables, true); //Last iteration, consumes the message
496
497 for i in (0..final_rounds).rev() {
498 let mut tmp = Vec::new();
499
500 //iterate nibbles
501 for n in 0..8 {
502 let v2 = *state.get(&(i + 8)).unwrap();
503 let v1 = state.get_mut(&i).unwrap();
504 tmp.push(xor_2_nibbles(stack, v1, v2, 0, n, tables.use_full_tables));
505
506 if last_round && n % 2 == 1 {
507 stack.to_altstack();
508 stack.to_altstack();
509 }
510 }
511 if !last_round {
512 for _ in 0..8 {
513 stack.to_altstack();
514 }
515 }
516 }
517}
518
519pub(crate) fn get_flags_for_block(i: u32, num_blocks: u32) -> u32 {
520 if num_blocks == 1 {

Callers 1

blake3Function · 0.70

Calls 6

init_stateFunction · 0.85
roundFunction · 0.85
permutateFunction · 0.85
xor_2_nibblesFunction · 0.85
getMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected