Index: trunk/i386/libsaio/asm.s =================================================================== --- trunk/i386/libsaio/asm.s (revision 2431) +++ trunk/i386/libsaio/asm.s (revision 2432) @@ -495,3 +495,30 @@ ret #endif + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// computeRand() +// +// Pike R. Alpha - 12 October 2014 +// + +LABEL(_computeRand) + pushl %edx + mov $0xa, %edx + +Repeat: + rdrand %eax + jae Ok + jmp Exit + +Ok: + dec %edx + pause + jne Repeat + mov $0x0, %eax + +Exit: + popl %edx + + ret + Index: trunk/i386/libsaio/load.c =================================================================== --- trunk/i386/libsaio/load.c (revision 2431) +++ trunk/i386/libsaio/load.c (revision 2432) @@ -136,7 +136,7 @@ if (mH->magic != MH_MAGIC) { - error("Mach-O file has bad magic number\n"); + error("Mach-O (i386) file has bad magic number\n"); return -1; } @@ -152,7 +152,7 @@ */ if (mH->magic != MH_MAGIC_64) { - error("Mach-O file has bad magic number\n"); + error("Mach-O file (x86_64) has bad magic number\n"); return -1; } Index: trunk/i386/libsaio/stringTable.c =================================================================== --- trunk/i386/libsaio/stringTable.c (revision 2431) +++ trunk/i386/libsaio/stringTable.c (revision 2432) @@ -613,8 +613,8 @@ int loadSystemConfig(config_file_t *config) { char *dirspec[] = { + "/OS X Install Data/com.apple.Boot.plist", "/Library/Preferences/SystemConfiguration/com.apple.Boot.plist", - "/OS X Install Data/com.apple.Boot.plist", }; int i, fd, count, ret=-1; Index: trunk/i386/libsaio/fake_efi.c =================================================================== --- trunk/i386/libsaio/fake_efi.c (revision 2431) +++ trunk/i386/libsaio/fake_efi.c (revision 2432) @@ -718,19 +718,83 @@ DT__AddProperty(chosenNode, "machine-signature", sizeof(EFI_UINT32), (EFI_UINT32 *)&MachineSig); -// -// + if(YOSEMITE) + { + // + // Pike R. Alpha - 12 October 2014 + // + UInt8 index = 0; + EFI_UINT16 PMTimerValue = 0; + EFI_UINT32 randomValue, tempValue, cpuTick; + EFI_UINT32 ecx, esi, edi = 0; + EFI_UINT32 rcx, rdx, rsi, rdi; + randomValue = tempValue = ecx = esi = edi = 0; // xor %ecx, %ecx + rcx = rdx = rsi = rdi = cpuTick = 0; + // LEAF_1 - Feature Information (Function 01h). + if (Platform.CPU.CPUID[CPUID_1][2] & 0x40000000) // Checking ecx:bit-30 + { + // + // i5/i7 Ivy Bridge and Haswell processors with RDRAND support. + // + EFI_UINT32 seedBuffer[16] = {0}; + // + // Main loop to get 16 qwords (four bytes each). + // + for (index = 0; index < 16; index++) // 0x17e12: + { + randomValue = computeRand(); // callq 0x18e20 + cpuTick = getCPUTick(); // callq 0x121a7 + randomValue = (randomValue ^ cpuTick); // xor %rdi, %rax + seedBuffer[index] = randomValue; // mov %rax,(%r15,%rsi,8) + } // jb 0x17e12 + DT__AddProperty(chosenNode, "random-seed", sizeof(seedBuffer), (EFI_UINT32*) &seedBuffer); + } + else + { + // + // All other processors without RDRAND support. + // + EFI_UINT8 seedBuffer[64] = {0}; + // + // Main loop to get the 64 bytes. + // + do // 0x17e55: + { + PMTimerValue = inw(0x408); // in (%dx), %ax + esi = PMTimerValue; // movzwl %ax, %esi + if (esi < ecx) // cmp %ecx, %esi + { + continue; // jb 0x17e55 (retry) + } + cpuTick = getCPUTick(); // callq 0x121a7 + rcx = (cpuTick >> 8); // mov %rax, %rcx + // shr $0x8, %rcx + rdx = (cpuTick >> 10); // mov %rax, %rdx + // shr $0x10, %rdx + rdi = rsi; // mov %rsi, %rdi + rdi = (rdi ^ cpuTick); // xor %rax, %rdi + rdi = (rdi ^ rcx); // xor %rcx, %rdi + rdi = (rdi ^ rdx); // xor %rdx, %rdi + seedBuffer[index] = (rdi & 0xff); // mov %dil, (%r15,%r12,1) + edi = (edi & 0x2f); // and $0x2f, %edi + edi = (edi + esi); // add %esi, %edi + index++; // inc r12 + ecx = (edi & 0xffff); // movzwl %di, %ecx + } while (index < 64); // cmp %r14d, %r12d + // jne 0x17e55 (next) + DT__AddProperty(chosenNode, "random-seed", sizeof(seedBuffer), (EFI_UINT8*) &seedBuffer); -// + } + } } /* Index: trunk/i386/libsaio/saio_internal.h =================================================================== --- trunk/i386/libsaio/saio_internal.h (revision 2431) +++ trunk/i386/libsaio/saio_internal.h (revision 2432) @@ -33,6 +33,7 @@ extern void halt(void); extern void startprog(unsigned int address, void *arg); extern void loader(UInt32 code, UInt32 cmdptr); +extern uint64_t computeRand(void); /* bios.s */ extern void bios(biosBuf_t *bb); Index: trunk/CHANGES =================================================================== --- trunk/CHANGES (revision 2431) +++ trunk/CHANGES (revision 2432) @@ -1,3 +1,4 @@ +- Pike R. Alpha : dinamic "random-seed" implementation ( http://www.insanelymac.com/forum/topic/301350-lets-make-random-seed-really-random/ ) - ErmaC : getCPUTick() helper function ( http://www.insanelymac.com/forum/topic/301350-lets-make-random-seed-really-random/ ) - ErmaC : Add Yosemite Icons detection for chameleon UI - blackosx : Add chameleon UI Icons for Yosemite