TITLE: Secret Santa algorithm that does not rely on a trusted 3rd party?
QUESTION [9 upvotes]: With a trusted 3rd party, running Secret Santa is easy: The 3rd party labels each person $1,\dotsc,n$, and then randomly chooses a derangement from among all possible derangements of $n$ numbers.  Person $i$ will then give a gift to the number in position $i$ of the derangement.  The trusted 3rd party is responsible for keeping the derangement secure, and for telling each person whom to give a gift to.
The question is: Is there an algorithm that would allow Secret Santa to be played without a trusted 3rd party?
I thought perhaps a clever use of secret keys and a one way hash function could accomplish it, but I've failed to find an algorithm so far.
So I'm looking for a description of a valid algorithm or a (informal) proof that one does not exist.
EDIT
I believe my problem is different from the possible duplicate.  I want a solution that will work for a distributed group of players.  That is, you cannot assume the players are in the same room and have the ability to shuffle envelopes or notecards or anything like that.  
To make this concrete, a valid solution must work across a group instant messenger or over group emails.
Also, to clarify again, it must be a random derangement and not merely a random n-cycle.

REPLY [5 votes]: How about this:

Everybody generates a random private-public key pair.
Everybody publishes their public key anonymously (see below).
Collaboratively choose a random seed:
a. Everybody chooses a random seed component.
b. Everybody publishes a hash of their seed component openly.
c. Everybody publishes their actual seed component openly.
d. The seed is the sum of the components published in step (c).
Use seed to derive a derangement of the public keys in a deterministic way. (Everybody can now do this for themselves).
Everybody encrypts their name with their secret santa's public key and publishes the ciphertext.
Everybody tries to decrypt all of the messages from the previous step with their own private key. When one of the decryptions succeed, they've found their target.

This assumes that "encrypting" with a public key uses some randomness to produces a non-deterministic result, so someone who has only the public key cannot tell whether a given cleartext and ciphertext match up or not. (This is a standard property of real public-key protocols, though not of textbook RSA).
The procedure does inherently make the cycle structure of the derangement public. In particular, everybody who is mutually santa with someone will know it. It is probably desirable to restrict oneself to "super-derangements" that don't have any $2$-cycles.
A variant that doesn't reveal the cycle structure, at the cost of not having a hard bound on the running time would be:

Everybody chooses a random number and hashes it to produce a "santa ID".
Everybody publishes their santa ID anonymously.
Collaboratively choose a random seed.
Use the seed to deterministically choose a bijection between santa IDs and target names.
If anyone got themselves as target, complain openly, proving that it is so by revealing the number they hashed to get their ID. Everybody starts over from step 1 with new random numbers for everything. On average, $e$ iterations will be needed before a derangement is found.


Both of the above need a sub-algorithm for publishing things anonymously:

Everybody generates a public-private key pair just for the publication sub-algorithm and publishes the public key.
Everybody selects a random permutation $(K_i)_{1\le i\le n}$ of all the public keys from step 1.
Everybody wraps their message in a series of encryptions:
$$ M_0 = \text{the message to publish} \\
 M_k = \operatorname{encypt}(K_k, M_{k-1}) \quad\text{for }1\le k\le n $$
Everybody publishes their own $M_n$.
Everybody tries to decrypt all the messages from the previous round. Publish all contents where decryption succeeds.
After repeating the previous step $n$ times, everybody's original messages will be on the table, and nobody knows where any of them comes from (except their own).

A large enough collusion might be able to break the anonymous publishing step by traffic analysis, but if everybody except a few players collude, the game has lost much of its meaning anyway.