From 8220e3782faa3ae9c97de7eb0b8dfa25264cd172 Mon Sep 17 00:00:00 2001 From: Shramee Srivastav Date: Wed, 29 May 2024 03:32:08 +0530 Subject: [PATCH] cleanup from_WordArray_to_u8array --- src/math/src/sha512.cairo | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/math/src/sha512.cairo b/src/math/src/sha512.cairo index 809948be..92fe0cc7 100644 --- a/src/math/src/sha512.cairo +++ b/src/math/src/sha512.cairo @@ -295,27 +295,25 @@ fn from_u8Array_to_WordArray(data: Array) -> Array { fn from_WordArray_to_u8array(data: Span) -> Array { let mut arr: Array = array![]; - let max_u8: u128 = MAX_U8.into(); let mut i = 0; // Use precomputed powers of 2 for shift right to avoid recomputation while (i != data.len()) { - let mut res: u128 = math_shr_precomputed((*data.at(i).data).into(), TWO_POW_56.into()) - & max_u8; + let mut res = math_shr_precomputed((*data.at(i).data).into(), TWO_POW_56) & MAX_U8; arr.append(res.try_into().unwrap()); - res = math_shr_precomputed((*data.at(i).data).into(), TWO_POW_48.into()) & max_u8; + res = math_shr_precomputed((*data.at(i).data).into(), TWO_POW_48) & MAX_U8; arr.append(res.try_into().unwrap()); - res = math_shr_precomputed((*data.at(i).data).into(), TWO_POW_40.into()) & max_u8; + res = math_shr_precomputed((*data.at(i).data).into(), TWO_POW_40) & MAX_U8; arr.append(res.try_into().unwrap()); - res = math_shr_precomputed((*data.at(i).data).into(), TWO_POW_32.into()) & max_u8; + res = math_shr_precomputed((*data.at(i).data).into(), TWO_POW_32) & MAX_U8; arr.append(res.try_into().unwrap()); - res = math_shr_precomputed((*data.at(i).data).into(), TWO_POW_24.into()) & max_u8; + res = math_shr_precomputed((*data.at(i).data).into(), TWO_POW_24) & MAX_U8; arr.append(res.try_into().unwrap()); - res = math_shr_precomputed((*data.at(i).data).into(), TWO_POW_16.into()) & max_u8; + res = math_shr_precomputed((*data.at(i).data).into(), TWO_POW_16) & MAX_U8; arr.append(res.try_into().unwrap()); - res = math_shr_precomputed((*data.at(i).data).into(), TWO_POW_8.into()) & max_u8; + res = math_shr_precomputed((*data.at(i).data).into(), TWO_POW_8) & MAX_U8; arr.append(res.try_into().unwrap()); - res = math_shr_precomputed((*data.at(i).data).into(), TWO_POW_0.into()) & max_u8; + res = math_shr_precomputed((*data.at(i).data).into(), TWO_POW_0) & MAX_U8; arr.append(res.try_into().unwrap()); i += 1; };