#include "testmore.h"
#include "capabilities.h"
#include "testbyteBuffer.h"
#if (CCRANDOM == 0)
entryPoint(CommonRandom,"Random Number Generation")
#else
#include <CommonCrypto/CommonRandomSPI.h>
static const int kTestTestCount = 1000;
static const int bufmax = kTestTestCount + 16;
int CommonRandom(int argc, char *const *argv)
{
int i;
uint8_t buf1[bufmax], buf2[bufmax], buf3[bufmax], buf4[bufmax], buf5[bufmax], buf6[bufmax];
CCRandomRef rngref;
CCRNGStatus retval;
plan_tests(kTestTestCount *3);
retval = CCRNGCreate(0, &rngref);
struct ccrng_state *devRandom = ccDevRandomGetRngState();
struct ccrng_state *drbg = ccDRBGGetRngState();
for(i=0; i<kTestTestCount; i++) {
size_t len = i+16;
CCRandomCopyBytes(kCCRandomDefault, buf1, len);
CCRandomCopyBytes(kCCRandomDevRandom, buf2, len);
CCRandomCopyBytes(rngref, buf3, len);
CCRandomCopyBytes(NULL, buf4, len);
ccrng_generate(devRandom, len, buf5);
ccrng_generate(drbg, len, buf6);
ok(memcmp(buf1, buf2, len), "Buffers aren't the same");
ok(memcmp(buf3, buf4, len), "Buffers aren't the same");
ok(memcmp(buf2, buf3, len), "Buffers aren't the same");
ok(memcmp(buf5, buf6, len), "Buffers aren't the same");
ok(memcmp(buf5, buf2, len), "Buffers aren't the same");
ok(memcmp(buf6, buf1, len), "Buffers aren't the same");
}
retval = CCRNGRelease(rngref);
return 0;
}
#endif