The source code for one of the most secretive parts of the iPhone's operating system appears to have been leaked online.

It could provide hackers with a treasure trove of information they could use to design new attacks against Apple's operating system iOS.

The code has seemingly been taken from the "iBoot" part of the iOS, the part of the computer that begins to boot the operating system when it is turned on.

Although it is not yet known whether the code came from inside Apple, security researchers believe it is authentic.

Speaking to online technology publication Motherboard, Jonathan Levin, an expert on iPhone internal software, said: "This is the biggest leak in history. It's a huge deal."

Mr Levin told Motherboard that the code seemed to be legitimate as it matched his own efforts to reverse engineer the software that powers iPhones.

The code was for the outdated iOS 9, released in September 2015, but it is expected that parts of the code may still be in use underpinning the iPhone's security in later releases.

Although initially published to a repository on programming website GitHub, the code has now been replaced with a copyright notice - with some suggesting this may prove its authenticity.

Andy Kays, chief technology officer at British cybersecurity firm Redscan, told Sky News: "The release of the iBoot code demonstrates that vendors can't take it for granted that source code will always remain hidden.

"Vendors relying excessively on code obfuscation to maintain the security of their products will always be vulnerable to leaks."

Mr Kays said that Apple has taken important steps to improve the protection of its products "so users of its latest devices don't need to be unduly concerned by the release of the iBoot firmware."