Add sha512 on pbkdf2 Sift

This commit is contained in:
Hugo Pointcheval 2020-04-29 23:04:20 +02:00
parent 8a112648bf
commit 46b1a5248c

View File

@ -82,6 +82,10 @@ func pbkdf2(hash: CCPBKDFAlgorithm, password: String, salt: String, keyByteCount
return derivedKeyData return derivedKeyData
} }
func pbkdf2sha512(password: String, salt: String, keyByteCount: Int, rounds: Int) -> Data? {
return pbkdf2(hash: CCPBKDFAlgorithm(kCCPRFHmacAlgSHA512), password: password, salt: salt, keyByteCount: keyByteCount, rounds: rounds)
}
func pbkdf2sha256(password: String, salt: String, keyByteCount: Int, rounds: Int) -> Data? { func pbkdf2sha256(password: String, salt: String, keyByteCount: Int, rounds: Int) -> Data? {
return pbkdf2(hash: CCPBKDFAlgorithm(kCCPRFHmacAlgSHA256), password: password, salt: salt, keyByteCount: keyByteCount, rounds: rounds) return pbkdf2(hash: CCPBKDFAlgorithm(kCCPRFHmacAlgSHA256), password: password, salt: salt, keyByteCount: keyByteCount, rounds: rounds)
} }
@ -174,8 +178,10 @@ public class SwiftNativeCryptoPlugin: NSObject, FlutterPlugin {
if (algo == "sha1") { if (algo == "sha1") {
keyBytes = pbkdf2sha1(password: password, salt: salt, keyByteCount: keyLength.intValue, rounds: iteration.intValue) keyBytes = pbkdf2sha1(password: password, salt: salt, keyByteCount: keyLength.intValue, rounds: iteration.intValue)
} else { } else if (algo == "sha256"){
keyBytes = pbkdf2sha256(password: password, salt: salt, keyByteCount: keyLength.intValue, rounds: iteration.intValue) keyBytes = pbkdf2sha256(password: password, salt: salt, keyByteCount: keyLength.intValue, rounds: iteration.intValue)
} else if (algo == "sha512"){
keyBytes = pbkdf2sha512(password: password, salt: salt, keyByteCount: keyLength.intValue, rounds: iteration.intValue)
} }
if keyBytes != nil { if keyBytes != nil {