The development of the Internet of Things (IoT) predicts several new applications, some of which are designed to be incorporated into e-health systems, and some technologies, like cloud computing and device-to-device communication (D2D), are promising for use in the support of resource-constrained devices employed in Mobile-health (m-health) and Telecare Medicine Information Systems (TMIS). In a scenario with billions of devices predicted for the IoT, it is essential to avoid performance and security problems, among others. Security is fundamental for the achievement of optimal performance regarding the sensibility of e-health shared data and, especially, the anonymity of patients and other entities, while it is also essential to consider the scarcity of bandwidth in wireless networks. This paper proposes a new mutual authentication protocol for m-health systems, which supports D2D communication, ensuring security and surpassing the performance and security of other authentication procedures reported in the literature. on communication channels, given a large number of new emerging devices. Therefore, computational costs must be reduced for the optimization of power resources.On the other hand, device-to-device (D2D) communication, commonly implemented by ad hoc wireless networks, enables patients' devices to connect directly to a medical entity to send health data collected by sensors and receive diagnoses faster than in the traditional way. The constant monitoring of patients and analyses of health reports are crucial for the avoidance of medical conditions, such as strokes and heart attacks, because the chances of a person being sick can be detected much faster.D2D communication provides a direct connection of devices with or without the intervention of traditional network infrastructure (e.g., 3rd Generation Partnership Project (3GPP) standards). Therefore, the ability to connect devices can provide data offload through nearby devices directly, thus reducing problems, such as congestion and scarcity of spectrum, and expanding network coverage by enabling devices to relay their data. D2D communication is promising for 5G technology and IoT due to its adaptation to support small and resource-constrained devices predicted by those two technologies. However, security schemes for D2D communication are still in the initial development stages, which require more research and studies for their improvement and consolidation, in addition to authentication and key agreement protocols adapted to them.D2D is suitable for e-health/m-health/TMIS since it can accelerate the transmission of data and provide a connection to devices located outside the coverage of 3GPP networks. This might be the key for the success of e-health/m-health/TMIS applications, because most data exchanged provide information on patients' health, e.g., heartbeat, blood sugar, and pressure, which is sensitive to delays for saving lives. Moreover, since e-health/m-health/TMIS devices are mostly resource-constrained, they require adapted traditional aut...