diff --git a/Cargo.toml b/Cargo.toml index 551d24c..040c8ca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ members = [ "cmac", "hmac", + "pmac", ] [patch.crates-io] diff --git a/pmac/Cargo.toml b/pmac/Cargo.toml new file mode 100644 index 0000000..c72aaa2 --- /dev/null +++ b/pmac/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "pmac" +version = "0.1.0" +authors = ["RustCrypto Developers"] +license = "MIT/Apache-2.0" +description = "Generic implementation of Parallelizable Message Authentication Code" +documentation = "https://docs.rs/cmac" +repository = "https://github.com/RustCrypto/MACs" +keywords = ["crypto", "mac", "pmac"] + +[dependencies] +crypto-mac = "0.5" +block-cipher-trait = "0.5" +dbl = "0.1" + +[dev-dependencies] +crypto-mac = { version = "0.5.2", features = ["dev"] } +aesni = "0.2" diff --git a/pmac/LICENSE-APACHE b/pmac/LICENSE-APACHE new file mode 100644 index 0000000..78173fa --- /dev/null +++ b/pmac/LICENSE-APACHE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +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. diff --git a/pmac/LICENSE-MIT b/pmac/LICENSE-MIT new file mode 100644 index 0000000..8dcb85b --- /dev/null +++ b/pmac/LICENSE-MIT @@ -0,0 +1,25 @@ +Copyright (c) 2017 Artyom Pavlov + +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. diff --git a/pmac/benches/aes128_pmac.rs b/pmac/benches/aes128_pmac.rs new file mode 100644 index 0000000..e67afe5 --- /dev/null +++ b/pmac/benches/aes128_pmac.rs @@ -0,0 +1,7 @@ +#![feature(test)] +#[macro_use] +extern crate crypto_mac; +extern crate pmac; +extern crate aesni; + +bench!(pmac::Pmac::, 16); diff --git a/pmac/benches/aes256_pmac.rs b/pmac/benches/aes256_pmac.rs new file mode 100644 index 0000000..46bcc04 --- /dev/null +++ b/pmac/benches/aes256_pmac.rs @@ -0,0 +1,7 @@ +#![feature(test)] +#[macro_use] +extern crate crypto_mac; +extern crate pmac; +extern crate aesni; + +bench!(pmac::Pmac::, 32); diff --git a/pmac/src/lib.rs b/pmac/src/lib.rs new file mode 100644 index 0000000..9c575e6 --- /dev/null +++ b/pmac/src/lib.rs @@ -0,0 +1,251 @@ +//! Generic implementation of Parallelizable Message Authentication Code (PMAC), +//! otherwise known as OMAC1. +//! +//! # Usage +//! We will use AES-128 block cipher from [aesni](https://docs.rs/aesni) crate. +//! +//! To get the authentication code: +//! +//! ```rust +//! extern crate pmac; +//! extern crate aesni; +//! +//! use aesni::Aes128; +//! use pmac::{Pmac, Mac}; +//! +//! # fn main() { +//! // Create `Mac` trait implementation, namely PMAC-AES128 +//! let mut mac = Pmac::::new(b"very secret key.").unwrap(); +//! mac.input(b"input message"); +//! +//! // `result` has type `MacResult` which is a thin wrapper around array of +//! // bytes for providing constant time equality check +//! let result = mac.result(); +//! // To get underlying array use `code` method, but be carefull, since +//! // incorrect use of the code value may permit timing attacks which defeat +//! // the security provided by the `MacResult` +//! let code_bytes = result.code(); +//! # } +//! ``` +//! +//! To verify the message: +//! +//! ```rust +//! # extern crate pmac; +//! # extern crate aesni; +//! # use aesni::Aes128; +//! # use pmac::{Pmac, Mac}; +//! # fn main() { +//! let mut mac = Pmac::::new(b"very secret key.").unwrap(); +//! +//! mac.input(b"input message"); +//! +//! # let mac2 = mac.clone(); +//! # let code_bytes = mac2.result().code(); +//! // `verify` will return `Ok(())` if code is correct, `Err(MacError)` otherwise +//! mac.verify(&code_bytes).unwrap(); +//! # } +//! ``` +#![no_std] +extern crate block_cipher_trait; +extern crate dbl; +pub extern crate crypto_mac; + +pub use crypto_mac::Mac; +use crypto_mac::{InvalidKeyLength, MacResult}; +use block_cipher_trait::{BlockCipher, NewVarKey}; +use block_cipher_trait::generic_array::{GenericArray, ArrayLength}; +use block_cipher_trait::generic_array::typenum::Unsigned; +use dbl::Dbl; + +use core::slice; + +type Block = GenericArray; +type ParBlocks = GenericArray, M>; + +/// Will use only precomputed table up to 16*2^20 = 16 MB of input data +/// (for 128 bit cipher), after that will dynamically calculate L value if +/// needed. In future it can become parameter of `Pmac`. +const LC_SIZE: usize = 20; + +/// Generic PMAC instance +#[derive(Clone)] +pub struct Pmac { + cipher: C, + l_inv: Block, + l_cache: [Block; LC_SIZE], + buffer: ParBlocks, + tag: Block, + offset: Block, + pos: usize, + counter: usize, +} + +#[inline(always)] +fn xor>(buf: &mut Block, data: &Block) { + for i in 0..L::to_usize() { + buf[i] ^= data[i]; + } +} + +impl Pmac + where C: BlockCipher + NewVarKey, Block: Dbl +{ + /// Process full buffer and update tag + #[inline(always)] + fn process_buffer(&mut self) { + let mut offset = self.offset.clone(); + let mut counter = self.counter; + let mut buf = self.buffer.clone(); + for val in buf.iter_mut() { + let l = self.get_l(counter); + xor(&mut offset, &l); + counter += 1; + xor(val, &offset); + } + self.counter = counter; + self.offset = offset; + + // encrypt blocks in the buffer + self.cipher.encrypt_blocks(&mut buf); + // and xor them into tag + for val in buf.iter() { + xor(&mut self.tag, val); + } + } + + /// Represent internall buffer as bytes slice (hopefully in future we will + /// be able to switch `&mut [u8]` to `&mut [u8; BlockSize*ParBlocks]`) + #[inline(always)] + fn as_mut_bytes(&mut self) -> &mut [u8] { + unsafe { + slice::from_raw_parts_mut( + &mut self.buffer + as *mut ParBlocks + as *mut u8, + C::BlockSize::to_usize()*C::ParBlocks::to_usize(), + ) + } + } + + #[inline(always)] + fn get_l(&self, counter: usize) -> Block { + let ntz = counter.trailing_zeros() as usize; + if ntz < LC_SIZE { + self.l_cache[ntz].clone() + } else { + let mut block = self.l_cache[LC_SIZE-1].clone(); + for _ in LC_SIZE-1..ntz { + block = block.dbl(); + } + block + } + } +} + +impl Mac for Pmac + where C: BlockCipher + NewVarKey, Block: Dbl +{ + type OutputSize = C::BlockSize; + + fn new(key: &[u8]) -> Result { + let cipher = C::new(key).map_err(|_| InvalidKeyLength)?; + + let mut l0 = Default::default(); + cipher.encrypt_block(&mut l0); + + let mut l_cache: [Block; LC_SIZE] = Default::default(); + l_cache[0] = l0.clone(); + for i in 1..LC_SIZE { + l_cache[i] = l_cache[i-1].clone().dbl(); + } + + let l_inv = l0.clone().inv_dbl(); + + Ok(Self { + cipher, l_inv, l_cache, + buffer: Default::default(), tag: Default::default(), + offset: Default::default(), + pos: 0, counter: 1, + }) + } + + #[inline] + fn input(&mut self, mut data: &[u8]) { + let n = C::BlockSize::to_usize()*C::ParBlocks::to_usize(); + + let p = self.pos; + let rem = n - p; + if data.len() >= rem { + let (l, r) = data.split_at(rem); + data = r; + self.as_mut_bytes()[p..].clone_from_slice(l); + } else { + self.as_mut_bytes()[p..p+data.len()] + .clone_from_slice(data); + self.pos += data.len(); + return; + } + + while data.len() >= n { + self.process_buffer(); + + let (l, r) = data.split_at(n); + self.as_mut_bytes().clone_from_slice(l); + data = r; + } + + self.pos = n; + + if data.len() != 0 { + self.process_buffer(); + self.as_mut_bytes()[..data.len()].clone_from_slice(data); + self.pos = data.len(); + } + } + + fn result(self) -> MacResult { + let mut tag = self.tag.clone(); + // Special case for empty input + if self.pos == 0 { + tag[0] = 0x80; + self.cipher.encrypt_block(&mut tag); + return MacResult::new(tag); + } + + let bs = C::BlockSize::to_usize(); + let k = self.pos % bs; + let is_full = k == 0; + // number of full blocks excluding last + let n = if is_full { (self.pos/bs) - 1 } else { self.pos/bs }; + assert!(n < C::ParBlocks::to_usize(), "invalid buffer positions"); + + let mut offset = self.offset.clone(); + let mut counter = self.counter; + for i in 0..n { + let mut buf = self.buffer[i].clone(); + + let l = self.get_l(counter); + xor(&mut offset, &l); + xor(&mut buf, &offset); + self.cipher.encrypt_block(&mut buf); + + xor(&mut tag, &buf); + counter += 1; + } + + if is_full { + xor(&mut tag, &self.buffer[n]); + xor(&mut tag, &self.l_inv); + } else { + let mut block = self.buffer[n].clone(); + block[k] = 0x80; + for v in block[k+1..].iter_mut() { *v = 0; } + xor(&mut tag, &block); + } + + self.cipher.encrypt_block(&mut tag); + + MacResult::new(tag) + } +} diff --git a/pmac/tests/data/aes128/1.input.bin b/pmac/tests/data/aes128/1.input.bin new file mode 100644 index 0000000..e69de29 diff --git a/pmac/tests/data/aes128/1.key.bin b/pmac/tests/data/aes128/1.key.bin new file mode 100644 index 0000000..b66efb8 Binary files /dev/null and b/pmac/tests/data/aes128/1.key.bin differ diff --git a/pmac/tests/data/aes128/1.output.bin b/pmac/tests/data/aes128/1.output.bin new file mode 100644 index 0000000..e366486 --- /dev/null +++ b/pmac/tests/data/aes128/1.output.bin @@ -0,0 +1 @@ +C™W,ÖêSA¸ÓXv§ Š÷ \ No newline at end of file diff --git a/pmac/tests/data/aes128/2.input.bin b/pmac/tests/data/aes128/2.input.bin new file mode 100644 index 0000000..8352675 Binary files /dev/null and b/pmac/tests/data/aes128/2.input.bin differ diff --git a/pmac/tests/data/aes128/2.key.bin b/pmac/tests/data/aes128/2.key.bin new file mode 100644 index 0000000..b66efb8 Binary files /dev/null and b/pmac/tests/data/aes128/2.key.bin differ diff --git a/pmac/tests/data/aes128/2.output.bin b/pmac/tests/data/aes128/2.output.bin new file mode 100644 index 0000000..36ec338 --- /dev/null +++ b/pmac/tests/data/aes128/2.output.bin @@ -0,0 +1 @@ +%k¥<™MðÅ8Šž' \ No newline at end of file diff --git a/pmac/tests/data/aes128/3.input.bin b/pmac/tests/data/aes128/3.input.bin new file mode 100644 index 0000000..b66efb8 Binary files /dev/null and b/pmac/tests/data/aes128/3.input.bin differ diff --git a/pmac/tests/data/aes128/3.key.bin b/pmac/tests/data/aes128/3.key.bin new file mode 100644 index 0000000..b66efb8 Binary files /dev/null and b/pmac/tests/data/aes128/3.key.bin differ diff --git a/pmac/tests/data/aes128/3.output.bin b/pmac/tests/data/aes128/3.output.bin new file mode 100644 index 0000000..c4a2117 --- /dev/null +++ b/pmac/tests/data/aes128/3.output.bin @@ -0,0 +1 @@ +뽂/¤XÚößÚ×Â}§c8 \ No newline at end of file diff --git a/pmac/tests/data/aes128/4.input.bin b/pmac/tests/data/aes128/4.input.bin new file mode 100644 index 0000000..dc8cabc Binary files /dev/null and b/pmac/tests/data/aes128/4.input.bin differ diff --git a/pmac/tests/data/aes128/4.key.bin b/pmac/tests/data/aes128/4.key.bin new file mode 100644 index 0000000..b66efb8 Binary files /dev/null and b/pmac/tests/data/aes128/4.key.bin differ diff --git a/pmac/tests/data/aes128/4.output.bin b/pmac/tests/data/aes128/4.output.bin new file mode 100644 index 0000000..0c74fff --- /dev/null +++ b/pmac/tests/data/aes128/4.output.bin @@ -0,0 +1 @@ +Ê ¿yŒu¥Œ™?U \ No newline at end of file diff --git a/pmac/tests/data/aes128/5.input.bin b/pmac/tests/data/aes128/5.input.bin new file mode 100644 index 0000000..fefa1cc Binary files /dev/null and b/pmac/tests/data/aes128/5.input.bin differ diff --git a/pmac/tests/data/aes128/5.key.bin b/pmac/tests/data/aes128/5.key.bin new file mode 100644 index 0000000..b66efb8 Binary files /dev/null and b/pmac/tests/data/aes128/5.key.bin differ diff --git a/pmac/tests/data/aes128/5.output.bin b/pmac/tests/data/aes128/5.output.bin new file mode 100644 index 0000000..2f8db71 --- /dev/null +++ b/pmac/tests/data/aes128/5.output.bin @@ -0,0 +1 @@ +ézÀNž^3™ÎSUÍt¼u \ No newline at end of file diff --git a/pmac/tests/data/aes128/6.input.bin b/pmac/tests/data/aes128/6.input.bin new file mode 100644 index 0000000..6fd520c Binary files /dev/null and b/pmac/tests/data/aes128/6.input.bin differ diff --git a/pmac/tests/data/aes128/6.key.bin b/pmac/tests/data/aes128/6.key.bin new file mode 100644 index 0000000..b66efb8 Binary files /dev/null and b/pmac/tests/data/aes128/6.key.bin differ diff --git a/pmac/tests/data/aes128/6.output.bin b/pmac/tests/data/aes128/6.output.bin new file mode 100644 index 0000000..b0c7a4c --- /dev/null +++ b/pmac/tests/data/aes128/6.output.bin @@ -0,0 +1 @@ +\º}^²O|†ÌÅFå=U \ No newline at end of file diff --git a/pmac/tests/data/aes128/7.input.bin b/pmac/tests/data/aes128/7.input.bin new file mode 100644 index 0000000..012b327 Binary files /dev/null and b/pmac/tests/data/aes128/7.input.bin differ diff --git a/pmac/tests/data/aes128/7.key.bin b/pmac/tests/data/aes128/7.key.bin new file mode 100644 index 0000000..b66efb8 Binary files /dev/null and b/pmac/tests/data/aes128/7.key.bin differ diff --git a/pmac/tests/data/aes128/7.output.bin b/pmac/tests/data/aes128/7.output.bin new file mode 100644 index 0000000..5206c10 --- /dev/null +++ b/pmac/tests/data/aes128/7.output.bin @@ -0,0 +1 @@ +ÂÉú™…öðÒ¯ù èÙ \ No newline at end of file diff --git a/pmac/tests/data/aes192/1.input.bin b/pmac/tests/data/aes192/1.input.bin new file mode 100644 index 0000000..e69de29 diff --git a/pmac/tests/data/aes192/1.key.bin b/pmac/tests/data/aes192/1.key.bin new file mode 100644 index 0000000..6cf0474 Binary files /dev/null and b/pmac/tests/data/aes192/1.key.bin differ diff --git a/pmac/tests/data/aes192/1.output.bin b/pmac/tests/data/aes192/1.output.bin new file mode 100644 index 0000000..9ad6809 --- /dev/null +++ b/pmac/tests/data/aes192/1.output.bin @@ -0,0 +1 @@ + c²²ÂvÞ“²ó~6Ú¾I \ No newline at end of file diff --git a/pmac/tests/data/aes192/2.input.bin b/pmac/tests/data/aes192/2.input.bin new file mode 100644 index 0000000..8352675 Binary files /dev/null and b/pmac/tests/data/aes192/2.input.bin differ diff --git a/pmac/tests/data/aes192/2.key.bin b/pmac/tests/data/aes192/2.key.bin new file mode 100644 index 0000000..6cf0474 Binary files /dev/null and b/pmac/tests/data/aes192/2.key.bin differ diff --git a/pmac/tests/data/aes192/2.output.bin b/pmac/tests/data/aes192/2.output.bin new file mode 100644 index 0000000..b135459 --- /dev/null +++ b/pmac/tests/data/aes192/2.output.bin @@ -0,0 +1 @@ +[¼C@u'BØ‚Šz¢Ã} \ No newline at end of file diff --git a/pmac/tests/data/aes192/3.input.bin b/pmac/tests/data/aes192/3.input.bin new file mode 100644 index 0000000..b66efb8 Binary files /dev/null and b/pmac/tests/data/aes192/3.input.bin differ diff --git a/pmac/tests/data/aes192/3.key.bin b/pmac/tests/data/aes192/3.key.bin new file mode 100644 index 0000000..6cf0474 Binary files /dev/null and b/pmac/tests/data/aes192/3.key.bin differ diff --git a/pmac/tests/data/aes192/3.output.bin b/pmac/tests/data/aes192/3.output.bin new file mode 100644 index 0000000..e2b1e24 Binary files /dev/null and b/pmac/tests/data/aes192/3.output.bin differ diff --git a/pmac/tests/data/aes192/4.input.bin b/pmac/tests/data/aes192/4.input.bin new file mode 100644 index 0000000..dc8cabc Binary files /dev/null and b/pmac/tests/data/aes192/4.input.bin differ diff --git a/pmac/tests/data/aes192/4.key.bin b/pmac/tests/data/aes192/4.key.bin new file mode 100644 index 0000000..6cf0474 Binary files /dev/null and b/pmac/tests/data/aes192/4.key.bin differ diff --git a/pmac/tests/data/aes192/4.output.bin b/pmac/tests/data/aes192/4.output.bin new file mode 100644 index 0000000..fd8ccf2 --- /dev/null +++ b/pmac/tests/data/aes192/4.output.bin @@ -0,0 +1 @@ +j|!Çs§1àZ¶Æ» \ No newline at end of file diff --git a/pmac/tests/data/aes192/5.input.bin b/pmac/tests/data/aes192/5.input.bin new file mode 100644 index 0000000..fefa1cc Binary files /dev/null and b/pmac/tests/data/aes192/5.input.bin differ diff --git a/pmac/tests/data/aes192/5.key.bin b/pmac/tests/data/aes192/5.key.bin new file mode 100644 index 0000000..6cf0474 Binary files /dev/null and b/pmac/tests/data/aes192/5.key.bin differ diff --git a/pmac/tests/data/aes192/5.output.bin b/pmac/tests/data/aes192/5.output.bin new file mode 100644 index 0000000..100835a --- /dev/null +++ b/pmac/tests/data/aes192/5.output.bin @@ -0,0 +1 @@ +eJYÜ—ÚŸh1‹ p¹ \ No newline at end of file diff --git a/pmac/tests/data/aes192/6.input.bin b/pmac/tests/data/aes192/6.input.bin new file mode 100644 index 0000000..6fd520c Binary files /dev/null and b/pmac/tests/data/aes192/6.input.bin differ diff --git a/pmac/tests/data/aes192/6.key.bin b/pmac/tests/data/aes192/6.key.bin new file mode 100644 index 0000000..6cf0474 Binary files /dev/null and b/pmac/tests/data/aes192/6.key.bin differ diff --git a/pmac/tests/data/aes192/6.output.bin b/pmac/tests/data/aes192/6.output.bin new file mode 100644 index 0000000..ee1fa7b --- /dev/null +++ b/pmac/tests/data/aes192/6.output.bin @@ -0,0 +1 @@ +µÿ ‡ŽƒD8ªö$¿ œ \ No newline at end of file diff --git a/pmac/tests/data/aes192/7.input.bin b/pmac/tests/data/aes192/7.input.bin new file mode 100644 index 0000000..012b327 Binary files /dev/null and b/pmac/tests/data/aes192/7.input.bin differ diff --git a/pmac/tests/data/aes192/7.key.bin b/pmac/tests/data/aes192/7.key.bin new file mode 100644 index 0000000..6cf0474 Binary files /dev/null and b/pmac/tests/data/aes192/7.key.bin differ diff --git a/pmac/tests/data/aes192/7.output.bin b/pmac/tests/data/aes192/7.output.bin new file mode 100644 index 0000000..85cb47d --- /dev/null +++ b/pmac/tests/data/aes192/7.output.bin @@ -0,0 +1 @@ +Ó®Â6)‹Á)õ7sÿP \ No newline at end of file diff --git a/pmac/tests/data/aes256/1.input.bin b/pmac/tests/data/aes256/1.input.bin new file mode 100644 index 0000000..e69de29 diff --git a/pmac/tests/data/aes256/1.key.bin b/pmac/tests/data/aes256/1.key.bin new file mode 100644 index 0000000..fefa1cc Binary files /dev/null and b/pmac/tests/data/aes256/1.key.bin differ diff --git a/pmac/tests/data/aes256/1.output.bin b/pmac/tests/data/aes256/1.output.bin new file mode 100644 index 0000000..eb9c651 --- /dev/null +++ b/pmac/tests/data/aes256/1.output.bin @@ -0,0 +1 @@ +æ õ/ç[¾‡«uŒ$”=‹ \ No newline at end of file diff --git a/pmac/tests/data/aes256/2.input.bin b/pmac/tests/data/aes256/2.input.bin new file mode 100644 index 0000000..8352675 Binary files /dev/null and b/pmac/tests/data/aes256/2.input.bin differ diff --git a/pmac/tests/data/aes256/2.key.bin b/pmac/tests/data/aes256/2.key.bin new file mode 100644 index 0000000..fefa1cc Binary files /dev/null and b/pmac/tests/data/aes256/2.key.bin differ diff --git a/pmac/tests/data/aes256/2.output.bin b/pmac/tests/data/aes256/2.output.bin new file mode 100644 index 0000000..43d2458 --- /dev/null +++ b/pmac/tests/data/aes256/2.output.bin @@ -0,0 +1 @@ +ÿá$Ì,û+ñïT 3<š \ No newline at end of file diff --git a/pmac/tests/data/aes256/3.input.bin b/pmac/tests/data/aes256/3.input.bin new file mode 100644 index 0000000..b66efb8 Binary files /dev/null and b/pmac/tests/data/aes256/3.input.bin differ diff --git a/pmac/tests/data/aes256/3.key.bin b/pmac/tests/data/aes256/3.key.bin new file mode 100644 index 0000000..fefa1cc Binary files /dev/null and b/pmac/tests/data/aes256/3.key.bin differ diff --git a/pmac/tests/data/aes256/3.output.bin b/pmac/tests/data/aes256/3.output.bin new file mode 100644 index 0000000..01e9771 --- /dev/null +++ b/pmac/tests/data/aes256/3.output.bin @@ -0,0 +1 @@ +…?ÛóùÍ68 iŠdw « \ No newline at end of file diff --git a/pmac/tests/data/aes256/4.input.bin b/pmac/tests/data/aes256/4.input.bin new file mode 100644 index 0000000..dc8cabc Binary files /dev/null and b/pmac/tests/data/aes256/4.input.bin differ diff --git a/pmac/tests/data/aes256/4.key.bin b/pmac/tests/data/aes256/4.key.bin new file mode 100644 index 0000000..fefa1cc Binary files /dev/null and b/pmac/tests/data/aes256/4.key.bin differ diff --git a/pmac/tests/data/aes256/4.output.bin b/pmac/tests/data/aes256/4.output.bin new file mode 100644 index 0000000..0b869ee --- /dev/null +++ b/pmac/tests/data/aes256/4.output.bin @@ -0,0 +1 @@ +w9_¾ì†ë–àRÍ \ No newline at end of file diff --git a/pmac/tests/data/aes256/5.input.bin b/pmac/tests/data/aes256/5.input.bin new file mode 100644 index 0000000..fefa1cc Binary files /dev/null and b/pmac/tests/data/aes256/5.input.bin differ diff --git a/pmac/tests/data/aes256/5.key.bin b/pmac/tests/data/aes256/5.key.bin new file mode 100644 index 0000000..fefa1cc Binary files /dev/null and b/pmac/tests/data/aes256/5.key.bin differ diff --git a/pmac/tests/data/aes256/5.output.bin b/pmac/tests/data/aes256/5.output.bin new file mode 100644 index 0000000..e88de99 --- /dev/null +++ b/pmac/tests/data/aes256/5.output.bin @@ -0,0 +1 @@ +ú%†xÈM810e>wôÀ \ No newline at end of file diff --git a/pmac/tests/data/aes256/6.input.bin b/pmac/tests/data/aes256/6.input.bin new file mode 100644 index 0000000..6fd520c Binary files /dev/null and b/pmac/tests/data/aes256/6.input.bin differ diff --git a/pmac/tests/data/aes256/6.key.bin b/pmac/tests/data/aes256/6.key.bin new file mode 100644 index 0000000..fefa1cc Binary files /dev/null and b/pmac/tests/data/aes256/6.key.bin differ diff --git a/pmac/tests/data/aes256/6.output.bin b/pmac/tests/data/aes256/6.output.bin new file mode 100644 index 0000000..251d81f --- /dev/null +++ b/pmac/tests/data/aes256/6.output.bin @@ -0,0 +1 @@ +íØ _KfvžîOëNÐá \ No newline at end of file diff --git a/pmac/tests/data/aes256/7.input.bin b/pmac/tests/data/aes256/7.input.bin new file mode 100644 index 0000000..012b327 Binary files /dev/null and b/pmac/tests/data/aes256/7.input.bin differ diff --git a/pmac/tests/data/aes256/7.key.bin b/pmac/tests/data/aes256/7.key.bin new file mode 100644 index 0000000..fefa1cc Binary files /dev/null and b/pmac/tests/data/aes256/7.key.bin differ diff --git a/pmac/tests/data/aes256/7.output.bin b/pmac/tests/data/aes256/7.output.bin new file mode 100644 index 0000000..db47d3c --- /dev/null +++ b/pmac/tests/data/aes256/7.output.bin @@ -0,0 +1 @@ +iªwò1ë ßù`õV)©n \ No newline at end of file diff --git a/pmac/tests/lib.rs b/pmac/tests/lib.rs new file mode 100644 index 0000000..63dec8d --- /dev/null +++ b/pmac/tests/lib.rs @@ -0,0 +1,38 @@ +//! Tests taken from: http://web.cs.ucdavis.edu/~rogaway/ocb/pmac-test.htm +#![no_std] +#[macro_use] +extern crate crypto_mac; +extern crate aesni; +extern crate pmac; + +use pmac::Pmac; +use pmac::crypto_mac::dev::{mac_test, Test}; +use aesni::{Aes128, Aes192, Aes256}; + + +#[test] +fn pmac_aes128() { + let tests = new_mac_tests!( + "aes128/1", "aes128/2", "aes128/3", "aes128/4", + "aes128/5", "aes128/6", "aes128/7" + ); + mac_test::>(&tests); +} + +#[test] +fn pmac_aes192() { + let tests = new_mac_tests!( + "aes192/1", "aes192/2", "aes192/3", "aes192/4", + "aes192/5", "aes192/6", "aes192/7" + ); + mac_test::>(&tests); +} + +#[test] +fn pmac_aes256() { + let tests = new_mac_tests!( + "aes256/1", "aes256/2", "aes256/3", "aes256/4", + "aes256/5", "aes256/6", "aes256/7" + ); + mac_test::>(&tests); +}