David Cameron does not regret his allegedly racist attack on Sadiq Khan in which he accused the London mayor of repeatedly sharing a platform with an Islamic State supporter, the former prime minister's spin doctor has said.

Labour MPs reacted with fury at the remarks during Prime Minister's Questions in the House of Commons as Mr Khan battled Tory Zac Goldsmith for the mayoralty, shouting "racist" at Mr Cameron.

Mr Goldsmith's unsuccessful campaign was widely criticised across political parties, with Labour former cabinet minister Yvette Cooper remarking that the "subtle dog-whistle is becoming a full-blown racist scream".

But Sir Craig Oliver, who was Mr Cameron's director of communications, said the former PM felt it was legitimate to call into question the judgment of Mr Khan, a Muslim, for appearing alongside Sulaiman Ghani.

He told the Press Association: "The reality is that he felt that that was what the campaign was coming up with, that was what was being said, and I think that he felt it was a legitimate thing to do at the time.

"I don't think he would resile from having done that, no."

In a wide-ranging interview ahead of the release of his book, Unleashing Demons: The Inside Story Of Brexit, Sir Craig said Jeremy Corbyn was "actively hostile" to the Remain campaign in the referendum.

He doubted the Labour leader would tell a "bald-faced lie" and vote for Brexit, but said he was clearly "in massive conflict".

Sir Craig said: "What we found with Labour was that Labour people at Stronger In got more face-time with the Conservative prime minister than they did with their own leader - they were at best equivocal towards the Stronger In campaign and often actively hostile.

"We would set up days with the Labour Party to do things only to find that they weren't prepared to do full media rounds that day, the story was very weak, or they were absent from the field of battle.

"When you're doing a campaign, you need every day to count and everybody to be firing on all cylinders, the Labour Party didn't do that.

"Was that incompetence? Was that the line? Was it a mixture of all of it? Was it the case that they thought, actually we shouldn't make it too easy for David Cameron, we do want to win but why make it so easy for a Conservative prime minister? I don't know.

"But the Labour Party definitely was in massive conflict over this and it is definitely true that the Labour people at Stronger In really struggled to get any traction."

He added: "There was a real opportunity for a leader of the Opposition to assert themselves on the national stage and say 'my party is united on this, I can be the person who drives this'.

"And what was interesting was he chose not to do that, he felt very equivocal about it - and was that because he was equivocal about Europe or was that because he was equivocal about helping a Conservative prime minister? I don't know but they were not very helpful, is the bottom line."

Sir Craig praised Theresa May for not revealing too much about her strategy for leaving the EU too early, despite suggestions that she appeared to be supporting a "hard Brexit" outside the single market.

"What she has been very careful not to do is tell us where we're going to end up on the single market, where are we going to be on the customs union, where are we going to be on financial passporting, if we leave the single market are we going for the WTO (World Trade Organisation) deal," he said.

"She's very, very careful about that and that's probably the right thing to do because it is a game of poker and it is a game of politics."

Away from the referendum, Sir Craig also reflected on Mr Cameron's time in office, revealing the former PM became close to French president Francois Hollande following the Paris terror attacks in November last year.

Asked who Mr Cameron's favourite world leader was, Sir Craig remarked: "Not necessarily his favourite one, but what I thought was interesting was how he devleoped a relationship with Hollande which was quite sort of sticky at first.

"But after the Paris attacks when we offered a lot of help to France in terms of intelligence and support, what was fascinating was seeing how that relationship went from quite frosty, because you know, Hollande was a socialist and he was very like Ed Miliband, and actually became very warm."