# sha256.rs - source
Source of the Rust file `/home/runner/.cargo/git/checkouts/k210-hal-1069b16e3180bc3a/795ac3f/src/sha256.rs`.
Keywords: rust, rustlang, rust-lang

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52

    //! Secure Hash Algorithm-256 (SHA256)

    use crate::pac::SHA256;
    use crate::sysctl::{self, APB0};

    /// SHA256 module abstraction
    pub struct Sha256 {
        sha256: SHA256,
    }

    impl Sha256 {
        pub fn sha256(sha256: SHA256, apb0: &mut APB0) -> Sha256 {
            apb0.enable();
            sysctl::clk_en_peri().modify(|_r, w|
                w.sha_clk_en().set_bit());
            sysctl::peri_reset().modify(|_r, w|
                w.sha_reset().set_bit());
            sysctl::peri_reset().modify(|_r, w|
                w.sha_reset().clear_bit());
            Sha256 { sha256 }
        }

        pub fn new_digest(self) -> Digest {
            todo!()
        }

        pub fn release(self) -> SHA256 {
            sysctl::clk_en_peri().modify(|_r, w|
                w.sha_clk_en().clear_bit());
            self.sha256
        }
    }

    pub struct Digest {
        sha256: SHA256,
    }

    impl Digest {
        pub fn write_u32(&mut self, n: u32) {
            let _todo = n;
            todo!()
        }

        pub fn finish(&self, out: &mut [u8; 32]) {
            let _todo = out;
            todo!()
        }

        pub fn free(self) -> Sha256 {
            Sha256 { sha256: self.sha256 }
        }
    }