     }
 
     private func hmac(algorithm: HMAC.Algorithm, key: String, message: String, expectedHMAC: String) {
-        let key = key.dataUsingEncoding(NSUTF8StringEncoding)!
-        let message = message.dataUsingEncoding(NSUTF8StringEncoding)!
-        let hmac = message.hmac(algorithm, key: key).hexString()
+        let keyData = key.dataUsingEncoding(NSUTF8StringEncoding)!
+        let messageData = message.dataUsingEncoding(NSUTF8StringEncoding)!
+        let hmac = messageData.hmac(algorithm, key: keyData).hexString()
         XCTAssertEqual(hmac, expectedHMAC)
+        XCTAssertEqual(hmac, message.hmac(algorithm, key: key))
     }
 
     // MARK: PBKDF
 
     func testDerivedKey_SHA1() {
+        calibrate(Consts.key, saltLength: Consts.pbkdfSalt.dataUsingEncoding(NSUTF8StringEncoding)!.length, pseudoRandomAlgorithm: .SHA1, derivedKeyLength: 16, msec: 100)
         PBKDF2(Consts.key, salt: Consts.pbkdfSalt, pseudoRandomAlgorithm: .SHA1, rounds: 20, derivedKeyLength: 16, expectedDerivedKey: Consts.pbkdfSHA1)
     }
 
     func testDerivedKey_SHA256() {
+        calibrate(Consts.key, saltLength: Consts.pbkdfSalt.dataUsingEncoding(NSUTF8StringEncoding)!.length, pseudoRandomAlgorithm: .SHA256, derivedKeyLength: 32, msec: 100)
         PBKDF2(Consts.key, salt: Consts.pbkdfSalt, pseudoRandomAlgorithm: .SHA256, rounds: 20, derivedKeyLength: 32, expectedDerivedKey: Consts.pbkdfSHA256)
     }
 
     func testDerivedKey_SHA512() {
+        calibrate(Consts.key, saltLength: Consts.pbkdfSalt.dataUsingEncoding(NSUTF8StringEncoding)!.length, pseudoRandomAlgorithm: .SHA512, derivedKeyLength: 64, msec: 100)
         PBKDF2(Consts.key, salt: Consts.pbkdfSalt, pseudoRandomAlgorithm: .SHA512, rounds: 20, derivedKeyLength: 64, expectedDerivedKey: Consts.pbkdfSHA512)
     }
 

        XCTAssertEqual(derivedKey.hexString(), expectedDerivedKey)
    }

    // MARK: Cryptor

    func testAES_CBC_128() {

        static let aesCiphertext_CBC_256_IV = "O49HzhxdRYMgzqQYx+pECj98Mxn+EtFy7ZnBE9yr+fPZXwgzWaLnLasoKszifIlHRnY3W0ehdWT2Zysaguorcw=="
    }

    // MARK: SCryptoError

    func testSCryptoError() {
        XCTAssertTrue(SCryptoError(rawValue: 0) == nil)
        XCTAssertTrue(SCryptoError(rawValue: -4300)! == .ParamError)
        XCTAssertTrue(SCryptoError(rawValue: -4301)! == .BufferTooSmall)
        XCTAssertTrue(SCryptoError(rawValue: -4302)! == .MemoryFailure)
        XCTAssertTrue(SCryptoError(rawValue: -4303)! == .AlignmentError)
        XCTAssertTrue(SCryptoError(rawValue: -4304)! == .DecodeError)
        XCTAssertTrue(SCryptoError(rawValue: -4305)! == .Unimplemented)
        XCTAssertTrue(SCryptoError(rawValue: -4306)! == .Overflow)
        XCTAssertTrue(SCryptoError(rawValue: -4307)! == .RNGFailure)

        XCTAssertTrue(SCryptoError.ParamError.rawValue == -4300)
        XCTAssertTrue(SCryptoError.BufferTooSmall.rawValue == -4301)
        XCTAssertTrue(SCryptoError.MemoryFailure.rawValue == -4302)
        XCTAssertTrue(SCryptoError.AlignmentError.rawValue == -4303)
        XCTAssertTrue(SCryptoError.DecodeError.rawValue == -4304)
        XCTAssertTrue(SCryptoError.Unimplemented.rawValue == -4305)
        XCTAssertTrue(SCryptoError.Overflow.rawValue == -4306)
        XCTAssertTrue(SCryptoError.RNGFailure.rawValue == -4307)
    }

    // MARK: Digest

    func testMD2() {
        digest(Consts.message, expectedDigest: Consts.MD2) { $0.MD2() }
        XCTAssertEqual(Consts.message.MD2(), Consts.MD2)
    }

    func testMD4() {
        digest(Consts.message, expectedDigest: Consts.MD4) { $0.MD4() }
        XCTAssertEqual(Consts.message.MD4(), Consts.MD4)
    }

    func testMD5() {
        digest(Consts.message, expectedDigest: Consts.MD5) { $0.MD5() }
        XCTAssertEqual(Consts.message.MD5(), Consts.MD5)
    }

    func testSHA1() {
        digest(Consts.message, expectedDigest: Consts.SHA1) { $0.SHA1() }
        XCTAssertEqual(Consts.message.SHA1(), Consts.SHA1)
    }

    func testSHA224() {
        digest(Consts.message, expectedDigest: Consts.SHA224) { $0.SHA224() }
        XCTAssertEqual(Consts.message.SHA224(), Consts.SHA224)
    }

    func testSHA256() {
        digest(Consts.message, expectedDigest: Consts.SHA256) { $0.SHA256() }
        XCTAssertEqual(Consts.message.SHA256(), Consts.SHA256)
    }

    func testSHA384() {
        digest(Consts.message, expectedDigest: Consts.SHA384) { $0.SHA384() }
        XCTAssertEqual(Consts.message.SHA384(), Consts.SHA384)
    }

    func testSHA512() {
        digest(Consts.message, expectedDigest: Consts.SHA512) { $0.SHA512() }
        XCTAssertEqual(Consts.message.SHA512(), Consts.SHA512)
    }

    private func digest(message: String, expectedDigest: String, algorithm: (NSData) -> NSData) {
        let messageData = message.dataUsingEncoding(NSUTF8StringEncoding)!
        let digest = algorithm(messageData).hexString()
        XCTAssertEqual(digest, expectedDigest)
    }

