In this paper we introduce ContikiSec, a secure network layer for wireless sensor networks, designed for the Contiki Operating System. ContikiSec has a configurable design, providing three security modes starting from confidentiality and integrity, and expanding to confidentiality, authentication, and integrity. ContikiSec has been designed to balance low energy consumption and security while conforming to a small memory footprint. Our design was based on performance evaluation of existing security primitives and is part of the contribution of this paper. Our evaluation was performed in the Modular Sensor Board hardware platform for wireless sensor networks, running Contiki. Contiki is an open source, highly portable operating system for wireless sensor networks (WSN) that is widely used in WSNs.