/** * Function Name: genMaster_key * * Description: * Generate all symmetric keys used for DSSE encrypted data structure, file collection, and client hash tables * * @param pKey: (output) symmetric keys being generated * @param prng: (input) pseudo-random number state * @return 0 if successful */ int DSSE_KeyGen::genMaster_key(MasterKey *pKey, prng_state* prng) { Krawczyk128_KDF* Kraw = new Krawczyk128_KDF(); int error; // generate src key material and extractor salt with Fortunate PRNG unsigned char pXTS[BLOCK_CIPHER_SIZE]; unsigned char pSKM[BLOCK_CIPHER_SIZE]; unsigned char pPRK[BLOCK_CIPHER_SIZE]; fortuna_read(pXTS,BLOCK_CIPHER_SIZE,prng); fortuna_read(pSKM,BLOCK_CIPHER_SIZE,prng); // Generate Pseudo Random Key using OMAC-128 if((error = Kraw->generate_128_PRK(pPRK, BLOCK_CIPHER_SIZE, pXTS, BLOCK_CIPHER_SIZE, pSKM, BLOCK_CIPHER_SIZE)) != CRYPT_OK) { printf("Error calling generate_128_PRK function: %d\n", error); exit(0); } // Generate key1 using Krawczyk Key Derivation Function if((error = Kraw->generate_krawczyk_128_KDF(pKey->key1, BLOCK_CIPHER_SIZE, (unsigned char *)"key1", 4, pPRK, BLOCK_CIPHER_SIZE)) != CRYPT_OK) { printf("Error calling krawczyk_128_kdf function: %d\n", error); exit(0); } Miscellaneous::print_ucharstring(pKey->key1,BLOCK_CIPHER_SIZE); cout<<endl; // Generate key2 using Krawczyk Key Derivation Function if((error = Kraw->generate_krawczyk_128_KDF(pKey->key2, BLOCK_CIPHER_SIZE, (unsigned char *)"key2", 4, pPRK, BLOCK_CIPHER_SIZE)) != CRYPT_OK) { printf("Error calling krawczyk_128_kdf function: %d\n", error); exit(0); } Miscellaneous::print_ucharstring(pKey->key2,BLOCK_CIPHER_SIZE); cout<<endl; // Generate key3 using Krawczyk Key Derivation Function if((error = Kraw->generate_krawczyk_128_KDF(pKey->key3, BLOCK_CIPHER_SIZE, (unsigned char *)"key3", 4, pPRK, BLOCK_CIPHER_SIZE)) != CRYPT_OK) { printf("Error calling krawczyk_128_kdf function: %d\n", error/*error_to_string(error)*/); exit(0); } Miscellaneous::print_ucharstring(pKey->key3,BLOCK_CIPHER_SIZE); cout<<endl; exit: delete Kraw; return 0; }
void CAESModule::generateKey(uint8_t * const pGeneratedKey) const { size_t const ByteRead = fortuna_read(pGeneratedKey, static_cast<unsigned long>(getKeySize()), &gInternalData.mRandomGenerator); FASSERT(ByteRead == getKeySize()); return; }
//generate 6 different functions and store in memory void generateRoundFunctions(unsigned char * seed, unsigned int * bufint, int blocks) { int err; int i=0; int j=0; unsigned char buf[4]; //bufint = malloc(blocks*sizeof(unsigned int)); int index = 0; prng_state prng; if ((err = fortuna_start(&prng)) != CRYPT_OK) { printf("start error: %s\n", error_to_string(err)); } if ((err = fortuna_add_entropy(seed, strlen(seed), &prng))!= CRYPT_OK) { printf("Add entropy error: %s\n", error_to_string(err)); } if ((err = fortuna_ready(&prng)) != CRYPT_OK) { printf("Ready error: %s\n", error_to_string(err)); } for(i=0;i<blocks;i++){ fortuna_read(buf,sizeof(buf),&prng); bufint[i] = *(unsigned int *)buf; } }
/** read(userdata, [size], [raw]) */ static int Lread(lua_State* L) { prng_state* prng = luaL_checkudata(L, 1, MYTYPE); int size = luaL_optint(L, 2, 128); unsigned char* buf = (unsigned char*) malloc(size); if (buf == NULL) { lua_pushnil(L); lua_pushstring (L, "allocation error"); return 2; } if (fortuna_read(buf, (unsigned long) size, prng) != size) { free(buf); lua_pushnil(L); lua_pushstring (L, "'fortuna' read error"); return 2; } if (lua_toboolean(L, 3)) lua_pushlstring(L, (const char*)buf, size); else { char* hex = (char*) malloc(2*size + 1); if (hex == NULL) { free(buf); lua_pushnil(L); lua_pushstring (L, "allocation error"); return 2; } int i; for (i = 0; i < size; i++) sprintf(hex + 2 * i, "%02x", buf[i]); lua_pushlstring(L, (const char*)hex, 2*size); free(hex); } free(buf); return 1; }
void getRandomIV(Tools::CSecureMemory &rIV) { rIV.allocate(gIVSize); size_t const ByteRead = fortuna_read(&rIV[0], static_cast<unsigned long>(rIV.getSize()), &gInternalData.mRandomGenerator); FASSERT(ByteRead == 16); return; }
static int sqlcipher_ltc_random(void *ctx, void *buffer, int length) { ltc_ctx *ltc = (ltc_ctx*)ctx; int rc; if((rc = fortuna_ready(&(ltc->prng))) != CRYPT_OK) { return SQLITE_ERROR; } fortuna_read(buffer, length, &(ltc->prng)); return SQLITE_OK; }
static int sqlcipher_ltc_random(void *ctx, void *buffer, int length) { #ifndef SQLCIPHER_LTC_NO_MUTEX_RAND sqlite3_mutex_enter(ltc_rand_mutex); #endif fortuna_read(buffer, length, &prng); #ifndef SQLCIPHER_LTC_NO_MUTEX_RAND sqlite3_mutex_leave(ltc_rand_mutex); #endif return SQLITE_OK; }
void getPadding(Tools::CSecureMemory &rPaddedMemory, Tools::CSecureMemory const &rUnpaddedMemory) { size_t const PaddingBytes = Tools::getPaddedMemory(rPaddedMemory, rUnpaddedMemory, gBlockSize); if (PaddingBytes) { size_t const ByteRead = fortuna_read(&rPaddedMemory[rPaddedMemory.getSize()-PaddingBytes], static_cast<unsigned long>(PaddingBytes), &gInternalData.mRandomGenerator); FASSERT(ByteRead == PaddingBytes); } return; }