private key – Why different results from HMAC_SHA512?

I am creating Crypto HD Wallet for IOS right now, and I need to generate master keys from seed, using HMAC_sha512 function. I am using OpenSSL library for that and HMAC function. The problem is that results from it differs from web site where I am checking it. What can be wrong?

I am checking result on the https://iancoleman.io/bip39/ website.

If I paste there my test seed which is:

04566640a205e779975193a404cdfb0829daabf256ea70198cd060eb4a4043766a24a62233e6d2ae907d3767256c9f9171f8be0d993af15848cfabf2fcade1c8

I get BIP32 root key:

xprv9s21ZrQH143K48Uym5n1kBFYhzBvvNscsmEvRbMUiHEthfzc9s8VC2Be19oRq8Y49cExD6pqMujrfuztq3SiR8YGfpjnkKJcFLtgqA7RdpE

But my code from the same seed generates this:

xprv9s21ZrQH143K4LPo1zX7NJaie2BnqR13Z1bJJDxV1MBHQnwNzrK42DQGiN2AX8YLi5QJ4ssSYf1KaNiFz1iZrEyupr2RPqyZ2Xx9C9zbr6u

I cannot understand why, who can, please help. My code below.


var seed = "04566640a205e779975193a404cdfb0829daabf256ea70198cd060eb4a4043766a24a62233e6d2ae907d3767256c9f9171f8be0d993af15848cfabf2fcade1c8"

func generateMasterKeys() {
   
        var result = (UInt8)(repeating: 0, count: 64)
        
        let btcSeed = "Bitcoin seed".uInt8Array()
        
        let seedBytes = seed.uInt8Array()
        
        HMAC(EVP_sha512(), btcSeed, Int32(btcSeed.count), seedBytes, seed.count, &result, nil)
        
        print("HMAC_512 result in HEX: (Data(result).hexEncodedString())")

        // f968ebeccfd01491dfe3f84972228f3e2df2adeb3a47d5f3362eecbcaf794b1ee4a79b404a5fa2891157321141d887f5ac906587507e7cb1a6b4164ffaa9c081

        masterPrivateKey = Data(result(0..<32)).hexEncodedString()
        masterChainCode = Data(result(32...)).hexEncodedString()
        


        print("Master private key: (masterPrivateKey)")
        print("Master Chain code: (masterChainCode)")
        // Master private key: f968ebeccfd01491dfe3f84972228f3e2df2adeb3a47d5f3362eecbcaf794b1e
        // Master Chain code: e4a79b404a5fa2891157321141d887f5ac906587507e7cb1a6b4164ffaa9c081
        
        base58check2(chainCode: masterChainCode, privateKey: masterPrivateKey)
        
}

func base58check2(chainCode: String, privateKey: String) {
        let networkType = "0488ADE4"
        let depth = "00"
        let parentFingerprint = "00000000"
        let keyIndex = "00000000"
        var hexToSerialize = networkType + depth + parentFingerprint + keyIndex + chainCode + "00" + privateKey
        
        let doubleSHA = SHA256.hash(data: hexToSerialize.hexaBytes).withUnsafeBytes { data2 in
            return SHA256.hash(data: data2)
        }
        
        hexToSerialize = hexToSerialize + doubleSHA.hexStr.prefix(8)
        print("hex to serialize: (hexToSerialize)")
        // 0488ADE4000000000000000000e4a79b404a5fa2891157321141d887f5ac906587507e7cb1a6b4164ffaa9c08100f968ebeccfd01491dfe3f84972228f3e2df2adeb3a47d5f3362eecbcaf794b1e22CA73DA
        
        let result = Base58.base58Encode(hexToSerialize.hexaToBytes)
        print("----==== ROOT KEY ====----")
        print(result) // xprv9s21ZrQH143K4LPo1zX7NJaie2BnqR13Z1bJJDxV1MBHQnwNzrK42DQGiN2AX8YLi5QJ4ssSYf1KaNiFz1iZrEyupr2RPqyZ2Xx9C9zbr6u

        // I need to get this:
        // xprv9s21ZrQH143K48Uym5n1kBFYhzBvvNscsmEvRbMUiHEthfzc9s8VC2Be19oRq8Y49cExD6pqMujrfuztq3SiR8YGfpjnkKJcFLtgqA7RdpE
        // But I get this:     
        // xprv9s21ZrQH143K4LPo1zX7NJaie2BnqR13Z1bJJDxV1MBHQnwNzrK42DQGiN2AX8YLi5QJ4ssSYf1KaNiFz1iZrEyupr2RPqyZ2Xx9C9zbr6u
        
    }

If I take generated root seed and decode it with Base58, I see that master key and private key completely different from mine.

        let decoded = Base58.base58Decode("xprv9s21ZrQH143K48Uym5n1kBFYhzBvvNscsmEvRbMUiHEthfzc9s8VC2Be19oRq8Y49cExD6pqMujrfuztq3SiR8YGfpjnkKJcFLtgqA7RdpE")!
        
        let decodedData = Data(decoded).hexEncodedString()
        
        print(decodedData) // 0488ade4000000000000000000d0074c1b7d5116fd851935a424f6624e288b50ce3df5ef53ca4d4a182347c9c400ff361fbd7249a379f04bc97990924148dc07ebcdbdc86eddcd97b9a6d36ee2bd9fea8f03

//        0488ade4 - network type the same
//        00 - depth the same
//        00000000 - parent fingerprint the same
//        00000000 - key index the same
//        d0074c1b7d5116fd851935a424f6624e288b50ce3df5ef53ca4d4a182347c9c4 - different private key
//        00
//        ff361fbd7249a379f04bc97990924148dc07ebcdbdc86eddcd97b9a6d36ee2bd - different chain code
//        9fea8f03 - thus different checksum