Hamas is desperate for the Egyptian blockade of its Gaza border to be lifted. Egypt wants that border to be secure and demands an end to the cooperation between Hamas and terrorists from Ansar Bait al-Maqdis, an organization that pledged allegiance to Islamic State leader Abu Bakr al-Baghdadi in 2015 and now calls itself “the Sinai Province of Islamic State.” This is the main stumbling block to a rapprochement between Cairo and Hamas.

Egypt has so far been unable to defeat Ansar Bait al-Maqdis, in spite of the large number of troops and superior armament sent to Sinai – well above the parameters set down in the peace treaty with Israel, which agreed to the move because the terrorists are also threatening its border. There have already been a number of attacks, such as the deadly ambush on Route 12. This week’s rocket fire on Eilat is an unwelcome reminder of the seriousness of the threat.

Can some understanding be achieved in Cairo, when there are three parties with conflicting agendas – and only two of them are taking part in the talks? The radical Sinai Province terrorist organization holds all the cards. Fueled by religious fervor, it is engaged in guerrilla warfare with no vulnerable territorial base and with no concern about the heavy toll in human life that it is incurring. While ceaselessly harassing the regime in north Sinai, it is also carrying out attacks inside the Egyptian mainland, dealing blow after blow to Egyptian President Abdel Fattah al-Sisi’s attempts to stabilize and improve the economy.

The so-called Sinai Province of Islamic State is also hampering Hamas efforts to maintain the contraband routes through the peninsula that supply the Gaza Strip with weapons, explosives and reinforcements. Hamas cooperates out of necessity, and apparently offers sanctuary in Gaza to wounded fighters from the organization, letting the Strip be used to experiment with new weapons and explosives.

In return, it receives help in smuggling military supplies and equipment through the few tunnels still working, in spite of Egypt’s determined efforts to eradicate them.

Hamas, though, is chafing at not having a free hand in Sinai, and there are signs of growing tensions, in spite of the ongoing cooperation between the two movements.

Some 700 Ansar Bait al-Maqdis fighters are allegedly inside Gaza, and Hamas adamantly refuses to hand them over to Egypt and lets them return to Sinai.

That is not to say that there are no other bones of contention between Hamas and Cairo. The last few years have been replete with tensions and outright confrontations.

Though Hamas is a fanatic Islamic organization bent on destroying Israel and setting up a caliphate on its ruins, it is first and foremost an offshoot of the Muslim Brotherhood, the movement that was forcibly ejected from power in Egypt by a popular uprising backed by the army, led by Sisi. The Brotherhood was branded a terrorist organization, and its followers are still fighting the new regime.

Hamas has been involved in a number of terrorist activities inside Egypt through its attempt to set up smuggling routes bringing Iranian missiles, explosives and terrorists from Sudan to Gaza through Sinai.

Hamas terrorists took part in attacks against Egyptian jails at the start of demonstrations against Mubarak in January 2011, and helped free imprisoned Izzadin Kassam senior commander Ayman Nofel and Sami Shihab, head of the Hezbollah cell captured in 2009 while plotting attacks against the Suez Canal under Iranian instructions. Hamas activists appeared to have participated in mass protests against Mubarak in Cairo.

Hamas has been accused of having killed Egyptian soldiers and policemen in the Sinai Peninsula, together with jihadist organizations.

The Egyptian government declared Izzadin Kassam, the “military” wing of Hamas, a terrorist organization, and its activities, as well as those of Hamas as a whole, were forbidden in Egypt.

Attempts to have Hamas branded a terrorist organization as well were squashed, probably at the government’s instigation, because it is also perceived as fighting for the Palestinian cause, to which Egypt is committed.

On the other hand, Hamas understands only too well that its sole access to the outside world is through the Rafah checkpoint, which Egypt opens once a month, and sometimes once every two months, for humanitarian purposes, thus putting enormous pressure on Gaza. The contraband tunnels which are Hamas’s military and economic lifeline are ruthlessly destroyed by the Egyptian Army.

The situation in the Gaza Strip is dire; electricity supply is restricted to a few hours a day, and Hamas leaders are desperate to offer hope to a population that is beginning to grumble openly. They would like to see Rafah permanently open, not only to defuse internal tensions but also to develop sound commercial relations with Egypt.

However, according to leaks from the recent Cairo meetings, discussions are not going well. There is very little room for compromise.

Not only will Hamas forever be the offshoot of the Brotherhood – focus of hatred in Egypt – but it will keep on smuggling advanced weapons through Sinai, in preparation for yet another round of fighting with Israel.

It will not hand over Islamic State terrorists who found sanctuary in Gaza, for fear of a frontal confrontation with the radical organization and even with its own Izzadin Kassam wing, which is tasked with relations with the Islamic State terrorists. The self-proclaimed Sinai Province, which is holding its own against the Egyptian Army, and which holds the key to the smuggling routes, appears to have nothing to worry about.

Hamas is desperately looking for a palatable compromise, though it cannot accept the conditions reportedly set down by Cairo – ending the rift with the Palestinian Authority and agreeing to a long-term truce with Israel, which, incidentally, would open the door to economic relations.

Hamas was reportedly also urged to come to an understanding with Israel concerning the two Israeli citizens who crossed into the Gaza Strip by mistake, and regarding the return of the remnants of two soldiers who were killed during Operation Protective Edge.

Nevertheless, intensive negotiations are being held behind closed doors – not only between Egypt and Hamas but inside the organization as well. At the same time, Hamas is holding secret elections to choose a new leadership. Haniyeh is seeking to oust Khaled Mashaal, who is seen as being no longer attuned to the plight of the people of Gaza. Results will be made public in a matter of weeks.

Will a new team be more amenable to a compromise with Egypt – or will it choose, out of desperation, to provoke a conflict with Israel, in order to gain the support of the Arab world and cause Europe to apply pressure on Israel? And what position will the new American administration adopt? Israel is closely monitoring a situation that could spin out of control, since there does not seem to be a ready solution to the standoff between Egypt and Hamas.

The writer, a fellow of The Jerusalem Center for Public Affairs, is a former ambassador to Romania, Egypt and Sweden.