# FPGA Implementation of Mutual Authentication Protocol for Medication Security System
## 4 Design and Implementation Results  
### XOR Method Medication Safety System Architecture  
The block diagram of the medication safety WSN mutual authentication protocol (Medication Safety System) scheme with the XOR method is shown in Figure 4.  
Figure 3: Password change phase.  
In Figure 4, the block diagram depicts the Medication Safety System (XOR method) scheme to verify the correctness of the received input cover-coded messages and passwords. The main function blocks include employing the cyclic redundancy check code method, generating the PADs required for decoding the received cover-coded password CCPWD, and inputting cover-coded messages. It also encodes the messages that are to be transmitted. The specific steps are as follows:  
Step 1: Initially, the user's identification UserID, cover-coded password CCPWD, and a cover-coded message of the most and the least bits are concatenated with their cyclic redundancy check code. The received data inputs of medication safety system are In_CCMsgM \(\parallel\) CRC and In_CCMsgL \(\parallel\) CRC. Then, the CRC_Check module calculates and verifies whether both the input most-bit cover-coded message In_CCMsgM and the input least-bit cover-coded message In_CCMsgL are correct using their corresponding CRC code. A signal named Check_done of CRC_Check module is outputted, which resembles true (bit value of 0, as the remainder, is all zero) or false (bit value of 1, as nonzero reminders).  
Step 2: Upon receiving input enable signal Check_done as a bit value of 0, FullPadgen module (0-active) can produce PAD1, PAD2, PAD3, PAD4, PAD5, and PAD6 in sequence under six control states as described later on in Figure 4. Meanwhile, when the FullPadgen module produces PAD2 on state {001}, an enable signal Dec_pwd is also sent to the DEC_CCPWD module. When enabled, the DEC_CCPWD module is used to operate decoding on CCPWD as shown below ( Equation (11)). The password PWD gained is fed back to the FullPadgen module for XOR-Padgen calculation of its 4 and 6 states.  
\[\text{PWD}=\text{CCPWD}\oplus\text{[PAD1, PAD2]}. \tag{11}\]  
Step 3: Once the FullPadgen module is completed with all six PADs produced, a Pad_done-enabling signal is given to the XOR_Op module, which begins to perform the XOR operation for decoding inputs In_CCMsgM and In_CCMsgL. After decoding, Msg (Equations (12) and (13)) is obtained, and then an internal signal is given followed by encoding to produce Out_CCMsgM and Out_CCMsgL (Equations (14) and (15)).  
\[\text{MsgM}=\text{In\_CCMsgM}\oplus\text{PAD3}. \tag{12}\]  
\[\text{MsgL}=\text{In\_CCMsgL}\oplus\text{PAD4}. \tag{13}\]  
\[\text{Out\_CCMsgM}=\text{MsgM}\oplus\text{PAD5}. \tag{14}\]  
\[\text{Out\_CCMsgL}=\text{MsgL}\oplus\text{PAD6}. \tag{15}\]  
Step 4: CCMsg_Mux module collects Out_CCMsgM and Out_CCMsgL, and then gives the Begin_crc signal to CRC_Gen module, which allows it to process cyclic redundancy check code encoding for Out_CCMsgM and Out_CCMsgL. At last, Out_CCMsgM \(\parallel\) CRC and Out_CCMsgL \(\parallel\) CRC are outputted.  
Figure 4: Block diagram of Medication Safety System (XOR method) scheme.