# chksum-rs/hash-sha1 architecture

> Architecture diagram of the GitHub repository chksum-rs/hash-sha1, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/chksum-rs/hash-sha1
- Repository: https://github.com/chksum-rs/hash-sha1

## Overview

##### Main Components

a. Input Interface Layer
- Batch Processing (hash function)
- Stream Processing (update function)

b. Core Processing Components (based on src/ directory structure)
- State Management (state.rs)
- Block Processing (block.rs)
- Digest Generation (digest.rs)

c. Testing & Verification Layer
- Standard Tests (tests/sha1.rs)
- Fuzzing Components (fuzz/fuzz_targets/)

##### Component Relationships

- Input Layer
- ↓
- State Management ←→ Block Processing
- ↓
- Digest Generation
- ↓
- Output (Hex/Bytes)

##### Specific Implementation Details

- Rectangles: Core processing modules
- Rounded rectangles: Input/Output interfaces
- Hexagons: State transformations

##### Important Elements to Highlight

a. Two Primary Usage Paths:
- Batch processing path (direct hash computation)
- Streaming path (incremental updates)

b. State Transformation Pipeline:
- How data blocks flow through the system
- Where state is maintained for streaming operations

##### Technical Details

Annotations for:
- Block size (512 bits)
- Digest size (160 bits)
- State buffer details
- Endianness handling

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Input
        BP["Batch Processing"]:::api
        SP["Stream Processing"]:::api
    end

    subgraph Core
        SM["State Management"]:::core
        BP_C["Block Processing"]:::core
        DG["Digest Generation"]:::core
    end

    subgraph Testing
        ST["Standard Tests"]:::test
        subgraph Fuzzing
            BF["Batch Fuzzing"]:::test
            SF["Stream Fuzzing"]:::test
        end
    end

    BP --> SM
    SP --> SM
    SM <--> BP_C
    BP_C --> DG
    DG --> Output

    subgraph Legend
        L1[Public API]:::api
        L2[Core Components]:::core
        L3[Testing]:::test
        Info[("• Block Size: 512 bits<br/>• Digest Size: 160 bits<br/>• MSRV: 1.63.0<br/>• Unsafe: Forbidden")]
    end

    %% Component Mappings
    click SM "https://github.com/chksum-rs/hash-sha1/blob/master/src/state.rs"
    click BP_C "https://github.com/chksum-rs/hash-sha1/blob/master/src/block.rs"
    click DG "https://github.com/chksum-rs/hash-sha1/blob/master/src/digest.rs"
    click BP "https://github.com/chksum-rs/hash-sha1/blob/master/src/lib.rs"
    click SP "https://github.com/chksum-rs/hash-sha1/blob/master/src/lib.rs"
    click ST "https://github.com/chksum-rs/hash-sha1/blob/master/tests/sha1.rs"
    click BF "https://github.com/chksum-rs/hash-sha1/blob/master/fuzz/fuzz_targets/hash.rs"
    click SF "https://github.com/chksum-rs/hash-sha1/blob/master/fuzz/fuzz_targets/update.rs"

    %% Styling
    classDef api fill:#3498db,stroke:#2980b9,color:white
    classDef core fill:#2ecc71,stroke:#27ae60,color:white
    classDef test fill:#95a5a6,stroke:#7f8c8d,color:white
```
