Win32 API 日本語リファレンス
ホームSecurity.Cryptography › GetRngInterface

GetRngInterface

関数
プロバイダーの乱数生成器関数テーブルを取得する。
DLLbcryptprimitives.dll呼出規約winapi

シグネチャ

// bcryptprimitives.dll
#include <windows.h>

NTSTATUS GetRngInterface(
    LPCWSTR pszProviderName,
    BCRYPT_RNG_FUNCTION_TABLE** ppFunctionTable,
    DWORD dwFlags
);

パラメーター

名前方向説明
pszProviderNameLPCWSTRin対象の暗号化プロバイダ名。NULLで既定プロバイダ。
ppFunctionTableBCRYPT_RNG_FUNCTION_TABLE**out乱数生成の関数テーブルBCRYPT_RNG_FUNCTION_TABLEへのポインタを受け取る出力先。
dwFlagsDWORDin動作を制御するフラグ。

戻り値の型: NTSTATUS

各言語での呼び出し定義

// bcryptprimitives.dll
#include <windows.h>

NTSTATUS GetRngInterface(
    LPCWSTR pszProviderName,
    BCRYPT_RNG_FUNCTION_TABLE** ppFunctionTable,
    DWORD dwFlags
);
[DllImport("bcryptprimitives.dll", ExactSpelling = true)]
static extern int GetRngInterface(
    [MarshalAs(UnmanagedType.LPWStr)] string pszProviderName,   // LPCWSTR
    IntPtr ppFunctionTable,   // BCRYPT_RNG_FUNCTION_TABLE** out
    uint dwFlags   // DWORD
);
<DllImport("bcryptprimitives.dll", ExactSpelling:=True)>
Public Shared Function GetRngInterface(
    <MarshalAs(UnmanagedType.LPWStr)> pszProviderName As String,   ' LPCWSTR
    ppFunctionTable As IntPtr,   ' BCRYPT_RNG_FUNCTION_TABLE** out
    dwFlags As UInteger   ' DWORD
) As Integer
End Function
' pszProviderName : LPCWSTR
' ppFunctionTable : BCRYPT_RNG_FUNCTION_TABLE** out
' dwFlags : DWORD
Declare PtrSafe Function GetRngInterface Lib "bcryptprimitives" ( _
    ByVal pszProviderName As LongPtr, _
    ByVal ppFunctionTable As LongPtr, _
    ByVal dwFlags As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetRngInterface = ctypes.windll.bcryptprimitives.GetRngInterface
GetRngInterface.restype = ctypes.c_int
GetRngInterface.argtypes = [
    wintypes.LPCWSTR,  # pszProviderName : LPCWSTR
    ctypes.c_void_p,  # ppFunctionTable : BCRYPT_RNG_FUNCTION_TABLE** out
    wintypes.DWORD,  # dwFlags : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('bcryptprimitives.dll')
GetRngInterface = Fiddle::Function.new(
  lib['GetRngInterface'],
  [
    Fiddle::TYPE_VOIDP,  # pszProviderName : LPCWSTR
    Fiddle::TYPE_VOIDP,  # ppFunctionTable : BCRYPT_RNG_FUNCTION_TABLE** out
    -Fiddle::TYPE_INT,  # dwFlags : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "bcryptprimitives")]
extern "system" {
    fn GetRngInterface(
        pszProviderName: *const u16,  // LPCWSTR
        ppFunctionTable: *mut *mut BCRYPT_RNG_FUNCTION_TABLE,  // BCRYPT_RNG_FUNCTION_TABLE** out
        dwFlags: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("bcryptprimitives.dll")]
public static extern int GetRngInterface([MarshalAs(UnmanagedType.LPWStr)] string pszProviderName, IntPtr ppFunctionTable, uint dwFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'bcryptprimitives_GetRngInterface' -Namespace Win32 -PassThru
# $api::GetRngInterface(pszProviderName, ppFunctionTable, dwFlags)
#uselib "bcryptprimitives.dll"
#func global GetRngInterface "GetRngInterface" sptr, sptr, sptr
; GetRngInterface pszProviderName, varptr(ppFunctionTable), dwFlags   ; 戻り値は stat
; pszProviderName : LPCWSTR -> "sptr"
; ppFunctionTable : BCRYPT_RNG_FUNCTION_TABLE** out -> "sptr"
; dwFlags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "bcryptprimitives.dll"
#cfunc global GetRngInterface "GetRngInterface" wstr, var, int
; res = GetRngInterface(pszProviderName, ppFunctionTable, dwFlags)
; pszProviderName : LPCWSTR -> "wstr"
; ppFunctionTable : BCRYPT_RNG_FUNCTION_TABLE** out -> "var"
; dwFlags : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; NTSTATUS GetRngInterface(LPCWSTR pszProviderName, BCRYPT_RNG_FUNCTION_TABLE** ppFunctionTable, DWORD dwFlags)
#uselib "bcryptprimitives.dll"
#cfunc global GetRngInterface "GetRngInterface" wstr, var, int
; res = GetRngInterface(pszProviderName, ppFunctionTable, dwFlags)
; pszProviderName : LPCWSTR -> "wstr"
; ppFunctionTable : BCRYPT_RNG_FUNCTION_TABLE** out -> "var"
; dwFlags : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	bcryptprimitives = windows.NewLazySystemDLL("bcryptprimitives.dll")
	procGetRngInterface = bcryptprimitives.NewProc("GetRngInterface")
)

// pszProviderName (LPCWSTR), ppFunctionTable (BCRYPT_RNG_FUNCTION_TABLE** out), dwFlags (DWORD)
r1, _, err := procGetRngInterface.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszProviderName))),
	uintptr(ppFunctionTable),
	uintptr(dwFlags),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // NTSTATUS
function GetRngInterface(
  pszProviderName: PWideChar;   // LPCWSTR
  ppFunctionTable: Pointer;   // BCRYPT_RNG_FUNCTION_TABLE** out
  dwFlags: DWORD   // DWORD
): Integer; stdcall;
  external 'bcryptprimitives.dll' name 'GetRngInterface';
result := DllCall("bcryptprimitives\GetRngInterface"
    , "WStr", pszProviderName   ; LPCWSTR
    , "Ptr", ppFunctionTable   ; BCRYPT_RNG_FUNCTION_TABLE** out
    , "UInt", dwFlags   ; DWORD
    , "Int")   ; return: NTSTATUS
●GetRngInterface(pszProviderName, ppFunctionTable, dwFlags) = DLL("bcryptprimitives.dll", "int GetRngInterface(char*, void*, dword)")
# 呼び出し: GetRngInterface(pszProviderName, ppFunctionTable, dwFlags)
# pszProviderName : LPCWSTR -> "char*"
# ppFunctionTable : BCRYPT_RNG_FUNCTION_TABLE** out -> "void*"
# dwFlags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "bcryptprimitives" fn GetRngInterface(
    pszProviderName: [*c]const u16, // LPCWSTR
    ppFunctionTable: [*c][*c]BCRYPT_RNG_FUNCTION_TABLE, // BCRYPT_RNG_FUNCTION_TABLE** out
    dwFlags: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;
proc GetRngInterface(
    pszProviderName: WideCString,  # LPCWSTR
    ppFunctionTable: ptr BCRYPT_RNG_FUNCTION_TABLE,  # BCRYPT_RNG_FUNCTION_TABLE** out
    dwFlags: uint32  # DWORD
): int32 {.importc: "GetRngInterface", stdcall, dynlib: "bcryptprimitives.dll".}
pragma(lib, "bcryptprimitives");
extern(Windows)
int GetRngInterface(
    const(wchar)* pszProviderName,   // LPCWSTR
    BCRYPT_RNG_FUNCTION_TABLE** ppFunctionTable,   // BCRYPT_RNG_FUNCTION_TABLE** out
    uint dwFlags   // DWORD
);
ccall((:GetRngInterface, "bcryptprimitives.dll"), stdcall, Int32,
      (Cwstring, Ptr{BCRYPT_RNG_FUNCTION_TABLE}, UInt32),
      pszProviderName, ppFunctionTable, dwFlags)
# pszProviderName : LPCWSTR -> Cwstring
# ppFunctionTable : BCRYPT_RNG_FUNCTION_TABLE** out -> Ptr{BCRYPT_RNG_FUNCTION_TABLE}
# dwFlags : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t GetRngInterface(
    const uint16_t* pszProviderName,
    void* ppFunctionTable,
    uint32_t dwFlags);
]]
local bcryptprimitives = ffi.load("bcryptprimitives")
-- bcryptprimitives.GetRngInterface(pszProviderName, ppFunctionTable, dwFlags)
-- pszProviderName : LPCWSTR
-- ppFunctionTable : BCRYPT_RNG_FUNCTION_TABLE** out
-- dwFlags : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('bcryptprimitives.dll');
const GetRngInterface = lib.func('__stdcall', 'GetRngInterface', 'int32_t', ['str16', 'void *', 'uint32_t']);
// GetRngInterface(pszProviderName, ppFunctionTable, dwFlags)
// pszProviderName : LPCWSTR -> 'str16'
// ppFunctionTable : BCRYPT_RNG_FUNCTION_TABLE** out -> 'void *'
// dwFlags : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("bcryptprimitives.dll", {
  GetRngInterface: { parameters: ["buffer", "pointer", "u32"], result: "i32" },
});
// lib.symbols.GetRngInterface(pszProviderName, ppFunctionTable, dwFlags)
// pszProviderName : LPCWSTR -> "buffer"
// ppFunctionTable : BCRYPT_RNG_FUNCTION_TABLE** out -> "pointer"
// dwFlags : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t GetRngInterface(
    const uint16_t* pszProviderName,
    void* ppFunctionTable,
    uint32_t dwFlags);
C, "bcryptprimitives.dll");
// $ffi->GetRngInterface(pszProviderName, ppFunctionTable, dwFlags);
// pszProviderName : LPCWSTR
// ppFunctionTable : BCRYPT_RNG_FUNCTION_TABLE** out
// dwFlags : DWORD
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Bcryptprimitives extends StdCallLibrary {
    Bcryptprimitives INSTANCE = Native.load("bcryptprimitives", Bcryptprimitives.class);
    int GetRngInterface(
        WString pszProviderName,   // LPCWSTR
        Pointer ppFunctionTable,   // BCRYPT_RNG_FUNCTION_TABLE** out
        int dwFlags   // DWORD
    );
}
@[Link("bcryptprimitives")]
lib Libbcryptprimitives
  fun GetRngInterface = GetRngInterface(
    pszProviderName : UInt16*,   # LPCWSTR
    ppFunctionTable : BCRYPT_RNG_FUNCTION_TABLE**,   # BCRYPT_RNG_FUNCTION_TABLE** out
    dwFlags : UInt32   # DWORD
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef GetRngInterfaceNative = Int32 Function(Pointer<Utf16>, Pointer<Void>, Uint32);
typedef GetRngInterfaceDart = int Function(Pointer<Utf16>, Pointer<Void>, int);
final GetRngInterface = DynamicLibrary.open('bcryptprimitives.dll')
    .lookupFunction<GetRngInterfaceNative, GetRngInterfaceDart>('GetRngInterface');
// pszProviderName : LPCWSTR -> Pointer<Utf16>
// ppFunctionTable : BCRYPT_RNG_FUNCTION_TABLE** out -> Pointer<Void>
// dwFlags : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function GetRngInterface(
  pszProviderName: PWideChar;   // LPCWSTR
  ppFunctionTable: Pointer;   // BCRYPT_RNG_FUNCTION_TABLE** out
  dwFlags: DWORD   // DWORD
): Integer; stdcall;
  external 'bcryptprimitives.dll' name 'GetRngInterface';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "GetRngInterface"
  c_GetRngInterface :: CWString -> Ptr () -> Word32 -> IO Int32
-- pszProviderName : LPCWSTR -> CWString
-- ppFunctionTable : BCRYPT_RNG_FUNCTION_TABLE** out -> Ptr ()
-- dwFlags : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let getrnginterface =
  foreign "GetRngInterface"
    ((ptr uint16_t) @-> (ptr void) @-> uint32_t @-> returning int32_t)
(* pszProviderName : LPCWSTR -> (ptr uint16_t) *)
(* ppFunctionTable : BCRYPT_RNG_FUNCTION_TABLE** out -> (ptr void) *)
(* dwFlags : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library bcryptprimitives (t "bcryptprimitives.dll"))
(cffi:use-foreign-library bcryptprimitives)

(cffi:defcfun ("GetRngInterface" get-rng-interface :convention :stdcall) :int32
  (psz-provider-name (:string :encoding :utf-16le))   ; LPCWSTR
  (pp-function-table :pointer)   ; BCRYPT_RNG_FUNCTION_TABLE** out
  (dw-flags :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $GetRngInterface = Win32::API::More->new('bcryptprimitives',
    'int GetRngInterface(LPCWSTR pszProviderName, LPVOID ppFunctionTable, DWORD dwFlags)');
# my $ret = $GetRngInterface->Call($pszProviderName, $ppFunctionTable, $dwFlags);
# pszProviderName : LPCWSTR -> LPCWSTR
# ppFunctionTable : BCRYPT_RNG_FUNCTION_TABLE** out -> LPVOID
# dwFlags : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型