-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR implements XTEA as described by various sources, including https://en.wikipedia.org/wiki/XTEA, XTEA is a historical cipher, which is no longer commonly used today, but some legacy software still uses it to this day. I tested that the cipher methods get properly unrolled, which boosts a 3x speed increase, and is one of the faster ciphers in this collection. (Hopefully there will be an unroll pragma sometime in the future) Partially solves #1 I decided against pre-computing keys as the computation is trivial, and doesn't have a noticeable impact on speed, probably because of memory accesses and that 256 byte don't fit easily in a cache line anyway.
- Loading branch information
Showing
13 changed files
with
400 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
name: xtea | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- "xtea/**" | ||
- "Cargo.*" | ||
push: | ||
branches: master | ||
|
||
defaults: | ||
run: | ||
working-directory: xtea | ||
|
||
env: | ||
CARGO_INCREMENTAL: 0 | ||
RUSTFLAGS: "-Dwarnings" | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
rust: | ||
- 1.65.0 # MSRV | ||
- stable | ||
target: | ||
- thumbv7em-none-eabi | ||
- wasm32-unknown-unknown | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: RustCrypto/actions/cargo-cache@master | ||
- uses: dtolnay/rust-toolchain@master | ||
with: | ||
toolchain: ${{ matrix.rust }} | ||
targets: ${{ matrix.target }} | ||
- run: cargo build --no-default-features --release --target ${{ matrix.target }} | ||
|
||
minimal-versions: | ||
uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master | ||
with: | ||
working-directory: ${{ github.workflow }} | ||
|
||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
rust: | ||
- 1.65.0 # MSRV | ||
- stable | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: RustCrypto/actions/cargo-cache@master | ||
- uses: dtolnay/rust-toolchain@master | ||
with: | ||
toolchain: ${{ matrix.rust }} | ||
- run: cargo check --all-features | ||
- run: cargo test --no-default-features | ||
- run: cargo test | ||
- run: cargo test --all-features |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## 0.1.0 (2024-05-11) | ||
- Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[package] | ||
name = "xtea" | ||
version = "0.1.0-pre" | ||
description = "XTEA block cipher" | ||
authors = ["RustCrypto Developers"] | ||
license = "MIT OR Apache-2.0" | ||
edition = "2021" | ||
rust-version = "1.65" | ||
readme = "README.md" | ||
documentation = "https://docs.rs/xtea" | ||
repository = "https://github.com/RustCrypto/block-ciphers" | ||
keywords = ["crypto", "xtea", "block-cipher"] | ||
categories = ["cryptography", "no-std"] | ||
|
||
[dependencies] | ||
cipher = "=0.5.0-pre.4" | ||
|
||
[dev-dependencies] | ||
cipher = { version = "=0.5.0-pre.4", features = ["dev"] } | ||
|
||
[features] | ||
zeroize = ["cipher/zeroize"] | ||
|
||
[package.metadata.docs.rs] | ||
all-features = true | ||
rustdoc-args = ["--cfg", "docsrs"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Copyright 2024 Kevin Ludwig | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Copyright (c) 2024 Kevin Ludwig | ||
|
||
Permission is hereby granted, free of charge, to any | ||
person obtaining a copy of this software and associated | ||
documentation files (the "Software"), to deal in the | ||
Software without restriction, including without | ||
limitation the rights to use, copy, modify, merge, | ||
publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software | ||
is furnished to do so, subject to the following | ||
conditions: | ||
|
||
The above copyright notice and this permission notice | ||
shall be included in all copies or substantial portions | ||
of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF | ||
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED | ||
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | ||
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT | ||
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR | ||
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# RustCrypto: XTEA Cipher | ||
|
||
[![crate][crate-image]][crate-link] | ||
[![Docs][docs-image]][docs-link] | ||
![Apache2/MIT licensed][license-image] | ||
![Rust Version][rustc-image] | ||
[![Project Chat][chat-image]][chat-link] | ||
[![Build Status][build-image]][build-link] | ||
[![HAZMAT][hazmat-image]][hazmat-link] | ||
|
||
Pure Rust implementation of the [XTEA block cipher][1]. | ||
|
||
[Documentation][docs-link] | ||
|
||
## ⚠️ Security Warning: [Hazmat!][hazmat-link] | ||
|
||
This crate does not ensure ciphertexts are authentic (i.e. by using a MAC to | ||
verify ciphertext integrity), which can lead to serious vulnerabilities | ||
if used incorrectly! | ||
|
||
No security audits of this crate have ever been performed, and it has not been | ||
thoroughly assessed to ensure its operation is constant-time on common CPU | ||
architectures. | ||
|
||
USE AT YOUR OWN RISK! | ||
|
||
## Minimum Supported Rust Version | ||
|
||
Rust **1.65** or higher. | ||
|
||
Minimum supported Rust version can be changed in the future, but it will be | ||
done with a minor version bump. | ||
|
||
## SemVer Policy | ||
|
||
- All on-by-default features of this library are covered by SemVer | ||
- MSRV is considered exempt from SemVer as noted above | ||
|
||
## License | ||
|
||
Licensed under either of: | ||
|
||
* [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) | ||
* [MIT license](http://opensource.org/licenses/MIT) | ||
|
||
at your option. | ||
|
||
### Contribution | ||
|
||
Unless you explicitly state otherwise, any contribution intentionally submitted | ||
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be | ||
dual licensed as above, without any additional terms or conditions. | ||
|
||
[//]: # (badges) | ||
|
||
[crate-image]: https://img.shields.io/crates/v/xtea.svg | ||
[crate-link]: https://crates.io/crates/xtea | ||
[docs-image]: https://docs.rs/xtea/badge.svg | ||
[docs-link]: https://docs.rs/xtea/ | ||
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg | ||
[rustc-image]: https://img.shields.io/badge/rustc-1.65+-blue.svg | ||
[hazmat-image]: https://img.shields.io/badge/crypto-hazmat%E2%9A%A0-red.svg | ||
[hazmat-link]: https://github.com/RustCrypto/meta/blob/master/HAZMAT.md | ||
[chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg | ||
[chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260039-block-ciphers | ||
[build-image]: https://github.com/RustCrypto/block-ciphers/workflows/xtea/badge.svg?branch=master&event=push | ||
[build-link]: https://github.com/RustCrypto/block-ciphers/actions?query=workflow%3Axtea | ||
|
||
[//]: # (general links) | ||
|
||
[1]: https://en.wikipedia.org/wiki/XTEA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#![feature(test)] | ||
extern crate test; | ||
|
||
use cipher::{block_decryptor_bench, block_encryptor_bench}; | ||
use xtea::Xtea; | ||
|
||
block_encryptor_bench!(Key: Xtea, xtea_encrypt_block, xtea_encrypt_blocks); | ||
block_decryptor_bench!(Key: Xtea, xtea_decrypt_block, xtea_decrypt_blocks); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub const DELTA: u32 = 0x9e3779b9; | ||
pub const ROUNDS: usize = 32; |
Oops, something went wrong.