瀏覽代碼

Prevent overflow

Marcin Krzyżanowski 7 年之前
父節點
當前提交
38343e69a5
共有 1 個文件被更改,包括 1 次插入1 次删除
  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
             for i in 0..<4 {
                 u += UInt32(counter[i])
-                counter[i] = UInt8(u)
+                counter[i] = UInt8(u & 0xFF)
                 u >>= 8
             }
             bytes = Array(bytes[ChaCha20.blockSize..<bytes.endIndex])