# A Traceable and Verifiable Tobacco Products Logistics System with GPS and RFID Technologies
## 3 The Proposed Scheme
### Authentication Phase  
In this phase, we assumed that user A is a sender, and user B is a receiver. Every sender and receiver needs to sign and verify their message with the \"Sign\" and \"Verify\" function that is shown in Algorithm 2. These two functions implement the ECDSA to achieve identity authentication. The sender generates a signature with a \"Sign\" function to the receiver. When the receiver receives the message, they execute a \"Verify\" function to verify. Similarly, when the receiver needs to respond to a message from the sender, the receiver also needs to execute a \"Sign\" function, then the sender needs to execute the \"Verify\" function when receiving the response message to ensure each other's true identities. The flow of the process is shown in Figure 7.  
Figure 6: The flowchart of the registration phase. Step 1. Firstly, user A chooses a random number \(k_{1}\), then generates the message:  
\[M_{1}=(ID_{A}||ID_{B}||T_{1}) \tag{2}\]  
Next, user A calculates the parameters of ECDSA:  
\[h_{1}=H(M_{1}) \tag{3}\]  
\[(x_{A_{1}},y_{A_{1}})=k_{1}G \tag{4}\]  
Figure 7: The flowchart of the authentication phase. Afterward, the signatures are generated by executing the function \"Sign\" in Algorithm 2. In detail, it generates the signatures with the parameters:  
\[r_{A_{1}}=x_{A_{1}}\text{mod}n \tag{5}\]  
\[s_{A_{1}}={x_{A_{1}}}^{-1}(h_{1}+r_{A_{1}}d_{A})\text{mod}n \tag{6}\]  
A message is encrypted by user B's public key:  
\[C_{A_{1}}=E_{Puk_{B}}(M_{1}) \tag{7}\]  
User A sends a message \((ID_{A},ID_{B},C_{A_{1}},(r_{A_{1}},s_{A_{1}}))\) to user B. 1. IDI receives the message at \(T_{2}\) and uses its private key to decrypt \(C_{A_{1}}\):  
\[M_{1}=D_{Prk_{B}}(C_{A_{1}}) \tag{8}\]  
Then, user B checks for the validation of the timestamp:  
Figure 6:0  
Next, user B executes the function \"Verify\" in Algorithm 2. In detail, it calculates the following parameters:  
Figure 6:1  
Figure 6:2  
Figure 6:3  
Figure 6:4  
User B uses those calculated parameters to validate the signature:  
Figure 6:5  
If the signature is valid, then user B selects a random number \(k_{2}\) and generates a message:  
Figure 6:6  
Next, user B calculates the hash value and the parameters of ECDSA to generate the signatures \((r_{B_{1}},s_{B_{1}})\). The signatures are generated by executing the function \"Sign\" in Algorithm 2:  
Figure 6:7  
Figure 6:8  
Figure 6:9  
\[M_{1}=(ID_{A}||ID_{B}||T_{1}) \tag{2}\]0  
A message is encrypted by user A's public key:  
\[M_{1}=(ID_{A}||ID_{B}||T_{1}) \tag{2}\]1  
Then, user B sends the message \((ID_{B},ID_{A},C_{B_{1}},(r_{B_{1}},s_{B_{1}}))\) to user A. 1. User A receives the message at \(T_{4}\), then decrypts the cipher message by its private key:  
\[M_{1}=(ID_{A}||ID_{B}||T_{1}) \tag{2}\]2Then, user A checks for the validation of the timestamp:  
\[M_{1}=(ID_{A}||ID_{B}||T_{1}) \tag{2}\]3  
Next, user A executes the function \"Verify\" in Algorithm 2. User A calculates the parameters:  
\[M_{1}=(ID_{A}||ID_{B}||T_{1}) \tag{2}\]4  
\[M_{1}=(ID_{A}||ID_{B}||T_{1}) \tag{2}\]5  
\[M_{1}=(ID_{A}||ID_{B}||T_{1}) \tag{2}\]6  
\[M_{1}=(ID_{A}||ID_{B}||T_{1}) \tag{2}\]7  
User A uses those calculated parameters to validate the signature:  
\[M_{1}=(ID_{A}||ID_{B}||T_{1}) \tag{2}\]8  
```
funcSign (h string, k string, d string) (r string, s string) { (x, y) = k * G;  r = x % n  s = (h + r * d)/x % n  return r, s } funcVerify (h string, r string, s string) (result string) {  u1 = h/s % n  u2 = r/s % n (x, y) = u1 * G + u2 * Q  if x == r {  return \"valid\" }else{  return \"invalid\" } }
```  
**Algorithm 2** Authentication of the proposed scheme.