Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions serpent/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# 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.0.1 (2020-05-23)

- Initial release
6 changes: 4 additions & 2 deletions serpent/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[package]
name = "serpent"
version = "0.6.0"
version = "0.0.1"
authors = ["Blocs <jonathan@cryptoblocs.fr>"]
license = "MIT/Apache-2.0"
license = "Apache-2.0 AND MIT"
readme = "README.md"
edition = "2018"
description = "Serpent block cipher : A Candidate Block Cipher for the Advanced Encryption Standard (AES)"
documentation = "https://docs.rs/serpent"
Expand All @@ -21,4 +22,5 @@ opaque-debug = "0.2"
block-cipher-trait = { version = "0.6", features = ["dev"] }

[badges]
maintenance = { status = "experimental" }
travis-ci = { repository = "RustCrypto/block-ciphers" }
40 changes: 40 additions & 0 deletions serpent/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# RustCrypto: `serpent` block cipher

[![crate][crate-image]][crate-link]
[![Docs][docs-image]][docs-link]
![Apache2/MIT licensed][license-image]

[Documentation][docs-link]

## Warnings

This is an experimental pure Rust implementation of the Serpent block cipher.

It has never received any review by professional cryptographers.

We recommend it should not be used in production applications.

**USE AT YOUR OWN RISK.**

## 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/serpent.svg
[crate-link]: https://crates.io/crates/serpent
[docs-image]: https://docs.rs/serpent/badge.svg
[docs-link]: https://docs.rs/serpent/
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
18 changes: 9 additions & 9 deletions serpent/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
//! [1]: https://www.cl.cam.ac.uk/~rja14/Papers/serpent.pdf
//! [2]: https://www.cl.cam.ac.uk/~fms27/serpent/
//! [3]: https://github.com/efb9-860a-e752-0dac/serpent
// #![no_std]

#![no_std]
#![forbid(unsafe_code)]

pub extern crate block_cipher_trait;
extern crate byteorder;
#[macro_use]
Expand All @@ -29,9 +31,7 @@ pub struct Serpent {
k: Subkeys,
}

fn get_bit(x: usize, i: usize) -> u8 {
(x >> i) as u8 & 0x01
}
fn get_bit(x: usize, i: usize) -> u8 { (x >> i) as u8 & 0x01 }

fn linear_transform_bitslice(input: Block128, output: &mut Block128) {
let mut words = [0u32; 4];
Expand Down Expand Up @@ -72,7 +72,8 @@ fn round_bitslice(
b_i: Block128,
k: Subkeys,
b_output: &mut Block128,
) {
)
{
let xored_block = xor_block(b_i, k[i]);

let s_i = apply_s_bitslice(i, xored_block);
Expand All @@ -88,7 +89,8 @@ fn round_inverse_bitslice(
b_i_next: Block128,
k: Subkeys,
b_output: &mut Block128,
) {
)
{
let mut s_i = [0u8; 16];
if i == ROUNDS - 1 {
s_i = xor_block(b_i_next, k[ROUNDS]);
Expand All @@ -101,9 +103,7 @@ fn round_inverse_bitslice(
*b_output = xor_block(xored, k[i]);
}

fn apply_s(index: usize, nibble: u8) -> u8 {
S[index % 8][nibble as usize]
}
fn apply_s(index: usize, nibble: u8) -> u8 { S[index % 8][nibble as usize] }
fn apply_s_inverse(index: usize, nibble: u8) -> u8 {
S_INVERSE[index % 8][nibble as usize]
}
Expand Down