A computer-implemented method performed by a plurality of clients and a server, each client of the plurality of clients having a data value, comprising: generating, by each client of the plurality of clients, a public key and a private key pair for an additively homomorphic encryption scheme; receiving, by the server from each client of the plurality of clients, the respective public key; transmitting, by the server to each client of the plurality of clients, the public keys; encrypting, by each client of the plurality of clients, its data value with the additively homomorphic encryption scheme using the public key of each other client of the plurality of clients; sending, by each client of the plurality of clients to the server, its encrypted data value; running, by each pair of the plurality of clients and through the server, a Diffie-Hellman key exchange protocol to generate a shared symmetric key; garbling, by each client of each pair using the shared symmetric key of the pair, its own input, wherein the garbled inputs characterize the respective data values from each of the clients in each pair; garbling, by one client of each pair using the shared symmetric key of the pair, a circuit encoding a comparison function; receiving, by the server from each pair of the plurality of clients, the corresponding garbled circuit and the corresponding two garbled inputs; evaluating, by the server and for each pair of clients from the plurality of clients, the garbled circuits using the garbled inputs to result in a plurality of comparison bits; sorting, by the server, the data values in an ascending or descending order by using the plurality of comparison bits to compute a rank of each data value: determining, by the server using the ranks, data characterizing a median value for the data values; and transmitting, by the server, the data characterizing the median value to each of the clients generating, by each client of the plurality of clients, a public key and a private key pair for an additively homomorphic encryption scheme; receiving, by the server from each client of the plurality of clients, the respective public key; transmitting, by the server to each client of the plurality of clients, the public keys; encrypting, by each client of the plurality of clients, its data value with the additively homomorphic encryption scheme using the public key of each other client of the plurality of clients; sending, by each client of the plurality of clients to the server, its encrypted data value; running, by each pair of the plurality of clients and through the server, a Diffie-Hellman key exchange protocol to generate a shared symmetric key; garbling, by each client of each pair using the shared symmetric key of the pair, its own input, wherein the garbled inputs characterize the respective data values from each of the clients in each pair; garbling, by one client of each pair using the shared symmetric key of the pair, a circuit encoding a comparison function; receiving, by the server from each pair of the plurality of clients, the corresponding garbled circuit and the corresponding two garbled inputs; evaluating, by the server and for each pair of clients from the plurality of clients, the garbled circuits using the garbled inputs to result in a plurality of comparison bits; sorting, by the server, the data values in an ascending or descending order by using the plurality of comparison bits to compute a rank of each data value: determining, by the server using the ranks, data characterizing a median value for the data values; and transmitting, by the server, the data characterizing the median value to each of the clients determining, by the server using the ranks, data characterizing a median value for the data values; and transmitting, by the server, the data characterizing the median value to each of the clients