Skip to content

Commit 54ef926

Browse files
add rust repos
including blowfish, des, rabbit, rc4, ripemd160, sha1, sha3, sha256, sha512
1 parent 99c5abe commit 54ef926

File tree

25 files changed

+2347
-2
lines changed

25 files changed

+2347
-2
lines changed

rust/aes/src/lib.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ pub fn getInvKeySchedule(keySize: u32, keyWords: &[u32]) -> Vec<u32> {
2020
}
2121

2222
#[wasm_bindgen]
23-
pub fn doEncrypt(mode: &str, nRounds: usize, nWordsReady: usize, blockSize: usize, iv: &[u32], dataWords: &mut [u32], keySchedule: &[u32]) {
23+
pub fn doEncrypt(mode: &str, nRounds: usize, nWordsReady: usize, blockSize: usize, iv: &[u32], dataWords: &mut [u32], keySchedule: &[u32]) -> Vec<u32> {
24+
let mut process: Vec<u32> = Vec::new();
2425
if nWordsReady > 0 {
2526
let mut offset: usize = 0;
2627
match mode.to_lowercase().as_str() {
@@ -32,6 +33,7 @@ pub fn doEncrypt(mode: &str, nRounds: usize, nWordsReady: usize, blockSize: usiz
3233
prevBlock = dataWords[offset..offset + blockSize].to_vec();
3334
offset += blockSize;
3435
}
36+
process = prevBlock;
3537
}
3638
"ecb" => {
3739
while offset < nWordsReady {
@@ -48,6 +50,7 @@ pub fn doEncrypt(mode: &str, nRounds: usize, nWordsReady: usize, blockSize: usiz
4850
prevBlock = dataWords[offset..offset + blockSize].to_vec();
4951
offset += blockSize;
5052
}
53+
process = prevBlock;
5154
}
5255
"ofb" => {
5356
let mut keystream = iv[0..blockSize].to_vec();
@@ -56,6 +59,7 @@ pub fn doEncrypt(mode: &str, nRounds: usize, nWordsReady: usize, blockSize: usiz
5659
xorBlock(blockSize, keystream.to_owned(), dataWords, offset);
5760
offset += blockSize;
5861
}
62+
process = keystream;
5963
}
6064
"ctr" => {
6165
let mut counter = iv[0..blockSize].to_vec();
@@ -68,14 +72,18 @@ pub fn doEncrypt(mode: &str, nRounds: usize, nWordsReady: usize, blockSize: usiz
6872
xorBlock(blockSize, keystream.to_owned(), dataWords, offset);
6973
offset += blockSize;
7074
}
75+
process = counter;
7176
}
7277
_ => {}
7378
}
7479
}
80+
81+
process
7582
}
7683

7784
#[wasm_bindgen]
78-
pub fn doDecrypt(mode: &str, nRounds: usize, nWordsReady: usize, blockSize: usize, iv: &[u32], dataWords: &mut [u32], keySchedule: &[u32], invKeySchedule: &[u32]) {
85+
pub fn doDecrypt(mode: &str, nRounds: usize, nWordsReady: usize, blockSize: usize, iv: &[u32], dataWords: &mut [u32], keySchedule: &[u32], invKeySchedule: &[u32]) -> Vec<u32> {
86+
let mut process: Vec<u32> = Vec::new();
7987
if nWordsReady > 0 {
8088
let mut offset: usize = 0;
8189
match mode.to_lowercase().as_str() {
@@ -88,6 +96,7 @@ pub fn doDecrypt(mode: &str, nRounds: usize, nWordsReady: usize, blockSize: usiz
8896
prevBlock = thisBlock;
8997
offset += blockSize;
9098
}
99+
process = prevBlock;
91100
}
92101
"ecb" => {
93102
while offset < nWordsReady {
@@ -105,6 +114,7 @@ pub fn doDecrypt(mode: &str, nRounds: usize, nWordsReady: usize, blockSize: usiz
105114
prevBlock = thisBlock;
106115
offset += blockSize;
107116
}
117+
process = prevBlock;
108118
}
109119
"ofb" => {
110120
let mut keystream = iv[0..blockSize].to_vec();
@@ -113,6 +123,7 @@ pub fn doDecrypt(mode: &str, nRounds: usize, nWordsReady: usize, blockSize: usiz
113123
xorBlock(blockSize, keystream.to_owned(), dataWords, offset);
114124
offset += blockSize;
115125
}
126+
process = keystream;
116127
}
117128
"ctr" => {
118129
let mut counter = iv[0..blockSize].to_vec();
@@ -125,10 +136,13 @@ pub fn doDecrypt(mode: &str, nRounds: usize, nWordsReady: usize, blockSize: usiz
125136
xorBlock(blockSize, keystream.to_owned(), dataWords, offset);
126137
offset += blockSize;
127138
}
139+
process = counter;
128140
}
129141
_ => {}
130142
}
131143
}
144+
145+
process
132146
}
133147

134148
fn xorBlock(blockSize: usize, block: Vec<u32>, words: &mut [u32], offset: usize) {

rust/blowfish/Cargo.toml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[package]
2+
name = "blowfish"
3+
version = "0.1.0"
4+
authors = ["Alanscut <[email protected]>"]
5+
edition = "2018"
6+
7+
[lib]
8+
crate-type = ["cdylib", "rlib"]
9+
10+
[features]
11+
default = ["console_error_panic_hook"]
12+
13+
[dependencies]
14+
wasm-bindgen = "0.2.63"
15+
16+
# The `console_error_panic_hook` crate provides better debugging of panics by
17+
# logging them with `console.error`. This is great for development, but requires
18+
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
19+
# code size when deploying.
20+
console_error_panic_hook = { version = "0.1.6", optional = true }
21+
22+
# `wee_alloc` is a tiny allocator for wasm that is only ~1K in code size
23+
# compared to the default allocator's ~10K. It is slower than the default
24+
# allocator, however.
25+
#
26+
# Unfortunately, `wee_alloc` requires nightly Rust when targeting wasm for now.
27+
wee_alloc = { version = "0.4.5", optional = true }
28+
29+
[dev-dependencies]
30+
wasm-bindgen-test = "0.3.13"
31+
32+
[profile.release]
33+
lto=true
34+
opt-level = 3

0 commit comments

Comments
 (0)