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

SslExportKeyingMaterial

関数
SSLマスター鍵から鍵生成材料をエクスポートする。
DLLncrypt.dll呼出規約winapi

シグネチャ

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

HRESULT SslExportKeyingMaterial(
    NCRYPT_PROV_HANDLE hSslProvider,
    NCRYPT_KEY_HANDLE hMasterKey,
    LPSTR sLabel,
    BYTE* pbRandoms,   // optional
    DWORD cbRandoms,
    BYTE* pbContextValue,   // optional
    WORD cbContextValue,
    BYTE* pbOutput,
    DWORD cbOutput,
    DWORD dwFlags
);

パラメーター

名前方向
hSslProviderNCRYPT_PROV_HANDLEin
hMasterKeyNCRYPT_KEY_HANDLEin
sLabelLPSTRin
pbRandomsBYTE*inoptional
cbRandomsDWORDin
pbContextValueBYTE*inoptional
cbContextValueWORDin
pbOutputBYTE*out
cbOutputDWORDin
dwFlagsDWORDin

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT SslExportKeyingMaterial(
    NCRYPT_PROV_HANDLE hSslProvider,
    NCRYPT_KEY_HANDLE hMasterKey,
    LPSTR sLabel,
    BYTE* pbRandoms,   // optional
    DWORD cbRandoms,
    BYTE* pbContextValue,   // optional
    WORD cbContextValue,
    BYTE* pbOutput,
    DWORD cbOutput,
    DWORD dwFlags
);
[DllImport("ncrypt.dll", ExactSpelling = true)]
static extern int SslExportKeyingMaterial(
    UIntPtr hSslProvider,   // NCRYPT_PROV_HANDLE
    UIntPtr hMasterKey,   // NCRYPT_KEY_HANDLE
    [MarshalAs(UnmanagedType.LPStr)] string sLabel,   // LPSTR
    IntPtr pbRandoms,   // BYTE* optional
    uint cbRandoms,   // DWORD
    IntPtr pbContextValue,   // BYTE* optional
    ushort cbContextValue,   // WORD
    IntPtr pbOutput,   // BYTE* out
    uint cbOutput,   // DWORD
    uint dwFlags   // DWORD
);
<DllImport("ncrypt.dll", ExactSpelling:=True)>
Public Shared Function SslExportKeyingMaterial(
    hSslProvider As UIntPtr,   ' NCRYPT_PROV_HANDLE
    hMasterKey As UIntPtr,   ' NCRYPT_KEY_HANDLE
    <MarshalAs(UnmanagedType.LPStr)> sLabel As String,   ' LPSTR
    pbRandoms As IntPtr,   ' BYTE* optional
    cbRandoms As UInteger,   ' DWORD
    pbContextValue As IntPtr,   ' BYTE* optional
    cbContextValue As UShort,   ' WORD
    pbOutput As IntPtr,   ' BYTE* out
    cbOutput As UInteger,   ' DWORD
    dwFlags As UInteger   ' DWORD
) As Integer
End Function
' hSslProvider : NCRYPT_PROV_HANDLE
' hMasterKey : NCRYPT_KEY_HANDLE
' sLabel : LPSTR
' pbRandoms : BYTE* optional
' cbRandoms : DWORD
' pbContextValue : BYTE* optional
' cbContextValue : WORD
' pbOutput : BYTE* out
' cbOutput : DWORD
' dwFlags : DWORD
Declare PtrSafe Function SslExportKeyingMaterial Lib "ncrypt" ( _
    ByVal hSslProvider As LongPtr, _
    ByVal hMasterKey As LongPtr, _
    ByVal sLabel As String, _
    ByVal pbRandoms As LongPtr, _
    ByVal cbRandoms As Long, _
    ByVal pbContextValue As LongPtr, _
    ByVal cbContextValue As Integer, _
    ByVal pbOutput As LongPtr, _
    ByVal cbOutput As Long, _
    ByVal dwFlags As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SslExportKeyingMaterial = ctypes.windll.ncrypt.SslExportKeyingMaterial
SslExportKeyingMaterial.restype = ctypes.c_int
SslExportKeyingMaterial.argtypes = [
    ctypes.c_size_t,  # hSslProvider : NCRYPT_PROV_HANDLE
    ctypes.c_size_t,  # hMasterKey : NCRYPT_KEY_HANDLE
    wintypes.LPCSTR,  # sLabel : LPSTR
    ctypes.POINTER(ctypes.c_ubyte),  # pbRandoms : BYTE* optional
    wintypes.DWORD,  # cbRandoms : DWORD
    ctypes.POINTER(ctypes.c_ubyte),  # pbContextValue : BYTE* optional
    ctypes.c_ushort,  # cbContextValue : WORD
    ctypes.POINTER(ctypes.c_ubyte),  # pbOutput : BYTE* out
    wintypes.DWORD,  # cbOutput : DWORD
    wintypes.DWORD,  # dwFlags : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ncrypt.dll')
SslExportKeyingMaterial = Fiddle::Function.new(
  lib['SslExportKeyingMaterial'],
  [
    Fiddle::TYPE_UINTPTR_T,  # hSslProvider : NCRYPT_PROV_HANDLE
    Fiddle::TYPE_UINTPTR_T,  # hMasterKey : NCRYPT_KEY_HANDLE
    Fiddle::TYPE_VOIDP,  # sLabel : LPSTR
    Fiddle::TYPE_VOIDP,  # pbRandoms : BYTE* optional
    -Fiddle::TYPE_INT,  # cbRandoms : DWORD
    Fiddle::TYPE_VOIDP,  # pbContextValue : BYTE* optional
    -Fiddle::TYPE_SHORT,  # cbContextValue : WORD
    Fiddle::TYPE_VOIDP,  # pbOutput : BYTE* out
    -Fiddle::TYPE_INT,  # cbOutput : DWORD
    -Fiddle::TYPE_INT,  # dwFlags : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "ncrypt")]
extern "system" {
    fn SslExportKeyingMaterial(
        hSslProvider: usize,  // NCRYPT_PROV_HANDLE
        hMasterKey: usize,  // NCRYPT_KEY_HANDLE
        sLabel: *mut u8,  // LPSTR
        pbRandoms: *mut u8,  // BYTE* optional
        cbRandoms: u32,  // DWORD
        pbContextValue: *mut u8,  // BYTE* optional
        cbContextValue: u16,  // WORD
        pbOutput: *mut u8,  // BYTE* out
        cbOutput: u32,  // DWORD
        dwFlags: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("ncrypt.dll")]
public static extern int SslExportKeyingMaterial(UIntPtr hSslProvider, UIntPtr hMasterKey, [MarshalAs(UnmanagedType.LPStr)] string sLabel, IntPtr pbRandoms, uint cbRandoms, IntPtr pbContextValue, ushort cbContextValue, IntPtr pbOutput, uint cbOutput, uint dwFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ncrypt_SslExportKeyingMaterial' -Namespace Win32 -PassThru
# $api::SslExportKeyingMaterial(hSslProvider, hMasterKey, sLabel, pbRandoms, cbRandoms, pbContextValue, cbContextValue, pbOutput, cbOutput, dwFlags)
#uselib "ncrypt.dll"
#func global SslExportKeyingMaterial "SslExportKeyingMaterial" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SslExportKeyingMaterial hSslProvider, hMasterKey, sLabel, varptr(pbRandoms), cbRandoms, varptr(pbContextValue), cbContextValue, varptr(pbOutput), cbOutput, dwFlags   ; 戻り値は stat
; hSslProvider : NCRYPT_PROV_HANDLE -> "sptr"
; hMasterKey : NCRYPT_KEY_HANDLE -> "sptr"
; sLabel : LPSTR -> "sptr"
; pbRandoms : BYTE* optional -> "sptr"
; cbRandoms : DWORD -> "sptr"
; pbContextValue : BYTE* optional -> "sptr"
; cbContextValue : WORD -> "sptr"
; pbOutput : BYTE* out -> "sptr"
; cbOutput : DWORD -> "sptr"
; dwFlags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ncrypt.dll"
#cfunc global SslExportKeyingMaterial "SslExportKeyingMaterial" sptr, sptr, str, var, int, var, int, var, int, int
; res = SslExportKeyingMaterial(hSslProvider, hMasterKey, sLabel, pbRandoms, cbRandoms, pbContextValue, cbContextValue, pbOutput, cbOutput, dwFlags)
; hSslProvider : NCRYPT_PROV_HANDLE -> "sptr"
; hMasterKey : NCRYPT_KEY_HANDLE -> "sptr"
; sLabel : LPSTR -> "str"
; pbRandoms : BYTE* optional -> "var"
; cbRandoms : DWORD -> "int"
; pbContextValue : BYTE* optional -> "var"
; cbContextValue : WORD -> "int"
; pbOutput : BYTE* out -> "var"
; cbOutput : DWORD -> "int"
; dwFlags : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT SslExportKeyingMaterial(NCRYPT_PROV_HANDLE hSslProvider, NCRYPT_KEY_HANDLE hMasterKey, LPSTR sLabel, BYTE* pbRandoms, DWORD cbRandoms, BYTE* pbContextValue, WORD cbContextValue, BYTE* pbOutput, DWORD cbOutput, DWORD dwFlags)
#uselib "ncrypt.dll"
#cfunc global SslExportKeyingMaterial "SslExportKeyingMaterial" intptr, intptr, str, var, int, var, int, var, int, int
; res = SslExportKeyingMaterial(hSslProvider, hMasterKey, sLabel, pbRandoms, cbRandoms, pbContextValue, cbContextValue, pbOutput, cbOutput, dwFlags)
; hSslProvider : NCRYPT_PROV_HANDLE -> "intptr"
; hMasterKey : NCRYPT_KEY_HANDLE -> "intptr"
; sLabel : LPSTR -> "str"
; pbRandoms : BYTE* optional -> "var"
; cbRandoms : DWORD -> "int"
; pbContextValue : BYTE* optional -> "var"
; cbContextValue : WORD -> "int"
; pbOutput : BYTE* out -> "var"
; cbOutput : DWORD -> "int"
; dwFlags : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	ncrypt = windows.NewLazySystemDLL("ncrypt.dll")
	procSslExportKeyingMaterial = ncrypt.NewProc("SslExportKeyingMaterial")
)

// hSslProvider (NCRYPT_PROV_HANDLE), hMasterKey (NCRYPT_KEY_HANDLE), sLabel (LPSTR), pbRandoms (BYTE* optional), cbRandoms (DWORD), pbContextValue (BYTE* optional), cbContextValue (WORD), pbOutput (BYTE* out), cbOutput (DWORD), dwFlags (DWORD)
r1, _, err := procSslExportKeyingMaterial.Call(
	uintptr(hSslProvider),
	uintptr(hMasterKey),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(sLabel))),
	uintptr(pbRandoms),
	uintptr(cbRandoms),
	uintptr(pbContextValue),
	uintptr(cbContextValue),
	uintptr(pbOutput),
	uintptr(cbOutput),
	uintptr(dwFlags),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function SslExportKeyingMaterial(
  hSslProvider: NativeUInt;   // NCRYPT_PROV_HANDLE
  hMasterKey: NativeUInt;   // NCRYPT_KEY_HANDLE
  sLabel: PAnsiChar;   // LPSTR
  pbRandoms: Pointer;   // BYTE* optional
  cbRandoms: DWORD;   // DWORD
  pbContextValue: Pointer;   // BYTE* optional
  cbContextValue: Word;   // WORD
  pbOutput: Pointer;   // BYTE* out
  cbOutput: DWORD;   // DWORD
  dwFlags: DWORD   // DWORD
): Integer; stdcall;
  external 'ncrypt.dll' name 'SslExportKeyingMaterial';
result := DllCall("ncrypt\SslExportKeyingMaterial"
    , "UPtr", hSslProvider   ; NCRYPT_PROV_HANDLE
    , "UPtr", hMasterKey   ; NCRYPT_KEY_HANDLE
    , "AStr", sLabel   ; LPSTR
    , "Ptr", pbRandoms   ; BYTE* optional
    , "UInt", cbRandoms   ; DWORD
    , "Ptr", pbContextValue   ; BYTE* optional
    , "UShort", cbContextValue   ; WORD
    , "Ptr", pbOutput   ; BYTE* out
    , "UInt", cbOutput   ; DWORD
    , "UInt", dwFlags   ; DWORD
    , "Int")   ; return: HRESULT
●SslExportKeyingMaterial(hSslProvider, hMasterKey, sLabel, pbRandoms, cbRandoms, pbContextValue, cbContextValue, pbOutput, cbOutput, dwFlags) = DLL("ncrypt.dll", "int SslExportKeyingMaterial(int, int, char*, void*, dword, void*, int, void*, dword, dword)")
# 呼び出し: SslExportKeyingMaterial(hSslProvider, hMasterKey, sLabel, pbRandoms, cbRandoms, pbContextValue, cbContextValue, pbOutput, cbOutput, dwFlags)
# hSslProvider : NCRYPT_PROV_HANDLE -> "int"
# hMasterKey : NCRYPT_KEY_HANDLE -> "int"
# sLabel : LPSTR -> "char*"
# pbRandoms : BYTE* optional -> "void*"
# cbRandoms : DWORD -> "dword"
# pbContextValue : BYTE* optional -> "void*"
# cbContextValue : WORD -> "int"
# pbOutput : BYTE* out -> "void*"
# cbOutput : DWORD -> "dword"
# dwFlags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。