Modify

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#2263 closed Feature Request (Completed)

Add CryptGenRandom Function to Crypt.au3 UDF

Reported by: wraithdu Owned by: AdmiralAlkex
Milestone: 3.3.9.5 Component: Standard UDFs
Version: Severity: None
Keywords: crypt udf cryptgenrandom Cc:

Description (last modified by guinness)

Here's the function:

; #FUNCTION# ===================================================================
; Name...........: _Crypt_GenRandom
; Description ...: Fill a buffer with cryptographically random data.
; Syntax.........: _Crypt_GenRandom($pBuffer, $iSize)
; Parameters ....: $pBuffer - Pointer to buffer to fill with random data.
;                  $iSize - Size of the buffer pointed to by $pBuffer.
; Return values .: Success - Returns True
;                  Failure - Returns False and sets @error.
; Author ........: Erik Pilsits (wraithdu)
; Modified ......:
; Remarks .......: 
; Related .......: 
; Link ..........: @@MsdnLink@@ CryptGenRandom
; Example .......: Yes
; ==============================================================================
Func _Crypt_GenRandom($pBuffer, $iSize)
    _Crypt_Startup()
    Local $aRet = DllCall(__Crypt_DllHandle(), "bool", "CryptGenRandom", "handle", __Crypt_Context(), "dword", $iSize, "ptr", $pBuffer)
    Local $nError = @error
    _Crypt_Shutdown()
    If $nError Or (Not $aRet[0]) Then
        Return SetError(1, 0, False)
    Else
        Return True
    EndIf
EndFunc   ;==>_Crypt_GenRandom

Attachments (0)

Change History (10)

comment:1 Changed 12 years ago by TicketCleanup

  • Version 3.3.9.4 deleted

Automatic ticket cleanup.

comment:2 Changed 12 years ago by wraithdu

I goofed a parameter. The first parameter should be $pBuffer.

Also this should be added to the Remarks:

MSDN notes about the buffer: Optionally, the application can fill this buffer with data to use as an auxiliary random seed.

comment:3 Changed 12 years ago by wraithdu

Example:

#include <Crypt.au3>
; generate 16 bytes of random data
Local $buff = DllStructCreate("byte[16]")
_Crypt_GenRandom(DllStructGetPtr($buff), DllStructGetSize($buff))
MsgBox(0, "Random data:", DllStructGetData($buff, 1))

comment:4 Changed 12 years ago by guinness

  • Description modified (diff)

comment:5 Changed 12 years ago by AdmiralAlkex

  • Owner set to AdmiralAlkex
  • Status changed from new to assigned

Whoever commits this need to remove the DllStructGetPtr() and fix the dll call.

Seems okay otherwise, so I'm assigning it to me and giving you a few days to comment if there's anything else.

comment:6 follow-up: Changed 12 years ago by guinness

What was the outcome of this?

comment:7 Changed 12 years ago by AdmiralAlkex

This ticket is referenced in revision: [7512]

comment:8 Changed 12 years ago by AdmiralAlkex

This ticket is referenced in revision: [7513]

comment:9 Changed 12 years ago by AdmiralAlkex

  • Milestone set to 3.3.9.5
  • Resolution set to Completed
  • Status changed from assigned to closed

Added by revision [7514] in version: 3.3.9.5

comment:10 in reply to: ↑ 6 Changed 12 years ago by AdmiralAlkex

Replying to guinness:

What was the outcome of this?

The Vogons did it.

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The owner will remain AdmiralAlkex.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.