-
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.
- Loading branch information
Showing
27 changed files
with
1,538 additions
and
1,096 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use crate::{ | ||
consts::{C1, C2, C3}, | ||
utils::{a, fe, fo}, | ||
Aria128, | ||
}; | ||
use cipher::{consts::U16, AlgorithmName, Key, KeyInit, KeySizeUser}; | ||
use core::fmt; | ||
|
||
impl KeySizeUser for Aria128 { | ||
type KeySize = U16; | ||
} | ||
|
||
impl KeyInit for Aria128 { | ||
fn new(key: &Key<Self>) -> Self { | ||
let kl = u128::from_be_bytes(key[0..16].try_into().unwrap()); | ||
let kr = u128::default(); | ||
|
||
let w0 = kl; | ||
let w1 = fo(w0 ^ C1) ^ kr; | ||
let w2 = fe(w1 ^ C2) ^ w0; | ||
let w3 = fo(w2 ^ C3) ^ w1; | ||
|
||
let ek = [ | ||
w0 ^ w1.rotate_right(19), | ||
w1 ^ w2.rotate_right(19), | ||
w2 ^ w3.rotate_right(19), | ||
w3 ^ w0.rotate_right(19), | ||
w0 ^ w1.rotate_right(31), | ||
w1 ^ w2.rotate_right(31), | ||
w2 ^ w3.rotate_right(31), | ||
w3 ^ w0.rotate_right(31), | ||
w0 ^ w1.rotate_left(61), | ||
w1 ^ w2.rotate_left(61), | ||
w2 ^ w3.rotate_left(61), | ||
w3 ^ w0.rotate_left(61), | ||
w0 ^ w1.rotate_left(31), | ||
]; | ||
|
||
let dk = [ | ||
ek[12], | ||
a(ek[11]), | ||
a(ek[10]), | ||
a(ek[9]), | ||
a(ek[8]), | ||
a(ek[7]), | ||
a(ek[6]), | ||
a(ek[5]), | ||
a(ek[4]), | ||
a(ek[3]), | ||
a(ek[2]), | ||
a(ek[1]), | ||
ek[0], | ||
]; | ||
|
||
Self { ek, dk } | ||
} | ||
} | ||
|
||
impl fmt::Debug for Aria128 { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
f.write_str("Aria128 { ... }") | ||
} | ||
} | ||
|
||
impl AlgorithmName for Aria128 { | ||
fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
f.write_str("Aria128") | ||
} | ||
} |
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,74 @@ | ||
use crate::{ | ||
consts::{C1, C2, C3}, | ||
utils::{a, fe, fo}, | ||
Aria192, | ||
}; | ||
use cipher::{consts::U24, AlgorithmName, Key, KeyInit, KeySizeUser}; | ||
use core::fmt; | ||
|
||
impl KeySizeUser for Aria192 { | ||
type KeySize = U24; | ||
} | ||
|
||
impl KeyInit for Aria192 { | ||
fn new(key: &Key<Self>) -> Self { | ||
let kl = u128::from_be_bytes(key[0..16].try_into().unwrap()); | ||
let kr = u64::from_be_bytes(key[16..24].try_into().unwrap()); | ||
let kr = (kr as u128) << 64; | ||
|
||
let w0 = kl; | ||
let w1 = fo(w0 ^ C2) ^ kr; | ||
let w2 = fe(w1 ^ C3) ^ w0; | ||
let w3 = fo(w2 ^ C1) ^ w1; | ||
|
||
let ek = [ | ||
w0 ^ w1.rotate_right(19), | ||
w1 ^ w2.rotate_right(19), | ||
w2 ^ w3.rotate_right(19), | ||
w3 ^ w0.rotate_right(19), | ||
w0 ^ w1.rotate_right(31), | ||
w1 ^ w2.rotate_right(31), | ||
w2 ^ w3.rotate_right(31), | ||
w3 ^ w0.rotate_right(31), | ||
w0 ^ w1.rotate_left(61), | ||
w1 ^ w2.rotate_left(61), | ||
w2 ^ w3.rotate_left(61), | ||
w3 ^ w0.rotate_left(61), | ||
w0 ^ w1.rotate_left(31), | ||
w1 ^ w2.rotate_left(31), | ||
w2 ^ w3.rotate_left(31), | ||
]; | ||
|
||
let dk = [ | ||
ek[14], | ||
a(ek[13]), | ||
a(ek[12]), | ||
a(ek[11]), | ||
a(ek[10]), | ||
a(ek[9]), | ||
a(ek[8]), | ||
a(ek[7]), | ||
a(ek[6]), | ||
a(ek[5]), | ||
a(ek[4]), | ||
a(ek[3]), | ||
a(ek[2]), | ||
a(ek[1]), | ||
ek[0], | ||
]; | ||
|
||
Self { ek, dk } | ||
} | ||
} | ||
|
||
impl fmt::Debug for Aria192 { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
f.write_str("Aria192 { ... }") | ||
} | ||
} | ||
|
||
impl AlgorithmName for Aria192 { | ||
fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
f.write_str("Aria192") | ||
} | ||
} |
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,77 @@ | ||
use crate::{ | ||
consts::{C1, C2, C3}, | ||
utils::{a, fe, fo}, | ||
Aria256, | ||
}; | ||
use cipher::{consts::U32, AlgorithmName, Key, KeyInit, KeySizeUser}; | ||
use core::fmt; | ||
|
||
impl KeySizeUser for Aria256 { | ||
type KeySize = U32; | ||
} | ||
|
||
impl KeyInit for Aria256 { | ||
fn new(key: &Key<Self>) -> Self { | ||
let kl = u128::from_be_bytes(key[0..16].try_into().unwrap()); | ||
let kr = u128::from_be_bytes(key[16..32].try_into().unwrap()); | ||
|
||
let w0 = kl; | ||
let w1 = fo(w0 ^ C3) ^ kr; | ||
let w2 = fe(w1 ^ C1) ^ w0; | ||
let w3 = fo(w2 ^ C2) ^ w1; | ||
|
||
let ek = [ | ||
w0 ^ w1.rotate_right(19), | ||
w1 ^ w2.rotate_right(19), | ||
w2 ^ w3.rotate_right(19), | ||
w3 ^ w0.rotate_right(19), | ||
w0 ^ w1.rotate_right(31), | ||
w1 ^ w2.rotate_right(31), | ||
w2 ^ w3.rotate_right(31), | ||
w3 ^ w0.rotate_right(31), | ||
w0 ^ w1.rotate_left(61), | ||
w1 ^ w2.rotate_left(61), | ||
w2 ^ w3.rotate_left(61), | ||
w3 ^ w0.rotate_left(61), | ||
w0 ^ w1.rotate_left(31), | ||
w1 ^ w2.rotate_left(31), | ||
w2 ^ w3.rotate_left(31), | ||
w3 ^ w0.rotate_left(31), | ||
w0 ^ w1.rotate_left(19), | ||
]; | ||
|
||
let dk = [ | ||
ek[16], | ||
a(ek[15]), | ||
a(ek[14]), | ||
a(ek[13]), | ||
a(ek[12]), | ||
a(ek[11]), | ||
a(ek[10]), | ||
a(ek[9]), | ||
a(ek[8]), | ||
a(ek[7]), | ||
a(ek[6]), | ||
a(ek[5]), | ||
a(ek[4]), | ||
a(ek[3]), | ||
a(ek[2]), | ||
a(ek[1]), | ||
ek[0], | ||
]; | ||
|
||
Self { ek, dk } | ||
} | ||
} | ||
|
||
impl fmt::Debug for Aria256 { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
f.write_str("Aria256 { ... }") | ||
} | ||
} | ||
|
||
impl AlgorithmName for Aria256 { | ||
fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
f.write_str("Aria256") | ||
} | ||
} |
Oops, something went wrong.