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

SslComputeEapKeyBlock

関数
SSLマスター鍵からEAP用の鍵ブロックを計算する。
DLLncrypt.dll呼出規約winapi

シグネチャ

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

HRESULT SslComputeEapKeyBlock(
    NCRYPT_PROV_HANDLE hSslProvider,
    NCRYPT_KEY_HANDLE hMasterKey,
    BYTE* pbRandoms,
    DWORD cbRandoms,
    BYTE* pbOutput,   // optional
    DWORD cbOutput,
    DWORD* pcbResult,
    DWORD dwFlags
);

パラメーター

名前方向説明
hSslProviderNCRYPT_PROV_HANDLEinSchannel SSLプロバイダのハンドル。
hMasterKeyNCRYPT_KEY_HANDLEinセッションのマスター鍵ハンドル。
pbRandomsBYTE*inクライアント/サーバランダム値を連結したデータへのポインタ。
cbRandomsDWORDinpbRandomsのバイト数。
pbOutputBYTE*outoptional生成されたEAP鍵ブロックを書き込む出力バッファ。
cbOutputDWORDinpbOutputのバイト数。
pcbResultDWORD*out実際に書き込まれた(または必要な)バイト数を受け取る出力先。
dwFlagsDWORDin動作を制御するフラグ。

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT SslComputeEapKeyBlock(
    NCRYPT_PROV_HANDLE hSslProvider,
    NCRYPT_KEY_HANDLE hMasterKey,
    BYTE* pbRandoms,
    DWORD cbRandoms,
    BYTE* pbOutput,   // optional
    DWORD cbOutput,
    DWORD* pcbResult,
    DWORD dwFlags
);
[DllImport("ncrypt.dll", ExactSpelling = true)]
static extern int SslComputeEapKeyBlock(
    UIntPtr hSslProvider,   // NCRYPT_PROV_HANDLE
    UIntPtr hMasterKey,   // NCRYPT_KEY_HANDLE
    IntPtr pbRandoms,   // BYTE*
    uint cbRandoms,   // DWORD
    IntPtr pbOutput,   // BYTE* optional, out
    uint cbOutput,   // DWORD
    out uint pcbResult,   // DWORD* out
    uint dwFlags   // DWORD
);
<DllImport("ncrypt.dll", ExactSpelling:=True)>
Public Shared Function SslComputeEapKeyBlock(
    hSslProvider As UIntPtr,   ' NCRYPT_PROV_HANDLE
    hMasterKey As UIntPtr,   ' NCRYPT_KEY_HANDLE
    pbRandoms As IntPtr,   ' BYTE*
    cbRandoms As UInteger,   ' DWORD
    pbOutput As IntPtr,   ' BYTE* optional, out
    cbOutput As UInteger,   ' DWORD
    <Out> ByRef pcbResult As UInteger,   ' DWORD* out
    dwFlags As UInteger   ' DWORD
) As Integer
End Function
' hSslProvider : NCRYPT_PROV_HANDLE
' hMasterKey : NCRYPT_KEY_HANDLE
' pbRandoms : BYTE*
' cbRandoms : DWORD
' pbOutput : BYTE* optional, out
' cbOutput : DWORD
' pcbResult : DWORD* out
' dwFlags : DWORD
Declare PtrSafe Function SslComputeEapKeyBlock Lib "ncrypt" ( _
    ByVal hSslProvider As LongPtr, _
    ByVal hMasterKey As LongPtr, _
    ByVal pbRandoms As LongPtr, _
    ByVal cbRandoms As Long, _
    ByVal pbOutput As LongPtr, _
    ByVal cbOutput As Long, _
    ByRef pcbResult 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

SslComputeEapKeyBlock = ctypes.windll.ncrypt.SslComputeEapKeyBlock
SslComputeEapKeyBlock.restype = ctypes.c_int
SslComputeEapKeyBlock.argtypes = [
    ctypes.c_size_t,  # hSslProvider : NCRYPT_PROV_HANDLE
    ctypes.c_size_t,  # hMasterKey : NCRYPT_KEY_HANDLE
    ctypes.POINTER(ctypes.c_ubyte),  # pbRandoms : BYTE*
    wintypes.DWORD,  # cbRandoms : DWORD
    ctypes.POINTER(ctypes.c_ubyte),  # pbOutput : BYTE* optional, out
    wintypes.DWORD,  # cbOutput : DWORD
    ctypes.POINTER(wintypes.DWORD),  # pcbResult : DWORD* out
    wintypes.DWORD,  # dwFlags : DWORD
]
require 'fiddle'
require 'fiddle/import'

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

var (
	ncrypt = windows.NewLazySystemDLL("ncrypt.dll")
	procSslComputeEapKeyBlock = ncrypt.NewProc("SslComputeEapKeyBlock")
)

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

extern "ncrypt" fn SslComputeEapKeyBlock(
    hSslProvider: usize, // NCRYPT_PROV_HANDLE
    hMasterKey: usize, // NCRYPT_KEY_HANDLE
    pbRandoms: [*c]u8, // BYTE*
    cbRandoms: u32, // DWORD
    pbOutput: [*c]u8, // BYTE* optional, out
    cbOutput: u32, // DWORD
    pcbResult: [*c]u32, // DWORD* out
    dwFlags: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;
proc SslComputeEapKeyBlock(
    hSslProvider: uint,  # NCRYPT_PROV_HANDLE
    hMasterKey: uint,  # NCRYPT_KEY_HANDLE
    pbRandoms: ptr uint8,  # BYTE*
    cbRandoms: uint32,  # DWORD
    pbOutput: ptr uint8,  # BYTE* optional, out
    cbOutput: uint32,  # DWORD
    pcbResult: ptr uint32,  # DWORD* out
    dwFlags: uint32  # DWORD
): int32 {.importc: "SslComputeEapKeyBlock", stdcall, dynlib: "ncrypt.dll".}
pragma(lib, "ncrypt");
extern(Windows)
int SslComputeEapKeyBlock(
    size_t hSslProvider,   // NCRYPT_PROV_HANDLE
    size_t hMasterKey,   // NCRYPT_KEY_HANDLE
    ubyte* pbRandoms,   // BYTE*
    uint cbRandoms,   // DWORD
    ubyte* pbOutput,   // BYTE* optional, out
    uint cbOutput,   // DWORD
    uint* pcbResult,   // DWORD* out
    uint dwFlags   // DWORD
);
ccall((:SslComputeEapKeyBlock, "ncrypt.dll"), stdcall, Int32,
      (Csize_t, Csize_t, Ptr{UInt8}, UInt32, Ptr{UInt8}, UInt32, Ptr{UInt32}, UInt32),
      hSslProvider, hMasterKey, pbRandoms, cbRandoms, pbOutput, cbOutput, pcbResult, dwFlags)
# hSslProvider : NCRYPT_PROV_HANDLE -> Csize_t
# hMasterKey : NCRYPT_KEY_HANDLE -> Csize_t
# pbRandoms : BYTE* -> Ptr{UInt8}
# cbRandoms : DWORD -> UInt32
# pbOutput : BYTE* optional, out -> Ptr{UInt8}
# cbOutput : DWORD -> UInt32
# pcbResult : DWORD* out -> Ptr{UInt32}
# dwFlags : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t SslComputeEapKeyBlock(
    uintptr_t hSslProvider,
    uintptr_t hMasterKey,
    uint8_t* pbRandoms,
    uint32_t cbRandoms,
    uint8_t* pbOutput,
    uint32_t cbOutput,
    uint32_t* pcbResult,
    uint32_t dwFlags);
]]
local ncrypt = ffi.load("ncrypt")
-- ncrypt.SslComputeEapKeyBlock(hSslProvider, hMasterKey, pbRandoms, cbRandoms, pbOutput, cbOutput, pcbResult, dwFlags)
-- hSslProvider : NCRYPT_PROV_HANDLE
-- hMasterKey : NCRYPT_KEY_HANDLE
-- pbRandoms : BYTE*
-- cbRandoms : DWORD
-- pbOutput : BYTE* optional, out
-- cbOutput : DWORD
-- pcbResult : DWORD* out
-- dwFlags : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('ncrypt.dll');
const SslComputeEapKeyBlock = lib.func('__stdcall', 'SslComputeEapKeyBlock', 'int32_t', ['uintptr_t', 'uintptr_t', 'uint8_t *', 'uint32_t', 'uint8_t *', 'uint32_t', 'uint32_t *', 'uint32_t']);
// SslComputeEapKeyBlock(hSslProvider, hMasterKey, pbRandoms, cbRandoms, pbOutput, cbOutput, pcbResult, dwFlags)
// hSslProvider : NCRYPT_PROV_HANDLE -> 'uintptr_t'
// hMasterKey : NCRYPT_KEY_HANDLE -> 'uintptr_t'
// pbRandoms : BYTE* -> 'uint8_t *'
// cbRandoms : DWORD -> 'uint32_t'
// pbOutput : BYTE* optional, out -> 'uint8_t *'
// cbOutput : DWORD -> 'uint32_t'
// pcbResult : DWORD* out -> 'uint32_t *'
// dwFlags : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("ncrypt.dll", {
  SslComputeEapKeyBlock: { parameters: ["usize", "usize", "pointer", "u32", "pointer", "u32", "pointer", "u32"], result: "i32" },
});
// lib.symbols.SslComputeEapKeyBlock(hSslProvider, hMasterKey, pbRandoms, cbRandoms, pbOutput, cbOutput, pcbResult, dwFlags)
// hSslProvider : NCRYPT_PROV_HANDLE -> "usize"
// hMasterKey : NCRYPT_KEY_HANDLE -> "usize"
// pbRandoms : BYTE* -> "pointer"
// cbRandoms : DWORD -> "u32"
// pbOutput : BYTE* optional, out -> "pointer"
// cbOutput : DWORD -> "u32"
// pcbResult : DWORD* out -> "pointer"
// dwFlags : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SslComputeEapKeyBlock(
    size_t hSslProvider,
    size_t hMasterKey,
    uint8_t* pbRandoms,
    uint32_t cbRandoms,
    uint8_t* pbOutput,
    uint32_t cbOutput,
    uint32_t* pcbResult,
    uint32_t dwFlags);
C, "ncrypt.dll");
// $ffi->SslComputeEapKeyBlock(hSslProvider, hMasterKey, pbRandoms, cbRandoms, pbOutput, cbOutput, pcbResult, dwFlags);
// hSslProvider : NCRYPT_PROV_HANDLE
// hMasterKey : NCRYPT_KEY_HANDLE
// pbRandoms : BYTE*
// cbRandoms : DWORD
// pbOutput : BYTE* optional, out
// cbOutput : DWORD
// pcbResult : DWORD* 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 Ncrypt extends StdCallLibrary {
    Ncrypt INSTANCE = Native.load("ncrypt", Ncrypt.class);
    int SslComputeEapKeyBlock(
        long hSslProvider,   // NCRYPT_PROV_HANDLE
        long hMasterKey,   // NCRYPT_KEY_HANDLE
        byte[] pbRandoms,   // BYTE*
        int cbRandoms,   // DWORD
        byte[] pbOutput,   // BYTE* optional, out
        int cbOutput,   // DWORD
        IntByReference pcbResult,   // DWORD* out
        int dwFlags   // DWORD
    );
}
@[Link("ncrypt")]
lib Libncrypt
  fun SslComputeEapKeyBlock = SslComputeEapKeyBlock(
    hSslProvider : LibC::SizeT,   # NCRYPT_PROV_HANDLE
    hMasterKey : LibC::SizeT,   # NCRYPT_KEY_HANDLE
    pbRandoms : UInt8*,   # BYTE*
    cbRandoms : UInt32,   # DWORD
    pbOutput : UInt8*,   # BYTE* optional, out
    cbOutput : UInt32,   # DWORD
    pcbResult : UInt32*,   # DWORD* 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 SslComputeEapKeyBlockNative = Int32 Function(UintPtr, UintPtr, Pointer<Uint8>, Uint32, Pointer<Uint8>, Uint32, Pointer<Uint32>, Uint32);
typedef SslComputeEapKeyBlockDart = int Function(int, int, Pointer<Uint8>, int, Pointer<Uint8>, int, Pointer<Uint32>, int);
final SslComputeEapKeyBlock = DynamicLibrary.open('ncrypt.dll')
    .lookupFunction<SslComputeEapKeyBlockNative, SslComputeEapKeyBlockDart>('SslComputeEapKeyBlock');
// hSslProvider : NCRYPT_PROV_HANDLE -> UintPtr
// hMasterKey : NCRYPT_KEY_HANDLE -> UintPtr
// pbRandoms : BYTE* -> Pointer<Uint8>
// cbRandoms : DWORD -> Uint32
// pbOutput : BYTE* optional, out -> Pointer<Uint8>
// cbOutput : DWORD -> Uint32
// pcbResult : DWORD* out -> Pointer<Uint32>
// dwFlags : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SslComputeEapKeyBlock(
  hSslProvider: NativeUInt;   // NCRYPT_PROV_HANDLE
  hMasterKey: NativeUInt;   // NCRYPT_KEY_HANDLE
  pbRandoms: Pointer;   // BYTE*
  cbRandoms: DWORD;   // DWORD
  pbOutput: Pointer;   // BYTE* optional, out
  cbOutput: DWORD;   // DWORD
  pcbResult: Pointer;   // DWORD* out
  dwFlags: DWORD   // DWORD
): Integer; stdcall;
  external 'ncrypt.dll' name 'SslComputeEapKeyBlock';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SslComputeEapKeyBlock"
  c_SslComputeEapKeyBlock :: CUIntPtr -> CUIntPtr -> Ptr Word8 -> Word32 -> Ptr Word8 -> Word32 -> Ptr Word32 -> Word32 -> IO Int32
-- hSslProvider : NCRYPT_PROV_HANDLE -> CUIntPtr
-- hMasterKey : NCRYPT_KEY_HANDLE -> CUIntPtr
-- pbRandoms : BYTE* -> Ptr Word8
-- cbRandoms : DWORD -> Word32
-- pbOutput : BYTE* optional, out -> Ptr Word8
-- cbOutput : DWORD -> Word32
-- pcbResult : DWORD* out -> Ptr Word32
-- dwFlags : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let sslcomputeeapkeyblock =
  foreign "SslComputeEapKeyBlock"
    (size_t @-> size_t @-> (ptr uint8_t) @-> uint32_t @-> (ptr uint8_t) @-> uint32_t @-> (ptr uint32_t) @-> uint32_t @-> returning int32_t)
(* hSslProvider : NCRYPT_PROV_HANDLE -> size_t *)
(* hMasterKey : NCRYPT_KEY_HANDLE -> size_t *)
(* pbRandoms : BYTE* -> (ptr uint8_t) *)
(* cbRandoms : DWORD -> uint32_t *)
(* pbOutput : BYTE* optional, out -> (ptr uint8_t) *)
(* cbOutput : DWORD -> uint32_t *)
(* pcbResult : DWORD* out -> (ptr uint32_t) *)
(* dwFlags : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library ncrypt (t "ncrypt.dll"))
(cffi:use-foreign-library ncrypt)

(cffi:defcfun ("SslComputeEapKeyBlock" ssl-compute-eap-key-block :convention :stdcall) :int32
  (h-ssl-provider :uint64)   ; NCRYPT_PROV_HANDLE
  (h-master-key :uint64)   ; NCRYPT_KEY_HANDLE
  (pb-randoms :pointer)   ; BYTE*
  (cb-randoms :uint32)   ; DWORD
  (pb-output :pointer)   ; BYTE* optional, out
  (cb-output :uint32)   ; DWORD
  (pcb-result :pointer)   ; DWORD* out
  (dw-flags :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SslComputeEapKeyBlock = Win32::API::More->new('ncrypt',
    'int SslComputeEapKeyBlock(WPARAM hSslProvider, WPARAM hMasterKey, LPVOID pbRandoms, DWORD cbRandoms, LPVOID pbOutput, DWORD cbOutput, LPVOID pcbResult, DWORD dwFlags)');
# my $ret = $SslComputeEapKeyBlock->Call($hSslProvider, $hMasterKey, $pbRandoms, $cbRandoms, $pbOutput, $cbOutput, $pcbResult, $dwFlags);
# hSslProvider : NCRYPT_PROV_HANDLE -> WPARAM
# hMasterKey : NCRYPT_KEY_HANDLE -> WPARAM
# pbRandoms : BYTE* -> LPVOID
# cbRandoms : DWORD -> DWORD
# pbOutput : BYTE* optional, out -> LPVOID
# cbOutput : DWORD -> DWORD
# pcbResult : DWORD* out -> LPVOID
# dwFlags : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。