## 3 Methodology
### Proposed ECC Key Distribution and Management
Hence, all the nodes are involved in the key exchange process by receiving a point \(P_{i-1}\) from the \(N_{g}\), and by computing a new point using its private key based on EC scalar multiplication as shown in the formula (2), where \(r_{i}\) is the private key of the node \(i\) and \(P_{i-1}\) is the public key computed by the previous node \(i-1\). \[P=\prod_{i=1,\ i\
eq j}^{N-1}r_{i}P_{i-1} \tag{4}\]  
Steps (9-10). After the cyclic exchange is complete; node \(j\) receives the last computed public key \(P\) from \(N_{g}\). It then uses it to compute its own shared key, as shown using Equation (5). \[P_{j}=r_{j}.P \tag{5}\]  
Step (11). In this step, the process will continue until all the nodes in the network compute their shared key (see Figure 3). Figure 3: Key exchange process depicting how node N4 computes its shared key. For example, with five nodes (GH, N1, N2, N3, and N4), having corresponding private keys \(a,\ b,\ c,\ d,\ and\ e\), respectively, if GH is the group head node, according to Figure 3, the shared keys (\(P_{n1}\) and \(P_{n2}\)) for node N1 and N2 is generated and distributed in the following order. \[P_{n1} =\left(\tau_{gh}.r_{n2}.r_{n3}.r_{n4}.G\right).r_{n1}\] \[P_{n2} =\left(\tau_{gh}.r_{n1}.r_{n3}.r_{n4}.G\right).r_{n2}\]  
where \(G\) is the generator point on the curve E, \(r_{n1}\), s is the corresponding integer private key for node N1, and \"..\" is scalar multiplication. We propose a family of distributed and localized group rekeying methods to solve the group rekeying issue for wireless sensor networks as shown in Algorithm 2 Table. When there is a change in group membership, the group key must be updated and redistributed to the rest of the nodes in the network in a way that is safe, dependable, and done in a timely manner. The group rekeying strategy in this paper relies on independence while generating a new set of keys to avoid any kind of prediction by intruders. In addition, the routing table is recalculated using the modified LEACH routing protocol. ```
Start
1 Initialize all the buffers in the nodes, i.e., \(P_{mid}-=-1\), NN, P, \(G\) and \(x_{i}\)
2 Choose a node to start keying
3 Generate new message with fields TYP=0, NC=0, \(P_{x}\)=\(G_{x}\), \(P_{y}\)=\(G_{y}\),\(S_{id}\)
4 Set the new message Id \(M_{id}=P_{mid}+1\)
5 Compute the new points using EC scalar multiplication
6 Increment NC by 1 and choose the next destination node \(D_{id}\) sequentially. 7 While \(D_{id}\) are not completely used up, do the following:
8 Route the message over the network and performs the following at each new hop
9 If \(P_{mid}\) is equals to \(M_{id}\) (i.e., old message hoping over)
10 Route the message over the network to another node
11 If \(P_{mid}\) is not equals to \(M_{id}\) (i.e., new message arrival)
12 Update the points on the curve \(P_{x}\) and \(P_{y}\) such that \(P_{x}=x_{i}P_{x,old}\) and \(P_{y}=x_{i}P_{y,old}\)
13 Increment NC by 1
14 Check if NC is equals to NN-1 (i.e., destination node after visiting all other nodes)
15 Return the shared key for the node i as \(S_{key}=P_{x}\) or \(P_{y}\)
16 Repeat step 3 to 18
17 If NC is not equals to NN-1 (i.e., new message arrives at non-destination node)
18 Repeat step 7 to 18
19 stop
```  
**Algorithm 2**EC Key Generation