# A Secure Median Implementation for the Federated Secure Computing Architecture
## 2 Preliminaries
### Secure Computing Framework  
A framework, in this context, refers to the structural foundation or the underlying structure within which a protocol operates. It provides a systematic way to design, analyze, and implement secure multiparty computation protocols. FSC is a recently developed free and open-source framework offloading complex cryptographic tasks to a server while providing an easy-to-use API to develop distributed applications (see [PERSON] and [PERSON] (2018) for a detailed description of the framework). In this architecture, every party runs its own server in a secure peer-to-peer network. By offloading the cryptography server side, the client side is free of dependencies and simple to program. The Framework provides microservices exposed through a RESTful API (The entire codebase is freely available at [[https://github.com/federatedsecure](https://github.com/federatedsecure)]([https://github.com/federatedsecure](https://github.com/federatedsecure)), last accessed: 20 August 2024).  
One of these microservices, SIMON, provides MPC functionality. Unlike monolithic MPC frameworks, SIMON does not provide a universal runtime for arbitrary bytecode. Instead, distinct functions must be individually implemented. Typically, these are provided server-side and run'stage' per stage with message passing between parties happening between stages. The messages are stored and aggregated in 'caches'. The next stage proceeds once all necessary inputs have been received in their respective caches. For example, a (not secure) computation of the sum of the inputs of \(M\) parties is displayed in Listing 1.  
```
1 classMicroprotocolSum(Microprotocol):
2
3 def__init__(self,microservice,properties,myself):
4 super()__init__(microservice,properties,myself)
5
6#therearempartiesinthenetwork
7 self.m=self.network.count
8
9#thereisongenericinputcache
10 self.register_cache('input',Cache())
11
12#theresultcacheaggregatesthesumofallmessagesit
13#receives
14#itis'ready'onceamessagefromallmpartieshavebeen
15#received
16 self.register_cache('result',CacheAdditive(minimum=self.m))
17
18#stage_0 startsonetheinputhasbeenreceived
19 self.register_stage(0,['input'],self.stage_0)
20
21#stage_1 startsonetheresultcacheisready
22 self.register_stage(1,['result'],self.stage_1)
23
24 defstage_0(self,args):
25
26#inthefirststageeveryonebroadcaststheirinputto
27#everybody
28 self.network.broadcast(args['input'],'result')
29
30#then,continuewiththenextstage(1)
31 return1,None
32
33 defstage_1(self,args):
34
35#afterallmessageshavebeenbroadcastedandreceived,
36#theresultisalreadystoredintheresultcache
37#exitthemicroprotocol(-1)andreturntheresult
38 return-1,{'result':args['result']}
```  
**Listing 1**.: Examplary (not secure) computation of the sum in Slmple Multiparty ComputatiON (SIMON).  
Figure 2 illustrates this example for two parties. Each party submits its input to the input cache. In stage 0, these inputs are broadcast and stored in the result cache, where they are automatically aggregated. Once all inputs have been received, the protocol moves to stage 1, where the final aggregated result is retrieved and returned.  
Please note that this example demonstrates a non-secure protocol for illustrative purposes. However, this staged approach ensures orderly execution, with each stage depending on the completion of the previous one, allowing the implementation of sequential protocols such as the secure summation protocol (see Algorithm 2), which is the basis for the secure \(k\)th-ranked element protocol (see Algorithm 1).