├── .github ├── dependabot.yml └── workflows │ ├── aes.yml │ ├── aria.yml │ ├── belt-block.yml │ ├── blowfish.yml │ ├── camellia.yml │ ├── cast5.yml │ ├── cast6.yml │ ├── des.yml │ ├── gift.yml │ ├── idea.yml │ ├── kuznyechik.yml │ ├── magma.yml │ ├── rc2.yml │ ├── rc5.yml │ ├── security-audit.yml │ ├── serpent.yml │ ├── sm4.yml │ ├── speck.yml │ ├── threefish.yml │ ├── twofish.yml │ ├── workspace.yml │ └── xtea.yml ├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── README.md ├── aes ├── CHANGELOG.md ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── benches │ └── mod.rs ├── src │ ├── armv8.rs │ ├── armv8 │ │ ├── encdec.rs │ │ ├── expand.rs │ │ ├── hazmat.rs │ │ └── test_expand.rs │ ├── autodetect.rs │ ├── hazmat.rs │ ├── lib.rs │ ├── macros.rs │ ├── ni.rs │ ├── ni │ │ ├── encdec.rs │ │ ├── expand.rs │ │ ├── hazmat.rs │ │ └── test_expand.rs │ ├── soft.rs │ └── soft │ │ ├── fixslice32.rs │ │ └── fixslice64.rs └── tests │ ├── data │ ├── aes128.blb │ ├── aes192.blb │ └── aes256.blb │ ├── hazmat.rs │ ├── mod.rs │ └── weak.rs ├── aria ├── CHANGELOG.md ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── benches │ └── mod.rs ├── src │ ├── aria128.rs │ ├── aria192.rs │ ├── aria256.rs │ ├── consts.rs │ ├── lib.rs │ └── utils.rs └── tests │ └── mod.rs ├── belt-block ├── CHANGELOG.md ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── benches │ └── mod.rs ├── src │ ├── cipher_impl.rs │ ├── consts.rs │ └── lib.rs └── tests │ └── mod.rs ├── blowfish ├── CHANGELOG.md ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── benches │ └── mod.rs ├── src │ ├── consts.rs │ └── lib.rs └── tests │ ├── data │ ├── blowfish.blb │ └── blowfish_le.blb │ └── mod.rs ├── camellia ├── CHANGELOG.md ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── benches │ └── mod.rs ├── src │ ├── camellia128.rs │ ├── camellia192.rs │ ├── camellia256.rs │ ├── consts.rs │ ├── lib.rs │ └── utils.rs └── tests │ ├── data │ ├── camellia128.blb │ ├── camellia192.blb │ └── camellia256.blb │ └── mod.rs ├── cast5 ├── CHANGELOG.md ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── benches │ └── mod.rs ├── src │ ├── consts.rs │ ├── lib.rs │ └── schedule.rs └── tests │ ├── data │ └── cast5.blb │ └── mod.rs ├── cast6 ├── CHANGELOG.md ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── benches │ └── mod.rs ├── src │ ├── consts.rs │ └── lib.rs └── tests │ └── mod.rs ├── des ├── CHANGELOG.md ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── benches │ └── mod.rs ├── src │ ├── consts.rs │ ├── des.rs │ ├── lib.rs │ ├── tdes.rs │ └── utils.rs └── tests │ ├── data │ ├── des.blb │ ├── tdes.blb │ └── tdes2.blb │ ├── mod.rs │ └── weak.rs ├── gift ├── .gitignore ├── CHANGELOG.md ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── benches │ └── gift128enc.rs ├── src │ ├── consts.rs │ ├── key_schedule.rs │ ├── lib.rs │ └── primitives.rs └── tests │ └── mod.rs ├── idea ├── CHANGELOG.md ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── benches │ └── mod.rs ├── src │ ├── consts.rs │ ├── lib.rs │ └── tests.rs └── tests │ ├── data │ └── idea.blb │ └── mod.rs ├── kuznyechik ├── CHANGELOG.md ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── benches │ └── mod.rs ├── src │ ├── big_soft │ │ ├── backends.rs │ │ └── mod.rs │ ├── compact_soft │ │ ├── backends.rs │ │ └── mod.rs │ ├── consts.rs │ ├── fused_tables.rs │ ├── gft.rs │ ├── lib.rs │ ├── neon │ │ ├── backends.rs │ │ └── mod.rs │ ├── sse2 │ │ ├── backends.rs │ │ └── mod.rs │ └── utils.rs └── tests │ └── mod.rs ├── magma ├── CHANGELOG.md ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── benches │ └── mod.rs └── src │ ├── lib.rs │ └── sboxes.rs ├── rc2 ├── CHANGELOG.md ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── benches │ └── mod.rs ├── src │ ├── consts.rs │ └── lib.rs └── tests │ ├── data │ ├── 1.input.bin │ ├── 1.key.bin │ ├── 1.output.bin │ ├── 2.input.bin │ ├── 2.key.bin │ ├── 2.output.bin │ ├── 3.input.bin │ ├── 3.key.bin │ ├── 3.output.bin │ ├── 4.input.bin │ ├── 4.key.bin │ ├── 4.output.bin │ ├── 5.input.bin │ ├── 5.key.bin │ ├── 5.output.bin │ ├── 6.input.bin │ ├── 6.key.bin │ ├── 6.output.bin │ ├── 7.input.bin │ ├── 7.key.bin │ ├── 7.output.bin │ ├── 8.input.bin │ ├── 8.key.bin │ └── 8.output.bin │ └── mod.rs ├── rc5 ├── CHANGELOG.md ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── benches │ └── mod.rs ├── src │ ├── lib.rs │ └── primitives.rs └── tests │ └── mod.rs ├── serpent ├── CHANGELOG.md ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── benches │ └── mod.rs ├── src │ ├── bitslice.rs │ ├── lib.rs │ └── unroll.rs └── tests │ ├── data │ ├── serpent128.blb │ ├── serpent192.blb │ └── serpent256.blb │ └── mod.rs ├── sm4 ├── CHANGELOG.md ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── benches │ └── mod.rs ├── src │ ├── consts.rs │ └── lib.rs └── tests │ └── mod.rs ├── speck ├── CHANGELOG.md ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── src │ └── lib.rs └── tests │ └── mod.rs ├── threefish ├── CHANGELOG.md ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── benches │ └── mod.rs ├── src │ ├── consts.rs │ └── lib.rs └── tests │ └── mod.rs ├── twofish ├── CHANGELOG.md ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── benches │ └── mod.rs ├── src │ ├── consts.rs │ ├── lib.rs │ └── tests.rs └── tests │ └── mod.rs └── xtea ├── CHANGELOG.md ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── benches └── mod.rs ├── src ├── consts.rs └── lib.rs └── tests └── mod.rs /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: cargo 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | open-pull-requests-limit: 10 8 | - package-ecosystem: github-actions 9 | directory: "/" 10 | schedule: 11 | interval: weekly 12 | open-pull-requests-limit: 10 13 | -------------------------------------------------------------------------------- /.github/workflows/aria.yml: -------------------------------------------------------------------------------- 1 | name: aria 2 | 3 | on: 4 | pull_request: 5 | paths: 6 | - ".github/workflows/aria.yml" 7 | - "aria/**" 8 | - "Cargo.*" 9 | push: 10 | branches: master 11 | 12 | defaults: 13 | run: 14 | working-directory: aria 15 | 16 | env: 17 | CARGO_INCREMENTAL: 0 18 | RUSTFLAGS: "-Dwarnings" 19 | 20 | jobs: 21 | build: 22 | runs-on: ubuntu-latest 23 | strategy: 24 | matrix: 25 | rust: 26 | - 1.85.0 # MSRV 27 | - stable 28 | target: 29 | - thumbv7em-none-eabi 30 | - wasm32-unknown-unknown 31 | steps: 32 | - uses: actions/checkout@v4 33 | - uses: RustCrypto/actions/cargo-cache@master 34 | - uses: dtolnay/rust-toolchain@master 35 | with: 36 | toolchain: ${{ matrix.rust }} 37 | targets: ${{ matrix.target }} 38 | - run: cargo build --no-default-features --release --target ${{ matrix.target }} 39 | 40 | minimal-versions: 41 | if: false # TODO: temp disabled due to unpublished prerelease dependencies 42 | uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master 43 | with: 44 | working-directory: ${{ github.workflow }} 45 | 46 | test: 47 | runs-on: ubuntu-latest 48 | strategy: 49 | matrix: 50 | rust: 51 | - 1.85.0 # MSRV 52 | - stable 53 | steps: 54 | - uses: actions/checkout@v4 55 | - uses: RustCrypto/actions/cargo-cache@master 56 | - uses: dtolnay/rust-toolchain@master 57 | with: 58 | toolchain: ${{ matrix.rust }} 59 | - run: cargo check --all-features 60 | - run: cargo test --no-default-features 61 | - run: cargo test 62 | - run: cargo test --all-features 63 | -------------------------------------------------------------------------------- /.github/workflows/belt-block.yml: -------------------------------------------------------------------------------- 1 | name: belt-block 2 | 3 | on: 4 | pull_request: 5 | paths: 6 | - ".github/workflows/belt-block.yml" 7 | - "belt-block/**" 8 | - "Cargo.*" 9 | push: 10 | branches: master 11 | 12 | defaults: 13 | run: 14 | working-directory: belt-block 15 | 16 | env: 17 | CARGO_INCREMENTAL: 0 18 | RUSTFLAGS: "-Dwarnings" 19 | 20 | jobs: 21 | build: 22 | runs-on: ubuntu-latest 23 | strategy: 24 | matrix: 25 | rust: 26 | - 1.85.0 # MSRV 27 | - stable 28 | target: 29 | - thumbv7em-none-eabi 30 | - wasm32-unknown-unknown 31 | steps: 32 | - uses: actions/checkout@v4 33 | - uses: RustCrypto/actions/cargo-cache@master 34 | - uses: dtolnay/rust-toolchain@master 35 | with: 36 | toolchain: ${{ matrix.rust }} 37 | targets: ${{ matrix.target }} 38 | - run: cargo build --no-default-features --release --target ${{ matrix.target }} 39 | 40 | minimal-versions: 41 | if: false # TODO: temp disabled due to unpublished prerelease dependencies 42 | uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master 43 | with: 44 | working-directory: ${{ github.workflow }} 45 | 46 | test: 47 | runs-on: ubuntu-latest 48 | strategy: 49 | matrix: 50 | rust: 51 | - 1.85.0 # MSRV 52 | - stable 53 | steps: 54 | - uses: actions/checkout@v4 55 | - uses: RustCrypto/actions/cargo-cache@master 56 | - uses: dtolnay/rust-toolchain@master 57 | with: 58 | toolchain: ${{ matrix.rust }} 59 | - run: cargo check --all-features 60 | - run: cargo test --no-default-features 61 | - run: cargo test 62 | - run: cargo test --all-features 63 | -------------------------------------------------------------------------------- /.github/workflows/blowfish.yml: -------------------------------------------------------------------------------- 1 | name: blowfish 2 | 3 | on: 4 | pull_request: 5 | paths: 6 | - ".github/workflows/blowfish.yml" 7 | - "blowfish/**" 8 | - "Cargo.*" 9 | push: 10 | branches: master 11 | 12 | defaults: 13 | run: 14 | working-directory: blowfish 15 | 16 | env: 17 | CARGO_INCREMENTAL: 0 18 | RUSTFLAGS: "-Dwarnings" 19 | 20 | jobs: 21 | build: 22 | runs-on: ubuntu-latest 23 | strategy: 24 | matrix: 25 | rust: 26 | - 1.85.0 # MSRV 27 | - stable 28 | target: 29 | - thumbv7em-none-eabi 30 | - wasm32-unknown-unknown 31 | steps: 32 | - uses: actions/checkout@v4 33 | - uses: RustCrypto/actions/cargo-cache@master 34 | - uses: dtolnay/rust-toolchain@master 35 | with: 36 | toolchain: ${{ matrix.rust }} 37 | targets: ${{ matrix.target }} 38 | - run: cargo build --no-default-features --release --target ${{ matrix.target }} 39 | 40 | minimal-versions: 41 | if: false # TODO: temp disabled due to unpublished prerelease dependencies 42 | uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master 43 | with: 44 | working-directory: ${{ github.workflow }} 45 | 46 | test: 47 | runs-on: ubuntu-latest 48 | strategy: 49 | matrix: 50 | rust: 51 | - 1.85.0 # MSRV 52 | - stable 53 | steps: 54 | - uses: actions/checkout@v4 55 | - uses: RustCrypto/actions/cargo-cache@master 56 | - uses: dtolnay/rust-toolchain@master 57 | with: 58 | toolchain: ${{ matrix.rust }} 59 | - run: cargo check --all-features 60 | - run: cargo test --no-default-features 61 | - run: cargo test 62 | - run: cargo test --all-features 63 | -------------------------------------------------------------------------------- /.github/workflows/camellia.yml: -------------------------------------------------------------------------------- 1 | name: camellia 2 | 3 | on: 4 | pull_request: 5 | paths: 6 | - ".github/workflows/camellia.yml" 7 | - "camellia/**" 8 | - "Cargo.*" 9 | push: 10 | branches: master 11 | 12 | defaults: 13 | run: 14 | working-directory: camellia 15 | 16 | env: 17 | CARGO_INCREMENTAL: 0 18 | RUSTFLAGS: "-Dwarnings" 19 | 20 | jobs: 21 | build: 22 | runs-on: ubuntu-latest 23 | strategy: 24 | matrix: 25 | rust: 26 | - 1.85.0 # MSRV 27 | - stable 28 | target: 29 | - thumbv7em-none-eabi 30 | - wasm32-unknown-unknown 31 | steps: 32 | - uses: actions/checkout@v4 33 | - uses: RustCrypto/actions/cargo-cache@master 34 | - uses: dtolnay/rust-toolchain@master 35 | with: 36 | toolchain: ${{ matrix.rust }} 37 | targets: ${{ matrix.target }} 38 | - run: cargo build --no-default-features --release --target ${{ matrix.target }} 39 | 40 | minimal-versions: 41 | if: false # TODO: temp disabled due to unpublished prerelease dependencies 42 | uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master 43 | with: 44 | working-directory: ${{ github.workflow }} 45 | 46 | test: 47 | runs-on: ubuntu-latest 48 | strategy: 49 | matrix: 50 | rust: 51 | - 1.85.0 # MSRV 52 | - stable 53 | steps: 54 | - uses: actions/checkout@v4 55 | - uses: RustCrypto/actions/cargo-cache@master 56 | - uses: dtolnay/rust-toolchain@master 57 | with: 58 | toolchain: ${{ matrix.rust }} 59 | - run: cargo check --all-features 60 | - run: cargo test --no-default-features 61 | - run: cargo test 62 | - run: cargo test --all-features 63 | -------------------------------------------------------------------------------- /.github/workflows/cast5.yml: -------------------------------------------------------------------------------- 1 | name: cast5 2 | 3 | on: 4 | pull_request: 5 | paths: 6 | - ".github/workflows/cast5.yml" 7 | - "cast5/**" 8 | - "Cargo.*" 9 | push: 10 | branches: master 11 | 12 | defaults: 13 | run: 14 | working-directory: cast5 15 | 16 | env: 17 | CARGO_INCREMENTAL: 0 18 | RUSTFLAGS: "-Dwarnings" 19 | 20 | jobs: 21 | build: 22 | runs-on: ubuntu-latest 23 | strategy: 24 | matrix: 25 | rust: 26 | - 1.85.0 # MSRV 27 | - stable 28 | target: 29 | - thumbv7em-none-eabi 30 | - wasm32-unknown-unknown 31 | steps: 32 | - uses: actions/checkout@v4 33 | - uses: RustCrypto/actions/cargo-cache@master 34 | - uses: dtolnay/rust-toolchain@master 35 | with: 36 | toolchain: ${{ matrix.rust }} 37 | targets: ${{ matrix.target }} 38 | - run: cargo build --no-default-features --release --target ${{ matrix.target }} 39 | 40 | minimal-versions: 41 | if: false # TODO: temp disabled due to unpublished prerelease dependencies 42 | uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master 43 | with: 44 | working-directory: ${{ github.workflow }} 45 | 46 | test: 47 | runs-on: ubuntu-latest 48 | strategy: 49 | matrix: 50 | rust: 51 | - 1.85.0 # MSRV 52 | - stable 53 | steps: 54 | - uses: actions/checkout@v4 55 | - uses: RustCrypto/actions/cargo-cache@master 56 | - uses: dtolnay/rust-toolchain@master 57 | with: 58 | toolchain: ${{ matrix.rust }} 59 | - run: cargo check --all-features 60 | - run: cargo test --no-default-features 61 | - run: cargo test 62 | - run: cargo test --all-features 63 | -------------------------------------------------------------------------------- /.github/workflows/cast6.yml: -------------------------------------------------------------------------------- 1 | name: cast6 2 | 3 | on: 4 | pull_request: 5 | paths: 6 | - ".github/workflows/cast6.yml" 7 | - "cast6/**" 8 | - "Cargo.*" 9 | push: 10 | branches: master 11 | 12 | defaults: 13 | run: 14 | working-directory: cast6 15 | 16 | env: 17 | CARGO_INCREMENTAL: 0 18 | RUSTFLAGS: "-Dwarnings" 19 | 20 | jobs: 21 | build: 22 | runs-on: ubuntu-latest 23 | strategy: 24 | matrix: 25 | rust: 26 | - 1.85.0 # MSRV 27 | - stable 28 | target: 29 | - thumbv7em-none-eabi 30 | - wasm32-unknown-unknown 31 | steps: 32 | - uses: actions/checkout@v4 33 | - uses: RustCrypto/actions/cargo-cache@master 34 | - uses: dtolnay/rust-toolchain@master 35 | with: 36 | toolchain: ${{ matrix.rust }} 37 | targets: ${{ matrix.target }} 38 | - run: cargo build --no-default-features --release --target ${{ matrix.target }} 39 | 40 | minimal-versions: 41 | if: false # TODO: temp disabled due to unpublished prerelease dependencies 42 | uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master 43 | with: 44 | working-directory: ${{ github.workflow }} 45 | 46 | test: 47 | runs-on: ubuntu-latest 48 | strategy: 49 | matrix: 50 | rust: 51 | - 1.85.0 # MSRV 52 | - stable 53 | steps: 54 | - uses: actions/checkout@v4 55 | - uses: RustCrypto/actions/cargo-cache@master 56 | - uses: dtolnay/rust-toolchain@master 57 | with: 58 | toolchain: ${{ matrix.rust }} 59 | - run: cargo check --all-features 60 | - run: cargo test --no-default-features 61 | - run: cargo test 62 | - run: cargo test --all-features 63 | -------------------------------------------------------------------------------- /.github/workflows/des.yml: -------------------------------------------------------------------------------- 1 | name: des 2 | 3 | on: 4 | pull_request: 5 | paths: 6 | - ".github/workflows/des.yml" 7 | - "des/**" 8 | - "Cargo.*" 9 | push: 10 | branches: master 11 | 12 | defaults: 13 | run: 14 | working-directory: des 15 | 16 | env: 17 | CARGO_INCREMENTAL: 0 18 | RUSTFLAGS: "-Dwarnings" 19 | 20 | jobs: 21 | build: 22 | runs-on: ubuntu-latest 23 | strategy: 24 | matrix: 25 | rust: 26 | - 1.85.0 # MSRV 27 | - stable 28 | target: 29 | - thumbv7em-none-eabi 30 | - wasm32-unknown-unknown 31 | steps: 32 | - uses: actions/checkout@v4 33 | - uses: RustCrypto/actions/cargo-cache@master 34 | - uses: dtolnay/rust-toolchain@master 35 | with: 36 | toolchain: ${{ matrix.rust }} 37 | target: ${{ matrix.target }} 38 | - run: cargo build --no-default-features --release --target ${{ matrix.target }} 39 | 40 | minimal-versions: 41 | if: false # TODO: temp disabled due to unpublished prerelease dependencies 42 | uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master 43 | with: 44 | working-directory: ${{ github.workflow }} 45 | 46 | test: 47 | runs-on: ubuntu-latest 48 | strategy: 49 | matrix: 50 | rust: 51 | - 1.85.0 # MSRV 52 | - stable 53 | steps: 54 | - uses: actions/checkout@v4 55 | - uses: RustCrypto/actions/cargo-cache@master 56 | - uses: dtolnay/rust-toolchain@master 57 | with: 58 | toolchain: ${{ matrix.rust }} 59 | - run: cargo check --all-features 60 | - run: cargo test --no-default-features 61 | - run: cargo test 62 | - run: cargo test --all-features 63 | -------------------------------------------------------------------------------- /.github/workflows/gift.yml: -------------------------------------------------------------------------------- 1 | name: gift 2 | 3 | on: 4 | pull_request: 5 | paths: 6 | - ".github/workflows/gift.yml" 7 | - "gift/**" 8 | - "Cargo.*" 9 | push: 10 | branches: master 11 | 12 | defaults: 13 | run: 14 | working-directory: gift 15 | 16 | env: 17 | CARGO_INCREMENTAL: 0 18 | RUSTFLAGS: "-Dwarnings" 19 | 20 | jobs: 21 | build: 22 | runs-on: ubuntu-latest 23 | strategy: 24 | matrix: 25 | rust: 26 | - 1.85.0 # MSRV 27 | - stable 28 | target: 29 | - thumbv7em-none-eabi 30 | - wasm32-unknown-unknown 31 | steps: 32 | - uses: actions/checkout@v4 33 | - uses: RustCrypto/actions/cargo-cache@master 34 | - uses: dtolnay/rust-toolchain@master 35 | with: 36 | toolchain: ${{ matrix.rust }} 37 | targets: ${{ matrix.target }} 38 | - run: cargo build --no-default-features --release --target ${{ matrix.target }} 39 | 40 | minimal-versions: 41 | if: false # TODO: temp disabled due to unpublished prerelease dependencies 42 | uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master 43 | with: 44 | working-directory: ${{ github.workflow }} 45 | 46 | test: 47 | runs-on: ubuntu-latest 48 | strategy: 49 | matrix: 50 | rust: 51 | - 1.85.0 # MSRV 52 | - stable 53 | steps: 54 | - uses: actions/checkout@v4 55 | - uses: RustCrypto/actions/cargo-cache@master 56 | - uses: dtolnay/rust-toolchain@master 57 | with: 58 | toolchain: ${{ matrix.rust }} 59 | - run: cargo check --all-features 60 | - run: cargo test --no-default-features 61 | - run: cargo test 62 | - run: cargo test --all-features 63 | -------------------------------------------------------------------------------- /.github/workflows/idea.yml: -------------------------------------------------------------------------------- 1 | name: idea 2 | 3 | on: 4 | pull_request: 5 | paths: 6 | - ".github/workflows/idea.yml" 7 | - "idea/**" 8 | - "Cargo.*" 9 | push: 10 | branches: master 11 | 12 | defaults: 13 | run: 14 | working-directory: idea 15 | 16 | env: 17 | CARGO_INCREMENTAL: 0 18 | RUSTFLAGS: "-Dwarnings" 19 | 20 | jobs: 21 | build: 22 | runs-on: ubuntu-latest 23 | strategy: 24 | matrix: 25 | rust: 26 | - 1.85.0 # MSRV 27 | - stable 28 | target: 29 | - thumbv7em-none-eabi 30 | - wasm32-unknown-unknown 31 | steps: 32 | - uses: actions/checkout@v4 33 | - uses: RustCrypto/actions/cargo-cache@master 34 | - uses: dtolnay/rust-toolchain@master 35 | with: 36 | toolchain: ${{ matrix.rust }} 37 | targets: ${{ matrix.target }} 38 | - run: cargo build --no-default-features --release --target ${{ matrix.target }} 39 | 40 | minimal-versions: 41 | if: false # TODO: temp disabled due to unpublished prerelease dependencies 42 | uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master 43 | with: 44 | working-directory: ${{ github.workflow }} 45 | 46 | test: 47 | runs-on: ubuntu-latest 48 | strategy: 49 | matrix: 50 | rust: 51 | - 1.85.0 # MSRV 52 | - stable 53 | steps: 54 | - uses: actions/checkout@v4 55 | - uses: RustCrypto/actions/cargo-cache@master 56 | - uses: dtolnay/rust-toolchain@master 57 | with: 58 | toolchain: ${{ matrix.rust }} 59 | - run: cargo check --all-features 60 | - run: cargo test --no-default-features 61 | - run: cargo test 62 | - run: cargo test --all-features 63 | -------------------------------------------------------------------------------- /.github/workflows/magma.yml: -------------------------------------------------------------------------------- 1 | name: magma 2 | 3 | on: 4 | pull_request: 5 | paths: 6 | - ".github/workflows/magma.yml" 7 | - "magma/**" 8 | - "Cargo.*" 9 | push: 10 | branches: master 11 | 12 | defaults: 13 | run: 14 | working-directory: magma 15 | 16 | env: 17 | CARGO_INCREMENTAL: 0 18 | RUSTFLAGS: "-Dwarnings" 19 | 20 | jobs: 21 | build: 22 | runs-on: ubuntu-latest 23 | strategy: 24 | matrix: 25 | rust: 26 | - 1.85.0 # MSRV 27 | - stable 28 | target: 29 | - thumbv7em-none-eabi 30 | - wasm32-unknown-unknown 31 | steps: 32 | - uses: actions/checkout@v4 33 | - uses: RustCrypto/actions/cargo-cache@master 34 | - uses: dtolnay/rust-toolchain@master 35 | with: 36 | toolchain: ${{ matrix.rust }} 37 | targets: ${{ matrix.target }} 38 | - run: cargo build --no-default-features --release --target ${{ matrix.target }} 39 | 40 | minimal-versions: 41 | if: false # TODO: temp disabled due to unpublished prerelease dependencies 42 | uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master 43 | with: 44 | working-directory: ${{ github.workflow }} 45 | 46 | test: 47 | runs-on: ubuntu-latest 48 | strategy: 49 | matrix: 50 | rust: 51 | - 1.85.0 # MSRV 52 | - stable 53 | steps: 54 | - uses: actions/checkout@v4 55 | - uses: RustCrypto/actions/cargo-cache@master 56 | - uses: dtolnay/rust-toolchain@master 57 | with: 58 | toolchain: ${{ matrix.rust }} 59 | - run: cargo check --all-features 60 | - run: cargo test --no-default-features 61 | - run: cargo test 62 | - run: cargo test --all-features 63 | -------------------------------------------------------------------------------- /.github/workflows/rc2.yml: -------------------------------------------------------------------------------- 1 | name: rc2 2 | 3 | on: 4 | pull_request: 5 | paths: 6 | - ".github/workflows/rc2.yml" 7 | - "rc2/**" 8 | - "Cargo.*" 9 | push: 10 | branches: master 11 | 12 | defaults: 13 | run: 14 | working-directory: rc2 15 | 16 | env: 17 | CARGO_INCREMENTAL: 0 18 | RUSTFLAGS: "-Dwarnings" 19 | 20 | jobs: 21 | build: 22 | runs-on: ubuntu-latest 23 | strategy: 24 | matrix: 25 | rust: 26 | - 1.85.0 # MSRV 27 | - stable 28 | target: 29 | - thumbv7em-none-eabi 30 | - wasm32-unknown-unknown 31 | steps: 32 | - uses: actions/checkout@v4 33 | - uses: RustCrypto/actions/cargo-cache@master 34 | - uses: dtolnay/rust-toolchain@master 35 | with: 36 | toolchain: ${{ matrix.rust }} 37 | targets: ${{ matrix.target }} 38 | - run: cargo build --no-default-features --release --target ${{ matrix.target }} 39 | 40 | minimal-versions: 41 | if: false # TODO: temp disabled due to unpublished prerelease dependencies 42 | uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master 43 | with: 44 | working-directory: ${{ github.workflow }} 45 | 46 | test: 47 | runs-on: ubuntu-latest 48 | strategy: 49 | matrix: 50 | rust: 51 | - 1.85.0 # MSRV 52 | - stable 53 | steps: 54 | - uses: actions/checkout@v4 55 | - uses: RustCrypto/actions/cargo-cache@master 56 | - uses: dtolnay/rust-toolchain@master 57 | with: 58 | toolchain: ${{ matrix.rust }} 59 | - run: cargo check --all-features 60 | - run: cargo test --no-default-features 61 | - run: cargo test 62 | - run: cargo test --all-features 63 | -------------------------------------------------------------------------------- /.github/workflows/rc5.yml: -------------------------------------------------------------------------------- 1 | name: rc5 2 | on: 3 | pull_request: 4 | paths: 5 | - ".github/workflows/rc5.yml" 6 | - "rc5/**" 7 | - "Cargo.*" 8 | push: 9 | branches: master 10 | 11 | defaults: 12 | run: 13 | working-directory: rc5 14 | 15 | env: 16 | CARGO_INCREMENTAL: 0 17 | RUSTFLAGS: "-Dwarnings" 18 | 19 | jobs: 20 | build: 21 | runs-on: ubuntu-latest 22 | strategy: 23 | matrix: 24 | rust: 25 | - 1.85.0 # MSRV 26 | - stable 27 | target: 28 | - thumbv7em-none-eabi 29 | - wasm32-unknown-unknown 30 | steps: 31 | - uses: actions/checkout@v4 32 | - uses: RustCrypto/actions/cargo-cache@master 33 | - uses: dtolnay/rust-toolchain@master 34 | with: 35 | toolchain: ${{ matrix.rust }} 36 | targets: ${{ matrix.target }} 37 | - run: cargo build --no-default-features --release --target ${{ matrix.target }} 38 | 39 | minimal-versions: 40 | if: false # TODO: temp disabled due to unpublished prerelease dependencies 41 | uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master 42 | with: 43 | working-directory: ${{ github.workflow }} 44 | 45 | test: 46 | runs-on: ubuntu-latest 47 | strategy: 48 | matrix: 49 | rust: 50 | - 1.85.0 # MSRV 51 | - stable 52 | steps: 53 | - uses: actions/checkout@v4 54 | - uses: RustCrypto/actions/cargo-cache@master 55 | - uses: dtolnay/rust-toolchain@master 56 | with: 57 | toolchain: ${{ matrix.rust }} 58 | - run: cargo check --all-features 59 | - run: cargo test --no-default-features 60 | - run: cargo test 61 | - run: cargo test --all-features 62 | -------------------------------------------------------------------------------- /.github/workflows/security-audit.yml: -------------------------------------------------------------------------------- 1 | name: Security Audit 2 | on: 3 | pull_request: 4 | paths: 5 | - .github/workflows/security-audit.yml 6 | - Cargo.lock 7 | push: 8 | branches: master 9 | paths: Cargo.lock 10 | schedule: 11 | - cron: "0 0 * * *" 12 | 13 | jobs: 14 | security_audit: 15 | name: Security Audit 16 | runs-on: ubuntu-24.04 17 | steps: 18 | - uses: actions/checkout@v4 19 | - name: Cache cargo bin 20 | uses: actions/cache@v3 21 | with: 22 | path: ~/.cargo/bin 23 | key: ${{ runner.os }}-cargo-audit-v0.20-ubuntu-24.04 24 | - uses: rustsec/audit-check@v2 25 | with: 26 | token: ${{ secrets.GITHUB_TOKEN }} 27 | -------------------------------------------------------------------------------- /.github/workflows/serpent.yml: -------------------------------------------------------------------------------- 1 | name: serpent 2 | 3 | on: 4 | pull_request: 5 | paths: 6 | - ".github/workflows/serpent.yml" 7 | - "serpent/**" 8 | - "Cargo.*" 9 | push: 10 | branches: master 11 | 12 | defaults: 13 | run: 14 | working-directory: serpent 15 | 16 | env: 17 | CARGO_INCREMENTAL: 0 18 | RUSTFLAGS: "-Dwarnings" 19 | 20 | jobs: 21 | build: 22 | runs-on: ubuntu-latest 23 | strategy: 24 | matrix: 25 | rust: 26 | - 1.85.0 # MSRV 27 | - stable 28 | target: 29 | - thumbv7em-none-eabi 30 | - wasm32-unknown-unknown 31 | steps: 32 | - uses: actions/checkout@v4 33 | - uses: RustCrypto/actions/cargo-cache@master 34 | - uses: dtolnay/rust-toolchain@master 35 | with: 36 | toolchain: ${{ matrix.rust }} 37 | targets: ${{ matrix.target }} 38 | - run: cargo build --no-default-features --release --target ${{ matrix.target }} 39 | - env: 40 | RUSTFLAGS: "-Dwarnings --cfg serpent_no_unroll" 41 | run: cargo build --no-default-features --release --target ${{ matrix.target }} 42 | 43 | minimal-versions: 44 | if: false # TODO: temp disabled due to unpublished prerelease dependencies 45 | uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master 46 | with: 47 | working-directory: ${{ github.workflow }} 48 | 49 | test: 50 | runs-on: ubuntu-latest 51 | strategy: 52 | matrix: 53 | rust: 54 | - 1.85.0 # MSRV 55 | - stable 56 | steps: 57 | - uses: actions/checkout@v4 58 | - uses: RustCrypto/actions/cargo-cache@master 59 | - uses: dtolnay/rust-toolchain@master 60 | with: 61 | toolchain: ${{ matrix.rust }} 62 | - run: cargo check --all-features 63 | - run: cargo test --no-default-features 64 | - run: cargo test 65 | - run: cargo test --all-features 66 | - env: 67 | RUSTFLAGS: "-Dwarnings --cfg serpent_no_unroll" 68 | run: cargo test --all-features 69 | -------------------------------------------------------------------------------- /.github/workflows/sm4.yml: -------------------------------------------------------------------------------- 1 | name: sm4 2 | 3 | on: 4 | pull_request: 5 | paths: 6 | - "sm4/**" 7 | - "Cargo.*" 8 | push: 9 | branches: master 10 | 11 | defaults: 12 | run: 13 | working-directory: sm4 14 | 15 | env: 16 | CARGO_INCREMENTAL: 0 17 | RUSTFLAGS: "-Dwarnings" 18 | 19 | jobs: 20 | build: 21 | runs-on: ubuntu-latest 22 | strategy: 23 | matrix: 24 | rust: 25 | - 1.85.0 # MSRV 26 | - stable 27 | target: 28 | - thumbv7em-none-eabi 29 | - wasm32-unknown-unknown 30 | steps: 31 | - uses: actions/checkout@v4 32 | - uses: RustCrypto/actions/cargo-cache@master 33 | - uses: dtolnay/rust-toolchain@master 34 | with: 35 | toolchain: ${{ matrix.rust }} 36 | targets: ${{ matrix.target }} 37 | - run: cargo build --no-default-features --release --target ${{ matrix.target }} 38 | 39 | minimal-versions: 40 | if: false # TODO: temp disabled due to unpublished prerelease dependencies 41 | uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master 42 | with: 43 | working-directory: ${{ github.workflow }} 44 | 45 | test: 46 | runs-on: ubuntu-latest 47 | strategy: 48 | matrix: 49 | rust: 50 | - 1.85.0 # MSRV 51 | - stable 52 | steps: 53 | - uses: actions/checkout@v4 54 | - uses: RustCrypto/actions/cargo-cache@master 55 | - uses: dtolnay/rust-toolchain@master 56 | with: 57 | toolchain: ${{ matrix.rust }} 58 | - run: cargo check --all-features 59 | - run: cargo test --no-default-features 60 | - run: cargo test 61 | - run: cargo test --all-features 62 | -------------------------------------------------------------------------------- /.github/workflows/speck.yml: -------------------------------------------------------------------------------- 1 | name: speck 2 | 3 | on: 4 | pull_request: 5 | paths: 6 | - ".github/workflows/speck.yml" 7 | - "speck/**" 8 | - "Cargo.*" 9 | push: 10 | branches: master 11 | 12 | defaults: 13 | run: 14 | working-directory: speck 15 | 16 | env: 17 | CARGO_INCREMENTAL: 0 18 | RUSTFLAGS: "-Dwarnings" 19 | 20 | jobs: 21 | build: 22 | runs-on: ubuntu-latest 23 | strategy: 24 | matrix: 25 | rust: 26 | - 1.85.0 # MSRV 27 | - stable 28 | target: 29 | - thumbv7em-none-eabi 30 | - wasm32-unknown-unknown 31 | steps: 32 | - uses: actions/checkout@v4 33 | - uses: dtolnay/rust-toolchain@master 34 | with: 35 | toolchain: ${{ matrix.rust }} 36 | targets: ${{ matrix.target }} 37 | - run: cargo build --no-default-features --release --target ${{ matrix.target }} 38 | 39 | minimal-versions: 40 | if: false # TODO: temp disabled due to unpublished prerelease dependencies 41 | runs-on: ubuntu-latest 42 | steps: 43 | - uses: actions/checkout@v4 44 | - uses: dtolnay/rust-toolchain@master 45 | with: 46 | toolchain: nightly 47 | - run: rm ../Cargo.toml 48 | - run: cargo update -Z minimal-versions 49 | - run: cargo test --release 50 | - run: cargo test --release --all-features 51 | 52 | test: 53 | runs-on: ubuntu-latest 54 | strategy: 55 | matrix: 56 | rust: 57 | - 1.85.0 # MSRV 58 | - stable 59 | steps: 60 | - uses: actions/checkout@v4 61 | - uses: dtolnay/rust-toolchain@master 62 | with: 63 | toolchain: ${{ matrix.rust }} 64 | - run: cargo check --all-features 65 | - run: cargo test --no-default-features 66 | - run: cargo test 67 | - run: cargo test --all-features 68 | -------------------------------------------------------------------------------- /.github/workflows/threefish.yml: -------------------------------------------------------------------------------- 1 | name: threefish 2 | 3 | on: 4 | pull_request: 5 | paths: 6 | - ".github/workflows/threefish.yml" 7 | - "threefish/**" 8 | - "Cargo.*" 9 | push: 10 | branches: master 11 | 12 | defaults: 13 | run: 14 | working-directory: threefish 15 | 16 | env: 17 | CARGO_INCREMENTAL: 0 18 | RUSTFLAGS: "-Dwarnings" 19 | 20 | jobs: 21 | build: 22 | runs-on: ubuntu-latest 23 | strategy: 24 | matrix: 25 | rust: 26 | - 1.85.0 # MSRV 27 | - stable 28 | target: 29 | - thumbv7em-none-eabi 30 | - wasm32-unknown-unknown 31 | steps: 32 | - uses: actions/checkout@v4 33 | - uses: RustCrypto/actions/cargo-cache@master 34 | - uses: dtolnay/rust-toolchain@master 35 | with: 36 | toolchain: ${{ matrix.rust }} 37 | targets: ${{ matrix.target }} 38 | - run: cargo build --no-default-features --release --target ${{ matrix.target }} 39 | 40 | minimal-versions: 41 | if: false # TODO: temp disabled due to unpublished prerelease dependencies 42 | uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master 43 | with: 44 | working-directory: ${{ github.workflow }} 45 | 46 | test: 47 | runs-on: ubuntu-latest 48 | strategy: 49 | matrix: 50 | rust: 51 | - 1.85.0 # MSRV 52 | - stable 53 | steps: 54 | - uses: actions/checkout@v4 55 | - uses: RustCrypto/actions/cargo-cache@master 56 | - uses: dtolnay/rust-toolchain@master 57 | with: 58 | toolchain: ${{ matrix.rust }} 59 | - run: cargo check --all-features 60 | - run: cargo test --no-default-features 61 | - run: cargo test 62 | - run: cargo test --all-features 63 | -------------------------------------------------------------------------------- /.github/workflows/twofish.yml: -------------------------------------------------------------------------------- 1 | name: twofish 2 | 3 | on: 4 | pull_request: 5 | paths: 6 | - ".github/workflows/twofish.yml" 7 | - "twofish/**" 8 | - "Cargo.*" 9 | push: 10 | branches: master 11 | 12 | defaults: 13 | run: 14 | working-directory: twofish 15 | 16 | env: 17 | CARGO_INCREMENTAL: 0 18 | RUSTFLAGS: "-Dwarnings" 19 | 20 | jobs: 21 | build: 22 | runs-on: ubuntu-latest 23 | strategy: 24 | matrix: 25 | rust: 26 | - 1.85.0 # MSRV 27 | - stable 28 | target: 29 | - thumbv7em-none-eabi 30 | - wasm32-unknown-unknown 31 | steps: 32 | - uses: actions/checkout@v4 33 | - uses: RustCrypto/actions/cargo-cache@master 34 | - uses: dtolnay/rust-toolchain@master 35 | with: 36 | toolchain: ${{ matrix.rust }} 37 | targets: ${{ matrix.target }} 38 | - run: cargo build --no-default-features --release --target ${{ matrix.target }} 39 | 40 | minimal-versions: 41 | if: false # TODO: temp disabled due to unpublished prerelease dependencies 42 | uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master 43 | with: 44 | working-directory: ${{ github.workflow }} 45 | 46 | test: 47 | runs-on: ubuntu-latest 48 | strategy: 49 | matrix: 50 | rust: 51 | - 1.85.0 # MSRV 52 | - stable 53 | steps: 54 | - uses: actions/checkout@v4 55 | - uses: RustCrypto/actions/cargo-cache@master 56 | - uses: dtolnay/rust-toolchain@master 57 | with: 58 | toolchain: ${{ matrix.rust }} 59 | - run: cargo check --all-features 60 | - run: cargo test --no-default-features 61 | - run: cargo test 62 | - run: cargo test --all-features 63 | -------------------------------------------------------------------------------- /.github/workflows/workspace.yml: -------------------------------------------------------------------------------- 1 | name: Workspace 2 | 3 | on: 4 | pull_request: 5 | paths-ignore: 6 | - README.md 7 | push: 8 | branches: master 9 | paths-ignore: 10 | - README.md 11 | 12 | jobs: 13 | clippy: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@v4 17 | - uses: RustCrypto/actions/cargo-cache@master 18 | - uses: dtolnay/rust-toolchain@master 19 | with: 20 | toolchain: 1.85.0 21 | components: clippy 22 | - run: cargo clippy --all --exclude aes --all-features -- -D warnings 23 | 24 | rustfmt: 25 | runs-on: ubuntu-latest 26 | steps: 27 | - name: Checkout sources 28 | uses: actions/checkout@v4 29 | 30 | - name: Install stable toolchain 31 | uses: dtolnay/rust-toolchain@master 32 | with: 33 | toolchain: stable 34 | components: rustfmt 35 | - name: Run cargo fmt 36 | run: cargo fmt --all -- --check 37 | -------------------------------------------------------------------------------- /.github/workflows/xtea.yml: -------------------------------------------------------------------------------- 1 | name: xtea 2 | 3 | on: 4 | pull_request: 5 | paths: 6 | - ".github/workflows/xtea.yml" 7 | - "xtea/**" 8 | - "Cargo.*" 9 | push: 10 | branches: master 11 | 12 | defaults: 13 | run: 14 | working-directory: xtea 15 | 16 | env: 17 | CARGO_INCREMENTAL: 0 18 | RUSTFLAGS: "-Dwarnings" 19 | 20 | jobs: 21 | build: 22 | runs-on: ubuntu-latest 23 | strategy: 24 | matrix: 25 | rust: 26 | - 1.85.0 # MSRV 27 | - stable 28 | target: 29 | - thumbv7em-none-eabi 30 | - wasm32-unknown-unknown 31 | steps: 32 | - uses: actions/checkout@v4 33 | - uses: RustCrypto/actions/cargo-cache@master 34 | - uses: dtolnay/rust-toolchain@master 35 | with: 36 | toolchain: ${{ matrix.rust }} 37 | targets: ${{ matrix.target }} 38 | - run: cargo build --no-default-features --release --target ${{ matrix.target }} 39 | 40 | minimal-versions: 41 | if: false # TODO: temp disabled due to unpublished prerelease dependencies 42 | uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master 43 | with: 44 | working-directory: ${{ github.workflow }} 45 | 46 | test: 47 | runs-on: ubuntu-latest 48 | strategy: 49 | matrix: 50 | rust: 51 | - 1.85.0 # MSRV 52 | - stable 53 | steps: 54 | - uses: actions/checkout@v4 55 | - uses: RustCrypto/actions/cargo-cache@master 56 | - uses: dtolnay/rust-toolchain@master 57 | with: 58 | toolchain: ${{ matrix.rust }} 59 | - run: cargo check --all-features 60 | - run: cargo test --no-default-features 61 | - run: cargo test 62 | - run: cargo test --all-features 63 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | **/Cargo.lock 3 | **/target/ 4 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | resolver = "3" 3 | members = [ 4 | "aes", 5 | "aria", 6 | "belt-block", 7 | "blowfish", 8 | "camellia", 9 | "cast5", 10 | "cast6", 11 | "des", 12 | "gift", 13 | "idea", 14 | "kuznyechik", 15 | "magma", 16 | "rc2", 17 | "rc5", 18 | "serpent", 19 | "sm4", 20 | "speck", 21 | "twofish", 22 | "threefish", 23 | "xtea", 24 | ] 25 | 26 | [profile.dev] 27 | opt-level = 2 28 | -------------------------------------------------------------------------------- /aes/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "aes" 3 | version = "0.9.0-rc.0" 4 | description = "Pure Rust implementation of the Advanced Encryption Standard (a.k.a. Rijndael)" 5 | authors = ["RustCrypto Developers"] 6 | license = "MIT OR Apache-2.0" 7 | edition = "2024" 8 | rust-version = "1.85" 9 | readme = "README.md" 10 | documentation = "https://docs.rs/aes" 11 | repository = "https://github.com/RustCrypto/block-ciphers" 12 | keywords = ["crypto", "aes", "rijndael", "block-cipher"] 13 | categories = ["cryptography", "no-std"] 14 | 15 | [dependencies] 16 | cfg-if = "1" 17 | cipher = "0.5.0-rc.0" 18 | zeroize = { version = "1.5.6", optional = true, default-features = false, features = [ 19 | "aarch64", 20 | ] } 21 | 22 | [target.'cfg(any(target_arch = "aarch64", target_arch = "x86_64", target_arch = "x86"))'.dependencies] 23 | cpufeatures = "0.2" 24 | 25 | [dev-dependencies] 26 | cipher = { version = "0.5.0-rc.0", features = ["dev"] } 27 | hex-literal = "1" 28 | 29 | [features] 30 | hazmat = [] # Expose cryptographically hazardous APIs 31 | 32 | [lints.rust.unexpected_cfgs] 33 | level = "warn" 34 | check-cfg = ["cfg(aes_compact)", "cfg(aes_force_soft)"] 35 | 36 | [package.metadata.docs.rs] 37 | all-features = true 38 | rustdoc-args = ["--cfg", "docsrs"] 39 | -------------------------------------------------------------------------------- /aes/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018-2024 The RustCrypto Project Developers 2 | Copyright (c) 2018 Artyom Pavlov 3 | 4 | Permission is hereby granted, free of charge, to any 5 | person obtaining a copy of this software and associated 6 | documentation files (the "Software"), to deal in the 7 | Software without restriction, including without 8 | limitation the rights to use, copy, modify, merge, 9 | publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software 11 | is furnished to do so, subject to the following 12 | conditions: 13 | 14 | The above copyright notice and this permission notice 15 | shall be included in all copies or substantial portions 16 | of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 19 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 20 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 21 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 22 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 25 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 | DEALINGS IN THE SOFTWARE. 27 | -------------------------------------------------------------------------------- /aes/benches/mod.rs: -------------------------------------------------------------------------------- 1 | #![feature(test)] 2 | extern crate test; 3 | 4 | use cipher::{KeyInit, block_decryptor_bench, block_encryptor_bench}; 5 | 6 | block_encryptor_bench!( 7 | Key: aes::Aes128, 8 | aes128_encrypt_block, 9 | aes128_encrypt_blocks, 10 | ); 11 | block_decryptor_bench!( 12 | Key: aes::Aes128, 13 | aes128_decrypt_block, 14 | aes128_decrypt_blocks, 15 | ); 16 | block_encryptor_bench!( 17 | Key: aes::Aes192, 18 | aes192_encrypt_block, 19 | aes192_encrypt_blocks, 20 | ); 21 | block_decryptor_bench!( 22 | Key: aes::Aes192, 23 | aes192_decrypt_block, 24 | aes192_decrypt_blocks, 25 | ); 26 | block_encryptor_bench!( 27 | Key: aes::Aes256, 28 | aes256_encrypt_block, 29 | aes256_encrypt_blocks, 30 | ); 31 | block_decryptor_bench!( 32 | Key: aes::Aes256, 33 | aes256_decrypt_block, 34 | aes256_decrypt_blocks, 35 | ); 36 | 37 | #[bench] 38 | fn aes128_new(bh: &mut test::Bencher) { 39 | bh.iter(|| { 40 | let key = test::black_box(Default::default()); 41 | let cipher = aes::Aes128::new(&key); 42 | test::black_box(&cipher); 43 | }); 44 | } 45 | 46 | #[bench] 47 | fn aes192_new(bh: &mut test::Bencher) { 48 | bh.iter(|| { 49 | let key = test::black_box(Default::default()); 50 | let cipher = aes::Aes192::new(&key); 51 | test::black_box(&cipher); 52 | }); 53 | } 54 | 55 | #[bench] 56 | fn aes256_new(bh: &mut test::Bencher) { 57 | bh.iter(|| { 58 | let key = test::black_box(Default::default()); 59 | let cipher = aes::Aes256::new(&key); 60 | test::black_box(&cipher); 61 | }); 62 | } 63 | -------------------------------------------------------------------------------- /aes/tests/data/aes128.blb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustCrypto/block-ciphers/73b104d31747ff763de345372ceab6eeffd04319/aes/tests/data/aes128.blb -------------------------------------------------------------------------------- /aes/tests/data/aes192.blb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustCrypto/block-ciphers/73b104d31747ff763de345372ceab6eeffd04319/aes/tests/data/aes192.blb -------------------------------------------------------------------------------- /aes/tests/data/aes256.blb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustCrypto/block-ciphers/73b104d31747ff763de345372ceab6eeffd04319/aes/tests/data/aes256.blb -------------------------------------------------------------------------------- /aes/tests/mod.rs: -------------------------------------------------------------------------------- 1 | //! Test vectors are from NESSIE: 2 | //! https://www.cosic.esat.kuleuven.be/nessie/testvectors/ 3 | 4 | cipher::block_cipher_test!(aes128_test, "aes128", aes::Aes128); 5 | cipher::block_cipher_test!(aes192_test, "aes192", aes::Aes192); 6 | cipher::block_cipher_test!(aes256_test, "aes256", aes::Aes256); 7 | -------------------------------------------------------------------------------- /aes/tests/weak.rs: -------------------------------------------------------------------------------- 1 | use aes::Aes128; 2 | use cipher::{Key, KeyInit}; 3 | use hex_literal::hex; 4 | 5 | #[test] 6 | fn test_weak_key() { 7 | for k in &[ 8 | hex!("00000000000000000000000000000000"), 9 | hex!("00000000000000000101010101010101"), 10 | hex!("00000000000000000100000000000000"), 11 | ] { 12 | let k = Key::::from(*k); 13 | assert!(Aes128::weak_key_test(&k).is_err()); 14 | } 15 | 16 | for k in &[ 17 | hex!("00000000010000000000000000000000"), 18 | hex!("00000000010000000101010101010101"), 19 | hex!("00000000010000000100000000000000"), 20 | ] { 21 | let k = Key::::from(*k); 22 | assert!(Aes128::weak_key_test(&k).is_ok()); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /aria/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 | 8 | ## 0.2.0 (UNRELEASED) 9 | ### Changed 10 | - Bump `cipher` dependency to v0.5 11 | - Edition changed to 2024 and MSRV bumped to 1.85 ([#472]) 12 | - Relax MSRV policy and allow MSRV bumps in patch releases ([#477]) 13 | 14 | [#472]: https://github.com/RustCrypto/block-ciphers/pull/472 15 | [#477]: https://github.com/RustCrypto/block-ciphers/pull/477 16 | 17 | ## 0.1.0 (2022-10-27) 18 | - Initial release ([#340]) 19 | 20 | [#340]: https://github.com/RustCrypto/block-ciphers/pull/340 21 | -------------------------------------------------------------------------------- /aria/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "aria" 3 | version = "0.2.0-pre" 4 | description = "Pure Rust implementation of the ARIA Encryption Algorithm" 5 | authors = ["RustCrypto Developers"] 6 | license = "MIT OR Apache-2.0" 7 | edition = "2024" 8 | rust-version = "1.85" 9 | readme = "README.md" 10 | documentation = "https://docs.rs/aria" 11 | repository = "https://github.com/RustCrypto/block-ciphers" 12 | keywords = ["crypto", "aria", "block-cipher"] 13 | categories = ["cryptography", "no-std"] 14 | 15 | [dependencies] 16 | cipher = "0.5.0-rc.0" 17 | 18 | [dev-dependencies] 19 | cipher = { version = "0.5.0-rc.0", features = ["dev"] } 20 | hex-literal = "1" 21 | 22 | [features] 23 | zeroize = ["cipher/zeroize"] 24 | 25 | [package.metadata.docs.rs] 26 | all-features = true 27 | rustdoc-args = ["--cfg", "docsrs"] 28 | -------------------------------------------------------------------------------- /aria/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2022-2024 The RustCrypto Project Developers 2 | 3 | Permission is hereby granted, free of charge, to any 4 | person obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the 6 | Software without restriction, including without 7 | limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software 10 | is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice 14 | shall be included in all copies or substantial portions 15 | of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 18 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 19 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 24 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /aria/README.md: -------------------------------------------------------------------------------- 1 | # RustCrypto: ARIA Cipher 2 | 3 | [![crate][crate-image]][crate-link] 4 | [![Docs][docs-image]][docs-link] 5 | ![Apache2/MIT licensed][license-image] 6 | ![Rust Version][rustc-image] 7 | [![Project Chat][chat-image]][chat-link] 8 | [![Build Status][build-image]][build-link] 9 | [![HAZMAT][hazmat-image]][hazmat-link] 10 | 11 | Pure Rust implementation of the [ARIA] block cipher. 12 | 13 | ## ⚠️ Security Warning: [Hazmat!][hazmat-link] 14 | 15 | This crate does not ensure ciphertexts are authentic (i.e. by using a MAC to 16 | verify ciphertext integrity), which can lead to serious vulnerabilities 17 | if used incorrectly! 18 | 19 | No security audits of this crate have ever been performed, and it has not been 20 | thoroughly assessed to ensure its operation is constant-time on common CPU 21 | architectures. 22 | 23 | USE AT YOUR OWN RISK! 24 | 25 | ## License 26 | 27 | Licensed under either of: 28 | 29 | * [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) 30 | * [MIT license](http://opensource.org/licenses/MIT) 31 | 32 | at your option. 33 | 34 | ### Contribution 35 | 36 | Unless you explicitly state otherwise, any contribution intentionally submitted 37 | for inclusion in the work by you, as defined in the Apache-2.0 license, shall be 38 | dual licensed as above, without any additional terms or conditions. 39 | 40 | [//]: # (badges) 41 | 42 | [crate-image]: https://img.shields.io/crates/v/aria.svg 43 | [crate-link]: https://crates.io/crates/aria 44 | [docs-image]: https://docs.rs/aria/badge.svg 45 | [docs-link]: https://docs.rs/aria/ 46 | [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg 47 | [rustc-image]: https://img.shields.io/badge/rustc-1.85+-blue.svg 48 | [hazmat-image]: https://img.shields.io/badge/crypto-hazmat%E2%9A%A0-red.svg 49 | [hazmat-link]: https://github.com/RustCrypto/meta/blob/master/HAZMAT.md 50 | [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg 51 | [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260039-block-ciphers 52 | [build-image]: https://github.com/RustCrypto/block-ciphers/workflows/aria/badge.svg?branch=master&event=push 53 | [build-link]: https://github.com/RustCrypto/block-ciphers/actions?query=workflow%3Aaria 54 | 55 | [//]: # (general links) 56 | 57 | [ARIA]: https://en.wikipedia.org/wiki/ARIA_(cipher) 58 | -------------------------------------------------------------------------------- /aria/benches/mod.rs: -------------------------------------------------------------------------------- 1 | #![feature(test)] 2 | extern crate test; 3 | 4 | use aria::{Aria128, Aria192, Aria256}; 5 | use cipher::{block_decryptor_bench, block_encryptor_bench}; 6 | 7 | block_encryptor_bench!(Key: Aria128, aria128_encrypt_block, aria128_encrypt_blocks); 8 | block_decryptor_bench!(Key: Aria128, aria128_decrypt_block, aria128_decrypt_blocks); 9 | 10 | block_encryptor_bench!(Key: Aria192, aria192_encrypt_block, aria192_encrypt_blocks); 11 | block_decryptor_bench!(Key: Aria192, aria192_decrypt_block, aria192_decrypt_blocks); 12 | 13 | block_encryptor_bench!(Key: Aria256, aria256_encrypt_block, aria256_encrypt_blocks); 14 | block_decryptor_bench!(Key: Aria256, aria256_decrypt_block, aria256_decrypt_blocks); 15 | -------------------------------------------------------------------------------- /aria/src/aria128.rs: -------------------------------------------------------------------------------- 1 | use crate::{ 2 | Aria128, 3 | consts::{C1, C2, C3}, 4 | utils::{a, fe, fo}, 5 | }; 6 | use cipher::{AlgorithmName, Key, KeyInit, KeySizeUser, consts::U16}; 7 | use core::fmt; 8 | 9 | impl KeySizeUser for Aria128 { 10 | type KeySize = U16; 11 | } 12 | 13 | impl KeyInit for Aria128 { 14 | fn new(key: &Key) -> Self { 15 | let kl = u128::from_be_bytes(key[0..16].try_into().unwrap()); 16 | let kr = u128::default(); 17 | 18 | let w0 = kl; 19 | let w1 = fo(w0 ^ C1) ^ kr; 20 | let w2 = fe(w1 ^ C2) ^ w0; 21 | let w3 = fo(w2 ^ C3) ^ w1; 22 | 23 | let ek = [ 24 | w0 ^ w1.rotate_right(19), 25 | w1 ^ w2.rotate_right(19), 26 | w2 ^ w3.rotate_right(19), 27 | w3 ^ w0.rotate_right(19), 28 | w0 ^ w1.rotate_right(31), 29 | w1 ^ w2.rotate_right(31), 30 | w2 ^ w3.rotate_right(31), 31 | w3 ^ w0.rotate_right(31), 32 | w0 ^ w1.rotate_left(61), 33 | w1 ^ w2.rotate_left(61), 34 | w2 ^ w3.rotate_left(61), 35 | w3 ^ w0.rotate_left(61), 36 | w0 ^ w1.rotate_left(31), 37 | ]; 38 | 39 | let dk = [ 40 | ek[12], 41 | a(ek[11]), 42 | a(ek[10]), 43 | a(ek[9]), 44 | a(ek[8]), 45 | a(ek[7]), 46 | a(ek[6]), 47 | a(ek[5]), 48 | a(ek[4]), 49 | a(ek[3]), 50 | a(ek[2]), 51 | a(ek[1]), 52 | ek[0], 53 | ]; 54 | 55 | Self { ek, dk } 56 | } 57 | } 58 | 59 | impl fmt::Debug for Aria128 { 60 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 61 | f.write_str("Aria128 { ... }") 62 | } 63 | } 64 | 65 | impl AlgorithmName for Aria128 { 66 | fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result { 67 | f.write_str("Aria128") 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /aria/src/aria192.rs: -------------------------------------------------------------------------------- 1 | use crate::{ 2 | Aria192, 3 | consts::{C1, C2, C3}, 4 | utils::{a, fe, fo}, 5 | }; 6 | use cipher::{AlgorithmName, Key, KeyInit, KeySizeUser, consts::U24}; 7 | use core::fmt; 8 | 9 | impl KeySizeUser for Aria192 { 10 | type KeySize = U24; 11 | } 12 | 13 | impl KeyInit for Aria192 { 14 | fn new(key: &Key) -> Self { 15 | let kl = u128::from_be_bytes(key[0..16].try_into().unwrap()); 16 | let kr = u64::from_be_bytes(key[16..24].try_into().unwrap()); 17 | let kr = (kr as u128) << 64; 18 | 19 | let w0 = kl; 20 | let w1 = fo(w0 ^ C2) ^ kr; 21 | let w2 = fe(w1 ^ C3) ^ w0; 22 | let w3 = fo(w2 ^ C1) ^ w1; 23 | 24 | let ek = [ 25 | w0 ^ w1.rotate_right(19), 26 | w1 ^ w2.rotate_right(19), 27 | w2 ^ w3.rotate_right(19), 28 | w3 ^ w0.rotate_right(19), 29 | w0 ^ w1.rotate_right(31), 30 | w1 ^ w2.rotate_right(31), 31 | w2 ^ w3.rotate_right(31), 32 | w3 ^ w0.rotate_right(31), 33 | w0 ^ w1.rotate_left(61), 34 | w1 ^ w2.rotate_left(61), 35 | w2 ^ w3.rotate_left(61), 36 | w3 ^ w0.rotate_left(61), 37 | w0 ^ w1.rotate_left(31), 38 | w1 ^ w2.rotate_left(31), 39 | w2 ^ w3.rotate_left(31), 40 | ]; 41 | 42 | let dk = [ 43 | ek[14], 44 | a(ek[13]), 45 | a(ek[12]), 46 | a(ek[11]), 47 | a(ek[10]), 48 | a(ek[9]), 49 | a(ek[8]), 50 | a(ek[7]), 51 | a(ek[6]), 52 | a(ek[5]), 53 | a(ek[4]), 54 | a(ek[3]), 55 | a(ek[2]), 56 | a(ek[1]), 57 | ek[0], 58 | ]; 59 | 60 | Self { ek, dk } 61 | } 62 | } 63 | 64 | impl fmt::Debug for Aria192 { 65 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 66 | f.write_str("Aria192 { ... }") 67 | } 68 | } 69 | 70 | impl AlgorithmName for Aria192 { 71 | fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result { 72 | f.write_str("Aria192") 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /aria/src/aria256.rs: -------------------------------------------------------------------------------- 1 | use crate::{ 2 | Aria256, 3 | consts::{C1, C2, C3}, 4 | utils::{a, fe, fo}, 5 | }; 6 | use cipher::{AlgorithmName, Key, KeyInit, KeySizeUser, consts::U32}; 7 | use core::fmt; 8 | 9 | impl KeySizeUser for Aria256 { 10 | type KeySize = U32; 11 | } 12 | 13 | impl KeyInit for Aria256 { 14 | fn new(key: &Key) -> Self { 15 | let kl = u128::from_be_bytes(key[0..16].try_into().unwrap()); 16 | let kr = u128::from_be_bytes(key[16..32].try_into().unwrap()); 17 | 18 | let w0 = kl; 19 | let w1 = fo(w0 ^ C3) ^ kr; 20 | let w2 = fe(w1 ^ C1) ^ w0; 21 | let w3 = fo(w2 ^ C2) ^ w1; 22 | 23 | let ek = [ 24 | w0 ^ w1.rotate_right(19), 25 | w1 ^ w2.rotate_right(19), 26 | w2 ^ w3.rotate_right(19), 27 | w3 ^ w0.rotate_right(19), 28 | w0 ^ w1.rotate_right(31), 29 | w1 ^ w2.rotate_right(31), 30 | w2 ^ w3.rotate_right(31), 31 | w3 ^ w0.rotate_right(31), 32 | w0 ^ w1.rotate_left(61), 33 | w1 ^ w2.rotate_left(61), 34 | w2 ^ w3.rotate_left(61), 35 | w3 ^ w0.rotate_left(61), 36 | w0 ^ w1.rotate_left(31), 37 | w1 ^ w2.rotate_left(31), 38 | w2 ^ w3.rotate_left(31), 39 | w3 ^ w0.rotate_left(31), 40 | w0 ^ w1.rotate_left(19), 41 | ]; 42 | 43 | let dk = [ 44 | ek[16], 45 | a(ek[15]), 46 | a(ek[14]), 47 | a(ek[13]), 48 | a(ek[12]), 49 | a(ek[11]), 50 | a(ek[10]), 51 | a(ek[9]), 52 | a(ek[8]), 53 | a(ek[7]), 54 | a(ek[6]), 55 | a(ek[5]), 56 | a(ek[4]), 57 | a(ek[3]), 58 | a(ek[2]), 59 | a(ek[1]), 60 | ek[0], 61 | ]; 62 | 63 | Self { ek, dk } 64 | } 65 | } 66 | 67 | impl fmt::Debug for Aria256 { 68 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 69 | f.write_str("Aria256 { ... }") 70 | } 71 | } 72 | 73 | impl AlgorithmName for Aria256 { 74 | fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result { 75 | f.write_str("Aria256") 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /aria/src/utils.rs: -------------------------------------------------------------------------------- 1 | use crate::consts::{DIFFUSE_CONSTS, SB1, SB2, SB3, SB4}; 2 | 3 | #[inline(always)] 4 | fn diffuse(x: [u8; 16]) -> u128 { 5 | DIFFUSE_CONSTS 6 | .iter() 7 | .zip(x) 8 | .map(|(a, b)| a * b as u128) 9 | .fold(0, |a, v| a ^ v) 10 | } 11 | 12 | #[inline(always)] 13 | pub(crate) fn a(x128: u128) -> u128 { 14 | diffuse(x128.to_be_bytes()) 15 | } 16 | 17 | pub(crate) fn sl2(x128: u128) -> u128 { 18 | let x = x128.to_be_bytes(); 19 | let y = [ 20 | SB3[x[0] as usize], 21 | SB4[x[1] as usize], 22 | SB1[x[2] as usize], 23 | SB2[x[3] as usize], 24 | SB3[x[4] as usize], 25 | SB4[x[5] as usize], 26 | SB1[x[6] as usize], 27 | SB2[x[7] as usize], 28 | SB3[x[8] as usize], 29 | SB4[x[9] as usize], 30 | SB1[x[10] as usize], 31 | SB2[x[11] as usize], 32 | SB3[x[12] as usize], 33 | SB4[x[13] as usize], 34 | SB1[x[14] as usize], 35 | SB2[x[15] as usize], 36 | ]; 37 | u128::from_be_bytes(y) 38 | } 39 | 40 | pub(crate) fn fo(x128: u128) -> u128 { 41 | let x = x128.to_be_bytes(); 42 | diffuse([ 43 | SB1[x[0] as usize], 44 | SB2[x[1] as usize], 45 | SB3[x[2] as usize], 46 | SB4[x[3] as usize], 47 | SB1[x[4] as usize], 48 | SB2[x[5] as usize], 49 | SB3[x[6] as usize], 50 | SB4[x[7] as usize], 51 | SB1[x[8] as usize], 52 | SB2[x[9] as usize], 53 | SB3[x[10] as usize], 54 | SB4[x[11] as usize], 55 | SB1[x[12] as usize], 56 | SB2[x[13] as usize], 57 | SB3[x[14] as usize], 58 | SB4[x[15] as usize], 59 | ]) 60 | } 61 | 62 | pub(crate) fn fe(x128: u128) -> u128 { 63 | let x = x128.to_be_bytes(); 64 | diffuse([ 65 | SB3[x[0] as usize], 66 | SB4[x[1] as usize], 67 | SB1[x[2] as usize], 68 | SB2[x[3] as usize], 69 | SB3[x[4] as usize], 70 | SB4[x[5] as usize], 71 | SB1[x[6] as usize], 72 | SB2[x[7] as usize], 73 | SB3[x[8] as usize], 74 | SB4[x[9] as usize], 75 | SB1[x[10] as usize], 76 | SB2[x[11] as usize], 77 | SB3[x[12] as usize], 78 | SB4[x[13] as usize], 79 | SB1[x[14] as usize], 80 | SB2[x[15] as usize], 81 | ]) 82 | } 83 | -------------------------------------------------------------------------------- /aria/tests/mod.rs: -------------------------------------------------------------------------------- 1 | use aria::{Aria128, Aria192, Aria256}; 2 | use cipher::{Array, BlockCipherDecrypt, BlockCipherEncrypt, KeyInit}; 3 | use hex_literal::hex; 4 | 5 | /// Test vector from RFC 5794, Appendix A.1 6 | #[test] 7 | fn test_rfc5794_a1() { 8 | let key = hex!("000102030405060708090a0b0c0d0e0f"); 9 | let pt = hex!("00112233445566778899aabbccddeeff"); 10 | let ct = hex!("d718fbd6ab644c739da95f3be6451778"); 11 | 12 | let c = Aria128::new_from_slice(&key).unwrap(); 13 | 14 | let mut buf = Array::from(pt); 15 | c.encrypt_block(&mut buf); 16 | assert_eq!(&buf, &ct); 17 | c.decrypt_block(&mut buf); 18 | assert_eq!(&buf, &pt); 19 | } 20 | 21 | /// Test vector from RFC 5794, Appendix A.2 22 | #[test] 23 | fn test_rfc5794_a2() { 24 | let key = hex!("000102030405060708090a0b0c0d0e0f1011121314151617"); 25 | let pt = hex!("00112233445566778899aabbccddeeff"); 26 | let ct = hex!("26449c1805dbe7aa25a468ce263a9e79"); 27 | 28 | let c = Aria192::new_from_slice(&key).unwrap(); 29 | 30 | let mut buf = Array::from(pt); 31 | c.encrypt_block(&mut buf); 32 | assert_eq!(&buf, &ct); 33 | c.decrypt_block(&mut buf); 34 | assert_eq!(&buf, &pt); 35 | } 36 | 37 | /// Test vector from RFC 5794, Appendix A.3 38 | #[test] 39 | fn test_rfc5794_a3() { 40 | let key = hex!("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"); 41 | let pt = hex!("00112233445566778899aabbccddeeff"); 42 | let ct = hex!("f92bd7c79fb72e2f2b8f80c1972d24fc"); 43 | 44 | let c = Aria256::new_from_slice(&key).unwrap(); 45 | 46 | let mut buf = Array::from(pt); 47 | c.encrypt_block(&mut buf); 48 | assert_eq!(&buf, &ct); 49 | c.decrypt_block(&mut buf); 50 | assert_eq!(&buf, &pt); 51 | } 52 | -------------------------------------------------------------------------------- /belt-block/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 | 8 | ## 0.2.0 (UNRELEASED) 9 | ### Changed 10 | - Bump `cipher` dependency to v0.5 11 | - Mark `to_u32` function as private ([#402]) 12 | - Edition changed to 2024 and MSRV bumped to 1.85 ([#472]) 13 | - Relax MSRV policy and allow MSRV bumps in patch releases ([#477]) 14 | 15 | [#402]: https://github.com/RustCrypto/block-ciphers/pull/402 16 | [#472]: https://github.com/RustCrypto/block-ciphers/pull/472 17 | [#477]: https://github.com/RustCrypto/block-ciphers/pull/477 18 | 19 | ## 0.1.2 (2023-04-15) 20 | ### Added 21 | - `belt_wblock_enc`, `belt_wblock_dec`, and `to_u32` functions ([#362]) 22 | 23 | [#362]: https://github.com/RustCrypto/block-ciphers/pull/362 24 | 25 | ## 0.1.1 (2022-09-23) 26 | ### Added 27 | - `belt_block_raw` function and `cipher` crate feature (enabled by default) ([#333]) 28 | 29 | [#333]: https://github.com/RustCrypto/block-ciphers/pull/333 30 | 31 | ## 0.1.0 (2022-09-14) 32 | - Initial release ([#328]) 33 | 34 | [#328]: https://github.com/RustCrypto/block-ciphers/pull/328 35 | -------------------------------------------------------------------------------- /belt-block/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "belt-block" 3 | version = "0.2.0-rc.0" 4 | description = "belt-block block cipher implementation" 5 | authors = ["RustCrypto Developers"] 6 | license = "MIT OR Apache-2.0" 7 | rust-version = "1.85" 8 | edition = "2024" 9 | readme = "README.md" 10 | documentation = "https://docs.rs/belt-block" 11 | repository = "https://github.com/RustCrypto/block-ciphers" 12 | keywords = ["crypto", "belt-block", "belt", "stb"] 13 | 14 | [dependencies] 15 | cipher = { version = "0.5.0-rc.0", optional = true } 16 | 17 | [dev-dependencies] 18 | cipher = { version = "0.5.0-rc.0", features = ["dev"] } 19 | hex-literal = "1" 20 | 21 | [features] 22 | default = ["cipher"] 23 | zeroize = ["cipher/zeroize"] 24 | 25 | [package.metadata.docs.rs] 26 | all-features = true 27 | rustdoc-args = ["--cfg", "docsrs"] 28 | -------------------------------------------------------------------------------- /belt-block/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2022 The RustCrypto Project Developers 2 | Copyright (c) 2022 Alexandr Kitaev, Artyom Pavlov 3 | 4 | Permission is hereby granted, free of charge, to any 5 | person obtaining a copy of this software and associated 6 | documentation files (the "Software"), to deal in the 7 | Software without restriction, including without 8 | limitation the rights to use, copy, modify, merge, 9 | publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software 11 | is furnished to do so, subject to the following 12 | conditions: 13 | 14 | The above copyright notice and this permission notice 15 | shall be included in all copies or substantial portions 16 | of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 19 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 20 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 21 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 22 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 25 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 | DEALINGS IN THE SOFTWARE. 27 | -------------------------------------------------------------------------------- /belt-block/README.md: -------------------------------------------------------------------------------- 1 | # RustCrypto: Belt-Block 2 | 3 | [![crate][crate-image]][crate-link] 4 | [![Docs][docs-image]][docs-link] 5 | ![Apache2/MIT licensed][license-image] 6 | ![Rust Version][rustc-image] 7 | [![Project Chat][chat-image]][chat-link] 8 | [![Build Status][build-image]][build-link] 9 | [![HAZMAT][hazmat-image]][hazmat-link] 10 | 11 | Pure Rust implementation of the [BelT] block cipher specified in [STB 34.101.31-2020]. 12 | 13 | ## ⚠️ Security Warning: [Hazmat!][hazmat-link] 14 | 15 | This crate does not ensure ciphertexts are authentic (i.e. by using a MAC to 16 | verify ciphertext integrity), which can lead to serious vulnerabilities 17 | if used incorrectly! 18 | 19 | No security audits of this crate have ever been performed, and it has not been 20 | thoroughly assessed to ensure its operation is constant-time on common CPU 21 | architectures. 22 | 23 | USE AT YOUR OWN RISK! 24 | 25 | ## License 26 | 27 | Licensed under either of: 28 | 29 | * [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) 30 | * [MIT license](http://opensource.org/licenses/MIT) 31 | 32 | at your option. 33 | 34 | ### Contribution 35 | 36 | Unless you explicitly state otherwise, any contribution intentionally submitted 37 | for inclusion in the work by you, as defined in the Apache-2.0 license, shall be 38 | dual licensed as above, without any additional terms or conditions. 39 | 40 | [//]: # (badges) 41 | 42 | [crate-image]: https://img.shields.io/crates/v/belt-block.svg 43 | [crate-link]: https://crates.io/crates/belt-block 44 | [docs-image]: https://docs.rs/belt-block/badge.svg 45 | [docs-link]: https://docs.rs/belt-block/ 46 | [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg 47 | [rustc-image]: https://img.shields.io/badge/rustc-1.85+-blue.svg 48 | [hazmat-image]: https://img.shields.io/badge/crypto-hazmat%E2%9A%A0-red.svg 49 | [hazmat-link]: https://github.com/RustCrypto/meta/blob/master/HAZMAT.md 50 | [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg 51 | [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260039-block-ciphers 52 | [build-image]: https://github.com/RustCrypto/block-ciphers/workflows/belt-block/badge.svg?branch=master&event=push 53 | [build-link]: https://github.com/RustCrypto/block-ciphers/actions?query=workflow%3Abelt-block 54 | 55 | [//]: # (general links) 56 | 57 | [BelT]: https://ru.wikipedia.org/wiki/BelT 58 | [STB 34.101.31-2020]: http://apmi.bsu.by/assets/files/std/belt-spec371.pdf 59 | -------------------------------------------------------------------------------- /belt-block/benches/mod.rs: -------------------------------------------------------------------------------- 1 | #![feature(test)] 2 | extern crate test; 3 | 4 | use belt_block::BeltBlock; 5 | use cipher::{block_decryptor_bench, block_encryptor_bench}; 6 | 7 | block_encryptor_bench!( 8 | Key: BeltBlock, 9 | beltblock_encrypt_block, 10 | beltblock_encrypt_blocks, 11 | ); 12 | block_decryptor_bench!( 13 | Key: BeltBlock, 14 | beltblock_decrypt_block, 15 | beltblock_decrypt_blocks, 16 | ); 17 | -------------------------------------------------------------------------------- /blowfish/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 | 8 | ## 0.10.0 (UNRELEASED) 9 | ### Changed 10 | - Bump `cipher` dependency to v0.5.0 11 | - Edition changed to 2024 and MSRV bumped to 1.85 ([#472]) 12 | - Relax MSRV policy and allow MSRV bumps in patch releases ([#477]) 13 | 14 | [#472]: https://github.com/RustCrypto/block-ciphers/pull/472 15 | [#477]: https://github.com/RustCrypto/block-ciphers/pull/477 16 | 17 | ## 0.9.1 (2022-02-17) 18 | ### Fixed 19 | - Minimal versions build ([#303]) 20 | 21 | [#303]: https://github.com/RustCrypto/block-ciphers/pull/303 22 | 23 | ## 0.9.0 (2022-02-10) 24 | ### Changed 25 | - Bump `cipher` dependency to v0.4 ([#284]) 26 | 27 | [#284]: https://github.com/RustCrypto/block-ciphers/pull/284 28 | 29 | ## 0.8.0 (2021-04-29) 30 | ### Changed 31 | - Bump `cipher` dependency to v0.3 ([#235]) 32 | 33 | [#235]: https://github.com/RustCrypto/block-ciphers/pull/235 34 | 35 | ## 0.7.0 (2020-10-16) 36 | ### Changed 37 | - Replace `block-cipher`/`stream-cipher` with `cipher` crate ([#167]) 38 | 39 | [#167]: https://github.com/RustCrypto/block-ciphers/pull/167 40 | 41 | ## 0.6.0 (2020-08-07) 42 | ### Changed 43 | - Bump `block-cipher` dependency to v0.8 ([#138]) 44 | - Bump `opaque-debug` dependency to v0.3 ([#140]) 45 | 46 | [#138]: https://github.com/RustCrypto/block-ciphers/pull/138 47 | [#140]: https://github.com/RustCrypto/block-ciphers/pull/140 48 | 49 | ## 0.5.0 (2020-06-08) 50 | ### Changed 51 | - Bump `block-cipher` dependency to v0.7 ([#88]) 52 | - Upgrade to Rust 2018 edition ([#88]) 53 | 54 | [#88]: https://github.com/RustCrypto/block-ciphers/pull/88 55 | 56 | ## 0.4.0 (2018-12-23) 57 | 58 | ## 0.3.1 (2018-12-17) 59 | 60 | ## 0.3.0 (2017-11-26) 61 | 62 | ## 0.2.1 (2016-12-16) 63 | 64 | ## 0.1.0 (2016-12-16) 65 | -------------------------------------------------------------------------------- /blowfish/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "blowfish" 3 | version = "0.10.0-rc.0" 4 | description = "Blowfish block cipher" 5 | authors = ["RustCrypto Developers"] 6 | license = "MIT OR Apache-2.0" 7 | edition = "2024" 8 | rust-version = "1.85" 9 | readme = "README.md" 10 | documentation = "https://docs.rs/blowfish" 11 | repository = "https://github.com/RustCrypto/block-ciphers" 12 | keywords = ["crypto", "blowfish", "block-cipher"] 13 | categories = ["cryptography", "no-std"] 14 | 15 | [dependencies] 16 | cipher = "0.5.0-rc.0" 17 | byteorder = { version = "1.1", default-features = false } 18 | 19 | [dev-dependencies] 20 | cipher = { version = "0.5.0-rc.0", features = ["dev"] } 21 | 22 | [features] 23 | bcrypt = [] 24 | zeroize = ["cipher/zeroize"] 25 | 26 | [package.metadata.docs.rs] 27 | all-features = true 28 | rustdoc-args = ["--cfg", "docsrs"] 29 | -------------------------------------------------------------------------------- /blowfish/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016-2024 The RustCrypto Project Developers 2 | 3 | Permission is hereby granted, free of charge, to any 4 | person obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the 6 | Software without restriction, including without 7 | limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software 10 | is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice 14 | shall be included in all copies or substantial portions 15 | of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 18 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 19 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 24 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /blowfish/README.md: -------------------------------------------------------------------------------- 1 | # RustCrypto: Blowfish Cipher 2 | 3 | [![crate][crate-image]][crate-link] 4 | [![Docs][docs-image]][docs-link] 5 | ![Apache2/MIT licensed][license-image] 6 | ![Rust Version][rustc-image] 7 | [![Project Chat][chat-image]][chat-link] 8 | [![Build Status][build-image]][build-link] 9 | [![HAZMAT][hazmat-image]][hazmat-link] 10 | 11 | Pure Rust implementation of the [Blowfish block cipher][1]. 12 | 13 | ## ⚠️ Security Warning: [Hazmat!][hazmat-link] 14 | 15 | This crate does not ensure ciphertexts are authentic (i.e. by using a MAC to 16 | verify ciphertext integrity), which can lead to serious vulnerabilities 17 | if used incorrectly! 18 | 19 | No security audits of this crate have ever been performed, and it has not been 20 | thoroughly assessed to ensure its operation is constant-time on common CPU 21 | architectures. 22 | 23 | USE AT YOUR OWN RISK! 24 | 25 | ## License 26 | 27 | Licensed under either of: 28 | 29 | * [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) 30 | * [MIT license](http://opensource.org/licenses/MIT) 31 | 32 | at your option. 33 | 34 | ### Contribution 35 | 36 | Unless you explicitly state otherwise, any contribution intentionally submitted 37 | for inclusion in the work by you, as defined in the Apache-2.0 license, shall be 38 | dual licensed as above, without any additional terms or conditions. 39 | 40 | [//]: # (badges) 41 | 42 | [crate-image]: https://img.shields.io/crates/v/blowfish.svg 43 | [crate-link]: https://crates.io/crates/blowfish 44 | [docs-image]: https://docs.rs/blowfish/badge.svg 45 | [docs-link]: https://docs.rs/blowfish/ 46 | [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg 47 | [rustc-image]: https://img.shields.io/badge/rustc-1.85+-blue.svg 48 | [hazmat-image]: https://img.shields.io/badge/crypto-hazmat%E2%9A%A0-red.svg 49 | [hazmat-link]: https://github.com/RustCrypto/meta/blob/master/HAZMAT.md 50 | [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg 51 | [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260039-block-ciphers 52 | [build-image]: https://github.com/RustCrypto/block-ciphers/workflows/blowfish/badge.svg?branch=master&event=push 53 | [build-link]: https://github.com/RustCrypto/block-ciphers/actions?query=workflow%3Ablowfish 54 | 55 | [//]: # (general links) 56 | 57 | [1]: https://en.wikipedia.org/wiki/Blowfish_(cipher) 58 | -------------------------------------------------------------------------------- /blowfish/benches/mod.rs: -------------------------------------------------------------------------------- 1 | #![feature(test)] 2 | extern crate test; 3 | 4 | use blowfish::Blowfish; 5 | use cipher::{block_decryptor_bench, block_encryptor_bench}; 6 | 7 | block_encryptor_bench!( 8 | Key: Blowfish, 9 | blowfish_encrypt_block, 10 | blowfish_encrypt_blocks, 11 | ); 12 | block_decryptor_bench!( 13 | Key: Blowfish, 14 | blowfish_decrypt_block, 15 | blowfish_decrypt_blocks, 16 | ); 17 | -------------------------------------------------------------------------------- /blowfish/tests/data/blowfish.blb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustCrypto/block-ciphers/73b104d31747ff763de345372ceab6eeffd04319/blowfish/tests/data/blowfish.blb -------------------------------------------------------------------------------- /blowfish/tests/data/blowfish_le.blb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustCrypto/block-ciphers/73b104d31747ff763de345372ceab6eeffd04319/blowfish/tests/data/blowfish_le.blb -------------------------------------------------------------------------------- /blowfish/tests/mod.rs: -------------------------------------------------------------------------------- 1 | cipher::block_cipher_test!(blowfish_test, "blowfish", blowfish::Blowfish); 2 | // Tests for BlowfishLE were randomly generated using implementation in this crate 3 | cipher::block_cipher_test!(blowfish_le_test, "blowfish_le", blowfish::BlowfishLE); 4 | -------------------------------------------------------------------------------- /camellia/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 | 8 | ## 0.2.0 (UNRELEASED) 9 | ### Changed 10 | - Bump `cipher` dependency to v0.5.0 11 | - Edition changed to 2024 and MSRV bumped to 1.85 ([#472]) 12 | - Relax MSRV policy and allow MSRV bumps in patch releases ([#477]) 13 | 14 | [#472]: https://github.com/RustCrypto/block-ciphers/pull/472 15 | [#477]: https://github.com/RustCrypto/block-ciphers/pull/477 16 | 17 | ## 0.1.0 (2022-09-26) 18 | - Initial release ([#293]) 19 | 20 | [#293]: https://github.com/RustCrypto/block-ciphers/pull/293 21 | -------------------------------------------------------------------------------- /camellia/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "camellia" 3 | version = "0.2.0-pre" 4 | description = "Camellia block cipher" 5 | authors = ["RustCrypto Developers"] 6 | license = "MIT OR Apache-2.0" 7 | edition = "2024" 8 | rust-version = "1.85" 9 | readme = "README.md" 10 | documentation = "https://docs.rs/camellia" 11 | repository = "https://github.com/RustCrypto/block-ciphers" 12 | keywords = ["crypto", "camellia", "block-cipher"] 13 | categories = ["cryptography", "no-std"] 14 | 15 | [dependencies] 16 | byteorder = { version = "1.1", default-features = false } 17 | cipher = "0.5.0-rc.0" 18 | 19 | [dev-dependencies] 20 | cipher = { version = "0.5.0-rc.0", features = ["dev"] } 21 | 22 | [features] 23 | zeroize = ["cipher/zeroize"] 24 | 25 | [package.metadata.docs.rs] 26 | all-features = true 27 | rustdoc-args = ["--cfg", "docsrs"] 28 | -------------------------------------------------------------------------------- /camellia/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2021-2024 The RustCrypto Project Developers 2 | Copyright (c) 2021 Shun Sakai 3 | 4 | Permission is hereby granted, free of charge, to any 5 | person obtaining a copy of this software and associated 6 | documentation files (the "Software"), to deal in the 7 | Software without restriction, including without 8 | limitation the rights to use, copy, modify, merge, 9 | publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software 11 | is furnished to do so, subject to the following 12 | conditions: 13 | 14 | The above copyright notice and this permission notice 15 | shall be included in all copies or substantial portions 16 | of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 19 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 20 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 21 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 22 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 25 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 | DEALINGS IN THE SOFTWARE. 27 | -------------------------------------------------------------------------------- /camellia/README.md: -------------------------------------------------------------------------------- 1 | # RustCrypto: Camellia Cipher 2 | 3 | [![crate][crate-image]][crate-link] 4 | [![Docs][docs-image]][docs-link] 5 | ![Apache2/MIT licensed][license-image] 6 | ![Rust Version][rustc-image] 7 | [![Project Chat][chat-image]][chat-link] 8 | [![Build Status][build-image]][build-link] 9 | [![HAZMAT][hazmat-image]][hazmat-link] 10 | 11 | Pure Rust implementation of the [Camellia block cipher][1]. 12 | 13 | ## ⚠️ Security Warning: [Hazmat!][hazmat-link] 14 | 15 | This crate does not ensure ciphertexts are authentic (i.e. by using a MAC to 16 | verify ciphertext integrity), which can lead to serious vulnerabilities 17 | if used incorrectly! 18 | 19 | No security audits of this crate have ever been performed, and it has not been 20 | thoroughly assessed to ensure its operation is constant-time on common CPU 21 | architectures. 22 | 23 | USE AT YOUR OWN RISK! 24 | 25 | ## License 26 | 27 | Licensed under either of: 28 | 29 | * [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) 30 | * [MIT license](http://opensource.org/licenses/MIT) 31 | 32 | at your option. 33 | 34 | ### Contribution 35 | 36 | Unless you explicitly state otherwise, any contribution intentionally submitted 37 | for inclusion in the work by you, as defined in the Apache-2.0 license, shall be 38 | dual licensed as above, without any additional terms or conditions. 39 | 40 | [//]: # (badges) 41 | 42 | [crate-image]: https://img.shields.io/crates/v/camellia.svg 43 | [crate-link]: https://crates.io/crates/camellia 44 | [docs-image]: https://docs.rs/camellia/badge.svg 45 | [docs-link]: https://docs.rs/camellia/ 46 | [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg 47 | [rustc-image]: https://img.shields.io/badge/rustc-1.85+-blue.svg 48 | [hazmat-image]: https://img.shields.io/badge/crypto-hazmat%E2%9A%A0-red.svg 49 | [hazmat-link]: https://github.com/RustCrypto/meta/blob/master/HAZMAT.md 50 | [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg 51 | [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260039-block-ciphers 52 | [build-image]: https://github.com/RustCrypto/block-ciphers/workflows/camellia/badge.svg?branch=master&event=push 53 | [build-link]: https://github.com/RustCrypto/block-ciphers/actions?query=workflow%3Acamellia 54 | 55 | [//]: # (general links) 56 | 57 | [1]: https://en.wikipedia.org/wiki/Camellia_(cipher) 58 | -------------------------------------------------------------------------------- /camellia/benches/mod.rs: -------------------------------------------------------------------------------- 1 | #![feature(test)] 2 | extern crate test; 3 | 4 | use camellia::{Camellia128, Camellia192, Camellia256}; 5 | use cipher::{block_decryptor_bench, block_encryptor_bench}; 6 | 7 | block_encryptor_bench!( 8 | Key: Camellia128, 9 | camellia128_encrypt_block, 10 | camellia128_encrypt_blocks 11 | ); 12 | block_decryptor_bench!( 13 | Key: Camellia128, 14 | camellia128_decrypt_block, 15 | camellia128_decrypt_blocks 16 | ); 17 | 18 | block_encryptor_bench!( 19 | Key: Camellia192, 20 | camellia192_encrypt_block, 21 | camellia192_encrypt_blocks 22 | ); 23 | block_decryptor_bench!( 24 | Key: Camellia192, 25 | camellia192_decrypt_block, 26 | camellia192_decrypt_blocks 27 | ); 28 | 29 | block_encryptor_bench!( 30 | Key: Camellia256, 31 | camellia256_encrypt_block, 32 | camellia256_encrypt_blocks 33 | ); 34 | block_decryptor_bench!( 35 | Key: Camellia256, 36 | camellia256_decrypt_block, 37 | camellia256_decrypt_blocks 38 | ); 39 | -------------------------------------------------------------------------------- /camellia/src/camellia128.rs: -------------------------------------------------------------------------------- 1 | use crate::{ 2 | Camellia128, 3 | utils::{gen_subkeys26, set_ka}, 4 | }; 5 | use cipher::{AlgorithmName, Key, KeyInit}; 6 | use core::{fmt, marker::PhantomData}; 7 | 8 | impl KeyInit for Camellia128 { 9 | fn new(key: &Key) -> Self { 10 | let kl = ( 11 | u64::from_be_bytes(key[0..8].try_into().unwrap()), 12 | u64::from_be_bytes(key[8..16].try_into().unwrap()), 13 | ); 14 | let kr = (u64::default(), u64::default()); 15 | 16 | let ka = set_ka(kl, kr); 17 | 18 | Self { 19 | k: gen_subkeys26(kl, ka), 20 | _pd: PhantomData, 21 | } 22 | } 23 | } 24 | 25 | impl fmt::Debug for Camellia128 { 26 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 27 | f.write_str("Camellia128 { ... }") 28 | } 29 | } 30 | 31 | impl AlgorithmName for Camellia128 { 32 | fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result { 33 | f.write_str("Camellia128") 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /camellia/src/camellia192.rs: -------------------------------------------------------------------------------- 1 | use crate::{ 2 | Camellia192, 3 | utils::{get_subkeys34, set_ka, set_kb}, 4 | }; 5 | use cipher::{AlgorithmName, Key, KeyInit}; 6 | use core::{fmt, marker::PhantomData}; 7 | 8 | impl KeyInit for Camellia192 { 9 | fn new(key: &Key) -> Self { 10 | let kl = ( 11 | u64::from_be_bytes(key[0..8].try_into().unwrap()), 12 | u64::from_be_bytes(key[8..16].try_into().unwrap()), 13 | ); 14 | let kr = u64::from_be_bytes(key[16..24].try_into().unwrap()); 15 | let kr = (kr, !kr); 16 | 17 | let ka = set_ka(kl, kr); 18 | let kb = set_kb(ka, kr); 19 | 20 | Self { 21 | k: get_subkeys34(kl, kr, ka, kb), 22 | _pd: PhantomData, 23 | } 24 | } 25 | } 26 | 27 | impl fmt::Debug for Camellia192 { 28 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 29 | f.write_str("Camellia192 { ... }") 30 | } 31 | } 32 | 33 | impl AlgorithmName for Camellia192 { 34 | fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result { 35 | f.write_str("Camellia192") 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /camellia/src/camellia256.rs: -------------------------------------------------------------------------------- 1 | use crate::{ 2 | Camellia256, 3 | utils::{get_subkeys34, set_ka, set_kb}, 4 | }; 5 | use cipher::{AlgorithmName, Key, KeyInit}; 6 | use core::{fmt, marker::PhantomData}; 7 | 8 | impl KeyInit for Camellia256 { 9 | fn new(key: &Key) -> Self { 10 | let kl = ( 11 | u64::from_be_bytes(key[0..8].try_into().unwrap()), 12 | u64::from_be_bytes(key[8..16].try_into().unwrap()), 13 | ); 14 | let kr = ( 15 | u64::from_be_bytes(key[16..24].try_into().unwrap()), 16 | u64::from_be_bytes(key[24..32].try_into().unwrap()), 17 | ); 18 | 19 | let ka = set_ka(kl, kr); 20 | let kb = set_kb(ka, kr); 21 | 22 | Self { 23 | k: get_subkeys34(kl, kr, ka, kb), 24 | _pd: PhantomData, 25 | } 26 | } 27 | } 28 | 29 | impl fmt::Debug for Camellia256 { 30 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 31 | f.write_str("Camellia256 { ... }") 32 | } 33 | } 34 | 35 | impl AlgorithmName for Camellia256 { 36 | fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result { 37 | f.write_str("Camellia256") 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /camellia/tests/data/camellia128.blb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustCrypto/block-ciphers/73b104d31747ff763de345372ceab6eeffd04319/camellia/tests/data/camellia128.blb -------------------------------------------------------------------------------- /camellia/tests/data/camellia192.blb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustCrypto/block-ciphers/73b104d31747ff763de345372ceab6eeffd04319/camellia/tests/data/camellia192.blb -------------------------------------------------------------------------------- /camellia/tests/data/camellia256.blb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustCrypto/block-ciphers/73b104d31747ff763de345372ceab6eeffd04319/camellia/tests/data/camellia256.blb -------------------------------------------------------------------------------- /camellia/tests/mod.rs: -------------------------------------------------------------------------------- 1 | //! Test vectors are from NESSIE: 2 | //! 3 | 4 | cipher::block_cipher_test!(camellia128_test, "camellia128", camellia::Camellia128); 5 | cipher::block_cipher_test!(camellia192_test, "camellia192", camellia::Camellia192); 6 | cipher::block_cipher_test!(camellia256_test, "camellia256", camellia::Camellia256); 7 | -------------------------------------------------------------------------------- /cast5/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 | 8 | ## 0.12.0 (UNRELEASED) 9 | ### Changed 10 | - Bump `cipher` dependency to v0.5.0 11 | - Edition changed to 2024 and MSRV bumped to 1.85 ([#472]) 12 | - Relax MSRV policy and allow MSRV bumps in patch releases ([#477]) 13 | 14 | [#472]: https://github.com/RustCrypto/block-ciphers/pull/472 15 | [#477]: https://github.com/RustCrypto/block-ciphers/pull/477 16 | 17 | ## 0.11.1 (2022-02-17) 18 | ### Fixed 19 | - Minimal versions build ([#303]) 20 | 21 | [#303]: https://github.com/RustCrypto/block-ciphers/pull/303 22 | 23 | ## 0.11.0 (2022-02-10) 24 | ### Changed 25 | - Bump `cipher` dependency to v0.4 ([#284]) 26 | 27 | [#284]: https://github.com/RustCrypto/block-ciphers/pull/284 28 | 29 | ## 0.10.0 (2021-04-29) 30 | ### Changed 31 | - Bump `cipher` dependency to v0.3 ([#235]) 32 | 33 | [#235]: https://github.com/RustCrypto/block-ciphers/pull/235 34 | 35 | ## 0.9.0 (2020-10-16) 36 | ### Changed 37 | - Replace `block-cipher`/`stream-cipher` with `cipher` crate ([#167]) 38 | 39 | [#167]: https://github.com/RustCrypto/block-ciphers/pull/167 40 | 41 | ## 0.8.0 (2020-08-07) 42 | ### Changed 43 | - Bump `block-cipher` dependency to v0.8 ([#138]) 44 | - Bump `opaque-debug` dependency to v0.3 ([#140]) 45 | 46 | [#138]: https://github.com/RustCrypto/block-ciphers/pull/138 47 | [#140]: https://github.com/RustCrypto/block-ciphers/pull/140 48 | 49 | ## 0.7.0 (2020-06-08) 50 | ### Changed 51 | - Bump `block-cipher` dependency to v0.7 ([#89]) 52 | - Upgrade to Rust 2018 edition ([#89]) 53 | 54 | [#89]: https://github.com/RustCrypto/block-ciphers/pull/89 55 | 56 | ## 0.6.0 (2019-03-11) 57 | - Initial release 58 | -------------------------------------------------------------------------------- /cast5/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cast5" 3 | version = "0.12.0-pre" 4 | description = "CAST5 block cipher" 5 | authors = ["RustCrypto Developers"] 6 | license = "MIT OR Apache-2.0" 7 | edition = "2024" 8 | rust-version = "1.85" 9 | readme = "README.md" 10 | documentation = "https://docs.rs/cast5" 11 | repository = "https://github.com/RustCrypto/block-ciphers" 12 | keywords = ["crypto", "cast5", "block-cipher"] 13 | categories = ["cryptography", "no-std"] 14 | 15 | [dependencies] 16 | cipher = "0.5.0-rc.0" 17 | 18 | [dev-dependencies] 19 | cipher = { version = "0.5.0-rc.0", features = ["dev"] } 20 | hex-literal = "1" 21 | 22 | [features] 23 | zeroize = ["cipher/zeroize"] 24 | 25 | [package.metadata.docs.rs] 26 | all-features = true 27 | rustdoc-args = ["--cfg", "docsrs"] 28 | -------------------------------------------------------------------------------- /cast5/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018-2024 The RustCrypto Project Developers 2 | Copyright (c) 2018-2019 Friedel Ziegelmayer 3 | 4 | Permission is hereby granted, free of charge, to any 5 | person obtaining a copy of this software and associated 6 | documentation files (the "Software"), to deal in the 7 | Software without restriction, including without 8 | limitation the rights to use, copy, modify, merge, 9 | publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software 11 | is furnished to do so, subject to the following 12 | conditions: 13 | 14 | The above copyright notice and this permission notice 15 | shall be included in all copies or substantial portions 16 | of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 19 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 20 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 21 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 22 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 25 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 | DEALINGS IN THE SOFTWARE. 27 | -------------------------------------------------------------------------------- /cast5/README.md: -------------------------------------------------------------------------------- 1 | # RustCrypto: CAST5 Cipher 2 | 3 | [![crate][crate-image]][crate-link] 4 | [![Docs][docs-image]][docs-link] 5 | ![Apache2/MIT licensed][license-image] 6 | ![Rust Version][rustc-image] 7 | [![Project Chat][chat-image]][chat-link] 8 | [![Build Status][build-image]][build-link] 9 | [![HAZMAT][hazmat-image]][hazmat-link] 10 | 11 | Pure Rust implementation of the [CAST5 block cipher][1]. 12 | 13 | 14 | 15 | ## ⚠️ Security Warning: [Hazmat!][hazmat-link] 16 | 17 | This crate does not ensure ciphertexts are authentic (i.e. by using a MAC to 18 | verify ciphertext integrity), which can lead to serious vulnerabilities 19 | if used incorrectly! 20 | 21 | No security audits of this crate have ever been performed, and it has not been 22 | thoroughly assessed to ensure its operation is constant-time on common CPU 23 | architectures. 24 | 25 | USE AT YOUR OWN RISK! 26 | 27 | ## License 28 | 29 | Licensed under either of: 30 | 31 | * [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) 32 | * [MIT license](http://opensource.org/licenses/MIT) 33 | 34 | at your option. 35 | 36 | ### Contribution 37 | 38 | Unless you explicitly state otherwise, any contribution intentionally submitted 39 | for inclusion in the work by you, as defined in the Apache-2.0 license, shall be 40 | dual licensed as above, without any additional terms or conditions. 41 | 42 | [//]: # (badges) 43 | 44 | [crate-image]: https://img.shields.io/crates/v/cast5.svg 45 | [crate-link]: https://crates.io/crates/cast5 46 | [docs-image]: https://docs.rs/cast5/badge.svg 47 | [docs-link]: https://docs.rs/cast5/ 48 | [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg 49 | [rustc-image]: https://img.shields.io/badge/rustc-1.85+-blue.svg 50 | [hazmat-image]: https://img.shields.io/badge/crypto-hazmat%E2%9A%A0-red.svg 51 | [hazmat-link]: https://github.com/RustCrypto/meta/blob/master/HAZMAT.md 52 | [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg 53 | [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260039-block-ciphers 54 | [build-image]: https://github.com/RustCrypto/block-ciphers/workflows/cast5/badge.svg?branch=master&event=push 55 | [build-link]: https://github.com/RustCrypto/block-ciphers/actions?query=workflow%3Acast5 56 | 57 | [//]: # (general links) 58 | 59 | [1]: https://en.wikipedia.org/wiki/CAST-128 60 | -------------------------------------------------------------------------------- /cast5/benches/mod.rs: -------------------------------------------------------------------------------- 1 | #![feature(test)] 2 | extern crate test; 3 | 4 | use cast5::Cast5; 5 | use cipher::{block_decryptor_bench, block_encryptor_bench}; 6 | 7 | block_encryptor_bench!(Key: Cast5, cast5_encrypt_block, cast5_encrypt_blocks); 8 | block_decryptor_bench!(Key: Cast5, cast5_decrypt_block, cast5_decrypt_blocks); 9 | -------------------------------------------------------------------------------- /cast5/tests/data/cast5.blb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustCrypto/block-ciphers/73b104d31747ff763de345372ceab6eeffd04319/cast5/tests/data/cast5.blb -------------------------------------------------------------------------------- /cast6/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 | 8 | ## 0.2.0 (UNRELEASED) 9 | ### Changed 10 | - Bump `cipher` dependency to v0.5.0 11 | - Edition changed to 2024 and MSRV bumped to 1.85 ([#472]) 12 | - Relax MSRV policy and allow MSRV bumps in patch releases ([#477]) 13 | 14 | [#472]: https://github.com/RustCrypto/block-ciphers/pull/472 15 | [#477]: https://github.com/RustCrypto/block-ciphers/pull/477 16 | 17 | ## 0.1.0 (2023-11-22) 18 | - Initial release 19 | -------------------------------------------------------------------------------- /cast6/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cast6" 3 | version = "0.2.0-pre" 4 | description = "CAST6 block cipher" 5 | authors = ["RustCrypto Developers"] 6 | license = "MIT OR Apache-2.0" 7 | edition = "2024" 8 | rust-version = "1.85" 9 | readme = "README.md" 10 | documentation = "https://docs.rs/cast6" 11 | repository = "https://github.com/RustCrypto/block-ciphers" 12 | keywords = ["crypto", "cast6", "block-cipher"] 13 | categories = ["cryptography", "no-std"] 14 | 15 | [dependencies] 16 | cipher = "0.5.0-rc.0" 17 | 18 | [dev-dependencies] 19 | cipher = { version = "0.5.0-rc.0", features = ["dev"] } 20 | hex-literal = "1" 21 | 22 | [features] 23 | zeroize = ["cipher/zeroize"] 24 | 25 | [package.metadata.docs.rs] 26 | all-features = true 27 | rustdoc-args = ["--cfg", "docsrs"] 28 | -------------------------------------------------------------------------------- /cast6/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2023-2024 The RustCrypto Project Developers 2 | 3 | Permission is hereby granted, free of charge, to any 4 | person obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the 6 | Software without restriction, including without 7 | limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software 10 | is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice 14 | shall be included in all copies or substantial portions 15 | of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 18 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 19 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 24 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /cast6/README.md: -------------------------------------------------------------------------------- 1 | # RustCrypto: CAST6 Cipher 2 | 3 | [![crate][crate-image]][crate-link] 4 | [![Docs][docs-image]][docs-link] 5 | ![Apache2/MIT licensed][license-image] 6 | ![Rust Version][rustc-image] 7 | [![Project Chat][chat-image]][chat-link] 8 | [![Build Status][build-image]][build-link] 9 | [![HAZMAT][hazmat-image]][hazmat-link] 10 | 11 | Pure Rust implementation of the [CAST6 block cipher][1]. 12 | 13 | ## ⚠️ Security Warning: [Hazmat!][hazmat-link] 14 | 15 | This crate does not ensure ciphertexts are authentic (i.e. by using a MAC to 16 | verify ciphertext integrity), which can lead to serious vulnerabilities 17 | if used incorrectly! 18 | 19 | No security audits of this crate have ever been performed, and it has not been 20 | thoroughly assessed to ensure its operation is constant-time on common CPU 21 | architectures. 22 | 23 | USE AT YOUR OWN RISK! 24 | 25 | ## License 26 | 27 | Licensed under either of: 28 | 29 | * [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) 30 | * [MIT license](http://opensource.org/licenses/MIT) 31 | 32 | at your option. 33 | 34 | ### Contribution 35 | 36 | Unless you explicitly state otherwise, any contribution intentionally submitted 37 | for inclusion in the work by you, as defined in the Apache-2.0 license, shall be 38 | dual licensed as above, without any additional terms or conditions. 39 | 40 | [//]: # (badges) 41 | 42 | [crate-image]: https://img.shields.io/crates/v/cast6.svg 43 | [crate-link]: https://crates.io/crates/cast6 44 | [docs-image]: https://docs.rs/cast6/badge.svg 45 | [docs-link]: https://docs.rs/cast6/ 46 | [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg 47 | [rustc-image]: https://img.shields.io/badge/rustc-1.85+-blue.svg 48 | [hazmat-image]: https://img.shields.io/badge/crypto-hazmat%E2%9A%A0-red.svg 49 | [hazmat-link]: https://github.com/RustCrypto/meta/blob/master/HAZMAT.md 50 | [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg 51 | [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260039-block-ciphers 52 | [build-image]: https://github.com/RustCrypto/block-ciphers/workflows/cast6/badge.svg?branch=master&event=push 53 | [build-link]: https://github.com/RustCrypto/block-ciphers/actions?query=workflow%3Acast6 54 | 55 | [//]: # (general links) 56 | 57 | [1]: https://en.wikipedia.org/wiki/CAST-256 58 | -------------------------------------------------------------------------------- /cast6/benches/mod.rs: -------------------------------------------------------------------------------- 1 | #![feature(test)] 2 | extern crate test; 3 | 4 | use cast6::Cast6; 5 | use cipher::{block_decryptor_bench, block_encryptor_bench}; 6 | 7 | block_encryptor_bench!(Key: Cast6, cast6_encrypt_block, cast6_encrypt_blocks); 8 | block_decryptor_bench!(Key: Cast6, cast6_decrypt_block, cast6_decrypt_blocks); 9 | -------------------------------------------------------------------------------- /cast6/tests/mod.rs: -------------------------------------------------------------------------------- 1 | use cast6::Cast6; 2 | use cipher::{Block, BlockCipherDecrypt, BlockCipherEncrypt, KeyInit}; 3 | use hex_literal::hex; 4 | 5 | /// Test vectors from RFC 2612 Appendix A 6 | /// https://tools.ietf.org/html/rfc2612#page-10 7 | #[test] 8 | fn rfc2144_a() { 9 | let key128 = hex!("2342bb9efa38542c0af75647f29f615d"); 10 | let key192 = hex!("2342bb9efa38542cbed0ac83940ac298bac77a7717942863"); 11 | let key256 = hex!("2342bb9efa38542cbed0ac83940ac2988d7c47ce264908461cc1b5137ae6b604"); 12 | let ct128 = hex!("c842a08972b43d20836c91d1b7530f6b"); 13 | let ct192 = hex!("1b386c0210dcadcbdd0e41aa08a7a7e8"); 14 | let ct256 = hex!("4f6a2038286897b9c9870136553317fa"); 15 | let pt = Block::::default(); 16 | 17 | let mut buf = pt; 18 | 19 | let c = Cast6::new_from_slice(&key128).unwrap(); 20 | c.encrypt_block(&mut buf); 21 | assert_eq!(buf, ct128); 22 | c.decrypt_block(&mut buf); 23 | assert_eq!(buf, pt); 24 | 25 | let c = Cast6::new_from_slice(&key192).unwrap(); 26 | c.encrypt_block(&mut buf); 27 | assert_eq!(buf, ct192); 28 | c.decrypt_block(&mut buf); 29 | assert_eq!(buf, pt); 30 | 31 | let c = Cast6::new_from_slice(&key256).unwrap(); 32 | c.encrypt_block(&mut buf); 33 | assert_eq!(buf, ct256); 34 | c.decrypt_block(&mut buf); 35 | assert_eq!(buf, pt); 36 | } 37 | -------------------------------------------------------------------------------- /des/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 | 8 | ## 0.9.0 (UNRELEASED) 9 | ### Added 10 | - Weak key detection in the `KeyInit::weak_key_test` method ([#465], [#468], [#469], [#470]) 11 | 12 | ### Changed 13 | - Bump `cipher` dependency to v0.5.0 14 | - Edition changed to 2024 and MSRV bumped to 1.85 ([#472]) 15 | - Relax MSRV policy and allow MSRV bumps in patch releases ([#477]) 16 | 17 | [#465]: https://github.com/RustCrypto/block-ciphers/pull/465 18 | [#468]: https://github.com/RustCrypto/block-ciphers/pull/468 19 | [#469]: https://github.com/RustCrypto/block-ciphers/pull/469 20 | [#470]: https://github.com/RustCrypto/block-ciphers/pull/470 21 | [#472]: https://github.com/RustCrypto/block-ciphers/pull/472 22 | [#477]: https://github.com/RustCrypto/block-ciphers/pull/477 23 | 24 | ## 0.8.1 (2022-02-17) 25 | ### Fixed 26 | - Minimal versions build ([#303]) 27 | 28 | [#303]: https://github.com/RustCrypto/block-ciphers/pull/303 29 | 30 | ## 0.8.0 (2022-02-10) 31 | ### Changed 32 | - Bump `cipher` dependency to v0.4 ([#284]) 33 | 34 | [#284]: https://github.com/RustCrypto/block-ciphers/pull/284 35 | 36 | ## 0.7.0 (2021-04-29) 37 | ### Changed 38 | - Bump `cipher` dependency to v0.3 ([#235]) 39 | 40 | [#235]: https://github.com/RustCrypto/block-ciphers/pull/235 41 | 42 | ## 0.6.0 (2020-10-16) 43 | ### Changed 44 | - Replace `block-cipher`/`stream-cipher` with `cipher` crate ([#167]) 45 | 46 | [#167]: https://github.com/RustCrypto/block-ciphers/pull/167 47 | 48 | ## 0.5.0 (2020-08-07) 49 | ### Changed 50 | - Bump `block-cipher` dependency to v0.8 ([#138]) 51 | - Bump `opaque-debug` dependency to v0.3 ([#140]) 52 | 53 | [#138]: https://github.com/RustCrypto/block-ciphers/pull/138 54 | [#140]: https://github.com/RustCrypto/block-ciphers/pull/140 55 | 56 | ## 0.4.0 (2020-06-08) 57 | ### Changed 58 | - Bump `block-cipher` dependency to v0.7 ([#90]) 59 | - Upgrade to Rust 2018 edition ([#90]) 60 | 61 | [#90]: https://github.com/RustCrypto/block-ciphers/pull/90 62 | 63 | ## 0.3.0 (2018-12-23) 64 | 65 | ## 0.2.0 (2018-11-14) 66 | 67 | ## 0.1.0 (2017-11-26) 68 | 69 | ## 0.0.4 (2017-01-18) 70 | 71 | ## 0.0.3 (2016-08-27) 72 | 73 | ## 0.0.2 (2016-08-10) 74 | 75 | ## 0.0.1 (2016-04-24) 76 | -------------------------------------------------------------------------------- /des/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "des" 3 | version = "0.9.0-rc.0" 4 | description = "DES and Triple DES (3DES, TDES) block ciphers implementation" 5 | authors = ["RustCrypto Developers"] 6 | license = "MIT OR Apache-2.0" 7 | edition = "2024" 8 | rust-version = "1.85" 9 | readme = "README.md" 10 | documentation = "https://docs.rs/des" 11 | repository = "https://github.com/RustCrypto/block-ciphers" 12 | keywords = ["crypto", "des", "tdes", "block-cipher"] 13 | categories = ["cryptography", "no-std"] 14 | 15 | [dependencies] 16 | cipher = "0.5.0-rc.0" 17 | 18 | [dev-dependencies] 19 | cipher = { version = "0.5.0-rc.0", features = ["dev"] } 20 | hex-literal = "1" 21 | 22 | [features] 23 | zeroize = ["cipher/zeroize"] 24 | 25 | [package.metadata.docs.rs] 26 | all-features = true 27 | rustdoc-args = ["--cfg", "docsrs"] 28 | -------------------------------------------------------------------------------- /des/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017-2024 The RustCrypto Project Developers 2 | Copyright (c) 2017 Gulshan Singh, Antoni Boucher, Artyom Pavlov 3 | 4 | Permission is hereby granted, free of charge, to any 5 | person obtaining a copy of this software and associated 6 | documentation files (the "Software"), to deal in the 7 | Software without restriction, including without 8 | limitation the rights to use, copy, modify, merge, 9 | publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software 11 | is furnished to do so, subject to the following 12 | conditions: 13 | 14 | The above copyright notice and this permission notice 15 | shall be included in all copies or substantial portions 16 | of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 19 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 20 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 21 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 22 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 25 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 | DEALINGS IN THE SOFTWARE. 27 | -------------------------------------------------------------------------------- /des/README.md: -------------------------------------------------------------------------------- 1 | # RustCrypto: Data Encryption Standard (DES) and 3DES 2 | 3 | [![crate][crate-image]][crate-link] 4 | [![Docs][docs-image]][docs-link] 5 | ![Apache2/MIT licensed][license-image] 6 | ![Rust Version][rustc-image] 7 | [![Project Chat][chat-image]][chat-link] 8 | [![Build Status][build-image]][build-link] 9 | [![HAZMAT][hazmat-image]][hazmat-link] 10 | 11 | Pure Rust implementation of the [DES cipher][1], including triple DES (3DES). 12 | 13 | 14 | 15 | ## ⚠️ Security Warning: [Hazmat!][hazmat-link] 16 | 17 | This crate does not ensure ciphertexts are authentic (i.e. by using a MAC to 18 | verify ciphertext integrity), which can lead to serious vulnerabilities 19 | if used incorrectly! 20 | 21 | No security audits of this crate have ever been performed, and it has not been 22 | thoroughly assessed to ensure its operation is constant-time on common CPU 23 | architectures. 24 | 25 | USE AT YOUR OWN RISK! 26 | 27 | ## License 28 | 29 | Licensed under either of: 30 | 31 | * [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) 32 | * [MIT license](http://opensource.org/licenses/MIT) 33 | 34 | at your option. 35 | 36 | ### Contribution 37 | 38 | Unless you explicitly state otherwise, any contribution intentionally submitted 39 | for inclusion in the work by you, as defined in the Apache-2.0 license, shall be 40 | dual licensed as above, without any additional terms or conditions. 41 | 42 | [//]: # (badges) 43 | 44 | [crate-image]: https://img.shields.io/crates/v/des.svg 45 | [crate-link]: https://crates.io/crates/des 46 | [docs-image]: https://docs.rs/des/badge.svg 47 | [docs-link]: https://docs.rs/des/ 48 | [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg 49 | [rustc-image]: https://img.shields.io/badge/rustc-1.85+-blue.svg 50 | [hazmat-image]: https://img.shields.io/badge/crypto-hazmat%E2%9A%A0-red.svg 51 | [hazmat-link]: https://github.com/RustCrypto/meta/blob/master/HAZMAT.md 52 | [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg 53 | [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260039-block-ciphers 54 | [build-image]: https://github.com/RustCrypto/block-ciphers/workflows/des/badge.svg?branch=master&event=push 55 | [build-link]: https://github.com/RustCrypto/block-ciphers/actions?query=workflow%3Ades 56 | 57 | [//]: # (general links) 58 | 59 | [1]: https://en.wikipedia.org/wiki/Data_Encryption_Standard 60 | -------------------------------------------------------------------------------- /des/benches/mod.rs: -------------------------------------------------------------------------------- 1 | #![feature(test)] 2 | extern crate test; 3 | 4 | use cipher::{block_decryptor_bench, block_encryptor_bench}; 5 | use des::{Des, TdesEde3}; 6 | 7 | block_encryptor_bench!(Key: Des, des_encrypt_block, des_encrypt_blocks); 8 | block_decryptor_bench!(Key: Des, des_decrypt_block, des_decrypt_blocks); 9 | 10 | block_encryptor_bench!( 11 | Key: TdesEde3, 12 | tdes_ede3_encrypt_block, 13 | tdes_ede3_encrypt_blocks, 14 | ); 15 | block_decryptor_bench!( 16 | Key: TdesEde3, 17 | tdes_ede3_decrypt_block, 18 | tdes_ede3_decrypt_blocks, 19 | ); 20 | -------------------------------------------------------------------------------- /des/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Pure Rust implementation of the [Data Encryption Standard][DES] (DES), 2 | //! including [Triple DES] (TDES, 3DES) block ciphers. 3 | //! 4 | //! # ⚠️ Security Warning: Hazmat! 5 | //! 6 | //! This crate implements only the low-level block cipher function, and is intended 7 | //! for use for implementing higher-level constructions *only*. It is NOT 8 | //! intended for direct use in applications. 9 | //! 10 | //! USE AT YOUR OWN RISK! 11 | //! 12 | //! [DES]: https://en.wikipedia.org/wiki/Data_Encryption_Standard 13 | //! [Triple DES]: https://en.wikipedia.org/wiki/Triple_DES 14 | 15 | #![no_std] 16 | #![doc( 17 | html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/26acc39f/logo.svg", 18 | html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/26acc39f/logo.svg" 19 | )] 20 | #![deny(unsafe_code)] 21 | #![cfg_attr(docsrs, feature(doc_auto_cfg))] 22 | #![warn(missing_docs, rust_2018_idioms)] 23 | 24 | pub use cipher; 25 | 26 | mod consts; 27 | mod des; 28 | mod tdes; 29 | mod utils; 30 | 31 | pub use crate::des::Des; 32 | pub use crate::tdes::{TdesEde2, TdesEde3, TdesEee2, TdesEee3}; 33 | 34 | /// Checks whether the key is weak. 35 | /// 36 | /// Returns 1 if the key is weak; otherwise, returns 0. 37 | fn weak_key_test(key: u64) -> u8 { 38 | let mut is_weak = 0u8; 39 | for &weak_key in crate::consts::WEAK_KEYS { 40 | is_weak |= u8::from(key == weak_key); 41 | } 42 | is_weak 43 | } 44 | -------------------------------------------------------------------------------- /des/tests/data/des.blb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustCrypto/block-ciphers/73b104d31747ff763de345372ceab6eeffd04319/des/tests/data/des.blb -------------------------------------------------------------------------------- /des/tests/data/tdes.blb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustCrypto/block-ciphers/73b104d31747ff763de345372ceab6eeffd04319/des/tests/data/tdes.blb -------------------------------------------------------------------------------- /des/tests/data/tdes2.blb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustCrypto/block-ciphers/73b104d31747ff763de345372ceab6eeffd04319/des/tests/data/tdes2.blb -------------------------------------------------------------------------------- /des/tests/mod.rs: -------------------------------------------------------------------------------- 1 | //! Test vectors are from NESSIE: 2 | //! https://www.cosic.esat.kuleuven.be/nessie/testvectors/ 3 | 4 | cipher::block_cipher_test!(des_test, "des", des::Des); 5 | cipher::block_cipher_test!(tdes_ede3_test, "tdes", des::TdesEde3); 6 | cipher::block_cipher_test!(tdes_ede2_test, "tdes2", des::TdesEde2); 7 | -------------------------------------------------------------------------------- /des/tests/weak.rs: -------------------------------------------------------------------------------- 1 | use cipher::{Key, KeyInit}; 2 | use des::{Des, TdesEde2, TdesEde3, TdesEee2, TdesEee3}; 3 | use hex_literal::hex; 4 | 5 | #[test] 6 | fn weak_des() { 7 | for k in &[ 8 | hex!("0101010101010101"), 9 | hex!("fefefefefefefefe"), 10 | hex!("e0e0e0e0f1f1f1f1"), 11 | ] { 12 | let k = Key::::from(*k); 13 | assert!(Des::weak_key_test(&k).is_err()); 14 | } 15 | 16 | for k in &[ 17 | hex!("010101010101010100000000000000000000000000000000"), 18 | hex!("0000000000000000fefefefefefefefe0000000000000000"), 19 | hex!("00000000000000000000000000000000e0e0e0e0f1f1f1f1"), 20 | hex!("010203040506070801020304050607081112131415161718"), 21 | hex!("010203040506070811121314151617180102030405060708"), 22 | hex!("111213141516171801020304050607080102030405060708"), 23 | ] { 24 | let k = Key::::from(*k); 25 | assert!(TdesEde3::weak_key_test(&k).is_err()); 26 | assert!(TdesEee3::weak_key_test(&k).is_err()); 27 | } 28 | 29 | for k in &[ 30 | hex!("01010101010101010000000000000000"), 31 | hex!("0000000000000000fefefefefefefefe"), 32 | hex!("0000000000000000e0e0e0e0f1f1f1f1"), 33 | hex!("01020304050607080102030405060708"), 34 | ] { 35 | let k = Key::::from(*k); 36 | assert!(TdesEde2::weak_key_test(&k).is_err()); 37 | assert!(TdesEee2::weak_key_test(&k).is_err()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /gift/.gitignore: -------------------------------------------------------------------------------- 1 | /target/* 2 | -------------------------------------------------------------------------------- /gift/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 | 8 | ## 0.2.0 (UNRELEASED) 9 | ### Changed 10 | - Bump `cipher` dependency to v0.5 11 | - Edition changed to 2024 and MSRV bumped to 1.85 ([#472]) 12 | - Relax MSRV policy and allow MSRV bumps in patch releases ([#477]) 13 | 14 | [#472]: https://github.com/RustCrypto/block-ciphers/pull/472 15 | [#477]: https://github.com/RustCrypto/block-ciphers/pull/477 16 | 17 | ## 0.1.0 (2022-08-16) 18 | - Initial release 19 | -------------------------------------------------------------------------------- /gift/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "gift-cipher" 3 | version = "0.0.1-rc.0" 4 | description = "Pure Rust implementation of the Gift block cipher" 5 | authors = ["RustCrypto Developers", "Schmid7k"] 6 | license = "MIT OR Apache-2.0" 7 | rust-version = "1.85" 8 | edition = "2024" 9 | readme = "README.md" 10 | documentation = "https://docs.rs/gift-cipher" 11 | repository = "https://github.com/RustCrypto/block-ciphers" 12 | keywords = ["crypto", "gift", "block-cipher"] 13 | categories = ["cryptography", "no-std"] 14 | 15 | [dependencies] 16 | cipher = "0.5.0-rc.0" 17 | 18 | [dev-dependencies] 19 | cipher = { version = "0.5.0-rc.0", features = ["dev"] } 20 | hex-literal = "1" 21 | 22 | [features] 23 | zeroize = ["cipher/zeroize"] 24 | 25 | [package.metadata.docs.rs] 26 | all-features = true 27 | rustdoc-args = ["--cfg", "docsrs"] 28 | -------------------------------------------------------------------------------- /gift/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2021-2024 The RustCrypto Project Developers 2 | Copyright (c) 2021 Shun Sakai 3 | 4 | Permission is hereby granted, free of charge, to any 5 | person obtaining a copy of this software and associated 6 | documentation files (the "Software"), to deal in the 7 | Software without restriction, including without 8 | limitation the rights to use, copy, modify, merge, 9 | publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software 11 | is furnished to do so, subject to the following 12 | conditions: 13 | 14 | The above copyright notice and this permission notice 15 | shall be included in all copies or substantial portions 16 | of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 19 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 20 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 21 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 22 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 25 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 | DEALINGS IN THE SOFTWARE. 27 | -------------------------------------------------------------------------------- /gift/README.md: -------------------------------------------------------------------------------- 1 | # RustCrypto: Gift Cipher 2 | 3 | [![crate][crate-image]][crate-link] 4 | [![Docs][docs-image]][docs-link] 5 | ![Apache2/MIT licensed][license-image] 6 | ![Rust Version][rustc-image] 7 | [![Project Chat][chat-image]][chat-link] 8 | [![Build Status][build-image]][build-link] 9 | [![HAZMAT][hazmat-image]][hazmat-link] 10 | 11 | Pure Rust implementation of the [Gift block cipher][1]. 12 | 13 | ## ⚠️ Security Warning: [Hazmat!][hazmat-link] 14 | 15 | This crate does not ensure ciphertexts are authentic (i.e. by using a MAC to 16 | verify ciphertext integrity), which can lead to serious vulnerabilities 17 | if used incorrectly! 18 | 19 | No security audits of this crate have ever been performed, and it has not been 20 | thoroughly assessed to ensure its operation is constant-time on common CPU 21 | architectures. 22 | 23 | USE AT YOUR OWN RISK! 24 | 25 | ## License 26 | 27 | Licensed under either of: 28 | 29 | * [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) 30 | * [MIT license](http://opensource.org/licenses/MIT) 31 | 32 | at your option. 33 | 34 | ### Contribution 35 | 36 | Unless you explicitly state otherwise, any contribution intentionally submitted 37 | for inclusion in the work by you, as defined in the Apache-2.0 license, shall be 38 | dual licensed as above, without any additional terms or conditions. 39 | 40 | [//]: # (badges) 41 | 42 | [crate-image]: https://img.shields.io/crates/v/gift-cipher.svg 43 | [crate-link]: https://crates.io/crates/gift-cipher 44 | [docs-image]: https://docs.rs/gift-cipher/badge.svg 45 | [docs-link]: https://docs.rs/gift-cipher/ 46 | [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg 47 | [rustc-image]: https://img.shields.io/badge/rustc-1.85+-blue.svg 48 | [hazmat-image]: https://img.shields.io/badge/crypto-hazmat%E2%9A%A0-red.svg 49 | [hazmat-link]: https://github.com/RustCrypto/meta/blob/master/HAZMAT.md 50 | [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg 51 | [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260039-block-ciphers 52 | [build-image]: https://github.com/RustCrypto/block-ciphers/actions/workflows/gift.yml/badge.svg 53 | [build-link]: https://github.com/RustCrypto/block-ciphers/actions/workflows/gift.yml 54 | 55 | [//]: # (general links) 56 | 57 | [1]: https://eprint.iacr.org/2017/622.pdf 58 | -------------------------------------------------------------------------------- /gift/benches/gift128enc.rs: -------------------------------------------------------------------------------- 1 | #![feature(test)] 2 | extern crate test; 3 | 4 | use cipher::{KeyInit, block_decryptor_bench, block_encryptor_bench}; 5 | use gift_cipher::Gift128; 6 | 7 | block_encryptor_bench!( 8 | Key: Gift128, 9 | gift128_encrypt_block, 10 | gift128_encrypt_blocks, 11 | ); 12 | block_decryptor_bench!( 13 | Key: Gift128, 14 | gift128_decrypt_block, 15 | gift128_decrypt_blocks, 16 | ); 17 | 18 | #[bench] 19 | fn gift128_new(bh: &mut test::Bencher) { 20 | bh.iter(|| { 21 | let key = test::black_box(Default::default()); 22 | let cipher = Gift128::new(&key); 23 | test::black_box(&cipher); 24 | }); 25 | } 26 | -------------------------------------------------------------------------------- /gift/src/consts.rs: -------------------------------------------------------------------------------- 1 | /// Gift round constants according to the fixsliced representation 2 | pub(crate) const GIFT_RC: [u32; 40] = [ 3 | 0x10000008, 0x80018000, 0x54000002, 0x01010181, 0x8000001f, 0x10888880, 0x6001e000, 0x51500002, 4 | 0x03030180, 0x8000002f, 0x10088880, 0x60016000, 0x41500002, 0x03030080, 0x80000027, 0x10008880, 5 | 0x4001e000, 0x11500002, 0x03020180, 0x8000002b, 0x10080880, 0x60014000, 0x01400002, 0x02020080, 6 | 0x80000021, 0x10000080, 0x0001c000, 0x51000002, 0x03010180, 0x8000002e, 0x10088800, 0x60012000, 7 | 0x40500002, 0x01030080, 0x80000006, 0x10008808, 0xc001a000, 0x14500002, 0x01020181, 0x8000001a, 8 | ]; 9 | -------------------------------------------------------------------------------- /gift/tests/mod.rs: -------------------------------------------------------------------------------- 1 | use cipher::{BlockCipherDecrypt, BlockCipherEncrypt, KeyInit, array::Array}; 2 | use gift_cipher::Gift128; 3 | use hex_literal::hex; 4 | 5 | const KEYS: [[u8; 16]; 3] = [ 6 | hex!("00000000000000000000000000000000"), 7 | hex!("fedcba9876543210fedcba9876543210"), 8 | hex!("d0f5c59a7700d3e799028fa9f90ad837"), 9 | ]; 10 | 11 | const PTEXT: [[u8; 16]; 3] = [ 12 | hex!("00000000000000000000000000000000"), 13 | hex!("fedcba9876543210fedcba9876543210"), 14 | hex!("e39c141fa57dba43f08a85b6a91f86c1"), 15 | ]; 16 | 17 | const CTEXT: [[u8; 16]; 3] = [ 18 | hex!("cd0bd738388ad3f668b15a36ceb6ff92"), 19 | hex!("8422241a6dbf5a9346af468409ee0152"), 20 | hex!("13ede67cbdcc3dbf400a62d6977265ea"), 21 | ]; 22 | 23 | #[test] 24 | fn test_vectors() { 25 | for i in 0..3 { 26 | let cipher = Gift128::new(&KEYS[i].into()); 27 | let mut buf = Array::from(PTEXT[i]); 28 | 29 | cipher.encrypt_block(&mut buf); 30 | assert_eq!(buf, CTEXT[i]); 31 | 32 | cipher.decrypt_block(&mut buf); 33 | assert_eq!(buf, PTEXT[i]); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /idea/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 | 8 | ## 0.6.0 (UNRELEASED) 9 | ### Changed 10 | - Bump `cipher` dependency to v0.5 11 | - Edition changed to 2024 and MSRV bumped to 1.85 ([#472]) 12 | - Relax MSRV policy and allow MSRV bumps in patch releases ([#477]) 13 | 14 | [#472]: https://github.com/RustCrypto/block-ciphers/pull/472 15 | [#477]: https://github.com/RustCrypto/block-ciphers/pull/477 16 | 17 | ## 0.5.1 (2022-02-17) 18 | ### Fixed 19 | - Minimal versions build ([#303]) 20 | 21 | [#303]: https://github.com/RustCrypto/block-ciphers/pull/303 22 | 23 | ## 0.5.0 (2022-02-10) 24 | ### Changed 25 | - Bump `cipher` dependency to v0.4 ([#284]) 26 | 27 | [#284]: https://github.com/RustCrypto/block-ciphers/pull/284 28 | 29 | ## 0.4.0 (2021-04-29) 30 | ### Changed 31 | - Bump `cipher` dependency to v0.3 ([#235]) 32 | 33 | [#235]: https://github.com/RustCrypto/block-ciphers/pull/235 34 | 35 | ## 0.3.0 (2020-10-16) 36 | ### Changed 37 | - Replace `block-cipher`/`stream-cipher` with `cipher` crate ([#167]) 38 | 39 | [#167]: https://github.com/RustCrypto/block-ciphers/pull/167 40 | 41 | ## 0.2.0 (2020-08-07) 42 | ### Changed 43 | - Bump `block-cipher` dependency to v0.8 ([#138]) 44 | - Bump `opaque-debug` dependency to v0.3 ([#140]) 45 | 46 | [#138]: https://github.com/RustCrypto/block-ciphers/pull/138 47 | [#140]: https://github.com/RustCrypto/block-ciphers/pull/140 48 | 49 | ## 0.1.0 (2020-06-08) 50 | ### Changed 51 | - Bump `block-cipher` dependency to v0.7 ([#91]) 52 | - Upgrade to Rust 2018 edition ([#91]) 53 | 54 | [#91]: https://github.com/RustCrypto/block-ciphers/pull/91 55 | 56 | ## 0.0.1 (2020-05-23) 57 | - Initial release 58 | -------------------------------------------------------------------------------- /idea/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "idea" 3 | version = "0.6.0-pre" 4 | description = "IDEA block cipher" 5 | authors = ["RustCrypto Developers"] 6 | license = "MIT OR Apache-2.0" 7 | edition = "2024" 8 | rust-version = "1.85" 9 | readme = "README.md" 10 | documentation = "https://docs.rs/idea" 11 | repository = "https://github.com/RustCrypto/block-ciphers" 12 | keywords = ["crypto", "idea", "block-cipher"] 13 | categories = ["cryptography", "no-std"] 14 | 15 | [dependencies] 16 | cipher = "0.5.0-rc.0" 17 | 18 | [dev-dependencies] 19 | cipher = { version = "0.5.0-rc.0", features = ["dev"] } 20 | 21 | [features] 22 | zeroize = ["cipher/zeroize"] 23 | 24 | [package.metadata.docs.rs] 25 | all-features = true 26 | rustdoc-args = ["--cfg", "docsrs"] 27 | -------------------------------------------------------------------------------- /idea/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017-2024 The RustCrypto Project Developers 2 | Copyright (c) 2017 Damian Czaja 3 | 4 | Permission is hereby granted, free of charge, to any 5 | person obtaining a copy of this software and associated 6 | documentation files (the "Software"), to deal in the 7 | Software without restriction, including without 8 | limitation the rights to use, copy, modify, merge, 9 | publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software 11 | is furnished to do so, subject to the following 12 | conditions: 13 | 14 | The above copyright notice and this permission notice 15 | shall be included in all copies or substantial portions 16 | of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 19 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 20 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 21 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 22 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 25 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 | DEALINGS IN THE SOFTWARE. 27 | -------------------------------------------------------------------------------- /idea/README.md: -------------------------------------------------------------------------------- 1 | # RustCrypto: International Data Encryption Algorithm (IDEA) 2 | 3 | [![crate][crate-image]][crate-link] 4 | [![Docs][docs-image]][docs-link] 5 | ![Apache2/MIT licensed][license-image] 6 | ![Rust Version][rustc-image] 7 | [![Project Chat][chat-image]][chat-link] 8 | [![Build Status][build-image]][build-link] 9 | [![HAZMAT][hazmat-image]][hazmat-link] 10 | 11 | Experimental Pure Rust implementation of the [IDEA block cipher][1]. 12 | 13 | ## ⚠️ Security Warning: [Hazmat!][hazmat-link] 14 | 15 | This crate does not ensure ciphertexts are authentic (i.e. by using a MAC to 16 | verify ciphertext integrity), which can lead to serious vulnerabilities 17 | if used incorrectly! 18 | 19 | No security audits of this crate have ever been performed, and it has not been 20 | thoroughly assessed to ensure its operation is constant-time on common CPU 21 | architectures. 22 | 23 | USE AT YOUR OWN RISK! 24 | 25 | ## License 26 | 27 | Licensed under either of: 28 | 29 | * [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) 30 | * [MIT license](http://opensource.org/licenses/MIT) 31 | 32 | at your option. 33 | 34 | ### Contribution 35 | 36 | Unless you explicitly state otherwise, any contribution intentionally submitted 37 | for inclusion in the work by you, as defined in the Apache-2.0 license, shall be 38 | dual licensed as above, without any additional terms or conditions. 39 | 40 | [//]: # (badges) 41 | 42 | [crate-image]: https://img.shields.io/crates/v/idea.svg 43 | [crate-link]: https://crates.io/crates/idea 44 | [docs-image]: https://docs.rs/idea/badge.svg 45 | [docs-link]: https://docs.rs/idea/ 46 | [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg 47 | [rustc-image]: https://img.shields.io/badge/rustc-1.85+-blue.svg 48 | [hazmat-image]: https://img.shields.io/badge/crypto-hazmat%E2%9A%A0-red.svg 49 | [hazmat-link]: https://github.com/RustCrypto/meta/blob/master/HAZMAT.md 50 | [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg 51 | [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260039-block-ciphers 52 | [build-image]: https://github.com/RustCrypto/block-ciphers/workflows/idea/badge.svg?branch=master&event=push 53 | [build-link]: https://github.com/RustCrypto/block-ciphers/actions?query=workflow%3Aidea 54 | 55 | [//]: # (general links) 56 | 57 | [1]: https://simple.wikipedia.org/wiki/International_Data_Encryption_Algorithm 58 | -------------------------------------------------------------------------------- /idea/benches/mod.rs: -------------------------------------------------------------------------------- 1 | #![feature(test)] 2 | extern crate test; 3 | 4 | use cipher::{block_decryptor_bench, block_encryptor_bench}; 5 | use idea::Idea; 6 | 7 | block_encryptor_bench!(Key: Idea, idea_encrypt_block, idea_encrypt_blocks); 8 | block_decryptor_bench!(Key: Idea, idea_decrypt_block, idea_decrypt_blocks); 9 | -------------------------------------------------------------------------------- /idea/src/consts.rs: -------------------------------------------------------------------------------- 1 | pub const ROUNDS: usize = 8; 2 | pub const LENGTH_SUB_KEYS: usize = ROUNDS * 6 + 4; 3 | pub const ONE: u32 = 0xffff; 4 | pub const FUYI: u32 = 0x10000; 5 | pub const MAXIM: u32 = 0x10001; 6 | -------------------------------------------------------------------------------- /idea/src/tests.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | #[test] 4 | #[rustfmt::skip] 5 | fn test_sub_key_generation() { 6 | let key: [u8; 16] = [ 7 | 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 8 | 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0x08, 9 | ]; 10 | let enc_keys: [u16; 52] = [ 11 | 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 12 | 0x0400, 0x0600, 0x0800, 0x0a00, 0x0c00, 0x0e00, 0x1000, 0x0200, 13 | 0x0010, 0x0014, 0x0018, 0x001c, 0x0020, 0x0004, 0x0008, 0x000c, 14 | 0x2800, 0x3000, 0x3800, 0x4000, 0x0800, 0x1000, 0x1800, 0x2000, 15 | 0x0070, 0x0080, 0x0010, 0x0020, 0x0030, 0x0040, 0x0050, 0x0060, 16 | 0x0000, 0x2000, 0x4000, 0x6000, 0x8000, 0xa000, 0xc000, 0xe001, 17 | 0x0080, 0x00c0, 0x0100, 0x0140, 18 | ]; 19 | let dec_keys: [u16; 52] = [ 20 | 0xfe01, 0xff40, 0xff00, 0x659a, 0xc000, 0xe001, 0xfffd, 0x8000, 21 | 0xa000, 0xcccc, 0x0000, 0x2000, 0xa556, 0xffb0, 0xffc0, 0x52ab, 22 | 0x0010, 0x0020, 0x554b, 0xff90, 0xe000, 0xfe01, 0x0800, 0x1000, 23 | 0x332d, 0xc800, 0xd000, 0xfffd, 0x0008, 0x000c, 0x4aab, 0xffe0, 24 | 0xffe4, 0xc001, 0x0010, 0x0014, 0xaa96, 0xf000, 0xf200, 0xff81, 25 | 0x0800, 0x0a00, 0x4925, 0xfc00, 0xfff8, 0x552b, 0x0005, 0x0006, 26 | 0x0001, 0xfffe, 0xfffd, 0xc001, 27 | ]; 28 | 29 | let idea = Idea::new_from_slice(&key).unwrap(); 30 | 31 | assert_eq!(&idea.enc_keys[..], &enc_keys[..]); 32 | assert_eq!(&idea.dec_keys[..], &dec_keys[..]); 33 | } 34 | -------------------------------------------------------------------------------- /idea/tests/data/idea.blb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustCrypto/block-ciphers/73b104d31747ff763de345372ceab6eeffd04319/idea/tests/data/idea.blb -------------------------------------------------------------------------------- /idea/tests/mod.rs: -------------------------------------------------------------------------------- 1 | //! Test vectors from: 2 | //! https://www.cosic.esat.kuleuven.be/nessie/testvectors/bc/idea/Idea-128-64.verified.test-vectors 3 | 4 | cipher::block_cipher_test!(idea_test, "idea", idea::Idea); 5 | -------------------------------------------------------------------------------- /kuznyechik/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "kuznyechik" 3 | version = "0.9.0-rc.0" 4 | description = "Kuznyechik (GOST R 34.12-2015) block cipher" 5 | authors = ["RustCrypto Developers"] 6 | license = "MIT OR Apache-2.0" 7 | edition = "2024" 8 | rust-version = "1.85" 9 | readme = "README.md" 10 | documentation = "https://docs.rs/kuznyechik" 11 | repository = "https://github.com/RustCrypto/block-ciphers" 12 | keywords = ["crypto", "kuznyechik", "gost", "block-cipher"] 13 | categories = ["cryptography", "no-std"] 14 | 15 | [dependencies] 16 | cipher = "0.5.0-rc.0" 17 | cfg-if = "1" 18 | 19 | [dev-dependencies] 20 | cipher = { version = "0.5.0-rc.0", features = ["dev"] } 21 | hex-literal = "1" 22 | 23 | [features] 24 | zeroize = ["cipher/zeroize"] 25 | 26 | [lints.rust.unexpected_cfgs] 27 | level = "warn" 28 | check-cfg = ['cfg(kuznyechik_backend, values("soft", "compact_soft"))'] 29 | 30 | [package.metadata.docs.rs] 31 | all-features = true 32 | rustdoc-args = ["--cfg", "docsrs"] 33 | -------------------------------------------------------------------------------- /kuznyechik/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017-2024 The RustCrypto Project Developers 2 | Copyright (c) 2017 Artyom Pavlov 3 | 4 | Permission is hereby granted, free of charge, to any 5 | person obtaining a copy of this software and associated 6 | documentation files (the "Software"), to deal in the 7 | Software without restriction, including without 8 | limitation the rights to use, copy, modify, merge, 9 | publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software 11 | is furnished to do so, subject to the following 12 | conditions: 13 | 14 | The above copyright notice and this permission notice 15 | shall be included in all copies or substantial portions 16 | of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 19 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 20 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 21 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 22 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 25 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 | DEALINGS IN THE SOFTWARE. 27 | -------------------------------------------------------------------------------- /kuznyechik/README.md: -------------------------------------------------------------------------------- 1 | # RustCrypto: Kuznyechik Cipher 2 | 3 | [![crate][crate-image]][crate-link] 4 | [![Docs][docs-image]][docs-link] 5 | ![Apache2/MIT licensed][license-image] 6 | ![Rust Version][rustc-image] 7 | [![Project Chat][chat-image]][chat-link] 8 | [![Build Status][build-image]][build-link] 9 | [![HAZMAT][hazmat-image]][hazmat-link] 10 | 11 | Pure Rust implementation of the Kuznyechik (GOST R 34.12-2015) block cipher 12 | 13 | ## ⚠️ Security Warning: [Hazmat!][hazmat-link] 14 | 15 | This crate does not ensure ciphertexts are authentic (i.e. by using a MAC to 16 | verify ciphertext integrity), which can lead to serious vulnerabilities 17 | if used incorrectly! 18 | 19 | No security audits of this crate have ever been performed, and it has not been 20 | thoroughly assessed to ensure its operation is constant-time on common CPU 21 | architectures. 22 | 23 | USE AT YOUR OWN RISK! 24 | 25 | ## License 26 | 27 | Licensed under either of: 28 | 29 | * [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) 30 | * [MIT license](http://opensource.org/licenses/MIT) 31 | 32 | at your option. 33 | 34 | ### Contribution 35 | 36 | Unless you explicitly state otherwise, any contribution intentionally submitted 37 | for inclusion in the work by you, as defined in the Apache-2.0 license, shall be 38 | dual licensed as above, without any additional terms or conditions. 39 | 40 | [//]: # (badges) 41 | 42 | [crate-image]: https://img.shields.io/crates/v/kuznyechik.svg 43 | [crate-link]: https://crates.io/crates/kuznyechik 44 | [docs-image]: https://docs.rs/kuznyechik/badge.svg 45 | [docs-link]: https://docs.rs/kuznyechik/ 46 | [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg 47 | [rustc-image]: https://img.shields.io/badge/rustc-1.85+-blue.svg 48 | [hazmat-image]: https://img.shields.io/badge/crypto-hazmat%E2%9A%A0-red.svg 49 | [hazmat-link]: https://github.com/RustCrypto/meta/blob/master/HAZMAT.md 50 | [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg 51 | [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260039-block-ciphers 52 | [build-image]: https://github.com/RustCrypto/block-ciphers/workflows/kuznyechik/badge.svg?branch=master&event=push 53 | [build-link]: https://github.com/RustCrypto/block-ciphers/actions?query=workflow%3Akuznyechik 54 | -------------------------------------------------------------------------------- /kuznyechik/benches/mod.rs: -------------------------------------------------------------------------------- 1 | #![feature(test)] 2 | extern crate test; 3 | 4 | use cipher::{block_decryptor_bench, block_encryptor_bench}; 5 | use kuznyechik::Kuznyechik; 6 | 7 | block_encryptor_bench!( 8 | Key: Kuznyechik, 9 | kuznyechik_encrypt_block, 10 | kuznyechik_encrypt_blocks, 11 | ); 12 | block_decryptor_bench!( 13 | Key: Kuznyechik, 14 | kuznyechik_decrypt_block, 15 | kuznyechik_decrypt_blocks, 16 | ); 17 | -------------------------------------------------------------------------------- /kuznyechik/src/big_soft/mod.rs: -------------------------------------------------------------------------------- 1 | use crate::{BlockSize, Key}; 2 | use cipher::{ 3 | BlockCipherDecClosure, BlockCipherDecrypt, BlockCipherEncClosure, BlockCipherEncrypt, 4 | }; 5 | 6 | mod backends; 7 | 8 | use backends::{DecBackend, EncBackend, RoundKeys, expand_enc_keys, inv_enc_keys}; 9 | 10 | #[derive(Clone)] 11 | pub(crate) struct EncDecKeys { 12 | enc: RoundKeys, 13 | dec: RoundKeys, 14 | } 15 | #[derive(Clone)] 16 | pub(crate) struct EncKeys(RoundKeys); 17 | #[derive(Clone)] 18 | pub(crate) struct DecKeys(RoundKeys); 19 | 20 | impl EncKeys { 21 | pub fn new(key: &Key) -> Self { 22 | Self(expand_enc_keys(key)) 23 | } 24 | } 25 | 26 | impl From for EncDecKeys { 27 | fn from(enc: EncKeys) -> Self { 28 | Self { 29 | dec: inv_enc_keys(&enc.0), 30 | enc: enc.0, 31 | } 32 | } 33 | } 34 | 35 | impl From for DecKeys { 36 | fn from(enc: EncKeys) -> Self { 37 | Self(inv_enc_keys(&enc.0)) 38 | } 39 | } 40 | 41 | impl BlockCipherEncrypt for crate::Kuznyechik { 42 | fn encrypt_with_backend(&self, f: impl BlockCipherEncClosure) { 43 | f.call(&mut EncBackend(&self.keys.enc)); 44 | } 45 | } 46 | 47 | impl BlockCipherDecrypt for crate::Kuznyechik { 48 | fn decrypt_with_backend(&self, f: impl BlockCipherDecClosure) { 49 | f.call(&mut DecBackend(&self.keys.dec)); 50 | } 51 | } 52 | 53 | impl BlockCipherEncrypt for crate::KuznyechikEnc { 54 | fn encrypt_with_backend(&self, f: impl BlockCipherEncClosure) { 55 | f.call(&mut EncBackend(&self.keys.0)); 56 | } 57 | } 58 | 59 | impl BlockCipherDecrypt for crate::KuznyechikDec { 60 | fn decrypt_with_backend(&self, f: impl BlockCipherDecClosure) { 61 | f.call(&mut DecBackend(&self.keys.0)); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /kuznyechik/src/compact_soft/mod.rs: -------------------------------------------------------------------------------- 1 | use crate::{BlockSize, Key}; 2 | use cipher::{ 3 | BlockCipherDecClosure, BlockCipherDecrypt, BlockCipherEncClosure, BlockCipherEncrypt, 4 | }; 5 | 6 | mod backends; 7 | 8 | use backends::{DecBackend, EncBackend, RoundKeys, expand}; 9 | 10 | #[derive(Clone)] 11 | pub(crate) struct EncDecKeys(RoundKeys); 12 | #[derive(Clone)] 13 | pub(crate) struct EncKeys(RoundKeys); 14 | #[derive(Clone)] 15 | pub(crate) struct DecKeys(RoundKeys); 16 | 17 | impl From for EncDecKeys { 18 | fn from(enc: EncKeys) -> Self { 19 | Self(enc.0) 20 | } 21 | } 22 | 23 | impl From for DecKeys { 24 | fn from(enc: EncKeys) -> Self { 25 | Self(enc.0) 26 | } 27 | } 28 | 29 | impl EncKeys { 30 | pub fn new(key: &Key) -> Self { 31 | Self(expand(key)) 32 | } 33 | } 34 | 35 | impl BlockCipherEncrypt for crate::Kuznyechik { 36 | fn encrypt_with_backend(&self, f: impl BlockCipherEncClosure) { 37 | f.call(&mut EncBackend(&self.keys.0)); 38 | } 39 | } 40 | 41 | impl BlockCipherDecrypt for crate::Kuznyechik { 42 | fn decrypt_with_backend(&self, f: impl BlockCipherDecClosure) { 43 | f.call(&mut DecBackend(&self.keys.0)); 44 | } 45 | } 46 | 47 | impl BlockCipherEncrypt for crate::KuznyechikEnc { 48 | fn encrypt_with_backend(&self, f: impl BlockCipherEncClosure) { 49 | f.call(&mut EncBackend(&self.keys.0)); 50 | } 51 | } 52 | 53 | impl BlockCipherDecrypt for crate::KuznyechikDec { 54 | fn decrypt_with_backend(&self, f: impl BlockCipherDecClosure) { 55 | f.call(&mut DecBackend(&self.keys.0)); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /kuznyechik/src/gft.rs: -------------------------------------------------------------------------------- 1 | //! Pre-computed mutliplication tables for coefficients of the linear transform 2 | 3 | pub(crate) const GFT_16: [u8; 256] = mul_table_gf256(16); 4 | pub(crate) const GFT_32: [u8; 256] = mul_table_gf256(32); 5 | pub(crate) const GFT_133: [u8; 256] = mul_table_gf256(133); 6 | pub(crate) const GFT_148: [u8; 256] = mul_table_gf256(148); 7 | pub(crate) const GFT_192: [u8; 256] = mul_table_gf256(192); 8 | pub(crate) const GFT_194: [u8; 256] = mul_table_gf256(194); 9 | pub(crate) const GFT_251: [u8; 256] = mul_table_gf256(251); 10 | 11 | const fn mul_gf256(mut a: u8, mut b: u8) -> u8 { 12 | let mut c = 0; 13 | while b != 0 { 14 | if b & 1 != 0 { 15 | c ^= a; 16 | } 17 | a = (a << 1) ^ if a & 0x80 != 0 { 0xC3 } else { 0x00 }; 18 | b >>= 1; 19 | } 20 | c 21 | } 22 | 23 | const fn mul_table_gf256(a: u8) -> [u8; 256] { 24 | let mut table = [0u8; 256]; 25 | let mut i = 0; 26 | while i < table.len() { 27 | table[i] = mul_gf256(a, i as u8); 28 | i += 1; 29 | } 30 | table 31 | } 32 | -------------------------------------------------------------------------------- /kuznyechik/src/neon/mod.rs: -------------------------------------------------------------------------------- 1 | use crate::{BlockSize, Key}; 2 | use cipher::{ 3 | BlockCipherDecClosure, BlockCipherDecrypt, BlockCipherEncClosure, BlockCipherEncrypt, 4 | }; 5 | 6 | mod backends; 7 | 8 | use backends::{DecBackend, EncBackend, RoundKeys, expand_enc_keys, inv_enc_keys}; 9 | 10 | #[derive(Clone)] 11 | pub(crate) struct EncDecKeys { 12 | enc: RoundKeys, 13 | dec: RoundKeys, 14 | } 15 | #[derive(Clone)] 16 | pub(crate) struct EncKeys(RoundKeys); 17 | #[derive(Clone)] 18 | pub(crate) struct DecKeys(RoundKeys); 19 | 20 | impl EncKeys { 21 | pub fn new(key: &Key) -> Self { 22 | Self(expand_enc_keys(key)) 23 | } 24 | } 25 | 26 | impl From for EncDecKeys { 27 | fn from(enc: EncKeys) -> Self { 28 | Self { 29 | dec: inv_enc_keys(&enc.0), 30 | enc: enc.0, 31 | } 32 | } 33 | } 34 | 35 | impl From for DecKeys { 36 | fn from(enc: EncKeys) -> Self { 37 | Self(inv_enc_keys(&enc.0)) 38 | } 39 | } 40 | 41 | impl BlockCipherEncrypt for crate::Kuznyechik { 42 | fn encrypt_with_backend(&self, f: impl BlockCipherEncClosure) { 43 | f.call(&EncBackend(&self.keys.enc)); 44 | } 45 | } 46 | 47 | impl BlockCipherDecrypt for crate::Kuznyechik { 48 | fn decrypt_with_backend(&self, f: impl BlockCipherDecClosure) { 49 | f.call(&DecBackend(&self.keys.dec)); 50 | } 51 | } 52 | 53 | impl BlockCipherEncrypt for crate::KuznyechikEnc { 54 | fn encrypt_with_backend(&self, f: impl BlockCipherEncClosure) { 55 | f.call(&EncBackend(&self.keys.0)); 56 | } 57 | } 58 | 59 | impl BlockCipherDecrypt for crate::KuznyechikDec { 60 | fn decrypt_with_backend(&self, f: impl BlockCipherDecClosure) { 61 | f.call(&DecBackend(&self.keys.0)); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /kuznyechik/src/sse2/mod.rs: -------------------------------------------------------------------------------- 1 | //! SSE2-based implementation based on 2 | 3 | use crate::{BlockSize, Key}; 4 | use cipher::{ 5 | BlockCipherDecClosure, BlockCipherDecrypt, BlockCipherEncClosure, BlockCipherEncrypt, 6 | }; 7 | 8 | mod backends; 9 | 10 | use backends::{DecBackend, EncBackend, RoundKeys, expand_enc_keys, inv_enc_keys}; 11 | 12 | #[derive(Clone)] 13 | pub(crate) struct EncDecKeys { 14 | enc: RoundKeys, 15 | dec: RoundKeys, 16 | } 17 | #[derive(Clone)] 18 | pub(crate) struct EncKeys(RoundKeys); 19 | #[derive(Clone)] 20 | pub(crate) struct DecKeys(RoundKeys); 21 | 22 | impl EncKeys { 23 | pub fn new(key: &Key) -> Self { 24 | Self(expand_enc_keys(key)) 25 | } 26 | } 27 | 28 | impl From for EncDecKeys { 29 | fn from(enc: EncKeys) -> Self { 30 | Self { 31 | dec: inv_enc_keys(&enc.0), 32 | enc: enc.0, 33 | } 34 | } 35 | } 36 | 37 | impl From for DecKeys { 38 | fn from(enc: EncKeys) -> Self { 39 | Self(inv_enc_keys(&enc.0)) 40 | } 41 | } 42 | 43 | impl BlockCipherEncrypt for crate::Kuznyechik { 44 | fn encrypt_with_backend(&self, f: impl BlockCipherEncClosure) { 45 | f.call(&EncBackend(&self.keys.enc)); 46 | } 47 | } 48 | 49 | impl BlockCipherDecrypt for crate::Kuznyechik { 50 | fn decrypt_with_backend(&self, f: impl BlockCipherDecClosure) { 51 | f.call(&DecBackend(&self.keys.dec)); 52 | } 53 | } 54 | 55 | impl BlockCipherEncrypt for crate::KuznyechikEnc { 56 | fn encrypt_with_backend(&self, f: impl BlockCipherEncClosure) { 57 | f.call(&EncBackend(&self.keys.0)); 58 | } 59 | } 60 | 61 | impl BlockCipherDecrypt for crate::KuznyechikDec { 62 | fn decrypt_with_backend(&self, f: impl BlockCipherDecClosure) { 63 | f.call(&DecBackend(&self.keys.0)); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /kuznyechik/src/utils.rs: -------------------------------------------------------------------------------- 1 | use crate::gft::{GFT_16, GFT_32, GFT_133, GFT_148, GFT_192, GFT_194, GFT_251}; 2 | 3 | #[inline(always)] 4 | const fn get_idx(b: usize, i: usize) -> usize { 5 | b.wrapping_sub(i) & 0x0F 6 | } 7 | 8 | #[inline(always)] 9 | const fn get_m(msg: [u8; 16], b: usize, i: usize) -> usize { 10 | msg[get_idx(b, i)] as usize 11 | } 12 | 13 | pub(crate) const fn l_step(mut msg: [u8; 16], i: usize) -> [u8; 16] { 14 | let mut x = msg[get_idx(15, i)]; 15 | x ^= GFT_148[get_m(msg, 14, i)]; 16 | x ^= GFT_32[get_m(msg, 13, i)]; 17 | x ^= GFT_133[get_m(msg, 12, i)]; 18 | x ^= GFT_16[get_m(msg, 11, i)]; 19 | x ^= GFT_194[get_m(msg, 10, i)]; 20 | x ^= GFT_192[get_m(msg, 9, i)]; 21 | x ^= msg[get_idx(8, i)]; 22 | x ^= GFT_251[get_m(msg, 7, i)]; 23 | x ^= msg[get_idx(6, i)]; 24 | x ^= GFT_192[get_m(msg, 5, i)]; 25 | x ^= GFT_194[get_m(msg, 4, i)]; 26 | x ^= GFT_16[get_m(msg, 3, i)]; 27 | x ^= GFT_133[get_m(msg, 2, i)]; 28 | x ^= GFT_32[get_m(msg, 1, i)]; 29 | x ^= GFT_148[get_m(msg, 0, i)]; 30 | msg[get_idx(15, i)] = x; 31 | msg 32 | } 33 | 34 | #[repr(align(16))] 35 | #[derive(Clone, Copy)] 36 | pub(crate) struct Align16(pub T); 37 | 38 | /// Constants used to generate round keys 39 | pub(crate) static KEYGEN: [Align16<[u8; 16]>; 32] = { 40 | let mut res = [Align16([0u8; 16]); 32]; 41 | let mut n = 0; 42 | while n < res.len() { 43 | let mut block = [0u8; 16]; 44 | block[15] = (n + 1) as u8; 45 | 46 | let mut i = 0; 47 | while i < 16 { 48 | block = l_step(block, i); 49 | i += 1; 50 | } 51 | res[n].0 = block; 52 | n += 1; 53 | } 54 | res 55 | }; 56 | -------------------------------------------------------------------------------- /magma/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 | 8 | ## 0.10.0 (UNRELEASED) 9 | ### Changed 10 | - Bump `cipher` dependency to v0.5 11 | - Edition changed to 2024 and MSRV bumped to 1.85 ([#472]) 12 | - Relax MSRV policy and allow MSRV bumps in patch releases ([#477]) 13 | 14 | [#472]: https://github.com/RustCrypto/block-ciphers/pull/472 15 | [#477]: https://github.com/RustCrypto/block-ciphers/pull/477 16 | 17 | ## 0.9.0 (2023-08-06) 18 | ### Breaking changes 19 | - API of the `Sbox` trait is changed, S-Box expansion is now performed 20 | internally, helper methods are removed. Most users of the crate should not be 21 | affected by this change. ([#376]) 22 | 23 | [#376]: https://github.com/RustCrypto/block-ciphers/pull/376 24 | 25 | ## 0.8.1 (2022-02-17) 26 | ### Fixed 27 | - Minimal versions build ([#303]) 28 | 29 | [#303]: https://github.com/RustCrypto/block-ciphers/pull/303 30 | 31 | ## 0.8.0 (2022-02-10) 32 | ### Changed 33 | - Bump `cipher` dependency to v0.4 ([#284]) 34 | 35 | [#284]: https://github.com/RustCrypto/block-ciphers/pull/284 36 | 37 | ## 0.7.0 (2021-04-29) 38 | ### Changed 39 | - Bump `cipher` dependency to v0.3 ([#235]) 40 | 41 | [#235]: https://github.com/RustCrypto/block-ciphers/pull/235 42 | 43 | ## 0.6.0 (2020-10-16) 44 | ### Changed 45 | - Replace `block-cipher`/`stream-cipher` with `cipher` crate ([#167]) 46 | 47 | [#167]: https://github.com/RustCrypto/block-ciphers/pull/167 48 | 49 | ## 0.5.0 (2020-08-07) 50 | ### Changed 51 | - Bump `block-cipher` dependency to v0.8 ([#138]) 52 | - Bump `opaque-debug` dependency to v0.3 ([#140]) 53 | - Use type parameter for S-box ([#141]) 54 | 55 | [#138]: https://github.com/RustCrypto/block-ciphers/pull/138 56 | [#140]: https://github.com/RustCrypto/block-ciphers/pull/140 57 | [#141]: https://github.com/RustCrypto/block-ciphers/pull/141 58 | 59 | ## 0.4.0 (2020-07-03) 60 | ### Changed 61 | - Bump `block-cipher` dependency to v0.7 ([#93]) 62 | - Upgrade to Rust 2018 edition ([#93]) 63 | 64 | ### Fixed 65 | - Byte order ([#118]) 66 | 67 | [#118]: https://github.com/RustCrypto/block-ciphers/pull/118 68 | [#93]: https://github.com/RustCrypto/block-ciphers/pull/93 69 | 70 | ## 0.3.0 (2018-12-23) 71 | 72 | ## 0.2.0 (2017-11-26) 73 | 74 | ## 0.1.1 (2017-01-11) 75 | 76 | ## 0.1.0 (2017-01-11) 77 | -------------------------------------------------------------------------------- /magma/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "magma" 3 | version = "0.10.0-rc.0" 4 | description = "Magma (GOST R 34.12-2015) block cipher" 5 | authors = ["RustCrypto Developers"] 6 | license = "MIT OR Apache-2.0" 7 | edition = "2024" 8 | rust-version = "1.85" 9 | readme = "README.md" 10 | documentation = "https://docs.rs/magma" 11 | repository = "https://github.com/RustCrypto/block-ciphers" 12 | keywords = ["crypto", "magma", "gost", "block-cipher"] 13 | categories = ["cryptography", "no-std"] 14 | 15 | [dependencies] 16 | cipher = "0.5.0-rc.0" 17 | 18 | [dev-dependencies] 19 | cipher = { version = "0.5.0-rc.0", features = ["dev"] } 20 | hex-literal = "1" 21 | 22 | [features] 23 | zeroize = ["cipher/zeroize"] 24 | 25 | [package.metadata.docs.rs] 26 | all-features = true 27 | rustdoc-args = ["--cfg", "docsrs"] 28 | -------------------------------------------------------------------------------- /magma/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017-2024 The RustCrypto Project Developers 2 | Copyright (c) 2017 Artyom Pavlov 3 | 4 | Permission is hereby granted, free of charge, to any 5 | person obtaining a copy of this software and associated 6 | documentation files (the "Software"), to deal in the 7 | Software without restriction, including without 8 | limitation the rights to use, copy, modify, merge, 9 | publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software 11 | is furnished to do so, subject to the following 12 | conditions: 13 | 14 | The above copyright notice and this permission notice 15 | shall be included in all copies or substantial portions 16 | of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 19 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 20 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 21 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 22 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 25 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 | DEALINGS IN THE SOFTWARE. 27 | -------------------------------------------------------------------------------- /magma/README.md: -------------------------------------------------------------------------------- 1 | # RustCrypto: Magma Cipher 2 | 3 | [![crate][crate-image]][crate-link] 4 | [![Docs][docs-image]][docs-link] 5 | ![Apache2/MIT licensed][license-image] 6 | ![Rust Version][rustc-image] 7 | [![Project Chat][chat-image]][chat-link] 8 | [![Build Status][build-image]][build-link] 9 | [![HAZMAT][hazmat-image]][hazmat-link] 10 | 11 | Pure Rust implementation of Magma (GOST 28147-89 and GOST R 34.12-2015) block cipher 12 | 13 | ## ⚠️ Security Warning: [Hazmat!][hazmat-link] 14 | 15 | This crate does not ensure ciphertexts are authentic (i.e. by using a MAC to 16 | verify ciphertext integrity), which can lead to serious vulnerabilities 17 | if used incorrectly! 18 | 19 | No security audits of this crate have ever been performed, and it has not been 20 | thoroughly assessed to ensure its operation is constant-time on common CPU 21 | architectures. 22 | 23 | USE AT YOUR OWN RISK! 24 | 25 | ## License 26 | 27 | Licensed under either of: 28 | 29 | * [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) 30 | * [MIT license](http://opensource.org/licenses/MIT) 31 | 32 | at your option. 33 | 34 | ### Contribution 35 | 36 | Unless you explicitly state otherwise, any contribution intentionally submitted 37 | for inclusion in the work by you, as defined in the Apache-2.0 license, shall be 38 | dual licensed as above, without any additional terms or conditions. 39 | 40 | [//]: # (badges) 41 | 42 | [crate-image]: https://img.shields.io/crates/v/magma.svg 43 | [crate-link]: https://crates.io/crates/magma 44 | [docs-image]: https://docs.rs/magma/badge.svg 45 | [docs-link]: https://docs.rs/magma/ 46 | [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg 47 | [rustc-image]: https://img.shields.io/badge/rustc-1.85+-blue.svg 48 | [hazmat-image]: https://img.shields.io/badge/crypto-hazmat%E2%9A%A0-red.svg 49 | [hazmat-link]: https://github.com/RustCrypto/meta/blob/master/HAZMAT.md 50 | [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg 51 | [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260039-block-ciphers 52 | [build-image]: https://github.com/RustCrypto/block-ciphers/workflows/magma/badge.svg?branch=master&event=push 53 | [build-link]: https://github.com/RustCrypto/block-ciphers/actions?query=workflow%3Amagma 54 | -------------------------------------------------------------------------------- /magma/benches/mod.rs: -------------------------------------------------------------------------------- 1 | #![feature(test)] 2 | extern crate test; 3 | 4 | use cipher::{block_decryptor_bench, block_encryptor_bench}; 5 | use magma::Magma; 6 | 7 | block_encryptor_bench!(Key: Magma, magma_encrypt_block, magma_encrypt_blocks); 8 | block_decryptor_bench!(Key: Magma, magma_decrypt_block, magma_decrypt_blocks); 9 | -------------------------------------------------------------------------------- /rc2/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 | 8 | ## 0.9.0 (UNRELEASED) 9 | ### Changed 10 | - Bump `cipher` dependency to v0.5 11 | - Edition changed to 2024 and MSRV bumped to 1.85 ([#472]) 12 | - Relax MSRV policy and allow MSRV bumps in patch releases ([#477]) 13 | 14 | [#472]: https://github.com/RustCrypto/block-ciphers/pull/472 15 | [#477]: https://github.com/RustCrypto/block-ciphers/pull/477 16 | 17 | ## 0.8.1 (2022-02-17) 18 | ### Fixed 19 | - Minimal versions build ([#303]) 20 | 21 | [#303]: https://github.com/RustCrypto/block-ciphers/pull/303 22 | 23 | ## 0.8.0 (2022-02-10) 24 | ### Changed 25 | - Bump `cipher` dependency to v0.4 ([#284]) 26 | 27 | [#284]: https://github.com/RustCrypto/block-ciphers/pull/284 28 | 29 | ## 0.7.0 (2021-04-29) 30 | ### Changed 31 | - Bump `cipher` dependency to v0.3 release ([#235]) 32 | 33 | [#235]: https://github.com/RustCrypto/block-ciphers/pull/235 34 | 35 | ## 0.6.0 (2020-10-16) 36 | ### Changed 37 | - Replace `block-cipher`/`stream-cipher` with `cipher` crate ([#167]) 38 | 39 | [#167]: https://github.com/RustCrypto/block-ciphers/pull/167 40 | 41 | ## 0.5.0 (2020-08-07) 42 | ### Changed 43 | - Bump `block-cipher` dependency to v0.8 ([#138]) 44 | - Bump `opaque-debug` dependency to v0.3 ([#140]) 45 | 46 | [#138]: https://github.com/RustCrypto/block-ciphers/pull/138 47 | [#140]: https://github.com/RustCrypto/block-ciphers/pull/140 48 | 49 | ## 0.4.0 (2020-06-08) 50 | ### Changed 51 | - Bump `block-cipher` dependency to v0.7 ([#94]) 52 | - Upgrade to Rust 2018 edition ([#94]) 53 | 54 | [#94]: https://github.com/RustCrypto/block-ciphers/pull/94 55 | 56 | ## 0.3.0 (2018-12-23) 57 | 58 | ## 0.2.0 (2017-11-26) 59 | 60 | ## 0.1.0 (2017-04-27) 61 | -------------------------------------------------------------------------------- /rc2/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rc2" 3 | version = "0.9.0-pre" 4 | description = "RC2 block cipher" 5 | authors = ["RustCrypto Developers"] 6 | license = "MIT OR Apache-2.0" 7 | edition = "2024" 8 | rust-version = "1.85" 9 | readme = "README.md" 10 | documentation = "https://docs.rs/rc2" 11 | repository = "https://github.com/RustCrypto/block-ciphers" 12 | keywords = ["crypto", "rc2", "block-cipher"] 13 | categories = ["cryptography", "no-std"] 14 | 15 | [dependencies] 16 | cipher = "0.5.0-rc.0" 17 | 18 | [dev-dependencies] 19 | cipher = { version = "0.5.0-rc.0", features = ["dev"] } 20 | 21 | [features] 22 | zeroize = ["cipher/zeroize"] 23 | 24 | [package.metadata.docs.rs] 25 | all-features = true 26 | rustdoc-args = ["--cfg", "docsrs"] 27 | -------------------------------------------------------------------------------- /rc2/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017-2024 The RustCrypto Project Developers 2 | Copyright (c) 2017 Damian Czaja 3 | 4 | Permission is hereby granted, free of charge, to any 5 | person obtaining a copy of this software and associated 6 | documentation files (the "Software"), to deal in the 7 | Software without restriction, including without 8 | limitation the rights to use, copy, modify, merge, 9 | publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software 11 | is furnished to do so, subject to the following 12 | conditions: 13 | 14 | The above copyright notice and this permission notice 15 | shall be included in all copies or substantial portions 16 | of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 19 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 20 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 21 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 22 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 25 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 | DEALINGS IN THE SOFTWARE. 27 | -------------------------------------------------------------------------------- /rc2/README.md: -------------------------------------------------------------------------------- 1 | # RustCrypto: RC2 Cipher 2 | 3 | [![crate][crate-image]][crate-link] 4 | [![Docs][docs-image]][docs-link] 5 | ![Apache2/MIT licensed][license-image] 6 | ![Rust Version][rustc-image] 7 | [![Project Chat][chat-image]][chat-link] 8 | [![Build Status][build-image]][build-link] 9 | [![HAZMAT][hazmat-image]][hazmat-link] 10 | 11 | Pure Rust implementation of the [RC2 block cipher][1]. 12 | 13 | ## ⚠️ Security Warning: [Hazmat!][hazmat-link] 14 | 15 | This crate does not ensure ciphertexts are authentic (i.e. by using a MAC to 16 | verify ciphertext integrity), which can lead to serious vulnerabilities 17 | if used incorrectly! 18 | 19 | No security audits of this crate have ever been performed, and it has not been 20 | thoroughly assessed to ensure its operation is constant-time on common CPU 21 | architectures. 22 | 23 | USE AT YOUR OWN RISK! 24 | 25 | ## License 26 | 27 | Licensed under either of: 28 | 29 | * [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) 30 | * [MIT license](http://opensource.org/licenses/MIT) 31 | 32 | at your option. 33 | 34 | ### Contribution 35 | 36 | Unless you explicitly state otherwise, any contribution intentionally submitted 37 | for inclusion in the work by you, as defined in the Apache-2.0 license, shall be 38 | dual licensed as above, without any additional terms or conditions. 39 | 40 | [//]: # (badges) 41 | 42 | [crate-image]: https://img.shields.io/crates/v/rc2.svg 43 | [crate-link]: https://crates.io/crates/rc2 44 | [docs-image]: https://docs.rs/rc2/badge.svg 45 | [docs-link]: https://docs.rs/rc2/ 46 | [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg 47 | [rustc-image]: https://img.shields.io/badge/rustc-1.85+-blue.svg 48 | [hazmat-image]: https://img.shields.io/badge/crypto-hazmat%E2%9A%A0-red.svg 49 | [hazmat-link]: https://github.com/RustCrypto/meta/blob/master/HAZMAT.md 50 | [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg 51 | [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260039-block-ciphers 52 | [build-image]: https://github.com/RustCrypto/block-ciphers/workflows/rc2/badge.svg?branch=master&event=push 53 | [build-link]: https://github.com/RustCrypto/block-ciphers/actions?query=workflow%3Arc2 54 | 55 | [//]: # (general links) 56 | 57 | [1]: https://en.wikipedia.org/wiki/RC2 58 | -------------------------------------------------------------------------------- /rc2/benches/mod.rs: -------------------------------------------------------------------------------- 1 | #![feature(test)] 2 | extern crate test; 3 | 4 | use cipher::{block_decryptor_bench, block_encryptor_bench}; 5 | use rc2::Rc2; 6 | 7 | block_encryptor_bench!(Key: Rc2, rc2_encrypt_block, rc2_encrypt_blocks); 8 | block_decryptor_bench!(Key: Rc2, rc2_decrypt_block, rc2_decrypt_blocks); 9 | -------------------------------------------------------------------------------- /rc2/src/consts.rs: -------------------------------------------------------------------------------- 1 | pub static PI_TABLE: [u8; 256] = [ 2 | 217, 120, 249, 196, 25, 221, 181, 237, 40, 233, 253, 121, 74, 160, 216, 157, 198, 126, 55, 131, 3 | 43, 118, 83, 142, 98, 76, 100, 136, 68, 139, 251, 162, 23, 154, 89, 245, 135, 179, 79, 19, 97, 4 | 69, 109, 141, 9, 129, 125, 50, 189, 143, 64, 235, 134, 183, 123, 11, 240, 149, 33, 34, 92, 107, 5 | 78, 130, 84, 214, 101, 147, 206, 96, 178, 28, 115, 86, 192, 20, 167, 140, 241, 220, 18, 117, 6 | 202, 31, 59, 190, 228, 209, 66, 61, 212, 48, 163, 60, 182, 38, 111, 191, 14, 218, 70, 105, 7, 7 | 87, 39, 242, 29, 155, 188, 148, 67, 3, 248, 17, 199, 246, 144, 239, 62, 231, 6, 195, 213, 47, 8 | 200, 102, 30, 215, 8, 232, 234, 222, 128, 82, 238, 247, 132, 170, 114, 172, 53, 77, 106, 42, 9 | 150, 26, 210, 113, 90, 21, 73, 116, 75, 159, 208, 94, 4, 24, 164, 236, 194, 224, 65, 110, 15, 10 | 81, 203, 204, 36, 145, 175, 80, 161, 244, 112, 57, 153, 124, 58, 133, 35, 184, 180, 122, 252, 11 | 2, 54, 91, 37, 85, 151, 49, 45, 93, 250, 152, 227, 138, 146, 174, 5, 223, 41, 16, 103, 108, 12 | 186, 201, 211, 0, 230, 207, 225, 158, 168, 44, 99, 22, 1, 63, 88, 226, 137, 169, 13, 56, 52, 13 | 27, 171, 51, 255, 176, 187, 72, 12, 95, 185, 177, 205, 46, 197, 243, 219, 71, 229, 165, 156, 14 | 119, 10, 166, 32, 104, 254, 127, 193, 173, 15 | ]; 16 | -------------------------------------------------------------------------------- /rc2/tests/data/1.input.bin: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rc2/tests/data/1.key.bin: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rc2/tests/data/1.output.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustCrypto/block-ciphers/73b104d31747ff763de345372ceab6eeffd04319/rc2/tests/data/1.output.bin -------------------------------------------------------------------------------- /rc2/tests/data/2.input.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustCrypto/block-ciphers/73b104d31747ff763de345372ceab6eeffd04319/rc2/tests/data/2.input.bin -------------------------------------------------------------------------------- /rc2/tests/data/2.key.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustCrypto/block-ciphers/73b104d31747ff763de345372ceab6eeffd04319/rc2/tests/data/2.key.bin -------------------------------------------------------------------------------- /rc2/tests/data/2.output.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustCrypto/block-ciphers/73b104d31747ff763de345372ceab6eeffd04319/rc2/tests/data/2.output.bin -------------------------------------------------------------------------------- /rc2/tests/data/3.input.bin: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /rc2/tests/data/3.key.bin: -------------------------------------------------------------------------------- 1 | 0 -------------------------------------------------------------------------------- /rc2/tests/data/3.output.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustCrypto/block-ciphers/73b104d31747ff763de345372ceab6eeffd04319/rc2/tests/data/3.output.bin -------------------------------------------------------------------------------- /rc2/tests/data/4.input.bin: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rc2/tests/data/4.key.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustCrypto/block-ciphers/73b104d31747ff763de345372ceab6eeffd04319/rc2/tests/data/4.key.bin -------------------------------------------------------------------------------- /rc2/tests/data/4.output.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustCrypto/block-ciphers/73b104d31747ff763de345372ceab6eeffd04319/rc2/tests/data/4.output.bin -------------------------------------------------------------------------------- /rc2/tests/data/5.input.bin: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rc2/tests/data/5.key.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustCrypto/block-ciphers/73b104d31747ff763de345372ceab6eeffd04319/rc2/tests/data/5.key.bin -------------------------------------------------------------------------------- /rc2/tests/data/5.output.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustCrypto/block-ciphers/73b104d31747ff763de345372ceab6eeffd04319/rc2/tests/data/5.output.bin -------------------------------------------------------------------------------- /rc2/tests/data/6.input.bin: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rc2/tests/data/6.key.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustCrypto/block-ciphers/73b104d31747ff763de345372ceab6eeffd04319/rc2/tests/data/6.key.bin -------------------------------------------------------------------------------- /rc2/tests/data/6.output.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustCrypto/block-ciphers/73b104d31747ff763de345372ceab6eeffd04319/rc2/tests/data/6.output.bin -------------------------------------------------------------------------------- /rc2/tests/data/7.input.bin: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rc2/tests/data/7.key.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustCrypto/block-ciphers/73b104d31747ff763de345372ceab6eeffd04319/rc2/tests/data/7.key.bin -------------------------------------------------------------------------------- /rc2/tests/data/7.output.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustCrypto/block-ciphers/73b104d31747ff763de345372ceab6eeffd04319/rc2/tests/data/7.output.bin -------------------------------------------------------------------------------- /rc2/tests/data/8.input.bin: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rc2/tests/data/8.key.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustCrypto/block-ciphers/73b104d31747ff763de345372ceab6eeffd04319/rc2/tests/data/8.key.bin -------------------------------------------------------------------------------- /rc2/tests/data/8.output.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustCrypto/block-ciphers/73b104d31747ff763de345372ceab6eeffd04319/rc2/tests/data/8.output.bin -------------------------------------------------------------------------------- /rc2/tests/mod.rs: -------------------------------------------------------------------------------- 1 | use cipher::array::Array; 2 | use cipher::{BlockCipherDecrypt, BlockCipherEncrypt, KeyInit}; 3 | 4 | struct Test { 5 | key: &'static [u8], 6 | input: &'static [u8], 7 | output: &'static [u8], 8 | } 9 | 10 | #[macro_export] 11 | macro_rules! new_tests { 12 | ( $( $name:expr ),* ) => { 13 | [$( 14 | Test { 15 | key: include_bytes!(concat!("data/", $name, ".key.bin")), 16 | input: include_bytes!(concat!("data/", $name, ".input.bin")), 17 | output: include_bytes!(concat!("data/", $name, ".output.bin")), 18 | }, 19 | )*] 20 | }; 21 | } 22 | 23 | #[test] 24 | #[allow(deprecated)] // uses `clone_from_slice` 25 | fn rc2() { 26 | let tests = new_tests!("1", "2", "3", "7"); 27 | for test in &tests { 28 | let cipher = rc2::Rc2::new_from_slice(test.key).unwrap(); 29 | 30 | let mut buf = Array::clone_from_slice(test.input); 31 | cipher.encrypt_block(&mut buf); 32 | assert_eq!(test.output, &buf[..]); 33 | 34 | let mut buf = Array::clone_from_slice(test.output); 35 | cipher.decrypt_block(&mut buf); 36 | assert_eq!(test.input, &buf[..]); 37 | } 38 | } 39 | 40 | #[test] 41 | #[allow(deprecated)] // uses `clone_from_slice` 42 | fn rc2_effective_key_64() { 43 | let tests = new_tests!("4", "5", "6"); 44 | for test in &tests { 45 | let cipher = rc2::Rc2::new_with_eff_key_len(test.key, 64); 46 | 47 | let mut buf = Array::clone_from_slice(test.input); 48 | cipher.encrypt_block(&mut buf); 49 | assert_eq!(test.output, &buf[..]); 50 | 51 | let mut buf = Array::clone_from_slice(test.output); 52 | cipher.decrypt_block(&mut buf); 53 | assert_eq!(test.input, &buf[..]); 54 | } 55 | } 56 | 57 | #[test] 58 | #[allow(deprecated)] // uses `clone_from_slice` 59 | fn rc2_effective_key_129() { 60 | let tests = new_tests!("8"); 61 | for test in &tests { 62 | let cipher = rc2::Rc2::new_with_eff_key_len(test.key, 129); 63 | 64 | let mut buf = Array::clone_from_slice(test.input); 65 | cipher.encrypt_block(&mut buf); 66 | assert_eq!(test.output, &buf[..]); 67 | 68 | let mut buf = Array::clone_from_slice(test.output); 69 | cipher.decrypt_block(&mut buf); 70 | assert_eq!(test.input, &buf[..]); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /rc5/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 | 8 | ## 0.1.0 (UNRELEASED) 9 | ### Changed 10 | - Bump `cipher` dependency to v0.5 11 | - Edition changed to 2024 and MSRV bumped to 1.85 ([#472]) 12 | - Relax MSRV policy and allow MSRV bumps in patch releases ([#477]) 13 | - Unlock parameter size, add u128 and u8 word size support ([#382]) 14 | 15 | ### Deprecated 16 | - Old predefined RC5 cipher types ([#382]) 17 | 18 | [#382]: https://github.com/RustCrypto/block-ciphers/pull/382 19 | [#472]: https://github.com/RustCrypto/block-ciphers/pull/472 20 | [#477]: https://github.com/RustCrypto/block-ciphers/pull/477 21 | 22 | ## 0.0.1 (2023-02-10) 23 | - Initial release 24 | -------------------------------------------------------------------------------- /rc5/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rc5" 3 | version = "0.1.0-pre" 4 | description = "RC5 block cipher" 5 | authors = ["RustCrypto Developers"] 6 | edition = "2024" 7 | license = "MIT OR Apache-2.0" 8 | rust-version = "1.85" 9 | readme = "README.md" 10 | repository = "https://github.com/RustCrypto/block-ciphers" 11 | keywords = ["crypto", "rc5", "block-cipher"] 12 | categories = ["cryptography"] 13 | 14 | [dependencies] 15 | cipher = "0.5.0-rc.0" 16 | 17 | [dev-dependencies] 18 | cipher = { version = "0.5.0-rc.0", features = ["dev"] } 19 | hex-literal = "1" 20 | 21 | [features] 22 | zeroize = ["cipher/zeroize"] 23 | 24 | [package.metadata.docs.rs] 25 | all-features = true 26 | rustdoc-args = ["--cfg", "docsrs"] 27 | -------------------------------------------------------------------------------- /rc5/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2022-2024 The RustCrypto Project Developers 2 | Copyright (c) 2022 Antonio Dropulic 3 | 4 | Permission is hereby granted, free of charge, to any 5 | person obtaining a copy of this software and associated 6 | documentation files (the "Software"), to deal in the 7 | Software without restriction, including without 8 | limitation the rights to use, copy, modify, merge, 9 | publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software 11 | is furnished to do so, subject to the following 12 | conditions: 13 | 14 | The above copyright notice and this permission notice 15 | shall be included in all copies or substantial portions 16 | of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 19 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 20 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 21 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 22 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 25 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 | DEALINGS IN THE SOFTWARE. 27 | -------------------------------------------------------------------------------- /rc5/README.md: -------------------------------------------------------------------------------- 1 | # [RustCrypto]: RC5 Cipher 2 | 3 | [![crate][crate-image]][crate-link] 4 | [![Docs][docs-image]][docs-link] 5 | [![Build Status][build-image]][build-link] 6 | ![Apache2/MIT licensed][license-image] 7 | ![Rust Version][rustc-image] 8 | [![Project Chat][chat-image]][chat-link] 9 | [![HAZMAT][hazmat-image]][hazmat-link] 10 | 11 | Pure Rust implementation of the [RC5] block cipher. 12 | 13 | ## ⚠️ Security Warning: [Hazmat!][hazmat-link] 14 | 15 | This crate does not ensure ciphertexts are authentic (i.e. by using a MAC to 16 | verify ciphertext integrity), which can lead to serious vulnerabilities 17 | if used incorrectly! 18 | 19 | No security audits of this crate have ever been performed, and it has not been 20 | thoroughly assessed to ensure its operation is constant-time on common CPU 21 | architectures. 22 | 23 | USE AT YOUR OWN RISK! 24 | 25 | ## License 26 | 27 | Licensed under either of: 28 | 29 | * [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) 30 | * [MIT license](http://opensource.org/licenses/MIT) 31 | 32 | at your option. 33 | 34 | ### Contribution 35 | 36 | Unless you explicitly state otherwise, any contribution intentionally submitted 37 | for inclusion in the work by you, as defined in the Apache-2.0 license, shall be 38 | dual licensed as above, without any additional terms or conditions. 39 | 40 | [//]: # (badges) 41 | 42 | [crate-image]: https://img.shields.io/crates/v/rc5.svg 43 | [crate-link]: https://crates.io/crates/rc5 44 | [docs-image]: https://docs.rs/rc5/badge.svg 45 | [docs-link]: https://docs.rs/rc5/ 46 | [build-image]: https://github.com/RustCrypto/block-ciphers/actions/workflows/rc5.yml/badge.svg 47 | [build-link]: https://github.com/RustCrypto/block-ciphers/actions/workflows/rc5.yml 48 | [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg 49 | [rustc-image]: https://img.shields.io/badge/rustc-1.85+-blue.svg 50 | [hazmat-image]: https://img.shields.io/badge/crypto-hazmat%E2%9A%A0-red.svg 51 | [hazmat-link]: https://github.com/RustCrypto/meta/blob/master/HAZMAT.md 52 | [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg 53 | [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260039-block-ciphers 54 | 55 | [//]: # (general links) 56 | 57 | [RustCrypto]: https://github.com/RustCrypto/ 58 | [RC5]: https://en.wikipedia.org/wiki/RC5 59 | -------------------------------------------------------------------------------- /rc5/benches/mod.rs: -------------------------------------------------------------------------------- 1 | #![feature(test)] 2 | extern crate test; 3 | 4 | use cipher::consts::*; 5 | use cipher::{block_decryptor_bench, block_encryptor_bench}; 6 | use rc5::RC5; 7 | 8 | block_encryptor_bench!( 9 | Key: RC5, 10 | rc5_32_12_16_encrypt_block, 11 | rc5_32_12_16_encrypt_blocks, 12 | ); 13 | block_decryptor_bench!( 14 | Key: RC5, 15 | rc5_32_12_16_decrypt_block, 16 | rc5_32_12_16_decrypt_blocks, 17 | ); 18 | 19 | block_encryptor_bench!( 20 | Key: RC5, 21 | rc5_32_16_16_encrypt_block, 22 | rc5_32_16_16_encrypt_blocks, 23 | ); 24 | block_decryptor_bench!( 25 | Key: RC5, 26 | rc5_32_16_16_decrypt_block, 27 | rc5_32_16_16_decrypt_blocks, 28 | ); 29 | -------------------------------------------------------------------------------- /serpent/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 | 8 | ## 0.6.0 (UNRELEASED) 9 | ### Added 10 | - `serpent_no_unroll` configuration flag ([#476]) 11 | 12 | ### Changed 13 | - Bump `cipher` dependency to v0.5 14 | - Edition changed to 2024 and MSRV bumped to 1.85 ([#472]) 15 | - Relax MSRV policy and allow MSRV bumps in patch releases ([#477]) 16 | - Improve bitslicing implementation ([#474]) 17 | 18 | [#472]: https://github.com/RustCrypto/block-ciphers/pull/472 19 | [#474]: https://github.com/RustCrypto/block-ciphers/pull/474 20 | [#476]: https://github.com/RustCrypto/block-ciphers/pull/476 21 | [#477]: https://github.com/RustCrypto/block-ciphers/pull/477 22 | 23 | ## 0.5.1 (2022-02-17) 24 | ### Fixed 25 | - Minimal versions build ([#303]) 26 | 27 | [#303]: https://github.com/RustCrypto/block-ciphers/pull/303 28 | 29 | ## 0.5.0 (2022-02-10) 30 | ### Changed 31 | - Bump `cipher` dependency to v0.4 ([#284]) 32 | 33 | [#284]: https://github.com/RustCrypto/block-ciphers/pull/284 34 | 35 | ## 0.4.0 (2021-04-29) 36 | ### Changed 37 | - Bump `cipher` dependency to v0.3 ([#235]) 38 | 39 | [#235]: https://github.com/RustCrypto/block-ciphers/pull/235 40 | 41 | ## 0.3.0 (2020-10-16) 42 | ### Changed 43 | - Replace `block-cipher`/`stream-cipher` with `cipher` crate ([#167]) 44 | 45 | [#167]: https://github.com/RustCrypto/block-ciphers/pull/167 46 | 47 | ## 0.2.0 (2020-08-07) 48 | ### Changed 49 | - Bump `block-cipher` dependency to v0.8 ([#138]) 50 | - Bump `opaque-debug` dependency to v0.3 ([#140]) 51 | 52 | [#138]: https://github.com/RustCrypto/block-ciphers/pull/138 53 | [#140]: https://github.com/RustCrypto/block-ciphers/pull/140 54 | 55 | ## 0.1.0 (2020-06-08) 56 | ### Added 57 | - Benchmarks ([#105]) 58 | 59 | ### Changed 60 | - Bump `block-cipher` dependency to v0.7 ([#95]) 61 | - Upgrade to Rust 2018 edition ([#95]) 62 | 63 | [#105]: https://github.com/RustCrypto/block-ciphers/pull/105 64 | [#95]: https://github.com/RustCrypto/block-ciphers/pull/95 65 | 66 | ## 0.0.1 (2020-05-23) 67 | - Initial release 68 | -------------------------------------------------------------------------------- /serpent/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "serpent" 3 | version = "0.6.0-pre" 4 | description = "Serpent block cipher" 5 | authors = ["RustCrypto Developers"] 6 | license = "MIT OR Apache-2.0" 7 | edition = "2024" 8 | rust-version = "1.85" 9 | readme = "README.md" 10 | documentation = "https://docs.rs/serpent" 11 | repository = "https://github.com/RustCrypto/block-ciphers" 12 | keywords = ["crypto", "serpent", "block-cipher"] 13 | categories = ["cryptography", "no-std"] 14 | 15 | [dependencies] 16 | cipher = "0.5.0-rc.0" 17 | 18 | [dev-dependencies] 19 | cipher = { version = "0.5.0-rc.0", features = ["dev"] } 20 | 21 | [features] 22 | zeroize = ["cipher/zeroize"] 23 | 24 | [package.metadata.docs.rs] 25 | all-features = true 26 | rustdoc-args = ["--cfg", "docsrs"] 27 | 28 | [lints.rust] 29 | unexpected_cfgs = { level = "warn", check-cfg = ['cfg(serpent_no_unroll)'] } 30 | -------------------------------------------------------------------------------- /serpent/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2019-2024 The RustCrypto Project Developers 2 | Copyright (c) 2019 Jonathan Serra 3 | 4 | Permission is hereby granted, free of charge, to any 5 | person obtaining a copy of this software and associated 6 | documentation files (the "Software"), to deal in the 7 | Software without restriction, including without 8 | limitation the rights to use, copy, modify, merge, 9 | publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software 11 | is furnished to do so, subject to the following 12 | conditions: 13 | 14 | The above copyright notice and this permission notice 15 | shall be included in all copies or substantial portions 16 | of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 19 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 20 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 21 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 22 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 25 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 | DEALINGS IN THE SOFTWARE. 27 | -------------------------------------------------------------------------------- /serpent/benches/mod.rs: -------------------------------------------------------------------------------- 1 | #![feature(test)] 2 | extern crate test; 3 | 4 | use cipher::{block_decryptor_bench, block_encryptor_bench}; 5 | use serpent::Serpent; 6 | 7 | block_encryptor_bench!(Key: Serpent, serpent_encrypt_block, serpent_encrypt_blocks); 8 | block_decryptor_bench!(Key: Serpent, serpent_decrypt_block, serpent_decrypt_blocks); 9 | -------------------------------------------------------------------------------- /serpent/src/unroll.rs: -------------------------------------------------------------------------------- 1 | #[cfg(not(serpent_no_unroll))] 2 | #[rustfmt::skip] 3 | macro_rules! unroll31 { 4 | ($i:ident, $body:block) => { 5 | let $i = 0; $body; 6 | let $i = 1; $body; 7 | let $i = 2; $body; 8 | let $i = 3; $body; 9 | let $i = 4; $body; 10 | let $i = 5; $body; 11 | let $i = 6; $body; 12 | let $i = 7; $body; 13 | let $i = 8; $body; 14 | let $i = 9; $body; 15 | let $i = 10; $body; 16 | let $i = 11; $body; 17 | let $i = 12; $body; 18 | let $i = 13; $body; 19 | let $i = 14; $body; 20 | let $i = 15; $body; 21 | let $i = 16; $body; 22 | let $i = 17; $body; 23 | let $i = 18; $body; 24 | let $i = 19; $body; 25 | let $i = 20; $body; 26 | let $i = 21; $body; 27 | let $i = 22; $body; 28 | let $i = 23; $body; 29 | let $i = 24; $body; 30 | let $i = 25; $body; 31 | let $i = 26; $body; 32 | let $i = 27; $body; 33 | let $i = 28; $body; 34 | let $i = 29; $body; 35 | let $i = 30; $body; 36 | }; 37 | } 38 | 39 | #[cfg(serpent_no_unroll)] 40 | macro_rules! unroll31 { 41 | ($i:ident, $body:block) => { 42 | for $i in 0..31 { 43 | $body; 44 | } 45 | }; 46 | } 47 | -------------------------------------------------------------------------------- /serpent/tests/data/serpent128.blb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustCrypto/block-ciphers/73b104d31747ff763de345372ceab6eeffd04319/serpent/tests/data/serpent128.blb -------------------------------------------------------------------------------- /serpent/tests/data/serpent192.blb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustCrypto/block-ciphers/73b104d31747ff763de345372ceab6eeffd04319/serpent/tests/data/serpent192.blb -------------------------------------------------------------------------------- /serpent/tests/data/serpent256.blb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustCrypto/block-ciphers/73b104d31747ff763de345372ceab6eeffd04319/serpent/tests/data/serpent256.blb -------------------------------------------------------------------------------- /serpent/tests/mod.rs: -------------------------------------------------------------------------------- 1 | //! Test vectors from Nessie: 2 | //! http://www.cs.technion.ac.il/~biham/Reports/Serpent/Serpent-128-128.verified.test-vectors 3 | 4 | cipher::block_cipher_test!(serpent128_test, "serpent128", serpent::Serpent); 5 | cipher::block_cipher_test!(serpent192_test, "serpent192", serpent::Serpent); 6 | cipher::block_cipher_test!(serpent256_test, "serpent256", serpent::Serpent); 7 | -------------------------------------------------------------------------------- /sm4/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 | 8 | ## 0.2.0 (UNRELEASED) 9 | ### Changed 10 | - Bump `cipher` dependency to v0.5 11 | - Edition changed to 2024 and MSRV bumped to 1.85 ([#472]) 12 | - Relax MSRV policy and allow MSRV bumps in patch releases ([#477]) 13 | 14 | [#472]: https://github.com/RustCrypto/block-ciphers/pull/472 15 | [#477]: https://github.com/RustCrypto/block-ciphers/pull/477 16 | 17 | ## 0.5.1 (2022-02-17) 18 | ### Fixed 19 | - Minimal versions build ([#303]) 20 | 21 | [#303]: https://github.com/RustCrypto/block-ciphers/pull/303 22 | 23 | ## 0.5.0 (2022-02-10) 24 | ### Changed 25 | - Bump `cipher` dependency to v0.4 ([#284]) 26 | 27 | [#284]: https://github.com/RustCrypto/block-ciphers/pull/284 28 | 29 | ## 0.4.0 (2021-04-29) 30 | ### Changed 31 | - Bump `cipher` dependency to v0.3 ([#235]) 32 | 33 | [#235]: https://github.com/RustCrypto/block-ciphers/pull/235 34 | 35 | ## 0.3.0 (2020-10-16) 36 | ### Changed 37 | - Replace `block-cipher`/`stream-cipher` with `cipher` crate ([#167]) 38 | 39 | [#167]: https://github.com/RustCrypto/block-ciphers/pull/167 40 | 41 | ## 0.2.0 (2020-08-07) 42 | ### Changed 43 | - Bump `block-cipher` dependency to v0.8 ([#138]) 44 | - Bump `opaque-debug` dependency to v0.3 ([#140]) 45 | 46 | [#138]: https://github.com/RustCrypto/block-ciphers/pull/138 47 | [#140]: https://github.com/RustCrypto/block-ciphers/pull/140 48 | 49 | ## 0.1.0 (2020-06-08) 50 | ### Changed 51 | - Bump `block-cipher` dependency to v0.7 ([#97]) 52 | - Upgrade to Rust 2018 edition ([#97]) 53 | 54 | [#97]: https://github.com/RustCrypto/block-ciphers/pull/97 55 | 56 | ## 0.0.1 (2020-05-23) 57 | - Initial release 58 | -------------------------------------------------------------------------------- /sm4/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "sm4" 3 | version = "0.6.0-pre" 4 | description = "SM4 block cipher algorithm" 5 | authors = ["RustCrypto Developers"] 6 | license = "MIT OR Apache-2.0" 7 | edition = "2024" 8 | rust-version = "1.85" 9 | readme = "README.md" 10 | documentation = "https://docs.rs/sm4" 11 | repository = "https://github.com/RustCrypto/block-ciphers" 12 | keywords = ["crypto", "sm4", "block-cipher"] 13 | categories = ["cryptography", "no-std"] 14 | 15 | [dependencies] 16 | cipher = "0.5.0-rc.0" 17 | 18 | [dev-dependencies] 19 | cipher = { version = "0.5.0-rc.0", features = ["dev"] } 20 | hex-literal = "1" 21 | 22 | [features] 23 | zeroize = ["cipher/zeroize"] 24 | 25 | [package.metadata.docs.rs] 26 | all-features = true 27 | rustdoc-args = ["--cfg", "docsrs"] 28 | -------------------------------------------------------------------------------- /sm4/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2020-2024 The RustCrypto Project Developers 2 | 3 | Permission is hereby granted, free of charge, to any 4 | person obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the 6 | Software without restriction, including without 7 | limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software 10 | is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice 14 | shall be included in all copies or substantial portions 15 | of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 18 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 19 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 24 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /sm4/README.md: -------------------------------------------------------------------------------- 1 | # RustCrypto: SM4 Cipher 2 | 3 | [![crate][crate-image]][crate-link] 4 | [![Docs][docs-image]][docs-link] 5 | ![Apache2/MIT licensed][license-image] 6 | ![Rust Version][rustc-image] 7 | [![Project Chat][chat-image]][chat-link] 8 | [![Build Status][build-image]][build-link] 9 | [![HAZMAT][hazmat-image]][hazmat-link] 10 | 11 | Pure Rust implementation of the [SM4 block cipher][1]. 12 | 13 | ## ⚠️ Security Warning: [Hazmat!][hazmat-link] 14 | 15 | This crate does not ensure ciphertexts are authentic (i.e. by using a MAC to 16 | verify ciphertext integrity), which can lead to serious vulnerabilities 17 | if used incorrectly! 18 | 19 | No security audits of this crate have ever been performed, and it has not been 20 | thoroughly assessed to ensure its operation is constant-time on common CPU 21 | architectures. 22 | 23 | USE AT YOUR OWN RISK! 24 | 25 | ## License 26 | 27 | Licensed under either of: 28 | 29 | * [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) 30 | * [MIT license](http://opensource.org/licenses/MIT) 31 | 32 | at your option. 33 | 34 | ### Contribution 35 | 36 | Unless you explicitly state otherwise, any contribution intentionally submitted 37 | for inclusion in the work by you, as defined in the Apache-2.0 license, shall be 38 | dual licensed as above, without any additional terms or conditions. 39 | 40 | [//]: # (badges) 41 | 42 | [crate-image]: https://img.shields.io/crates/v/sm4.svg 43 | [crate-link]: https://crates.io/crates/sm4 44 | [docs-image]: https://docs.rs/sm4/badge.svg 45 | [docs-link]: https://docs.rs/sm4/ 46 | [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg 47 | [rustc-image]: https://img.shields.io/badge/rustc-1.85+-blue.svg 48 | [hazmat-image]: https://img.shields.io/badge/crypto-hazmat%E2%9A%A0-red.svg 49 | [hazmat-link]: https://github.com/RustCrypto/meta/blob/master/HAZMAT.md 50 | [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg 51 | [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260039-block-ciphers 52 | [build-image]: https://github.com/RustCrypto/block-ciphers/workflows/sm4/badge.svg?branch=master&event=push 53 | [build-link]: https://github.com/RustCrypto/block-ciphers/actions?query=workflow%3Asm4 54 | 55 | [//]: # (general links) 56 | 57 | [1]: https://en.wikipedia.org/wiki/SM4_(cipher) 58 | -------------------------------------------------------------------------------- /sm4/benches/mod.rs: -------------------------------------------------------------------------------- 1 | #![feature(test)] 2 | extern crate test; 3 | 4 | use cipher::{block_decryptor_bench, block_encryptor_bench}; 5 | use sm4::Sm4; 6 | 7 | block_encryptor_bench!(Key: Sm4, sm4_encrypt_block, sm4_encrypt_blocks); 8 | block_decryptor_bench!(Key: Sm4, sm4_decrypt_block, sm4_decrypt_blocks); 9 | -------------------------------------------------------------------------------- /sm4/src/consts.rs: -------------------------------------------------------------------------------- 1 | pub(crate) const SBOX: [u8; 256] = [ 2 | 0xd6, 0x90, 0xe9, 0xfe, 0xcc, 0xe1, 0x3d, 0xb7, 0x16, 0xb6, 0x14, 0xc2, 0x28, 0xfb, 0x2c, 0x05, 3 | 0x2b, 0x67, 0x9a, 0x76, 0x2a, 0xbe, 0x04, 0xc3, 0xaa, 0x44, 0x13, 0x26, 0x49, 0x86, 0x06, 0x99, 4 | 0x9c, 0x42, 0x50, 0xf4, 0x91, 0xef, 0x98, 0x7a, 0x33, 0x54, 0x0b, 0x43, 0xed, 0xcf, 0xac, 0x62, 5 | 0xe4, 0xb3, 0x1c, 0xa9, 0xc9, 0x08, 0xe8, 0x95, 0x80, 0xdf, 0x94, 0xfa, 0x75, 0x8f, 0x3f, 0xa6, 6 | 0x47, 0x07, 0xa7, 0xfc, 0xf3, 0x73, 0x17, 0xba, 0x83, 0x59, 0x3c, 0x19, 0xe6, 0x85, 0x4f, 0xa8, 7 | 0x68, 0x6b, 0x81, 0xb2, 0x71, 0x64, 0xda, 0x8b, 0xf8, 0xeb, 0x0f, 0x4b, 0x70, 0x56, 0x9d, 0x35, 8 | 0x1e, 0x24, 0x0e, 0x5e, 0x63, 0x58, 0xd1, 0xa2, 0x25, 0x22, 0x7c, 0x3b, 0x01, 0x21, 0x78, 0x87, 9 | 0xd4, 0x00, 0x46, 0x57, 0x9f, 0xd3, 0x27, 0x52, 0x4c, 0x36, 0x02, 0xe7, 0xa0, 0xc4, 0xc8, 0x9e, 10 | 0xea, 0xbf, 0x8a, 0xd2, 0x40, 0xc7, 0x38, 0xb5, 0xa3, 0xf7, 0xf2, 0xce, 0xf9, 0x61, 0x15, 0xa1, 11 | 0xe0, 0xae, 0x5d, 0xa4, 0x9b, 0x34, 0x1a, 0x55, 0xad, 0x93, 0x32, 0x30, 0xf5, 0x8c, 0xb1, 0xe3, 12 | 0x1d, 0xf6, 0xe2, 0x2e, 0x82, 0x66, 0xca, 0x60, 0xc0, 0x29, 0x23, 0xab, 0x0d, 0x53, 0x4e, 0x6f, 13 | 0xd5, 0xdb, 0x37, 0x45, 0xde, 0xfd, 0x8e, 0x2f, 0x03, 0xff, 0x6a, 0x72, 0x6d, 0x6c, 0x5b, 0x51, 14 | 0x8d, 0x1b, 0xaf, 0x92, 0xbb, 0xdd, 0xbc, 0x7f, 0x11, 0xd9, 0x5c, 0x41, 0x1f, 0x10, 0x5a, 0xd8, 15 | 0x0a, 0xc1, 0x31, 0x88, 0xa5, 0xcd, 0x7b, 0xbd, 0x2d, 0x74, 0xd0, 0x12, 0xb8, 0xe5, 0xb4, 0xb0, 16 | 0x89, 0x69, 0x97, 0x4a, 0x0c, 0x96, 0x77, 0x7e, 0x65, 0xb9, 0xf1, 0x09, 0xc5, 0x6e, 0xc6, 0x84, 17 | 0x18, 0xf0, 0x7d, 0xec, 0x3a, 0xdc, 0x4d, 0x20, 0x79, 0xee, 0x5f, 0x3e, 0xd7, 0xcb, 0x39, 0x48, 18 | ]; 19 | 20 | pub(crate) const FK: [u32; 4] = [0xa3b1bac6, 0x56aa3350, 0x677d9197, 0xb27022dc]; 21 | 22 | pub(crate) const CK: [u32; 32] = [ 23 | 0x00070e15, 0x1c232a31, 0x383f464d, 0x545b6269, 0x70777e85, 0x8c939aa1, 0xa8afb6bd, 0xc4cbd2d9, 24 | 0xe0e7eef5, 0xfc030a11, 0x181f262d, 0x343b4249, 0x50575e65, 0x6c737a81, 0x888f969d, 0xa4abb2b9, 25 | 0xc0c7ced5, 0xdce3eaf1, 0xf8ff060d, 0x141b2229, 0x30373e45, 0x4c535a61, 0x686f767d, 0x848b9299, 26 | 0xa0a7aeb5, 0xbcc3cad1, 0xd8dfe6ed, 0xf4fb0209, 0x10171e25, 0x2c333a41, 0x484f565d, 0x646b7279, 27 | ]; 28 | -------------------------------------------------------------------------------- /sm4/tests/mod.rs: -------------------------------------------------------------------------------- 1 | //! Test vectors are from GM/T 0002-2012 2 | 3 | use cipher::{BlockCipherDecrypt, BlockCipherEncrypt, KeyInit}; 4 | use hex_literal::hex; 5 | use sm4::Sm4; 6 | 7 | #[test] 8 | fn sm4_example_1() { 9 | let key = hex!("0123456789abcdeffedcba9876543210"); 10 | let plaintext = key; 11 | let ciphertext = hex!("681EDF34D206965E86B3E94F536E4246"); 12 | let cipher = Sm4::new(&key.into()); 13 | 14 | let mut block = plaintext.into(); 15 | cipher.encrypt_block(&mut block); 16 | 17 | assert_eq!(&ciphertext, block.as_slice()); 18 | 19 | cipher.decrypt_block(&mut block); 20 | assert_eq!(&plaintext, block.as_slice()); 21 | } 22 | 23 | #[test] 24 | fn sm4_example_2() { 25 | let key = hex!("0123456789abcdeffedcba9876543210"); 26 | let plaintext = key; 27 | let ciphertext = hex!("595298c7c6fd271f0402f804c33d3f66"); 28 | 29 | let cipher = Sm4::new(&key.into()); 30 | 31 | let mut block = plaintext.into(); 32 | for _ in 0..1_000_000 { 33 | cipher.encrypt_block(&mut block); 34 | } 35 | assert_eq!(&ciphertext, block.as_slice()); 36 | 37 | for _ in 0..1_000_000 { 38 | cipher.decrypt_block(&mut block); 39 | } 40 | assert_eq!(&plaintext, block.as_slice()); 41 | } 42 | -------------------------------------------------------------------------------- /speck/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 | 8 | ## 0.1.0 (UNRELEASED) 9 | ### Changed 10 | - Bump `cipher` dependency to v0.5 11 | - Edition changed to 2024 and MSRV bumped to 1.85 ([#472]) 12 | - Relax MSRV policy and allow MSRV bumps in patch releases ([#477]) 13 | 14 | [#472]: https://github.com/RustCrypto/block-ciphers/pull/472 15 | [#477]: https://github.com/RustCrypto/block-ciphers/pull/477 16 | 17 | ## 0.0.1 (2024-05-17) 18 | - Initial release 19 | -------------------------------------------------------------------------------- /speck/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "speck-cipher" 3 | version = "0.0.0" 4 | authors = ["RustCrypto Developers"] 5 | license = "Apache-2.0 OR MIT" 6 | description = "Speck block cipher algorithm" 7 | documentation = "https://docs.rs/speck" 8 | repository = "https://github.com/RustCrypto/block-ciphers/tree/master/speck" 9 | readme = "README.md" 10 | edition = "2024" 11 | rust-version = "1.85" 12 | keywords = ["crypto", "speck", "block-cipher"] 13 | categories = ["cryptography", "no-std"] 14 | 15 | [dependencies] 16 | cipher = "0.5.0-rc.0" 17 | 18 | [dev-dependencies] 19 | cipher = { version = "0.5.0-rc.0", features = ["dev"] } 20 | hex-literal = "1" 21 | 22 | [features] 23 | zeroize = ["cipher/zeroize"] 24 | 25 | [package.metadata.docs.rs] 26 | all-features = true 27 | rustdoc-args = ["--cfg", "docsrs"] 28 | -------------------------------------------------------------------------------- /speck/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2023-2024 The RustCrypto Project Developers 2 | 3 | Permission is hereby granted, free of charge, to any 4 | person obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the 6 | Software without restriction, including without 7 | limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software 10 | is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice 14 | shall be included in all copies or substantial portions 15 | of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 18 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 19 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 24 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /speck/README.md: -------------------------------------------------------------------------------- 1 | # RustCrypto: Speck Cipher 2 | 3 | [![crate][crate-image]][crate-link] 4 | [![Docs][docs-image]][docs-link] 5 | ![Apache2/MIT licensed][license-image] 6 | ![Rust Version][rustc-image] 7 | [![Project Chat][chat-image]][chat-link] 8 | [![Build Status][build-image]][build-link] 9 | [![HAZMAT][hazmat-image]][hazmat-link] 10 | 11 | Pure Rust implementation of the [Speck block cipher][1]. 12 | 13 | ## ⚠️ Security Warning: [Hazmat!][hazmat-link] 14 | 15 | This crate does not ensure ciphertexts are authentic (i.e. by using a MAC to 16 | verify ciphertext integrity), which can lead to serious vulnerabilities 17 | if used incorrectly! 18 | 19 | No security audits of this crate have ever been performed, and it has not been 20 | thoroughly assessed to ensure its operation is constant-time on common CPU 21 | architectures. 22 | 23 | USE AT YOUR OWN RISK! 24 | 25 | ## License 26 | 27 | Licensed under either of: 28 | 29 | * [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) 30 | * [MIT license](http://opensource.org/licenses/MIT) 31 | 32 | at your option. 33 | 34 | ### Contribution 35 | 36 | Unless you explicitly state otherwise, any contribution intentionally submitted 37 | for inclusion in the work by you, as defined in the Apache-2.0 license, shall be 38 | dual licensed as above, without any additional terms or conditions. 39 | 40 | [//]: # (badges) 41 | 42 | [crate-image]: https://img.shields.io/crates/v/speck-cipher.svg 43 | [crate-link]: https://crates.io/crates/speck-cipher 44 | [docs-image]: https://docs.rs/speck-cipher/badge.svg 45 | [docs-link]: https://docs.rs/speck-cipher/ 46 | [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg 47 | [rustc-image]: https://img.shields.io/badge/rustc-1.85+-blue.svg 48 | [hazmat-image]: https://img.shields.io/badge/crypto-hazmat%E2%9A%A0-red.svg 49 | [hazmat-link]: https://github.com/RustCrypto/meta/blob/master/HAZMAT.md 50 | [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg 51 | [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260039-block-ciphers 52 | [build-image]: https://github.com/RustCrypto/block-ciphers/workflows/speck/badge.svg?branch=master&event=push 53 | [build-link]: https://github.com/RustCrypto/block-ciphers/actions?query=workflow%3Aspeck 54 | 55 | [//]: # (general links) 56 | 57 | [1]: https://en.wikipedia.org/wiki/Speck_(cipher) 58 | -------------------------------------------------------------------------------- /threefish/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 | 8 | ## 0.6.0 (UNRELEASED) 9 | ### Changed 10 | - Bump `cipher` dependency to v0.5 11 | - Edition changed to 2024 and MSRV bumped to 1.85 ([#472]) 12 | - Relax MSRV policy and allow MSRV bumps in patch releases ([#477]) 13 | 14 | [#472]: https://github.com/RustCrypto/block-ciphers/pull/472 15 | [#477]: https://github.com/RustCrypto/block-ciphers/pull/477 16 | 17 | ## 0.5.2 (2023-06-09) 18 | ### Added 19 | - `new_with_tweak_u64`, `encrypt_block_u64`, and `decrypt_block_u64` methods ([#364]) 20 | 21 | ### Changed 22 | - `cipher` is now an (enabled by default) optional dependency ([#364]) 23 | 24 | [#364]: https://github.com/RustCrypto/block-ciphers/pull/364 25 | 26 | ## 0.5.1 (2022-02-17) 27 | ### Fixed 28 | - Minimal versions build ([#303]) 29 | 30 | [#303]: https://github.com/RustCrypto/block-ciphers/pull/303 31 | 32 | ## 0.5.0 (2022-02-10) 33 | ### Changed 34 | - Bump `cipher` dependency to v0.4 ([#284]) 35 | 36 | [#284]: https://github.com/RustCrypto/block-ciphers/pull/284 37 | 38 | ## 0.4.0 (2021-04-29) 39 | ### Changed 40 | - Bump `cipher` dependency to v0.3 ([#235]) 41 | 42 | [#235]: https://github.com/RustCrypto/block-ciphers/pull/235 43 | 44 | ## 0.3.0 (2020-10-16) 45 | ### Changed 46 | - Replace `block-cipher`/`stream-cipher` with `cipher` crate ([#167]) 47 | 48 | [#167]: https://github.com/RustCrypto/block-ciphers/pull/167 49 | 50 | ## 0.2.0 (2020-08-07) 51 | ### Changed 52 | - Bump `block-cipher` dependency to v0.8 ([#138]) 53 | - Bump `opaque-debug` dependency to v0.3 ([#140]) 54 | 55 | [#138]: https://github.com/RustCrypto/block-ciphers/pull/138 56 | [#140]: https://github.com/RustCrypto/block-ciphers/pull/140 57 | 58 | ## 0.1.0 (2020-06-08) 59 | ### Changed 60 | - Bump `block-cipher` dependency to v0.7 ([#99]) 61 | - Upgrade to Rust 2018 edition ([#99]) 62 | 63 | [#99]: https://github.com/RustCrypto/block-ciphers/pull/99 64 | 65 | ## 0.0.1 (2020-05-23) 66 | - Initial release 67 | -------------------------------------------------------------------------------- /threefish/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "threefish" 3 | version = "0.6.0-pre" 4 | description = "Threefish block cipher" 5 | authors = ["The Rust-Crypto Project Developers"] 6 | license = "MIT OR Apache-2.0" 7 | edition = "2024" 8 | rust-version = "1.85" 9 | readme = "README.md" 10 | documentation = "https://docs.rs/threefish" 11 | repository = "https://github.com/RustCrypto/block-ciphers" 12 | keywords = ["crypto", "threefish", "block-cipher"] 13 | categories = ["cryptography", "no-std"] 14 | 15 | [dependencies] 16 | cipher = { version = "0.5.0-rc.0", optional = true } 17 | zeroize = { version = "1.6", optional = true, default-features = false } 18 | 19 | [dev-dependencies] 20 | cipher = { version = "0.5.0-rc.0", features = ["dev"] } 21 | hex-literal = "1" 22 | 23 | [features] 24 | default = ["cipher"] 25 | 26 | [package.metadata.docs.rs] 27 | all-features = true 28 | rustdoc-args = ["--cfg", "docsrs"] 29 | -------------------------------------------------------------------------------- /threefish/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016-2024 The RustCrypto Project Developers 2 | Copyright (c) 2016-2017 Christian Barcenas, Artyom Pavlov 3 | 4 | Permission is hereby granted, free of charge, to any 5 | person obtaining a copy of this software and associated 6 | documentation files (the "Software"), to deal in the 7 | Software without restriction, including without 8 | limitation the rights to use, copy, modify, merge, 9 | publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software 11 | is furnished to do so, subject to the following 12 | conditions: 13 | 14 | The above copyright notice and this permission notice 15 | shall be included in all copies or substantial portions 16 | of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 19 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 20 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 21 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 22 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 25 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 | DEALINGS IN THE SOFTWARE. 27 | -------------------------------------------------------------------------------- /threefish/README.md: -------------------------------------------------------------------------------- 1 | # RustCrypto: Threefish Cipher 2 | 3 | [![crate][crate-image]][crate-link] 4 | [![Docs][docs-image]][docs-link] 5 | ![Apache2/MIT licensed][license-image] 6 | ![Rust Version][rustc-image] 7 | [![Project Chat][chat-image]][chat-link] 8 | [![Build Status][build-image]][build-link] 9 | [![HAZMAT][hazmat-image]][hazmat-link] 10 | 11 | Pure Rust implementation of the [Threefish block cipher][1]. 12 | 13 | ## ⚠️ Security Warning: [Hazmat!][hazmat-link] 14 | 15 | This crate does not ensure ciphertexts are authentic (i.e. by using a MAC to 16 | verify ciphertext integrity), which can lead to serious vulnerabilities 17 | if used incorrectly! 18 | 19 | No security audits of this crate have ever been performed, and it has not been 20 | thoroughly assessed to ensure its operation is constant-time on common CPU 21 | architectures. 22 | 23 | USE AT YOUR OWN RISK! 24 | 25 | ## License 26 | 27 | Licensed under either of: 28 | 29 | * [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) 30 | * [MIT license](http://opensource.org/licenses/MIT) 31 | 32 | at your option. 33 | 34 | ### Contribution 35 | 36 | Unless you explicitly state otherwise, any contribution intentionally submitted 37 | for inclusion in the work by you, as defined in the Apache-2.0 license, shall be 38 | dual licensed as above, without any additional terms or conditions. 39 | 40 | [//]: # (badges) 41 | 42 | [crate-image]: https://img.shields.io/crates/v/threefish.svg 43 | [crate-link]: https://crates.io/crates/threefish 44 | [docs-image]: https://docs.rs/threefish/badge.svg 45 | [docs-link]: https://docs.rs/threefish/ 46 | [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg 47 | [rustc-image]: https://img.shields.io/badge/rustc-1.85+-blue.svg 48 | [hazmat-image]: https://img.shields.io/badge/crypto-hazmat%E2%9A%A0-red.svg 49 | [hazmat-link]: https://github.com/RustCrypto/meta/blob/master/HAZMAT.md 50 | [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg 51 | [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260039-block-ciphers 52 | [build-image]: https://github.com/RustCrypto/block-ciphers/workflows/threefish/badge.svg?branch=master&event=push 53 | [build-link]: https://github.com/RustCrypto/block-ciphers/actions?query=workflow%3Athreefish 54 | 55 | [//]: # (general links) 56 | 57 | [1]: https://en.wikipedia.org/wiki/Threefish 58 | -------------------------------------------------------------------------------- /threefish/benches/mod.rs: -------------------------------------------------------------------------------- 1 | #![feature(test)] 2 | extern crate test; 3 | 4 | use cipher::{block_decryptor_bench, block_encryptor_bench}; 5 | use threefish::{Threefish256, Threefish512, Threefish1024}; 6 | 7 | block_encryptor_bench!( 8 | Key: Threefish256, 9 | threefish256_encrypt_block, 10 | threefish256_encrypt_blocks, 11 | ); 12 | block_decryptor_bench!( 13 | Key: Threefish256, 14 | threefish256_decrypt_block, 15 | threefish256_decrypt_blocks, 16 | ); 17 | 18 | block_encryptor_bench!( 19 | Key: Threefish512, 20 | threefish512_encrypt_block, 21 | threefish512_encrypt_blocks, 22 | ); 23 | block_decryptor_bench!( 24 | Key: Threefish512, 25 | threefish512_decrypt_block, 26 | threefish512_decrypt_blocks, 27 | ); 28 | 29 | block_encryptor_bench!( 30 | Key: Threefish1024, 31 | threefish1024_encrypt_block, 32 | threefish1024_encrypt_blocks, 33 | ); 34 | block_decryptor_bench!( 35 | Key: Threefish1024, 36 | threefish1024_decrypt_block, 37 | threefish1024_decrypt_blocks, 38 | ); 39 | -------------------------------------------------------------------------------- /threefish/src/consts.rs: -------------------------------------------------------------------------------- 1 | #![allow(clippy::unreadable_literal)] 2 | 3 | // Magic constant for key schedule 4 | pub const C240: u64 = 0x1BD11BDAA9FC1A22; 5 | 6 | // Rotation constants for the different key lengths 7 | pub const R256: [[u8; 2]; 8] = [ 8 | [14, 16], 9 | [52, 57], 10 | [23, 40], 11 | [5, 37], 12 | [25, 33], 13 | [46, 12], 14 | [58, 22], 15 | [32, 32], 16 | ]; 17 | 18 | pub const R512: [[u8; 4]; 8] = [ 19 | [46, 36, 19, 37], 20 | [33, 27, 14, 42], 21 | [17, 49, 36, 39], 22 | [44, 9, 54, 56], 23 | [39, 30, 34, 24], 24 | [13, 50, 10, 17], 25 | [25, 29, 39, 43], 26 | [8, 35, 56, 22], 27 | ]; 28 | 29 | pub const R1024: [[u8; 8]; 8] = [ 30 | [24, 13, 8, 47, 8, 17, 22, 37], 31 | [38, 19, 10, 55, 49, 18, 23, 52], 32 | [33, 4, 51, 13, 34, 41, 59, 17], 33 | [5, 20, 48, 41, 47, 28, 16, 25], 34 | [41, 9, 37, 31, 12, 47, 44, 30], 35 | [16, 34, 56, 51, 4, 53, 42, 41], 36 | [31, 44, 47, 46, 19, 42, 44, 25], 37 | [9, 48, 35, 52, 23, 31, 37, 20], 38 | ]; 39 | 40 | // Permutation tables for the different key lengths 41 | pub const P256: [u8; 4] = [0, 3, 2, 1]; 42 | pub const P512: [u8; 8] = [6, 1, 0, 7, 2, 5, 4, 3]; 43 | pub const P1024: [u8; 16] = [0, 15, 2, 11, 6, 13, 4, 9, 14, 1, 8, 5, 10, 3, 12, 7]; 44 | -------------------------------------------------------------------------------- /twofish/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 | 8 | ## 0.8.0 (UNRELEASED) 9 | ### Changed 10 | - Bump `cipher` dependency to v0.5 11 | - Edition changed to 2024 and MSRV bumped to 1.85 ([#472]) 12 | - Relax MSRV policy and allow MSRV bumps in patch releases ([#477]) 13 | 14 | [#472]: https://github.com/RustCrypto/block-ciphers/pull/472 15 | [#477]: https://github.com/RustCrypto/block-ciphers/pull/477 16 | 17 | ## 0.7.1 (2022-02-17) 18 | ### Fixed 19 | - Minimal versions build ([#303]) 20 | 21 | [#303]: https://github.com/RustCrypto/block-ciphers/pull/303 22 | 23 | ## 0.7.0 (2022-02-10) 24 | ### Changed 25 | - Bump `cipher` dependency to v0.4 ([#284]) 26 | 27 | [#284]: https://github.com/RustCrypto/block-ciphers/pull/284 28 | 29 | ## 0.6.0 (2021-04-29) 30 | ### Changed 31 | - Bump `cipher` dependency to v0.3 ([#235]) 32 | 33 | [#235]: https://github.com/RustCrypto/block-ciphers/pull/235 34 | 35 | ## 0.5.0 (2020-10-16) 36 | ### Changed 37 | - Replace `block-cipher`/`stream-cipher` with `cipher` crate ([#167]) 38 | 39 | [#167]: https://github.com/RustCrypto/block-ciphers/pull/167 40 | 41 | ## 0.4.0 (2020-08-07) 42 | ### Changed 43 | - Bump `block-cipher` dependency to v0.8 ([#138]) 44 | - Bump `opaque-debug` dependency to v0.3 ([#140]) 45 | 46 | [#138]: https://github.com/RustCrypto/block-ciphers/pull/138 47 | [#140]: https://github.com/RustCrypto/block-ciphers/pull/140 48 | 49 | ## 0.3.0 (2020-06-08) 50 | ### Changed 51 | - Bump `block-cipher` dependency to v0.7 ([#100]) 52 | - Upgrade to Rust 2018 edition ([#100]) 53 | 54 | [#100]: https://github.com/RustCrypto/block-ciphers/pull/100 55 | 56 | ## 0.2.0 (2018-12-23) 57 | 58 | ## 0.1.0 (2017-11-26) 59 | -------------------------------------------------------------------------------- /twofish/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "twofish" 3 | version = "0.8.0-pre" 4 | description = "Twofish block cipher" 5 | authors = ["RustCrypto Developers"] 6 | license = "MIT OR Apache-2.0" 7 | edition = "2024" 8 | rust-version = "1.85" 9 | readme = "README.md" 10 | documentation = "https://docs.rs/twofish" 11 | repository = "https://github.com/RustCrypto/block-ciphers" 12 | keywords = ["crypto", "twofish", "block-cipher"] 13 | categories = ["cryptography", "no-std"] 14 | 15 | [dependencies] 16 | cipher = "0.5.0-rc.0" 17 | 18 | [dev-dependencies] 19 | cipher = { version = "0.5.0-rc.0", features = ["dev"] } 20 | hex-literal = "1" 21 | 22 | [features] 23 | zeroize = ["cipher/zeroize"] 24 | 25 | [package.metadata.docs.rs] 26 | all-features = true 27 | rustdoc-args = ["--cfg", "docsrs"] 28 | -------------------------------------------------------------------------------- /twofish/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017-2024 The RustCrypto Project Developers 2 | Copyright (c) 2017 Alexander Krotov 3 | 4 | Permission is hereby granted, free of charge, to any 5 | person obtaining a copy of this software and associated 6 | documentation files (the "Software"), to deal in the 7 | Software without restriction, including without 8 | limitation the rights to use, copy, modify, merge, 9 | publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software 11 | is furnished to do so, subject to the following 12 | conditions: 13 | 14 | The above copyright notice and this permission notice 15 | shall be included in all copies or substantial portions 16 | of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 19 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 20 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 21 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 22 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 25 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 | DEALINGS IN THE SOFTWARE. 27 | -------------------------------------------------------------------------------- /twofish/README.md: -------------------------------------------------------------------------------- 1 | # RustCrypto: Twofish Cipher 2 | 3 | [![crate][crate-image]][crate-link] 4 | [![Docs][docs-image]][docs-link] 5 | ![Apache2/MIT licensed][license-image] 6 | ![Rust Version][rustc-image] 7 | [![Project Chat][chat-image]][chat-link] 8 | [![Build Status][build-image]][build-link] 9 | [![HAZMAT][hazmat-image]][hazmat-link] 10 | 11 | Pure Rust implementation of the [Twofish block cipher][1]. 12 | 13 | ## ⚠️ Security Warning: [Hazmat!][hazmat-link] 14 | 15 | This crate does not ensure ciphertexts are authentic (i.e. by using a MAC to 16 | verify ciphertext integrity), which can lead to serious vulnerabilities 17 | if used incorrectly! 18 | 19 | No security audits of this crate have ever been performed, and it has not been 20 | thoroughly assessed to ensure its operation is constant-time on common CPU 21 | architectures. 22 | 23 | USE AT YOUR OWN RISK! 24 | 25 | ## License 26 | 27 | Licensed under either of: 28 | 29 | * [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) 30 | * [MIT license](http://opensource.org/licenses/MIT) 31 | 32 | at your option. 33 | 34 | ### Contribution 35 | 36 | Unless you explicitly state otherwise, any contribution intentionally submitted 37 | for inclusion in the work by you, as defined in the Apache-2.0 license, shall be 38 | dual licensed as above, without any additional terms or conditions. 39 | 40 | [//]: # (badges) 41 | 42 | [crate-image]: https://img.shields.io/crates/v/twofish.svg 43 | [crate-link]: https://crates.io/crates/twofish 44 | [docs-image]: https://docs.rs/twofish/badge.svg 45 | [docs-link]: https://docs.rs/twofish/ 46 | [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg 47 | [rustc-image]: https://img.shields.io/badge/rustc-1.85+-blue.svg 48 | [hazmat-image]: https://img.shields.io/badge/crypto-hazmat%E2%9A%A0-red.svg 49 | [hazmat-link]: https://github.com/RustCrypto/meta/blob/master/HAZMAT.md 50 | [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg 51 | [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260039-block-ciphers 52 | [build-image]: https://github.com/RustCrypto/block-ciphers/workflows/twofish/badge.svg?branch=master&event=push 53 | [build-link]: https://github.com/RustCrypto/block-ciphers/actions?query=workflow%3Atwofish 54 | 55 | [//]: # (general links) 56 | 57 | [1]: https://en.wikipedia.org/wiki/Twofish 58 | -------------------------------------------------------------------------------- /twofish/benches/mod.rs: -------------------------------------------------------------------------------- 1 | #![feature(test)] 2 | extern crate test; 3 | 4 | use cipher::{block_decryptor_bench, block_encryptor_bench}; 5 | use twofish::Twofish; 6 | 7 | block_encryptor_bench!(Key: Twofish, twofish_encrypt_block, twofish_encrypt_blocks); 8 | block_decryptor_bench!(Key: Twofish, twofish_decrypt_block, twofish_decrypt_blocks); 9 | -------------------------------------------------------------------------------- /twofish/src/consts.rs: -------------------------------------------------------------------------------- 1 | pub const QORD: [[usize; 5]; 4] = [ 2 | [1, 1, 0, 0, 1], 3 | [0, 1, 1, 0, 0], 4 | [0, 0, 0, 1, 1], 5 | [1, 0, 1, 1, 0], 6 | ]; 7 | 8 | #[rustfmt::skip] 9 | pub const QBOX: [[[u8; 16]; 4]; 2] = [ 10 | [ 11 | [ 12 | 0x8, 0x1, 0x7, 0xD, 0x6, 0xF, 0x3, 0x2, 13 | 0x0, 0xB, 0x5, 0x9, 0xE, 0xC, 0xA, 0x4, 14 | ], [ 15 | 0xE, 0xC, 0xB, 0x8, 0x1, 0x2, 0x3, 0x5, 16 | 0xF, 0x4, 0xA, 0x6, 0x7, 0x0, 0x9, 0xD, 17 | ], [ 18 | 0xB, 0xA, 0x5, 0xE, 0x6, 0xD, 0x9, 0x0, 19 | 0xC, 0x8, 0xF, 0x3, 0x2, 0x4, 0x7, 0x1, 20 | ], [ 21 | 0xD, 0x7, 0xF, 0x4, 0x1, 0x2, 0x6, 0xE, 22 | 0x9, 0xB, 0x3, 0x0, 0x8, 0x5, 0xC, 0xA, 23 | ], 24 | ], [ 25 | [ 26 | 0x2, 0x8, 0xB, 0xD, 0xF, 0x7, 0x6, 0xE, 27 | 0x3, 0x1, 0x9, 0x4, 0x0, 0xA, 0xC, 0x5, 28 | ], [ 29 | 0x1, 0xE, 0x2, 0xB, 0x4, 0xC, 0x3, 0x7, 30 | 0x6, 0xD, 0xA, 0x5, 0xF, 0x9, 0x0, 0x8, 31 | ], [ 32 | 0x4, 0xC, 0x7, 0x5, 0x1, 0x6, 0x9, 0xA, 33 | 0x0, 0xE, 0xD, 0x8, 0x2, 0xB, 0x3, 0xF, 34 | ], [ 35 | 0xB, 0x9, 0x5, 0x1, 0xC, 0x3, 0xD, 0xE, 36 | 0x6, 0x4, 0x7, 0xF, 0x2, 0x0, 0x8, 0xA, 37 | ], 38 | ] 39 | ]; 40 | 41 | pub const RS: [[u8; 8]; 4] = [ 42 | [0x01, 0xa4, 0x55, 0x87, 0x5a, 0x58, 0xdb, 0x9e], 43 | [0xa4, 0x56, 0x82, 0xf3, 0x1e, 0xc6, 0x68, 0xe5], 44 | [0x02, 0xa1, 0xfc, 0xc1, 0x47, 0xae, 0x3d, 0x19], 45 | [0xa4, 0x55, 0x87, 0x5a, 0x58, 0xdb, 0x9e, 0x03], 46 | ]; 47 | 48 | // 0x169 (x⁸ + x⁶ + x⁵ + x³ + 1) 49 | pub const MDS_POLY: u8 = 0x69; 50 | // 0x14d (x⁸ + x⁶ + x³ + x² + 1) 51 | pub const RS_POLY: u8 = 0x4d; 52 | -------------------------------------------------------------------------------- /xtea/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 | 8 | ## 0.2.0 (UNRELEASED) 9 | ### Changed 10 | - Bump `cipher` dependency to v0.5 11 | - Edition changed to 2024 and MSRV bumped to 1.85 ([#472]) 12 | - Relax MSRV policy and allow MSRV bumps in patch releases ([#477]) 13 | 14 | [#472]: https://github.com/RustCrypto/block-ciphers/pull/472 15 | [#477]: https://github.com/RustCrypto/block-ciphers/pull/477 16 | 17 | ## 0.1.0 (2024-05-11) 18 | - Initial release 19 | -------------------------------------------------------------------------------- /xtea/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "xtea" 3 | version = "0.0.1-pre.0" 4 | description = "XTEA block cipher" 5 | authors = ["RustCrypto Developers"] 6 | license = "MIT OR Apache-2.0" 7 | edition = "2024" 8 | rust-version = "1.85" 9 | readme = "README.md" 10 | documentation = "https://docs.rs/xtea" 11 | repository = "https://github.com/RustCrypto/block-ciphers" 12 | keywords = ["crypto", "xtea", "block-cipher"] 13 | categories = ["cryptography", "no-std"] 14 | 15 | [dependencies] 16 | cipher = "0.5.0-rc.0" 17 | 18 | [dev-dependencies] 19 | cipher = { version = "0.5.0-rc.0", features = ["dev"] } 20 | 21 | [features] 22 | zeroize = ["cipher/zeroize"] 23 | 24 | [package.metadata.docs.rs] 25 | all-features = true 26 | rustdoc-args = ["--cfg", "docsrs"] 27 | -------------------------------------------------------------------------------- /xtea/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | Copyright 2024 Kevin Ludwig 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /xtea/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2024 The RustCrypto Project Developers 2 | Copyright (c) 2024 Kevin Ludwig 3 | 4 | Permission is hereby granted, free of charge, to any 5 | person obtaining a copy of this software and associated 6 | documentation files (the "Software"), to deal in the 7 | Software without restriction, including without 8 | limitation the rights to use, copy, modify, merge, 9 | publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software 11 | is furnished to do so, subject to the following 12 | conditions: 13 | 14 | The above copyright notice and this permission notice 15 | shall be included in all copies or substantial portions 16 | of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 19 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 20 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 21 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 22 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 25 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 | DEALINGS IN THE SOFTWARE. 27 | -------------------------------------------------------------------------------- /xtea/README.md: -------------------------------------------------------------------------------- 1 | # RustCrypto: XTEA Cipher 2 | 3 | [![crate][crate-image]][crate-link] 4 | [![Docs][docs-image]][docs-link] 5 | ![Apache2/MIT licensed][license-image] 6 | ![Rust Version][rustc-image] 7 | [![Project Chat][chat-image]][chat-link] 8 | [![Build Status][build-image]][build-link] 9 | [![HAZMAT][hazmat-image]][hazmat-link] 10 | 11 | Pure Rust implementation of the [XTEA block cipher][1]. 12 | 13 | ## ⚠️ Security Warning: [Hazmat!][hazmat-link] 14 | 15 | This crate does not ensure ciphertexts are authentic (i.e. by using a MAC to 16 | verify ciphertext integrity), which can lead to serious vulnerabilities 17 | if used incorrectly! 18 | 19 | No security audits of this crate have ever been performed, and it has not been 20 | thoroughly assessed to ensure its operation is constant-time on common CPU 21 | architectures. 22 | 23 | USE AT YOUR OWN RISK! 24 | 25 | ## License 26 | 27 | Licensed under either of: 28 | 29 | * [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) 30 | * [MIT license](http://opensource.org/licenses/MIT) 31 | 32 | at your option. 33 | 34 | ### Contribution 35 | 36 | Unless you explicitly state otherwise, any contribution intentionally submitted 37 | for inclusion in the work by you, as defined in the Apache-2.0 license, shall be 38 | dual licensed as above, without any additional terms or conditions. 39 | 40 | [//]: # (badges) 41 | 42 | [crate-image]: https://img.shields.io/crates/v/xtea.svg 43 | [crate-link]: https://crates.io/crates/xtea 44 | [docs-image]: https://docs.rs/xtea/badge.svg 45 | [docs-link]: https://docs.rs/xtea/ 46 | [license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg 47 | [rustc-image]: https://img.shields.io/badge/rustc-1.85+-blue.svg 48 | [hazmat-image]: https://img.shields.io/badge/crypto-hazmat%E2%9A%A0-red.svg 49 | [hazmat-link]: https://github.com/RustCrypto/meta/blob/master/HAZMAT.md 50 | [chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg 51 | [chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260039-block-ciphers 52 | [build-image]: https://github.com/RustCrypto/block-ciphers/workflows/xtea/badge.svg?branch=master&event=push 53 | [build-link]: https://github.com/RustCrypto/block-ciphers/actions?query=workflow%3Axtea 54 | 55 | [//]: # (general links) 56 | 57 | [1]: https://en.wikipedia.org/wiki/XTEA 58 | -------------------------------------------------------------------------------- /xtea/benches/mod.rs: -------------------------------------------------------------------------------- 1 | #![feature(test)] 2 | extern crate test; 3 | 4 | use cipher::{block_decryptor_bench, block_encryptor_bench}; 5 | use xtea::Xtea; 6 | 7 | block_encryptor_bench!(Key: Xtea, xtea_encrypt_block, xtea_encrypt_blocks); 8 | block_decryptor_bench!(Key: Xtea, xtea_decrypt_block, xtea_decrypt_blocks); 9 | -------------------------------------------------------------------------------- /xtea/src/consts.rs: -------------------------------------------------------------------------------- 1 | pub const DELTA: u32 = 0x9e3779b9; 2 | pub const ROUNDS: usize = 32; 3 | -------------------------------------------------------------------------------- /xtea/tests/mod.rs: -------------------------------------------------------------------------------- 1 | use cipher::{BlockCipherDecrypt, BlockCipherEncrypt, KeyInit, array::Array}; 2 | use xtea::Xtea; 3 | 4 | #[test] 5 | fn xtea() { 6 | // https://web.archive.org/web/20231115163347/https://asecuritysite.com/encryption/xtea 7 | let key = b"0123456789012345"; 8 | let plaintext = b"ABCDEFGH"; 9 | let ciphertext = [0xea, 0x0c, 0x3d, 0x7c, 0x1c, 0x22, 0x55, 0x7f]; 10 | let cipher = Xtea::new_from_slice(key).unwrap(); 11 | 12 | let mut block = Array(*plaintext); 13 | cipher.encrypt_block(&mut block); 14 | assert_eq!(ciphertext, block.as_slice()); 15 | 16 | cipher.decrypt_block(&mut block); 17 | assert_eq!(plaintext, block.as_slice()); 18 | } 19 | --------------------------------------------------------------------------------