security: Generate random block in Tpm.
Change-Id: Ia65d32802ed0ebc76605ae7975ea02f4c2db737d
diff --git a/tests/security/test-sec-tpm-osx.cpp b/tests/security/test-sec-tpm-osx.cpp
index 5bd0467..a0a3bb9 100644
--- a/tests/security/test-sec-tpm-osx.cpp
+++ b/tests/security/test-sec-tpm-osx.cpp
@@ -65,6 +65,26 @@
tpm.deleteKeyPairInTpm(keyName);
}
+BOOST_AUTO_TEST_CASE (RandomGenerator)
+{
+ SecTpmOsx tpm;
+
+ size_t scale = 1000;
+ size_t size = 256 * scale;
+ uint8_t* block = new uint8_t[size];
+ tpm.generateRandomBlock(block, size);
+
+ map<uint8_t, int> counter;
+ for(size_t i = 0; i < size; i++)
+ counter[block[i]] += 1;
+
+ float dev = 0.0;
+ for(size_t i = 0; i != 255; i++)
+ dev += ((counter[i] - scale) * (counter[i] - scale)) * 1.0 / (scale * scale);
+
+ BOOST_CHECK_CLOSE(dev / 256, 0.001, 100);
+
+}
BOOST_AUTO_TEST_SUITE_END()
} // namespace ndn