Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added RNG support for non-Linux/BSD systems #9

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions lib/Transforms/Obfuscation/PrngAESCtr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -764,18 +764,25 @@ void PrngAESCtr::prng_seed () {
}

devrandom.close();
DEBUG_WITH_TYPE ("cprng", dbgs() << "CPNRG seeded with /dev/random");

memset(ctr, 0, 16);

// Once the seed is there, we compute the
// AES128 key-schedule
aes_compute_ks(ks, key);

seeded = true;
DEBUG_WITH_TYPE ("cprng", dbgs() << "CPRNG seeded with /dev/random");

} else {
ctx.emitError (Twine ("Cannot open /dev/random"));
srand((unsigned int)__rdtsc());
uint8_t tempKey[16];

for (int i = 0; i < 16; i++)
tempKey[i] = rand() % 255;
memcpy(key, tempKey, 16);
DEBUG_WITH_TYPE("cprng", dbgs() << "CPRNG seeded with rand()");
}

memset(ctr, 0, 16);

// Once the seed is there, we compute the
// AES128 key-schedule
aes_compute_ks(ks, key);

seeded = true;
}

void PrngAESCtr::inc_ctr() {
Expand Down