## 5 Proposed Source Authentication Schemes
### Simple Packet Aggregation (SPA)  
The simplest way to support source authentication for code dissemination with variable packet size is to simply aggregate packets as depicted in Figure 5. We employ a Secure Deluge [1] which uses a hash chain. In this scheme, a source can precompute a hash value of the next packet and embed it in the current packet since a new code image is built prior to the transmission. Then, a receiver can authenticate the next packet using the previously received hash value.  
When a new code image is available, a BS splits it into pages which are further divided into packets with a fixed size. All packets are indexed sequentially, and a hash value is calculated using the next packet on the reverse order. The hash value is then appended to the end of the current packet, thereby forming a _basic packet_ which is the basic unit to be transmitted as follows:  
\[BP_{i,j}\ =\ \left\{\begin{array}{ll}Pkt_{i,j}\ ||\ h_{i,j+1},&h_{i,j+1}\ =\ H( BP_{i,j+1}),\ i\in[1,x],\ j\in[1,y-1]\\ Pkt_{i,j}\ ||\ h_{i+1,1},&h_{i+1,1}\ =\ H(BP_{i+1,1}),\ i\in[1,x-1],\ j=y\\ Pkt_{i,j},&i\ =\ x,\ j=y\end{array}\right. \tag{1}\]  
Figure 5: An example of SPA.  
where \(Pkt_{ij}\) is a \(j\)-th packet in Page \(i\) and \(h_{i,j}\) is a hash value on the basic packet containing \(Pkt_{ij}\). \(x\) and \(y\) are the number of pages in the code image and the number of packets in one page, respectively. Finally, the hash of the first basic packet (\(h_{1,1}\)) is signed by the BS with the BS's private key to ensure source authentication. Figure 5a shows how to create basic packets with a hash value.  
Once basic packets are ready, the BS first sends a hash value on the first basic packet (\(h_{1,1}\)) with a digital signature (\(sig(h_{1,1})\)) to a neighbor node. The receiver first verifies the digital signature of the hash using a BS's public key preloaded in each sensor node prior to deployment. If the digital signature is valid, the receiver stores the hash value which is used to authenticate the subsequent basic packet. The BS now transmits packets to the neighbor node by aggregating basic packets depending on the link quality as follows:  
\[BS\rightarrow*:\quad[header]\big{|}BP_{i,j}\big{|}|BP_{i,j+1}\big{|}|\cdots \big{|}|BP_{i,j+n}\big{]} \tag{2}\]  
where \(n\) depends on the link quality. It is worth noting that the \(BS\) can send basic packets without aggregation in severe channel condition. Upon receiving an aggregated packet, the receiver splits it into the original basic packets. This is easy because each sensor node knows the length of a basic packet. After calculating the hash value on the first basic packet, the receiver compares it with the previously received hash value. Denoting the previously received hash value and the currently received basic packet by \(h_{i,j}\) and \(BP_{i,j}\), the basic packet is considered valid if:  
\[h_{i,j}\ ==\ H(BP_{i,j})\,\qquad i\in[1,\ x],\ j\in[1,\ y] \tag{3}\]  
where \(H\) is a hash function. If the hash values are the same, the basic packet is authenticated and the receiver assures that it comes from the real BS and is not modified during transmission. Finally, the hash value in the basic packet is stored to be used to authenticate the next packet. In the same way, all next packets can be verified. When all packets in one page are received, the receiver becomes a new sender. A new sender can send a packet by aggregating basic packets depending on the link quality. Figure 5b,c illustrates the process of aggregation and verification. The SPA scheme is very simple, but has the hash overhead per basic packet and supports only the multiples of the size of a basic packet.