@@ -165,7 +165,11 @@ impl DigestOp for DigestContext256 {
165165 // Safe iteration with proper bounds checking
166166 for ( i, chunk) in result. chunks_exact ( 4 ) . enumerate ( ) . take ( 8 ) {
167167 if let Ok ( bytes) = chunk. try_into ( ) {
168- words[ i] = u32:: from_le_bytes ( bytes) ;
168+ if let Some ( word) = words. get_mut ( i) {
169+ * word = u32:: from_le_bytes ( bytes) ;
170+ } else {
171+ return Err ( CryptoError :: OperationFailed ) ;
172+ }
169173 } else {
170174 return Err ( CryptoError :: OperationFailed ) ;
171175 }
@@ -203,7 +207,11 @@ impl DigestOp for DigestContext384 {
203207 // Safe iteration with proper bounds checking
204208 for ( i, chunk) in result. chunks_exact ( 4 ) . enumerate ( ) . take ( 12 ) {
205209 if let Ok ( bytes) = chunk. try_into ( ) {
206- words[ i] = u32:: from_le_bytes ( bytes) ;
210+ if let Some ( word) = words. get_mut ( i) {
211+ * word = u32:: from_le_bytes ( bytes) ;
212+ } else {
213+ return Err ( CryptoError :: OperationFailed ) ;
214+ }
207215 } else {
208216 return Err ( CryptoError :: OperationFailed ) ;
209217 }
@@ -241,7 +249,11 @@ impl DigestOp for DigestContext512 {
241249 // Safe iteration with proper bounds checking
242250 for ( i, chunk) in result. chunks_exact ( 4 ) . enumerate ( ) . take ( 16 ) {
243251 if let Ok ( bytes) = chunk. try_into ( ) {
244- words[ i] = u32:: from_le_bytes ( bytes) ;
252+ if let Some ( word) = words. get_mut ( i) {
253+ * word = u32:: from_le_bytes ( bytes) ;
254+ } else {
255+ return Err ( CryptoError :: OperationFailed ) ;
256+ }
245257 } else {
246258 return Err ( CryptoError :: OperationFailed ) ;
247259 }
0 commit comments