pub fn normalize(message: &Trits<T1B1>) -> Result<TritBuf<T1B1Buf>, Error> {
    if message.len() != HASH_LENGTH {
        return Err(Error::InvalidMessageLength(message.len()));
    }

    let mut normalized = [0i8; WotsSecurityLevel::High as usize * MESSAGE_FRAGMENT_LENGTH_TRYTES];

    for i in 0..WotsSecurityLevel::High as usize {
        let mut sum: i16 = 0;

        for j in (i * MESSAGE_FRAGMENT_LENGTH_TRYTES)..((i + 1) * MESSAGE_FRAGMENT_LENGTH_TRYTES) {
            // Safe to unwrap because 3 trits can't underflow/overflow an i8.
            normalized[j] = i8::try_from(&message[j * 3..j * 3 + 3]).unwrap();
            sum += i16::from(normalized[j]);
        }

        while sum > 0 {
            for t in &mut normalized[i * MESSAGE_FRAGMENT_LENGTH_TRYTES..(i + 1) * MESSAGE_FRAGMENT_LENGTH_TRYTES] {
                if (*t as i8) > Tryte::MIN_VALUE as i8 {
                    *t -= 1;
                    break;
                }
            }
            sum -= 1;
        }

        while sum < 0 {
            for t in &mut normalized[i * MESSAGE_FRAGMENT_LENGTH_TRYTES..(i + 1) * MESSAGE_FRAGMENT_LENGTH_TRYTES] {
                if (*t as i8) < Tryte::MAX_VALUE as i8 {
                    *t += 1;
                    break;
                }
            }
            sum += 1;
        }
    }

    // This usage of unsafe is fine since we are creating the normalized trits inside this function and we know that the
    // content can't go wrong.
    Ok(unsafe {
        Trits::<T3B1>::from_raw_unchecked(&normalized, normalized.len() * 3)
            .to_buf::<T3B1Buf>()
            .encode::<T1B1Buf>()
    })
}
/// Since the Winternitz One-Time Signature Scheme is based on hash chains, producing a signatures for a message - by
/// definition - also reveals all the signatures for messages that are element-wise larger than the original message.
/// As such, it is a crucial requirement for every W-OTS scheme to prevent this. While the original paper, mentioned
/// above, uses an additional checksum for exactly that purpose, this scheme normalizes the message (i.e. assures that
/// the sum over all it's elements is zero). Since no normalized messages can be element-wise larger than another
/// normalized messages, this attack vector is prevented.
Since the Winternitz One-Time Signature Scheme is based on hash chains, producing a signatures for a message - by
definition - also reveals all the signatures for messages that are element-wise larger than the original message.
As such, it is a crucial requirement for every W-OTS scheme to prevent this. While the original paper, mentioned
above, uses an additional checksum for exactly that purpose, this scheme normalizes the message . Since no normalized messages can be element-wise larger than another
normalized messages, this attack vector is prevented.
Since the Winternitz One - Time Signature Scheme is based on hash chains producing a signatures for a message - by definition - also reveals all the signatures for messages that are element - wise larger than the original message . As such it is a crucial requirement for every W - OTS scheme to prevent this . While the original paper mentioned above uses an additional checksum for exactly that purpose this scheme normalizes the message . Since no normalized messages can be element - wise larger than another normalized messages this attack vector is prevented .
pub fn normalize(message: &Trits<T1B1>) -> Result<TritBuf<T1B1Buf>, Error> {
    if message.len() != HASH_LENGTH {
        return Err(Error::InvalidMessageLength(message.len()));
    }
    let mut normalized = [0i8; WotsSecurityLevel::High as usize * MESSAGE_FRAGMENT_LENGTH_TRYTES];
    for i in 0..WotsSecurityLevel::High as usize {
        let mut sum: i16 = 0;
        for j in (i * MESSAGE_FRAGMENT_LENGTH_TRYTES)..((i + 1) * MESSAGE_FRAGMENT_LENGTH_TRYTES) {
            // Safe to unwrap because 3 trits can't underflow/overflow an i8.
            normalized[j] = i8::try_from(&message[j * 3..j * 3 + 3]).unwrap();
            sum += i16::from(normalized[j]);
        }
        while sum > 0 {
            for t in &mut normalized[i * MESSAGE_FRAGMENT_LENGTH_TRYTES..(i + 1) * MESSAGE_FRAGMENT_LENGTH_TRYTES] {
                if (*t as i8) > Tryte::MIN_VALUE as i8 {
                    *t -= 1;
                    break;
                }
            }
            sum -= 1;
        }
        while sum < 0 {
            for t in &mut normalized[i * MESSAGE_FRAGMENT_LENGTH_TRYTES..(i + 1) * MESSAGE_FRAGMENT_LENGTH_TRYTES] {
                if (*t as i8) < Tryte::MAX_VALUE as i8 {
                    *t += 1;
                    break;
                }
            }
            sum += 1;
        }
    }
    // This usage of unsafe is fine since we are creating the normalized trits inside this function and we know that the
    // content can't go wrong.
    Ok(unsafe {
        Trits::<T3B1>::from_raw_unchecked(&normalized, normalized.len() * 3)
            .to_buf::<T3B1Buf>()
            .encode::<T1B1Buf>()
    })
}
pub fn normalize ( message : & Trits < T1B1 > ) -> Result < TritBuf < T1B1Buf > , Error > { if message . len ( ) != HASH_LENGTH { return Err ( Error :: InvalidMessageLength ( message . len ( ) ) ) ; } let mut normalized = [ 0i8 ; WotsSecurityLevel :: High as usize * MESSAGE_FRAGMENT_LENGTH_TRYTES ] ; for i in 0 .. WotsSecurityLevel :: High as usize { let mut sum : i16 = 0 ; for j in ( i * MESSAGE_FRAGMENT_LENGTH_TRYTES ) .. ( ( i + 1 ) * MESSAGE_FRAGMENT_LENGTH_TRYTES ) { // Safe to unwrap because 3 trits can't underflow/overflow an i8. normalized [ j ] = i8 :: try_from ( & message [ j * 3 .. j * 3 + 3 ] ) . unwrap ( ) ; sum += i16 :: from ( normalized [ j ] ) ; } while sum > 0 { for t in & mut normalized [ i * MESSAGE_FRAGMENT_LENGTH_TRYTES .. ( i + 1 ) * MESSAGE_FRAGMENT_LENGTH_TRYTES ] { if ( * t as i8 ) > Tryte :: MIN_VALUE as i8 { * t -= 1 ; break ; } } sum -= 1 ; } while sum < 0 { for t in & mut normalized [ i * MESSAGE_FRAGMENT_LENGTH_TRYTES .. ( i + 1 ) * MESSAGE_FRAGMENT_LENGTH_TRYTES ] { if ( * t as i8 ) < Tryte :: MAX_VALUE as i8 { * t += 1 ; break ; } } sum += 1 ; } } // This usage of unsafe is fine since we are creating the normalized trits inside this function and we know that the // content can't go wrong. Ok ( unsafe { Trits :: < T3B1 > :: from_raw_unchecked ( & normalized , normalized . len ( ) * 3 ) . to_buf :: < T3B1Buf > ( ) . encode :: < T1B1Buf > ( ) } ) }
Since the Winternitz One-Time Signature Scheme is based on hash chains, producing a signatures for a message - by
definition - also reveals all the signatures for messages that are element-wise larger than the original message.
Since the Winternitz One - Time Signature Scheme is based on hash chains producing a signatures for a message - by definition - also reveals all the signatures for messages that are element - wise larger than the original message .
message
&Trits<T1B1>
message
&Trits<T1B1>