The Royal Navy has been tasked with accompanying British-flagged ships through the Strait of Hormuz to protect them from Iranian attack.