## 4 Secure Authentication and Prescription Safety Protocol
It also checks the message freshness by taking the difference from \(T_{1}\) to guard against replay attacks. After that, the TS computes the temporary key of the patient by multiplying the received \(X_{A}\) with \(d\) which was pre-generated by the TS as \(Y^{\prime}_{A}=dX_{A}\). To verify whether the message is original, the TS computes the Patient's (A) masked identity as \(R_{p}F=R_{p}dP=dX_{A}\). It also decrypts \(P_{A}\) to obtain security credentials, including \(ID_{A},\ M_{A}\), N1, MAC \((M_{A})\), and \(ID_{B}\). The hash of these values is calculated as \(M^{\prime}_{A}=H\big{(}PW_{p}||ID_{A}||ID_{B}\big{)}\) and is then compared to verify the equality of \(M_{A}\) and \(M^{\prime}_{A}\) to ensure message integrity. Otherwise, the message is discarded. The (MAC\((M_{A})\)) provides data integrity for \(M_{A}\). The trusted server computes the following steps. (i) \(\text{Decrypt}\ C_{A}\) using \(K_{A-TS}\) to get \(\{(X_{A}||\ P_{A}||\ T_{1})\}\)  
(ii) \(\text{Computer}\ Y^{\prime}_{A}=dX_{A}\)  
(iii) \(\text{Decrypts}\ P_{A}\) using \(K_{H(Y_{A})}\) to get \(\{ID_{A},\ M_{A},N_{1},\) MAC\((M_{A}),ID_{B}\}\)  
(iv) \(\text{Compute:}\ M^{\prime}_{A}=H\big{(}PW_{p}||ID_{A}||ID_{B}\big{)}\)  
(v) \(\text{If}\ Verify\ (MAC^{\prime}(M_{A})\!=\ MAC(M_{A}))\) then discard  
(vi) \(\text{If}\ M_{A}\ \text{NOT equals}\ M^{\prime}_{A}\ \text{then discard message}\)  
C. Step-III: TS-based Mutual Authentication of B&A  
After verification, the TS picks a random number \(R_{\text{Ts}}\) and then computes \(Z_{TS}=H(ID_{TS}||ID_{B}||R_{\text{Ts}})\) using identities of B and TS. It also generates a nonce number N\({}_{2}\) to get its hash with identities of communicating parties A and B. After that, TS calculates the XOR of hash value with \(Z_{TS}\) to get a new temporary ID for B. The value of \(C_{TS}\) is obtained by encrypting \((ID_{A}||Z_{TS}||\ T_{2}||\ N_{2})\) using the pre-established key \(K_{TS-B}\). The TS transmits the temporary identity \(ID_{B\_T}\) and cipher text \(C_{TS}\) to B. (i) \(Z_{TS}=H(ID_{TS}||ID_{B}||R_{\text{Ts}})\)  
(ii) \(ID_{B\sim T}=Z_{TS}\ XOR\ \{H(ID_{B}||ID_{A}||N_{2})\}\)3. \(C_{TS}=E_{K_{TS-B}}(ID_{A}||Z_{TS}||\ T_{2}||N_{2}||ID_{B\sim T})\) \(TS\to B:\ \{ID_{TS},\ C_{TS}\}\) Doctor/Nurse (B) receives the message \(\{ID_{TS},\ C_{TS}\}\) and decrypts it to get the other party's prescription details and TS validity by computing the set time stamp threshold value, nonce number, received masked-ID values, and decrypted message using the pre-share key from the TS. At each end, entity \(E_{K_{TS}}\) is used as a key to encrypt secure credentials in addition to MAC and the hash function application to make them more secure. (i)  Decrypt using \(K_{TS-B}\) to get \(\{(ID_{A}||Z_{TS}||\ T_{2}||\ N_{2})\}\) (ii)  If \(\{Z_{TS}\ XOR\ \{H(ID_{B}||ID_{A}||N_{2})\}\}\) NOT Equals \(ID_{B\sim T}\) then discard (iii) \(X_{B}=R_{B}P\), \(Y_{B}=R_{B}F\) (iv) \(M_{B}=H(PW_{B}||ID_{TS}||ID_{B})\) (v) \(P_{B}=E_{H_{Y_{B}}}(ID_{B}||M_{B}||N_{3}||\ \text{MAC}(M_{B})||ID_{TS})\) (vi) \(C_{B}=E_{K_{B-TS}}(X_{B}||\ P_{B}||\ T_{3})\) \(B\to TS:\ \{ID_{B\sim T},\ C_{B}\}\)  TS receives the message \(\{ID_{B\sim T},\ C_{B}\}\) and decrypts it to get \(\left(X_{B}||\ P_{B}||\ T_{3}\right).\) After that, the TS computes \(Y^{\prime}_{B}=dX_{B}\) which is equal to \(dR_{B}P=\ R_{B}dP=\ R_{B}F=\ Y_{B}\) calculated at Doctor/Nurse (B). It further decrypts the \(P_{B}\) to get \(ID_{B},\ M_{B},N_{3},\text{MAC}(M_{B})\) and \(ID_{TS}\), as illustrated in steps below. After that, the TS verifies the message's integrity by computing and comparing the hash of the message. Finally, it computes the common parameters \(CP_{A}\) and \(CP_{B}\) for both parties and forwards them to the Patient (A) and doctor/nurse (B) for session key computation.