cryptocol 0.19.7

A cryptographic library that includes big number arithmetic operations, hash algorithms, symmetric-key cryptographic encryption/decryption algorithms, asymmetric-key (public-key) cryptographic encryption/decryption algorithms, pseudo random number generators, etc. Hash algorithms includes MD4, MD5, SHA224, SHA256, SHA384, SHA512, SHA3, etc. Symmetric key encryption algorithms include DES, AES, etc. Public key encryption algorithms include RSA, ECC, etc.
Documentation
// Copyright 2024, 2025 PARK Youngho.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
// This file may not be copied, modified, or distributed
// except according to those terms.


use crate::hash::SHA2_256_Generic;
use crate::random::{ Random_Engine, SALT };


impl<const H0: u32, const H1: u32, const H2: u32, const H3: u32,
    const H4: u32, const H5: u32, const H6: u32, const H7: u32,
    const ROUND: usize,
    const K00: u32, const K01: u32, const K02: u32, const K03: u32,
    const K04: u32, const K05: u32, const K06: u32, const K07: u32,
    const K08: u32, const K09: u32, const K10: u32, const K11: u32,
    const K12: u32, const K13: u32, const K14: u32, const K15: u32,
    const K16: u32, const K17: u32, const K18: u32, const K19: u32,
    const K20: u32, const K21: u32, const K22: u32, const K23: u32,
    const K24: u32, const K25: u32, const K26: u32, const K27: u32,
    const K28: u32, const K29: u32, const K30: u32, const K31: u32,
    const K32: u32, const K33: u32, const K34: u32, const K35: u32,
    const K36: u32, const K37: u32, const K38: u32, const K39: u32,
    const K40: u32, const K41: u32, const K42: u32, const K43: u32,
    const K44: u32, const K45: u32, const K46: u32, const K47: u32,
    const K48: u32, const K49: u32, const K50: u32, const K51: u32,
    const K52: u32, const K53: u32, const K54: u32, const K55: u32,
    const K56: u32, const K57: u32, const K58: u32, const K59: u32,
    const K60: u32, const K61: u32, const K62: u32, const K63: u32,
    const RR2: u32, const RR6: u32, const RR7: u32, const RR11: u32, 
    const RR13: u32, const RR17: u32, const RR18: u32, const RR19: u32, 
    const RR22: u32, const RR25: u32, const SR3: i32, const SR10: i32>
Random_Engine for SHA2_256_Generic<8, H0, H1, H2, H3, H4, H5, H6, H7, ROUND,
                                    K00, K01, K02, K03, K04, K05, K06, K07,
                                    K08, K09, K10, K11, K12, K13, K14, K15,
                                    K16, K17, K18, K19, K20, K21, K22, K23,
                                    K24, K25, K26, K27, K28, K29, K30, K31,
                                    K32, K33, K34, K35, K36, K37, K38, K39,
                                    K40, K41, K42, K43, K44, K45, K46, K47,
                                    K48, K49, K50, K51, K52, K53, K54, K55,
                                    K56, K57, K58, K59, K60, K61, K62, K63,
                                    RR2, RR6, RR7, RR11, RR13, RR17, RR18, RR19, 
                                    RR22, RR25, SR3, SR10>
{
    fn sow_array(&mut self, message: &[u64; 8], original: &[u64; 8])
    {
        let mut m = [0_u64; 8];
        for i in 0..8
            { m[i] = message[i] ^ original[i]; }
        self.digest_array(&m);
    }

    fn harvest(&mut self, count: u128, message: &[u64; 8]) -> [u64; 8]
    {
        self.digest_array(message);
        let salt1: u64;
        let salt2: u64;
        if count == 0
        {
            salt1 = SALT;
            salt2 = SALT.rotate_left(1);
        }
        else
        {
            salt1 = 0;
            salt2 = 0;
        }

        self.tangle(salt1);
        let a: [u32; 8] = self.get_hash_value_in_array();
        self.tangle(salt2);
        let b: [u32; 8] = self.get_hash_value_in_array();
        
        let mut res = [0_u64; 8];
        for i in 0..8
            { res[i] = ((a[i] as u64) << 32) | (b[i] as u64); }
        res
    }
}