Browse Source

Poly not crashing finally

Marcin Krzyżanowski 11 years ago
parent
commit
035a023751
2 changed files with 8 additions and 8 deletions
  1. 5 5
      CryptoSwift/Poly1305.swift
  2. 3 3
      CryptoSwiftTests/CipherTests.swift

+ 5 - 5
CryptoSwift/Poly1305.swift

@@ -62,7 +62,7 @@ public class Poly1305 {
         var u:UInt16 = 0
         for i in 0..<h.count {
             u = u &+ UInt16(h[i]) &+ UInt16(c[i])
-            h[0] = Byte(u)
+            h[0] = Byte.withValue(u)
             u = u &>> 8 // u = u >> 8
         }
         return true
@@ -77,20 +77,20 @@ public class Poly1305 {
 
         for i in 0..<16 {
             u = u &+ hr[i];
-            h[i] = Byte(u) & 0xff;
+            h[i] = Byte.withValue(u) // crash! h[i] = UInt8(u) & 0xff
             u = u >> 8;
         }
         
         u = u &+ hr[16]
-        h[16] = Byte(u) & 0x03
+        h[16] = Byte.withValue(u) & 0x03
         u = u >> 2
         u += (u << 2); /* u *= 5; */
         for i in 0..<16 {
             u = u &+ UInt32(h[i])
-            h[i] = Byte(u) & 0xff
+            h[i] = Byte.withValue(u) // crash! h[i] = UInt8(u) & 0xff
             u = u >> 8
         }
-        h[16] = h[16] &+ Byte(u);
+        h[16] = h[16] &+ Byte.withValue(u);
         
         return true
     }

+ 3 - 3
CryptoSwiftTests/CipherTests.swift

@@ -48,9 +48,9 @@ class CipherTests: XCTestCase {
                                  0x2a,0x7d,0xfb,0x4b,0x3d,0x33,0x05,0xd9]
         
         
-//        let poly = Poly1305(key: key);
-//        let mac:[Byte] = [Byte](count: 16, repeatedValue: 0);
-//        poly.auth(mac, m: msg)
+        let poly = Poly1305(key: key);
+        let mac:[Byte] = [Byte](count: 16, repeatedValue: 0);
+        poly.auth(mac, m: msg)
     }
 
     func testChaCha20() {