Ver Fonte

Use ZeroPadding in HMAC. Update README.

Marcin Krzyżanowski há 9 anos atrás
pai
commit
71dc6af7be
2 ficheiros alterados com 3 adições e 4 exclusões
  1. 1 0
      README.md
  2. 2 4
      Sources/CryptoSwift/HMAC.swift

+ 1 - 0
README.md

@@ -56,6 +56,7 @@ Good mood
 
 
 #### Data padding
 #### Data padding
 - [PKCS#7](http://tools.ietf.org/html/rfc5652#section-6.3)
 - [PKCS#7](http://tools.ietf.org/html/rfc5652#section-6.3)
+- Zero padding
 - NoPadding
 - NoPadding
 
 
 ##Why
 ##Why

+ 2 - 4
Sources/CryptoSwift/HMAC.swift

@@ -63,10 +63,8 @@ final public class HMAC {
                 self.key = hash
                 self.key = hash
             }
             }
         }
         }
-        
-        if (key.count < variant.blockSize()) { // keys shorter than blocksize are zero-padded
-            self.key = key + Array<UInt8>(repeating: 0, count: variant.blockSize() - key.count)
-        }
+
+        self.key = ZeroPadding().add(to: key, blockSize: variant.blockSize())
     }
     }
 
 
     public func authenticate(bytes:Array<UInt8>) -> Array<UInt8>? {
     public func authenticate(bytes:Array<UInt8>) -> Array<UInt8>? {