Bladeren bron

tagSize -> tagLength

Marcin Krzyzanowski 6 jaren geleden
bovenliggende
commit
5f7df9629e
2 gewijzigde bestanden met toevoegingen van 7 en 11 verwijderingen
  1. 0 4
      Sources/CryptoSwift/BlockMode/BlockModeOptions.swift
  2. 7 7
      Sources/CryptoSwift/BlockMode/GCM.swift

+ 0 - 4
Sources/CryptoSwift/BlockMode/BlockModeOptions.swift

@@ -20,10 +20,6 @@ public struct BlockModeOption: OptionSet {
         self.rawValue = rawValue
     }
 
-    public init(rawValue: Int, authenticationTagSize: Int) {
-        self.rawValue = rawValue
-    }
-
     static let none = BlockModeOption(rawValue: 1 << 0)
     static let initializationVectorRequired = BlockModeOption(rawValue: 1 << 1)
     static let paddingRequired = BlockModeOption(rawValue: 1 << 2)

+ 7 - 7
Sources/CryptoSwift/BlockMode/GCM.swift

@@ -28,7 +28,7 @@ public final class GCM: BlockMode {
         var additionalBufferSize: Int {
             switch self {
             case .combined:
-                return GCMModeWorker.tagSize
+                return GCMModeWorker.tagLength
             case .detached:
                 return 0
             }
@@ -88,7 +88,7 @@ final class GCMModeWorker: BlockModeWorker, FinalizingModeWorker {
     var didCalculateTag: ((Array<UInt8>) -> Void)?
 
     // 128 bit tag. Other possible tags 4,8,12,13,14,15,16
-    fileprivate static let tagSize = 16
+    fileprivate static let tagLength = 16
     // GCM nonce is 96-bits by default. It's the most effective length for the IV
     private static let nonceSize = 12
 
@@ -170,7 +170,7 @@ final class GCMModeWorker: BlockModeWorker, FinalizingModeWorker {
     func finalize(encrypt ciphertext: ArraySlice<UInt8>) throws -> Array<UInt8> {
         // Calculate MAC tag.
         let ghash = gf.ghashFinish()
-        let tag = Array((ghash ^ eky0).bytes.prefix(GCMModeWorker.tagSize))
+        let tag = Array((ghash ^ eky0).bytes.prefix(GCMModeWorker.tagLength))
 
         // Notify handler
         didCalculateTag?(tag)
@@ -191,10 +191,10 @@ final class GCMModeWorker: BlockModeWorker, FinalizingModeWorker {
         switch mode {
         case .combined:
             // overwrite expectedTag property used later for verification
-            self.expectedTag = Array(ciphertext.suffix(GCMModeWorker.tagSize))
-            // gf.ciphertextLength = gf.ciphertextLength - GCMModeWorker.tagSize
+            self.expectedTag = Array(ciphertext.suffix(GCMModeWorker.tagLength))
+            // gf.ciphertextLength = gf.ciphertextLength - GCMModeWorker.tagLength
             // strip tag from the plaintext.
-            return ciphertext[ciphertext.startIndex..<ciphertext.endIndex.advanced(by: -Swift.min(GCMModeWorker.tagSize,ciphertext.count))]
+            return ciphertext[ciphertext.startIndex..<ciphertext.endIndex.advanced(by: -Swift.min(GCMModeWorker.tagLength,ciphertext.count))]
         case .detached:
             return ciphertext
         }
@@ -203,7 +203,7 @@ final class GCMModeWorker: BlockModeWorker, FinalizingModeWorker {
     func didDecryptLast(block plaintext: ArraySlice<UInt8>) throws -> Array<UInt8> {
         // Calculate MAC tag.
         let ghash = gf.ghashFinish()
-        let computedTag = Array((ghash ^ eky0).bytes.prefix(GCMModeWorker.tagSize))
+        let computedTag = Array((ghash ^ eky0).bytes.prefix(GCMModeWorker.tagLength))
 
         // Validate tag
         if let expectedTag = self.expectedTag, computedTag == expectedTag {