Skip to content

Commit

Permalink
Merge 60a6f49 into 8b2230b
Browse files Browse the repository at this point in the history
  • Loading branch information
kanav99 committed Apr 28, 2021
2 parents 8b2230b + 60a6f49 commit 394a9e5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 51 deletions.
7 changes: 3 additions & 4 deletions src/self_encryptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,22 +600,21 @@ fn get_pad_key_and_iv(
let this_pre_hash = &sorted_map[chunk_number].pre_hash;
let n_1_pre_hash = &sorted_map[n_1].pre_hash;
let n_2_pre_hash = &sorted_map[n_2].pre_hash;
assert_ne!(n_1_pre_hash.len(), 0);
assert_ne!(n_2_pre_hash.len(), 0);
assert_eq!(n_1_pre_hash.len(), HASH_SIZE);
assert_eq!(n_2_pre_hash.len(), HASH_SIZE);

let mut pad = [0u8; PAD_SIZE];
let mut key = [0u8; KEY_SIZE];
let mut iv = [0u8; IV_SIZE];

for (pad_iv_el, element) in pad
.iter_mut()
.chain(iv.iter_mut())
.zip(this_pre_hash.iter().chain(n_2_pre_hash.iter()))
{
*pad_iv_el = *element;
}

for (key_el, element) in key.iter_mut().zip(n_1_pre_hash.iter()) {
for (key_el, element) in key.iter_mut().chain(iv.iter_mut()).zip(n_1_pre_hash.iter()) {
*key_el = *element;
}

Expand Down
3 changes: 1 addition & 2 deletions src/sequential/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@ pub fn get_pad_key_and_iv(chunk_index: usize, chunks: &[ChunkDetails]) -> (Pad,

for (pad_iv_el, element) in pad
.iter_mut()
.chain(iv.iter_mut())
.zip(this_pre_hash.iter().chain(n_2_pre_hash.iter()))
{
*pad_iv_el = *element;
}

for (key_el, element) in key.iter_mut().zip(n_1_pre_hash.iter()) {
for (key_el, element) in key.iter_mut().chain(iv.iter_mut()).zip(n_1_pre_hash.iter()) {
*key_el = *element;
}

Expand Down
90 changes: 45 additions & 45 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,9 @@ async fn write_random_sizes_out_of_sequence_with_gaps_and_overlaps(
async fn cross_platform_check() {
#[rustfmt::skip]
static EXPECTED_HASHES: [[u8; 32]; 3] = [
[90, 123, 178, 77, 189, 56, 250, 228, 43, 186, 33, 61, 74, 91, 212, 16, 157, 230, 227, 31, 132, 167, 178, 127, 44, 33, 184, 3, 80, 29, 195, 41],
[28, 140, 54, 94, 73, 131, 229, 215, 75, 243, 169, 19, 239, 219, 112, 252, 107, 16, 114, 249, 219, 17, 212, 110, 99, 192, 86, 182, 30, 208, 213, 64],
[148, 67, 120, 59, 152, 244, 232, 6, 37, 187, 230, 153, 188, 190, 244, 156, 218, 116, 25, 129, 208, 78, 180, 236, 123, 14, 82, 255, 209, 231, 22, 129],
[19, 108, 102, 255, 128, 233, 109, 189, 190, 233, 41, 63, 63, 138, 214, 249, 106, 84, 201, 23, 7, 58, 106, 78, 188, 172, 111, 148, 245, 160, 133, 186],
[114, 117, 152, 126, 135, 111, 36, 211, 180, 31, 218, 187, 110, 75, 78, 238, 69, 210, 84, 34, 101, 16, 111, 36, 244, 207, 142, 127, 105, 74, 229, 255],
[247, 254, 6, 213, 162, 170, 240, 233, 104, 210, 240, 176, 24, 102, 165, 192, 179, 134, 155, 232, 104, 23, 210, 123, 11, 198, 91, 89, 17, 162, 214, 64],
];

let mut chars0 = Vec::<u8>::new();
Expand Down Expand Up @@ -440,8 +440,8 @@ async fn cross_platform_check2() -> Result<(), SelfEncryptionError> {
]
.to_vec(),
hash: [
248, 130, 126, 24, 65, 196, 21, 116, 150, 177, 242, 95, 221, 83, 149, 182, 190,
205, 67, 23, 123, 71, 198, 217, 210, 26, 108, 104, 226, 20, 218, 64,
130, 129, 210, 14, 124, 211, 239, 103, 149, 16, 206, 197, 81, 0, 41, 239, 38, 254,
192, 5, 173, 35, 19, 29, 133, 251, 44, 204, 57, 237, 37, 124,
]
.to_vec(),
chunk_num: 0,
Expand All @@ -454,8 +454,8 @@ async fn cross_platform_check2() -> Result<(), SelfEncryptionError> {
]
.to_vec(),
hash: [
18, 159, 244, 105, 187, 191, 246, 249, 87, 141, 67, 211, 58, 66, 134, 255, 150,
208, 180, 171, 192, 111, 29, 186, 91, 148, 231, 45, 113, 105, 136, 202,
42, 62, 224, 152, 136, 214, 91, 160, 125, 249, 229, 115, 81, 220, 213, 34, 29, 173,
235, 99, 67, 210, 234, 160, 79, 254, 208, 174, 117, 127, 205, 36,
]
.to_vec(),
chunk_num: 0,
Expand All @@ -468,8 +468,8 @@ async fn cross_platform_check2() -> Result<(), SelfEncryptionError> {
]
.to_vec(),
hash: [
122, 136, 131, 108, 167, 36, 157, 132, 244, 145, 104, 32, 217, 12, 238, 220, 110,
27, 50, 152, 172, 17, 66, 223, 251, 25, 212, 94, 142, 110, 132, 203,
200, 203, 81, 29, 131, 156, 60, 140, 166, 254, 103, 60, 212, 223, 22, 41, 85, 192,
140, 154, 33, 34, 188, 94, 84, 101, 62, 254, 164, 81, 209, 154,
]
.to_vec(),
chunk_num: 0,
Expand All @@ -482,8 +482,8 @@ async fn cross_platform_check2() -> Result<(), SelfEncryptionError> {
]
.to_vec(),
hash: [
95, 101, 4, 248, 190, 107, 61, 100, 154, 28, 217, 156, 80, 177, 100, 62, 205, 98,
84, 234, 177, 29, 202, 153, 165, 201, 220, 48, 137, 69, 114, 30,
42, 138, 132, 73, 12, 78, 47, 136, 153, 177, 25, 247, 202, 227, 145, 31, 193, 9,
33, 63, 89, 160, 240, 51, 189, 72, 94, 193, 75, 144, 58, 233,
]
.to_vec(),
chunk_num: 0,
Expand All @@ -496,8 +496,8 @@ async fn cross_platform_check2() -> Result<(), SelfEncryptionError> {
]
.to_vec(),
hash: [
229, 205, 229, 159, 248, 80, 166, 205, 17, 198, 25, 160, 92, 222, 124, 245, 174,
115, 130, 228, 117, 211, 61, 253, 82, 36, 197, 67, 106, 60, 33, 210,
220, 162, 48, 182, 212, 178, 139, 207, 231, 191, 209, 53, 187, 22, 66, 221, 242,
66, 220, 19, 96, 201, 137, 25, 101, 184, 1, 178, 80, 204, 253, 179,
]
.to_vec(),
chunk_num: 0,
Expand All @@ -510,8 +510,8 @@ async fn cross_platform_check2() -> Result<(), SelfEncryptionError> {
]
.to_vec(),
hash: [
72, 114, 190, 123, 137, 144, 19, 58, 46, 98, 42, 42, 32, 22, 250, 239, 40, 191, 85,
193, 248, 243, 119, 35, 205, 131, 97, 106, 141, 241, 149, 245,
168, 232, 79, 142, 149, 51, 198, 62, 224, 177, 45, 203, 243, 51, 12, 23, 104, 80,
174, 5, 246, 234, 54, 70, 58, 11, 100, 117, 60, 67, 65, 64,
]
.to_vec(),
chunk_num: 0,
Expand All @@ -524,8 +524,8 @@ async fn cross_platform_check2() -> Result<(), SelfEncryptionError> {
]
.to_vec(),
hash: [
57, 85, 13, 143, 39, 227, 226, 221, 59, 104, 169, 74, 10, 232, 242, 131, 220, 126,
4, 85, 84, 43, 81, 102, 148, 97, 165, 37, 118, 56, 189, 192,
199, 114, 193, 185, 26, 6, 140, 71, 142, 73, 45, 198, 110, 126, 232, 182, 226, 85,
137, 210, 69, 24, 139, 163, 236, 47, 155, 130, 43, 229, 148, 172,
]
.to_vec(),
chunk_num: 0,
Expand All @@ -538,8 +538,8 @@ async fn cross_platform_check2() -> Result<(), SelfEncryptionError> {
]
.to_vec(),
hash: [
93, 249, 109, 233, 188, 240, 18, 231, 63, 202, 255, 90, 160, 31, 54, 191, 36, 85,
75, 29, 84, 141, 204, 112, 254, 11, 116, 129, 63, 15, 2, 66,
151, 255, 185, 86, 239, 216, 199, 233, 149, 16, 247, 122, 156, 66, 178, 95, 32,
219, 218, 228, 63, 23, 34, 207, 140, 20, 75, 2, 225, 3, 243, 193,
]
.to_vec(),
chunk_num: 0,
Expand All @@ -552,8 +552,8 @@ async fn cross_platform_check2() -> Result<(), SelfEncryptionError> {
]
.to_vec(),
hash: [
56, 110, 198, 24, 230, 120, 195, 219, 227, 31, 129, 221, 182, 202, 3, 146, 2, 223,
67, 21, 114, 84, 65, 108, 18, 235, 239, 62, 175, 220, 138, 201,
126, 221, 146, 123, 252, 37, 250, 160, 75, 182, 9, 39, 80, 87, 93, 229, 173, 203,
31, 203, 208, 190, 226, 111, 87, 78, 246, 141, 85, 237, 82, 87,
]
.to_vec(),
chunk_num: 0,
Expand All @@ -566,8 +566,8 @@ async fn cross_platform_check2() -> Result<(), SelfEncryptionError> {
]
.to_vec(),
hash: [
176, 75, 146, 134, 244, 24, 27, 63, 160, 231, 223, 50, 124, 237, 115, 200, 213, 88,
148, 205, 98, 22, 69, 146, 11, 228, 82, 29, 170, 82, 110, 45,
109, 123, 118, 55, 228, 175, 144, 231, 103, 223, 51, 185, 146, 37, 47, 46, 185,
208, 140, 202, 231, 18, 70, 47, 48, 245, 254, 93, 185, 120, 17, 143,
]
.to_vec(),
chunk_num: 0,
Expand All @@ -580,8 +580,8 @@ async fn cross_platform_check2() -> Result<(), SelfEncryptionError> {
]
.to_vec(),
hash: [
184, 133, 215, 104, 56, 111, 160, 119, 201, 247, 23, 236, 92, 28, 171, 221, 79,
232, 237, 159, 27, 19, 177, 176, 15, 23, 161, 163, 66, 159, 242, 210,
85, 8, 26, 126, 9, 32, 28, 70, 112, 134, 226, 170, 46, 25, 115, 222, 131, 175, 117,
141, 96, 45, 201, 108, 148, 142, 12, 27, 184, 109, 44, 70,
]
.to_vec(),
chunk_num: 0,
Expand All @@ -594,8 +594,8 @@ async fn cross_platform_check2() -> Result<(), SelfEncryptionError> {
]
.to_vec(),
hash: [
49, 232, 225, 31, 240, 54, 141, 164, 15, 217, 164, 149, 222, 144, 11, 59, 134, 214,
126, 179, 105, 30, 190, 131, 89, 27, 240, 190, 124, 226, 198, 150,
240, 135, 94, 165, 73, 209, 176, 218, 159, 232, 76, 254, 32, 84, 238, 245, 226, 2,
227, 194, 95, 48, 125, 227, 42, 118, 85, 160, 39, 83, 2, 124,
]
.to_vec(),
chunk_num: 0,
Expand All @@ -608,8 +608,8 @@ async fn cross_platform_check2() -> Result<(), SelfEncryptionError> {
]
.to_vec(),
hash: [
17, 219, 169, 42, 190, 205, 249, 126, 131, 68, 38, 223, 73, 115, 93, 112, 62, 36,
183, 193, 140, 224, 55, 194, 89, 227, 69, 129, 251, 109, 214, 53,
198, 136, 45, 128, 93, 197, 174, 93, 27, 19, 218, 211, 184, 14, 214, 97, 182, 149,
36, 161, 66, 19, 118, 105, 240, 100, 104, 1, 192, 87, 236, 132,
]
.to_vec(),
chunk_num: 0,
Expand All @@ -622,8 +622,8 @@ async fn cross_platform_check2() -> Result<(), SelfEncryptionError> {
]
.to_vec(),
hash: [
165, 173, 226, 206, 228, 178, 246, 235, 26, 163, 155, 125, 0, 205, 205, 36, 64, 86,
234, 222, 69, 114, 119, 7, 12, 196, 25, 126, 193, 205, 60, 114,
187, 81, 209, 66, 106, 200, 142, 130, 197, 102, 170, 211, 120, 197, 65, 210, 229,
57, 27, 231, 120, 217, 180, 231, 34, 155, 32, 41, 78, 74, 193, 115,
]
.to_vec(),
chunk_num: 0,
Expand All @@ -636,8 +636,8 @@ async fn cross_platform_check2() -> Result<(), SelfEncryptionError> {
]
.to_vec(),
hash: [
1, 63, 38, 182, 193, 210, 99, 152, 89, 107, 90, 17, 230, 73, 159, 81, 102, 57, 247,
106, 68, 225, 33, 192, 209, 0, 196, 53, 242, 35, 108, 96,
145, 170, 97, 191, 204, 99, 185, 85, 4, 199, 204, 34, 104, 219, 97, 0, 184, 167,
32, 173, 83, 249, 254, 42, 251, 10, 168, 231, 211, 67, 70, 120,
]
.to_vec(),
chunk_num: 0,
Expand All @@ -650,8 +650,8 @@ async fn cross_platform_check2() -> Result<(), SelfEncryptionError> {
]
.to_vec(),
hash: [
23, 162, 40, 30, 19, 91, 183, 249, 44, 142, 229, 130, 88, 59, 48, 115, 117, 210,
223, 201, 112, 61, 114, 209, 96, 133, 128, 150, 33, 234, 92, 67,
130, 233, 29, 245, 160, 80, 144, 117, 139, 251, 91, 240, 232, 173, 233, 168, 61,
138, 88, 0, 92, 133, 16, 118, 29, 118, 131, 218, 42, 197, 132, 54,
]
.to_vec(),
chunk_num: 0,
Expand All @@ -664,8 +664,8 @@ async fn cross_platform_check2() -> Result<(), SelfEncryptionError> {
]
.to_vec(),
hash: [
177, 48, 239, 237, 6, 81, 178, 34, 44, 125, 146, 74, 170, 12, 72, 237, 128, 157,
43, 20, 70, 35, 246, 95, 240, 124, 236, 50, 211, 28, 253, 13,
0, 52, 220, 168, 128, 29, 228, 70, 0, 29, 73, 244, 83, 7, 171, 237, 31, 236, 231,
24, 148, 14, 100, 16, 117, 82, 41, 11, 216, 126, 209, 127,
]
.to_vec(),
chunk_num: 0,
Expand All @@ -678,8 +678,8 @@ async fn cross_platform_check2() -> Result<(), SelfEncryptionError> {
]
.to_vec(),
hash: [
75, 61, 6, 107, 79, 230, 247, 5, 216, 162, 59, 66, 230, 241, 190, 226, 105, 185,
20, 191, 117, 79, 150, 152, 104, 202, 109, 124, 142, 177, 167, 23,
77, 246, 174, 53, 36, 156, 19, 157, 46, 142, 60, 60, 122, 133, 52, 118, 73, 80, 40,
205, 174, 231, 211, 110, 38, 8, 189, 206, 102, 252, 166, 34,
]
.to_vec(),
chunk_num: 0,
Expand All @@ -692,8 +692,8 @@ async fn cross_platform_check2() -> Result<(), SelfEncryptionError> {
]
.to_vec(),
hash: [
18, 159, 244, 105, 187, 191, 246, 249, 87, 141, 67, 211, 58, 66, 134, 255, 150,
208, 180, 171, 192, 111, 29, 186, 91, 148, 231, 45, 113, 105, 136, 202,
42, 62, 224, 152, 136, 214, 91, 160, 125, 249, 229, 115, 81, 220, 213, 34, 29, 173,
235, 99, 67, 210, 234, 160, 79, 254, 208, 174, 117, 127, 205, 36,
]
.to_vec(),
chunk_num: 0,
Expand All @@ -706,8 +706,8 @@ async fn cross_platform_check2() -> Result<(), SelfEncryptionError> {
]
.to_vec(),
hash: [
42, 242, 254, 92, 95, 88, 84, 152, 206, 210, 173, 147, 63, 233, 12, 97, 179, 180,
180, 161, 15, 55, 241, 163, 79, 123, 64, 234, 13, 157, 247, 100,
105, 178, 124, 23, 220, 180, 219, 83, 254, 79, 65, 107, 122, 98, 193, 172, 222,
160, 246, 13, 251, 141, 220, 254, 135, 181, 52, 194, 43, 136, 100, 101,
]
.to_vec(),
chunk_num: 0,
Expand All @@ -720,8 +720,8 @@ async fn cross_platform_check2() -> Result<(), SelfEncryptionError> {
]
.to_vec(),
hash: [
11, 138, 109, 122, 129, 132, 242, 156, 53, 48, 249, 168, 40, 130, 114, 195, 224,
98, 246, 23, 129, 45, 220, 242, 140, 12, 168, 65, 234, 0, 40, 11,
68, 132, 63, 86, 220, 69, 168, 139, 77, 35, 192, 220, 250, 13, 169, 144, 99, 212,
253, 136, 192, 107, 77, 209, 211, 14, 222, 78, 151, 149, 226, 34,
]
.to_vec(),
chunk_num: 0,
Expand Down

0 comments on commit 394a9e5

Please sign in to comment.