diff --git a/daemon/src/Makefile.am b/daemon/src/Makefile.am
index 7d7e190ce8c3ca043566b02ad675a0ee6226642a..b7bfeab1a3175a9b5f4b7ec209378af802aea1c5 100644
--- a/daemon/src/Makefile.am
+++ b/daemon/src/Makefile.am
@@ -51,7 +51,8 @@ noinst_HEADERS = \
 		noncopyable.h \
 		cc_thread.h \
 		cc_config.h \
-		sfl_types.h
+		sfl_types.h \
+		array_size.h
 
 libsflphone_la_LIBADD = \
 	$(top_builddir)/libs/iax2/libiax2.la \
diff --git a/daemon/src/array_size.h b/daemon/src/array_size.h
new file mode 100644
index 0000000000000000000000000000000000000000..9bca08aadb5aa4b6d88f3ad49c71816e063eb7f5
--- /dev/null
+++ b/daemon/src/array_size.h
@@ -0,0 +1,39 @@
+/*
+ *  Copyright (C) 2004-2012 Savoir-Faire Linux Inc.
+ *  Author: Tristan Matthews <tristan.matthews@savoirfairelinux.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *  Additional permission under GNU GPL version 3 section 7:
+ *
+ *  If you modify this program, or any covered work, by linking or
+ *  combining it with the OpenSSL project's OpenSSL library (or a
+ *  modified version of that library), containing parts covered by the
+ *  terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
+ *  grants you additional permission to convey the resulting work.
+ *  Corresponding Source for a non-source form of such a combination
+ *  shall include the source code for the parts of OpenSSL used as well
+ *  as that of the covered work.
+ */
+
+#ifndef ARRAY_SIZE_H_
+#define ARRAY_SIZE_H_
+
+// Returns the number of elements in a, calculated at compile-time
+#define ARRAYSIZE(a) \
+      ((sizeof(a) / sizeof(*(a))) / \
+         static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
+
+#endif // ARRAY_SIZE_H_
diff --git a/daemon/src/audio/audiortp/audio_srtp_session.cpp b/daemon/src/audio/audiortp/audio_srtp_session.cpp
index 7ad1ee5ee68beb0a732816c4672644262e42de1e..38567d1b629cdbe7dbc29971401039429b9b3cc3 100644
--- a/daemon/src/audio/audiortp/audio_srtp_session.cpp
+++ b/daemon/src/audio/audiortp/audio_srtp_session.cpp
@@ -29,6 +29,7 @@
  */
 #include "audio_srtp_session.h"
 #include "logger.h"
+#include "array_size.h"
 
 #include <openssl/sha.h>
 #include <openssl/hmac.h>
@@ -103,12 +104,9 @@ namespace {
         std::vector<unsigned char> random_key(length);
 
         // Generate ryptographically strong pseudo-random bytes
-        int err;
-
-        if ((err = RAND_bytes(&(*random_key.begin()), length)) != 1)
+        if (RAND_bytes(&(*random_key.begin()), length) != 1)
             DEBUG("Error occured while generating cryptographically strong pseudo-random key");
 
-        assert((sizeof dest / sizeof dest[0]) <= length);
         memcpy(dest, &(*random_key.begin()), length);
     }
 }
@@ -211,6 +209,7 @@ void AudioSrtpSession::initializeLocalMasterKey()
     DEBUG("AudioSrtp: Init local master key");
     // @TODO key may have different length depending on cipher suite
     localMasterKeyLength_ = sfl::CryptoSuites[localCryptoSuite_].masterKeyLength / 8;
+    assert(ARRAYSIZE(localMasterKey_) >= localMasterKeyLength_);
     DEBUG("AudioSrtp: Local master key length %d", localMasterKeyLength_);
     buffer_fill(localMasterKey_, localMasterKeyLength_);
 }
@@ -219,6 +218,7 @@ void AudioSrtpSession::initializeLocalMasterSalt()
 {
     // @TODO key may have different length depending on cipher suite
     localMasterSaltLength_ = sfl::CryptoSuites[localCryptoSuite_].masterSaltLength / 8;
+    assert(ARRAYSIZE(localMasterSalt_) >= localMasterSaltLength_);
     DEBUG("AudioSrtp: Local master salt length %d", localMasterSaltLength_);
     buffer_fill(localMasterSalt_, localMasterSaltLength_);
 }
diff --git a/daemon/src/audio/audiortp/audio_srtp_session.h b/daemon/src/audio/audiortp/audio_srtp_session.h
index 97b9b2ce675dbd848ea6c76c235a2f50e2e33dc3..a84cfccc847b3ae4e1fc1827383e422289bcf9ee 100644
--- a/daemon/src/audio/audiortp/audio_srtp_session.h
+++ b/daemon/src/audio/audiortp/audio_srtp_session.h
@@ -153,22 +153,22 @@ class AudioSrtpSession : public AudioSymmetricRtpSession {
         uint8 localMasterKey_[16];
 
         /** local master key length in byte */
-        int localMasterKeyLength_;
+        size_t localMasterKeyLength_;
 
         uint8 localMasterSalt_[14];
 
         /** local master salt length in byte */
-        int localMasterSaltLength_;
+        size_t localMasterSaltLength_;
 
         uint8 remoteMasterKey_[16];
 
         /** remote master key length in byte */
-        int remoteMasterKeyLength_;
+        size_t remoteMasterKeyLength_;
 
         uint8 remoteMasterSalt_[14];
 
         /** remote master salt length in byte */
-        int remoteMasterSaltLength_;
+        size_t remoteMasterSaltLength_;
 
         /** Used to make sure remote crypto context not initialized wice. */
         bool remoteOfferIsSet_;
diff --git a/daemon/test/delaydetectiontest.cpp b/daemon/test/delaydetectiontest.cpp
index db5280bf7c607a016ea0a117b98ff457222bb0e5..aaed8881ef83f9798645ba4b36ae6d07ee7e1b48 100644
--- a/daemon/test/delaydetectiontest.cpp
+++ b/daemon/test/delaydetectiontest.cpp
@@ -31,6 +31,7 @@
 
 #include "delaydetectiontest.h"
 #include <cstring>
+#include "array_size.h"
 
 void DelayDetectionTest::testCrossCorrelation()
 {
diff --git a/daemon/test/test_utils.h b/daemon/test/test_utils.h
index 154de60e53742b630dff1044e53ea89a7f3b681b..4102a28131d66ff5462acacb17206cabec05d13c 100644
--- a/daemon/test/test_utils.h
+++ b/daemon/test/test_utils.h
@@ -34,9 +34,4 @@
 #define TITLE() DEBUG("-------------------- %s --------------------\n", \
         __PRETTY_FUNCTION__)
 
-// Returns the number of elements in a, calculated at compile-time
-#define ARRAYSIZE(a) \
-      ((sizeof(a) / sizeof(*(a))) / \
-         static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
-
 #endif // TEST_UTILS_H_