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

BCRYPT_RNG_FUNCTION_TABLE

構造体
サイズx64: 48 バイト / x86: 24 バイト

サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。

フィールド

フィールドサイズx64x86説明
VersionBCRYPT_INTERFACE_VERSION4+0+0CNG乱数生成インターフェイスのバージョン。
OpenAlgorithmProviderBCryptOpenAlgorithmProviderFn8/4+8+4アルゴリズムプロバイダーを開く関数ポインタ。
GetPropertyBCryptGetPropertyFn8/4+16+8プロパティを取得する関数ポインタ。
SetPropertyBCryptSetPropertyFn8/4+24+12プロパティを設定する関数ポインタ。
CloseAlgorithmProviderBCryptCloseAlgorithmProviderFn8/4+32+16アルゴリズムプロバイダーを閉じる関数ポインタ。
GenRandomBCryptGenRandomFn8/4+40+20乱数を生成する関数ポインタ。

各言語での定義

#include <windows.h>

// BCRYPT_INTERFACE_VERSION  (x64 4 / x86 4 バイト)
typedef struct BCRYPT_INTERFACE_VERSION {
    WORD MajorVersion;
    WORD MinorVersion;
} BCRYPT_INTERFACE_VERSION;

// BCRYPT_RNG_FUNCTION_TABLE  (x64 48 / x86 24 バイト)
typedef struct BCRYPT_RNG_FUNCTION_TABLE {
    BCRYPT_INTERFACE_VERSION Version;
    BCryptOpenAlgorithmProviderFn OpenAlgorithmProvider;
    BCryptGetPropertyFn GetProperty;
    BCryptSetPropertyFn SetProperty;
    BCryptCloseAlgorithmProviderFn CloseAlgorithmProvider;
    BCryptGenRandomFn GenRandom;
} BCRYPT_RNG_FUNCTION_TABLE;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct BCRYPT_INTERFACE_VERSION
{
    public ushort MajorVersion;
    public ushort MinorVersion;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct BCRYPT_RNG_FUNCTION_TABLE
{
    public BCRYPT_INTERFACE_VERSION Version;
    public IntPtr OpenAlgorithmProvider;
    public IntPtr GetProperty;
    public IntPtr SetProperty;
    public IntPtr CloseAlgorithmProvider;
    public IntPtr GenRandom;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure BCRYPT_INTERFACE_VERSION
    Public MajorVersion As UShort
    Public MinorVersion As UShort
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure BCRYPT_RNG_FUNCTION_TABLE
    Public Version As BCRYPT_INTERFACE_VERSION
    Public OpenAlgorithmProvider As IntPtr
    Public GetProperty As IntPtr
    Public SetProperty As IntPtr
    Public CloseAlgorithmProvider As IntPtr
    Public GenRandom As IntPtr
End Structure
import ctypes
from ctypes import wintypes

class BCRYPT_INTERFACE_VERSION(ctypes.Structure):
    _fields_ = [
        ("MajorVersion", ctypes.c_ushort),
        ("MinorVersion", ctypes.c_ushort),
    ]

class BCRYPT_RNG_FUNCTION_TABLE(ctypes.Structure):
    _fields_ = [
        ("Version", BCRYPT_INTERFACE_VERSION),
        ("OpenAlgorithmProvider", ctypes.c_void_p),
        ("GetProperty", ctypes.c_void_p),
        ("SetProperty", ctypes.c_void_p),
        ("CloseAlgorithmProvider", ctypes.c_void_p),
        ("GenRandom", ctypes.c_void_p),
    ]
#[repr(C)]
pub struct BCRYPT_INTERFACE_VERSION {
    pub MajorVersion: u16,
    pub MinorVersion: u16,
}

#[repr(C)]
pub struct BCRYPT_RNG_FUNCTION_TABLE {
    pub Version: BCRYPT_INTERFACE_VERSION,
    pub OpenAlgorithmProvider: *mut core::ffi::c_void,
    pub GetProperty: *mut core::ffi::c_void,
    pub SetProperty: *mut core::ffi::c_void,
    pub CloseAlgorithmProvider: *mut core::ffi::c_void,
    pub GenRandom: *mut core::ffi::c_void,
}
import "golang.org/x/sys/windows"

type BCRYPT_INTERFACE_VERSION struct {
	MajorVersion uint16
	MinorVersion uint16
}

type BCRYPT_RNG_FUNCTION_TABLE struct {
	Version BCRYPT_INTERFACE_VERSION
	OpenAlgorithmProvider uintptr
	GetProperty uintptr
	SetProperty uintptr
	CloseAlgorithmProvider uintptr
	GenRandom uintptr
}
type
  BCRYPT_INTERFACE_VERSION = record
    MajorVersion: Word;
    MinorVersion: Word;
  end;

  BCRYPT_RNG_FUNCTION_TABLE = record
    Version: BCRYPT_INTERFACE_VERSION;
    OpenAlgorithmProvider: Pointer;
    GetProperty: Pointer;
    SetProperty: Pointer;
    CloseAlgorithmProvider: Pointer;
    GenRandom: Pointer;
  end;
const BCRYPT_INTERFACE_VERSION = extern struct {
    MajorVersion: u16,
    MinorVersion: u16,
};

const BCRYPT_RNG_FUNCTION_TABLE = extern struct {
    Version: BCRYPT_INTERFACE_VERSION,
    OpenAlgorithmProvider: ?*anyopaque,
    GetProperty: ?*anyopaque,
    SetProperty: ?*anyopaque,
    CloseAlgorithmProvider: ?*anyopaque,
    GenRandom: ?*anyopaque,
};
type
  BCRYPT_INTERFACE_VERSION {.bycopy.} = object
    MajorVersion: uint16
    MinorVersion: uint16

  BCRYPT_RNG_FUNCTION_TABLE {.bycopy.} = object
    Version: BCRYPT_INTERFACE_VERSION
    OpenAlgorithmProvider: pointer
    GetProperty: pointer
    SetProperty: pointer
    CloseAlgorithmProvider: pointer
    GenRandom: pointer
struct BCRYPT_INTERFACE_VERSION
{
    ushort MajorVersion;
    ushort MinorVersion;
}

struct BCRYPT_RNG_FUNCTION_TABLE
{
    BCRYPT_INTERFACE_VERSION Version;
    void* OpenAlgorithmProvider;
    void* GetProperty;
    void* SetProperty;
    void* CloseAlgorithmProvider;
    void* GenRandom;
}

HSP用 定義

HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x86 レイアウト)
; BCRYPT_RNG_FUNCTION_TABLE サイズ: 24 バイト(x86)
dim st, 6    ; 4byte整数×6(構造体サイズ 24 / 4 切り上げ)
; Version : BCRYPT_INTERFACE_VERSION (+0, 4byte)  varptr(st)+0 を基点に操作(4byte:入れ子/配列)
; OpenAlgorithmProvider : BCryptOpenAlgorithmProviderFn (+4, 4byte)  st.1 = 値  /  値 = st.1   (lpoke/lpeek も可)
; GetProperty : BCryptGetPropertyFn (+8, 4byte)  st.2 = 値  /  値 = st.2   (lpoke/lpeek も可)
; SetProperty : BCryptSetPropertyFn (+12, 4byte)  st.3 = 値  /  値 = st.3   (lpoke/lpeek も可)
; CloseAlgorithmProvider : BCryptCloseAlgorithmProviderFn (+16, 4byte)  st.4 = 値  /  値 = st.4   (lpoke/lpeek も可)
; GenRandom : BCryptGenRandomFn (+20, 4byte)  st.5 = 値  /  値 = st.5   (lpoke/lpeek も可)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; BCRYPT_RNG_FUNCTION_TABLE サイズ: 48 バイト(x64)
dim st, 12    ; 4byte整数×12(構造体サイズ 48 / 4 切り上げ)
; Version : BCRYPT_INTERFACE_VERSION (+0, 4byte)  varptr(st)+0 を基点に操作(4byte:入れ子/配列)
; OpenAlgorithmProvider : BCryptOpenAlgorithmProviderFn (+8, 8byte)  qpoke st,8,値 / qpeek(st,8)  ※IronHSPのみ。3.7/3.8は lpoke st,8,下位 : lpoke st,12,上位
; GetProperty : BCryptGetPropertyFn (+16, 8byte)  qpoke st,16,値 / qpeek(st,16)  ※IronHSPのみ。3.7/3.8は lpoke st,16,下位 : lpoke st,20,上位
; SetProperty : BCryptSetPropertyFn (+24, 8byte)  qpoke st,24,値 / qpeek(st,24)  ※IronHSPのみ。3.7/3.8は lpoke st,24,下位 : lpoke st,28,上位
; CloseAlgorithmProvider : BCryptCloseAlgorithmProviderFn (+32, 8byte)  qpoke st,32,値 / qpeek(st,32)  ※IronHSPのみ。3.7/3.8は lpoke st,32,下位 : lpoke st,36,上位
; GenRandom : BCryptGenRandomFn (+40, 8byte)  qpoke st,40,値 / qpeek(st,40)  ※IronHSPのみ。3.7/3.8は lpoke st,40,下位 : lpoke st,44,上位
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global BCRYPT_INTERFACE_VERSION
    #field short MajorVersion
    #field short MinorVersion
#endstruct

#defstruct global BCRYPT_RNG_FUNCTION_TABLE
    #field BCRYPT_INTERFACE_VERSION Version
    #field intptr OpenAlgorithmProvider
    #field intptr GetProperty
    #field intptr SetProperty
    #field intptr CloseAlgorithmProvider
    #field intptr GenRandom
#endstruct

stdim st, BCRYPT_RNG_FUNCTION_TABLE        ; NSTRUCT 変数を確保