X-Git-Url: https://git.saurik.com/apple/security.git/blobdiff_plain/b04fe171f0375ecd5d8a24747ca1dff85720a0ca..6b200bc335dc93c5516ccb52f14bd896d8c7fad7:/SecurityTests/cspxutils/randTest/randTest.c diff --git a/SecurityTests/cspxutils/randTest/randTest.c b/SecurityTests/cspxutils/randTest/randTest.c deleted file mode 100644 index 5466d62f..00000000 --- a/SecurityTests/cspxutils/randTest/randTest.c +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Simple interactive CSP RNG exerciser. - */ -#include -#include -#include -#include -#include -#include "cspwrap.h" -#include "common.h" - -#define RAND_ALG CSSM_ALGID_APPLE_YARROW -#define BUFSIZE 32 - -static void usage(char **argv) -{ - printf("usage: %s [options]\n", argv[0]); - printf("Options:\n"); - printf(" D (CSP/DL; default = bare CSP)\n"); - exit(1); -} - -static void dumpBuf(uint8 *buf, - unsigned len) -{ - unsigned i; - - printf(" "); - for(i=0; i gen a new one - // else use this - CSSM_CRYPTO_DATA_PTR seed, // optional - unsigned len, - CSSM_BOOL weMalloc) -{ - CSSM_RETURN crtn; - CSSM_DATA data = {0, NULL}; - - /* optional existing context */ - if(ccHand == 0) { - crtn = CSSM_CSP_CreateRandomGenContext( - cspHand, - RAND_ALG, - seed, - len, - &ccHand); - if(crtn) { - printError("CSSM_CSP_CreateRandomGenContext", crtn); - return; - } - } - - /* who mallocs the data? */ - if(weMalloc) { - data.Data = (uint8 *)appMalloc(len, NULL); - if(data.Data == NULL) { - printf("***malloc failure\n"); - return; - } - data.Length = len; - } - - /* go for it */ - crtn = CSSM_GenerateRandom(ccHand, &data); - if(crtn) { - printError("CSSM_GenerateRandom", crtn); - return; - } - - dumpBuf(data.Data, data.Length); - appFree(data.Data, NULL); - return; -} - -#define SEED_SIZE 32 - -/* - * CryptoData callback for optional random seed. - */ -CSSM_RETURN seedCallback( - CSSM_DATA_PTR OutData, - void *CallerCtx) -{ - int i, j; - static unsigned char seed[SEED_SIZE]; - - OutData->Length = SEED_SIZE; - OutData->Data = seed; - for(i=SEED_SIZE, j=0; i>0; i--, j++) { - seed[j] = i; - } - return CSSM_OK; -} - -int main(int argc, char **argv) -{ - int arg; - char *argp; - CSSM_CSP_HANDLE cspHand; - CSSM_CC_HANDLE ccHand = 0; - CSSM_RETURN crtn; - CSSM_BOOL bareCsp = CSSM_TRUE; - char resp = 'n'; - // initial op = get random data - CSSM_BOOL weMalloc = CSSM_FALSE; - unsigned char seed[SEED_SIZE]; - CSSM_CRYPTO_DATA cseed; - int i; - unsigned reqLen = 16; - CSSM_BOOL explicitSeed; - - for(arg=1; arg