flat assembler
Message board for the users of flat assembler.

Index > Main > RDRAND problem

Author
Thread Post new topic Reply to topic
magicSqr



Joined: 27 Aug 2011
Posts: 105
magicSqr 16 Dec 2012, 17:15
Hi,

from http://software.intel.com/en-us/articles/intel-digital-random-number-generator-drng-software-implementation-guide

Image

If I run the following

Code:
format PE64 console
entry start

include '%fasminc%\win64ax.inc'

;**************************************************************************************************
section '.text' code readable executable

    start:
        xor     eax, eax
        cpuid
        bt      ecx, 30
        jnc     .noGood
    .good:
        cinvoke printf, goodStr
        jmp     .finished
    .noGood:
        cinvoke printf, noGoodStr
    .finished:
        rdrand  eax
        invoke ExitProcess, 0


;**************************************************************************************************
section '.data' data readable writeable

goodStr         db "RDRAND available", 00
noGoodStr       db "RDRAND not available", 00

;**************************************************************************************************
section '.idata' import data readable writeable

library msvcrt, 'msvcrt.dll',\
        kernel32, 'kernel32.dll'

include '%fasminc%\api\Kernel32.inc'

import  msvcrt,\
        printf, 'printf'
    


I am told bit 30 is set so I have rdrand support but then the code crashes at the

Code:
rdrand  eax
    


Any ideas?

thx
Post 16 Dec 2012, 17:15
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 16 Dec 2012, 17:29
Check the references, you are very likely to need EAX set to a value other than zero before issuing CPUID (if I remember right, EAX will only hold the maximum standard function supported and EBX, ECX and EDX will hold "GenuineIntel" or something like that)
Post 16 Dec 2012, 17:29
View user's profile Send private message Reply with quote
magicSqr



Joined: 27 Aug 2011
Posts: 105
magicSqr 16 Dec 2012, 17:57
thx loco, that was the problem. I should have eax = 1.
Post 16 Dec 2012, 17:57
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 17 Dec 2012, 00:24
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 22:10; edited 1 time in total
Post 17 Dec 2012, 00:24
View user's profile Send private message Reply with quote
BAiC



Joined: 22 Mar 2011
Posts: 272
Location: California
BAiC 31 Dec 2012, 23:10
fyi: you're executing the RDRAND opcode when the processor detects that it isn't supported. it falls through:
Code:
    .noGood: 
        cinvoke printf, noGoodStr 
    .finished: 
        rdrand  eax     


use something like:
Code:
        bt      ecx, 30 
        jnc     .noGood 
        cinvoke printf, goodStr 
        rdrand  eax 
        invoke ExitProcess, 0 
.noGood: 
        cinvoke printf, noGoodStr 
        invoke ExitProcess, 0     

_________________
byte me.
Post 31 Dec 2012, 23:10
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1903
DOS386 07 Feb 2013, 08:32
Post 07 Feb 2013, 08:32
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.