Преглед на файлове

Reduce expression complexity to appease compiler

Adolfo Martinelli преди 8 години
родител
ревизия
9f9112573c
променени са 2 файла, в които са добавени 15 реда и са изтрити 16 реда
  1. 8 13
      Sources/CryptoSwift/AES.swift
  2. 7 3
      Sources/CryptoSwift/MD5.swift

+ 8 - 13
Sources/CryptoSwift/AES.swift

@@ -307,19 +307,14 @@ fileprivate extension AES {
         var rk2: Array<Array<UInt32>> = expandKey(key, variant: variant)
         var rk2: Array<Array<UInt32>> = expandKey(key, variant: variant)
 
 
         for r in 1 ..< rounds {
         for r in 1 ..< rounds {
-            var w: UInt32
-
-            w = rk2[r][0]
-            rk2[r][0] = U1[Int(B0(w))] ^ U2[Int(B1(w))] ^ U3[Int(B2(w))] ^ U4[Int(B3(w))]
-
-            w = rk2[r][1]
-            rk2[r][1] = U1[Int(B0(w))] ^ U2[Int(B1(w))] ^ U3[Int(B2(w))] ^ U4[Int(B3(w))]
-
-            w = rk2[r][2]
-            rk2[r][2] = U1[Int(B0(w))] ^ U2[Int(B1(w))] ^ U3[Int(B2(w))] ^ U4[Int(B3(w))]
-
-            w = rk2[r][3]
-            rk2[r][3] = U1[Int(B0(w))] ^ U2[Int(B1(w))] ^ U3[Int(B2(w))] ^ U4[Int(B3(w))]
+            for i in 0..<4 {
+                let w = rk2[r][i]
+                let u1 = U1[Int(B0(w))]
+                let u2 = U2[Int(B1(w))]
+                let u3 = U3[Int(B2(w))]
+                let u4 = U4[Int(B3(w))]
+                rk2[r][i] = u1^u2^u3^u4
+            }
         }
         }
 
 
         return rk2
         return rk2

+ 7 - 3
Sources/CryptoSwift/MD5.swift

@@ -101,10 +101,14 @@ public final class MD5: DigestType {
 
 
             // break chunk into sixteen 32-bit words M[j], 0 ≤ j ≤ 15 and get M[g] value
             // break chunk into sixteen 32-bit words M[j], 0 ≤ j ≤ 15 and get M[g] value
             let gAdvanced = g << 2
             let gAdvanced = g << 2
-            var Mg = UInt32(chunk[chunk.startIndex &+ gAdvanced]) | UInt32(chunk[chunk.startIndex &+ gAdvanced &+ 1]) << 8 | UInt32(chunk[chunk.startIndex &+ gAdvanced &+ 2]) << 16
-                Mg = Mg | UInt32(chunk[chunk.startIndex &+ gAdvanced &+ 3]) << 24
 
 
-            B = B &+ rotateLeft(A &+ F &+ k[j] &+ Mg, by: s[j])
+            let mg0 = UInt32(chunk[chunk.startIndex &+ gAdvanced])
+            let mg1 = UInt32(chunk[chunk.startIndex &+ gAdvanced &+ 1]) << 8
+            let mg2 = UInt32(chunk[chunk.startIndex &+ gAdvanced &+ 2]) << 16
+            let mg3 = UInt32(chunk[chunk.startIndex &+ gAdvanced &+ 3]) << 24
+            let mg = (mg0 | mg1 | mg2) | mg3
+
+            B = B &+ rotateLeft(A &+ F &+ k[j] &+ mg, by: s[j])
             A = dTemp
             A = dTemp
         }
         }