In this paper, we consider distributed embedded systems in which privacy or confidentiality of the internal communication is critical, and present an approach to optimize cryptographic algorithms under strict timing constraints. We have developed a technique searching for the best system-affordable cryptographic protection for the messages transmitted over the internal communication bus. On account of the complexity of the problem, finding the optimal solution is only feasible for very small systems. Therefore, we formulate the technique in two efficient metaheuristics, and study their performance from extensive experiments.