Chameleon

Chameleon Commit Details

Date:2014-10-21 20:17:55 (9 years 4 months ago)
Author:ErmaC
Commit:2432
Parents: 2431
Message:Pike R. Alpha : dinamic "random-seed" implementation see: http://www.insanelymac.com/forum/topic/301350-lets-make-random-seed-r eally-random
Changes:
M/trunk/i386/libsaio/fake_efi.c
M/trunk/CHANGES
M/trunk/i386/libsaio/saio_internal.h
M/trunk/i386/libsaio/stringTable.c
M/trunk/i386/libsaio/load.c
M/trunk/i386/libsaio/asm.s

File differences

trunk/i386/libsaio/asm.s
495495
496496
497497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
ret
#endif
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// computeRand()
//
// Pike R. Alpha - 12 October 2014
//
LABEL(_computeRand)
pushl%edx
mov$0xa,%edx
Repeat:
rdrand%eax
jaeOk
jmpExit
Ok:
dec%edx
pause
jneRepeat
mov$0x0,%eax
Exit:
popl%edx
ret
trunk/i386/libsaio/load.c
136136
137137
138138
139
139
140140
141141
142142
......
152152
153153
154154
155
155
156156
157157
158158
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;
}
*/
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;
}
trunk/i386/libsaio/stringTable.c
613613
614614
615615
616
616617
617
618618
619619
620620
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;
trunk/i386/libsaio/fake_efi.c
718718
719719
720720
721
722
721
722
723
724
725
726
727
728
729
730
723731
732
733
724734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
725752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
726768
769
770
771
772
727773
774
775
776
777
778
779
780
781
782
728783
784
729785
786
787
788
789
730790
791
792
731793
794
732795
733
796
797
734798
735799
736800
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();// callq0x18e20
cpuTick = getCPUTick();// callq0x121a7
randomValue = (randomValue ^ cpuTick);// xor%rdi,%rax
seedBuffer[index] = randomValue;// mov%rax,(%r15,%rsi,8)
}// jb0x17e12
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;// jb0x17e55(retry)
}
cpuTick = getCPUTick();// callq0x121a7
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++;// incr12
ecx = (edi & 0xffff);// movzwl%di,%ecx
} while (index < 64);// cmp%r14d,%r12d
// jne0x17e55(next)
DT__AddProperty(chosenNode, "random-seed", sizeof(seedBuffer), (EFI_UINT8*) &seedBuffer);
//
}
}
}
/*
trunk/i386/libsaio/saio_internal.h
3333
3434
3535
36
3637
3738
3839
extern voidhalt(void);
extern voidstartprog(unsigned int address, void *arg);
extern voidloader(UInt32 code, UInt32 cmdptr);
extern uint64_tcomputeRand(void);
/* bios.s */
extern void bios(biosBuf_t *bb);
trunk/CHANGES
1
12
23
34
- 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

Archive Download the corresponding diff file

Revision: 2432