Browse Source

Prevent overflow

Marcin Krzyżanowski 8 years ago
parent
commit
38343e69a5
1 changed files with 1 additions and 1 deletions
  1. 1 1
      Sources/CryptoSwift/ChaCha20.swift

+ 1 - 1
Sources/CryptoSwift/ChaCha20.swift

@@ -223,7 +223,7 @@ public final class ChaCha20: BlockCipher {
             var u: UInt32 = 1
             var u: UInt32 = 1
             for i in 0..<4 {
             for i in 0..<4 {
                 u += UInt32(counter[i])
                 u += UInt32(counter[i])
-                counter[i] = UInt8(u)
+                counter[i] = UInt8(u & 0xFF)
                 u >>= 8
                 u >>= 8
             }
             }
             bytes = Array(bytes[ChaCha20.blockSize..<bytes.endIndex])
             bytes = Array(bytes[ChaCha20.blockSize..<bytes.endIndex])