A distributed security mechanism for resource-constrained IoT devices