Research Article

Research on Agricultural Product Traceability Technology (Economic Value) Based on Information Supervision and Cloud Computing

Algorithm 3

Merkle tree algorithm.
The input: list info = [T1, T2, …, t1, t2, …]
The output: root hash merkle_root
Define hashed_info[] to hold the result of the hash operation
Define the array temp_info[] to hold the result of each layer of hash
for true do
 for index = 0; index < len(list_info); index+ = 2 do
  current = list_info[index];
  cur_right = list_info[index+1];
  cur_hash = sha256(current);
  cur_right_hash = sha256(cur_right);
  hashed_info[list_info[index]] = cur_hash;
  hashed_info[list_info[index + 1]] = cur_right_hash;
  Place (cur_hash + cur_right_hash) in temp_info[];
 end for
 if len(list_info) = = 1 then
  break;
 else
  list_info = temp_info;
 end if
end for
The last hash in the hashed_info array is merkle_root
return merkle_root