ホーム › Security.Cryptography › SslLookupCipherLengths
SslLookupCipherLengths
関数指定暗号スイートの鍵やMACなどの長さ情報を取得する。
シグネチャ
// ncrypt.dll
#include <windows.h>
HRESULT SslLookupCipherLengths(
NCRYPT_PROV_HANDLE hSslProvider,
DWORD dwProtocol,
DWORD dwCipherSuite,
DWORD dwKeyType,
NCRYPT_SSL_CIPHER_LENGTHS* pCipherLengths,
DWORD cbCipherLengths,
DWORD dwFlags
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hSslProvider | NCRYPT_PROV_HANDLE | in | Schannel SSLプロバイダのハンドル。 |
| dwProtocol | DWORD | in | 対象のSSL/TLSプロトコルバージョンを示す値。 |
| dwCipherSuite | DWORD | in | 対象の暗号スイートを示す値。 |
| dwKeyType | DWORD | in | 鍵の種類を示す値。 |
| pCipherLengths | NCRYPT_SSL_CIPHER_LENGTHS* | out | 取得した暗号スイートの各種長さ情報を格納するNCRYPT_SSL_CIPHER_LENGTHS。 |
| cbCipherLengths | DWORD | in | pCipherLengths構造体のバイト数。 |
| dwFlags | DWORD | in | 動作を制御するフラグ。 |
戻り値の型: HRESULT
各言語での呼び出し定義
// ncrypt.dll
#include <windows.h>
HRESULT SslLookupCipherLengths(
NCRYPT_PROV_HANDLE hSslProvider,
DWORD dwProtocol,
DWORD dwCipherSuite,
DWORD dwKeyType,
NCRYPT_SSL_CIPHER_LENGTHS* pCipherLengths,
DWORD cbCipherLengths,
DWORD dwFlags
);[DllImport("ncrypt.dll", ExactSpelling = true)]
static extern int SslLookupCipherLengths(
UIntPtr hSslProvider, // NCRYPT_PROV_HANDLE
uint dwProtocol, // DWORD
uint dwCipherSuite, // DWORD
uint dwKeyType, // DWORD
IntPtr pCipherLengths, // NCRYPT_SSL_CIPHER_LENGTHS* out
uint cbCipherLengths, // DWORD
uint dwFlags // DWORD
);<DllImport("ncrypt.dll", ExactSpelling:=True)>
Public Shared Function SslLookupCipherLengths(
hSslProvider As UIntPtr, ' NCRYPT_PROV_HANDLE
dwProtocol As UInteger, ' DWORD
dwCipherSuite As UInteger, ' DWORD
dwKeyType As UInteger, ' DWORD
pCipherLengths As IntPtr, ' NCRYPT_SSL_CIPHER_LENGTHS* out
cbCipherLengths As UInteger, ' DWORD
dwFlags As UInteger ' DWORD
) As Integer
End Function' hSslProvider : NCRYPT_PROV_HANDLE
' dwProtocol : DWORD
' dwCipherSuite : DWORD
' dwKeyType : DWORD
' pCipherLengths : NCRYPT_SSL_CIPHER_LENGTHS* out
' cbCipherLengths : DWORD
' dwFlags : DWORD
Declare PtrSafe Function SslLookupCipherLengths Lib "ncrypt" ( _
ByVal hSslProvider As LongPtr, _
ByVal dwProtocol As Long, _
ByVal dwCipherSuite As Long, _
ByVal dwKeyType As Long, _
ByVal pCipherLengths As LongPtr, _
ByVal cbCipherLengths 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
SslLookupCipherLengths = ctypes.windll.ncrypt.SslLookupCipherLengths
SslLookupCipherLengths.restype = ctypes.c_int
SslLookupCipherLengths.argtypes = [
ctypes.c_size_t, # hSslProvider : NCRYPT_PROV_HANDLE
wintypes.DWORD, # dwProtocol : DWORD
wintypes.DWORD, # dwCipherSuite : DWORD
wintypes.DWORD, # dwKeyType : DWORD
ctypes.c_void_p, # pCipherLengths : NCRYPT_SSL_CIPHER_LENGTHS* out
wintypes.DWORD, # cbCipherLengths : DWORD
wintypes.DWORD, # dwFlags : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ncrypt.dll')
SslLookupCipherLengths = Fiddle::Function.new(
lib['SslLookupCipherLengths'],
[
Fiddle::TYPE_UINTPTR_T, # hSslProvider : NCRYPT_PROV_HANDLE
-Fiddle::TYPE_INT, # dwProtocol : DWORD
-Fiddle::TYPE_INT, # dwCipherSuite : DWORD
-Fiddle::TYPE_INT, # dwKeyType : DWORD
Fiddle::TYPE_VOIDP, # pCipherLengths : NCRYPT_SSL_CIPHER_LENGTHS* out
-Fiddle::TYPE_INT, # cbCipherLengths : DWORD
-Fiddle::TYPE_INT, # dwFlags : DWORD
],
Fiddle::TYPE_INT)#[link(name = "ncrypt")]
extern "system" {
fn SslLookupCipherLengths(
hSslProvider: usize, // NCRYPT_PROV_HANDLE
dwProtocol: u32, // DWORD
dwCipherSuite: u32, // DWORD
dwKeyType: u32, // DWORD
pCipherLengths: *mut NCRYPT_SSL_CIPHER_LENGTHS, // NCRYPT_SSL_CIPHER_LENGTHS* out
cbCipherLengths: u32, // DWORD
dwFlags: u32 // DWORD
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("ncrypt.dll")]
public static extern int SslLookupCipherLengths(UIntPtr hSslProvider, uint dwProtocol, uint dwCipherSuite, uint dwKeyType, IntPtr pCipherLengths, uint cbCipherLengths, uint dwFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ncrypt_SslLookupCipherLengths' -Namespace Win32 -PassThru
# $api::SslLookupCipherLengths(hSslProvider, dwProtocol, dwCipherSuite, dwKeyType, pCipherLengths, cbCipherLengths, dwFlags)#uselib "ncrypt.dll"
#func global SslLookupCipherLengths "SslLookupCipherLengths" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SslLookupCipherLengths hSslProvider, dwProtocol, dwCipherSuite, dwKeyType, varptr(pCipherLengths), cbCipherLengths, dwFlags ; 戻り値は stat
; hSslProvider : NCRYPT_PROV_HANDLE -> "sptr"
; dwProtocol : DWORD -> "sptr"
; dwCipherSuite : DWORD -> "sptr"
; dwKeyType : DWORD -> "sptr"
; pCipherLengths : NCRYPT_SSL_CIPHER_LENGTHS* out -> "sptr"
; cbCipherLengths : DWORD -> "sptr"
; dwFlags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "ncrypt.dll" #cfunc global SslLookupCipherLengths "SslLookupCipherLengths" sptr, int, int, int, var, int, int ; res = SslLookupCipherLengths(hSslProvider, dwProtocol, dwCipherSuite, dwKeyType, pCipherLengths, cbCipherLengths, dwFlags) ; hSslProvider : NCRYPT_PROV_HANDLE -> "sptr" ; dwProtocol : DWORD -> "int" ; dwCipherSuite : DWORD -> "int" ; dwKeyType : DWORD -> "int" ; pCipherLengths : NCRYPT_SSL_CIPHER_LENGTHS* out -> "var" ; cbCipherLengths : DWORD -> "int" ; dwFlags : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ncrypt.dll" #cfunc global SslLookupCipherLengths "SslLookupCipherLengths" sptr, int, int, int, sptr, int, int ; res = SslLookupCipherLengths(hSslProvider, dwProtocol, dwCipherSuite, dwKeyType, varptr(pCipherLengths), cbCipherLengths, dwFlags) ; hSslProvider : NCRYPT_PROV_HANDLE -> "sptr" ; dwProtocol : DWORD -> "int" ; dwCipherSuite : DWORD -> "int" ; dwKeyType : DWORD -> "int" ; pCipherLengths : NCRYPT_SSL_CIPHER_LENGTHS* out -> "sptr" ; cbCipherLengths : DWORD -> "int" ; dwFlags : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT SslLookupCipherLengths(NCRYPT_PROV_HANDLE hSslProvider, DWORD dwProtocol, DWORD dwCipherSuite, DWORD dwKeyType, NCRYPT_SSL_CIPHER_LENGTHS* pCipherLengths, DWORD cbCipherLengths, DWORD dwFlags) #uselib "ncrypt.dll" #cfunc global SslLookupCipherLengths "SslLookupCipherLengths" intptr, int, int, int, var, int, int ; res = SslLookupCipherLengths(hSslProvider, dwProtocol, dwCipherSuite, dwKeyType, pCipherLengths, cbCipherLengths, dwFlags) ; hSslProvider : NCRYPT_PROV_HANDLE -> "intptr" ; dwProtocol : DWORD -> "int" ; dwCipherSuite : DWORD -> "int" ; dwKeyType : DWORD -> "int" ; pCipherLengths : NCRYPT_SSL_CIPHER_LENGTHS* out -> "var" ; cbCipherLengths : DWORD -> "int" ; dwFlags : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT SslLookupCipherLengths(NCRYPT_PROV_HANDLE hSslProvider, DWORD dwProtocol, DWORD dwCipherSuite, DWORD dwKeyType, NCRYPT_SSL_CIPHER_LENGTHS* pCipherLengths, DWORD cbCipherLengths, DWORD dwFlags) #uselib "ncrypt.dll" #cfunc global SslLookupCipherLengths "SslLookupCipherLengths" intptr, int, int, int, intptr, int, int ; res = SslLookupCipherLengths(hSslProvider, dwProtocol, dwCipherSuite, dwKeyType, varptr(pCipherLengths), cbCipherLengths, dwFlags) ; hSslProvider : NCRYPT_PROV_HANDLE -> "intptr" ; dwProtocol : DWORD -> "int" ; dwCipherSuite : DWORD -> "int" ; dwKeyType : DWORD -> "int" ; pCipherLengths : NCRYPT_SSL_CIPHER_LENGTHS* out -> "intptr" ; cbCipherLengths : DWORD -> "int" ; dwFlags : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
ncrypt = windows.NewLazySystemDLL("ncrypt.dll")
procSslLookupCipherLengths = ncrypt.NewProc("SslLookupCipherLengths")
)
// hSslProvider (NCRYPT_PROV_HANDLE), dwProtocol (DWORD), dwCipherSuite (DWORD), dwKeyType (DWORD), pCipherLengths (NCRYPT_SSL_CIPHER_LENGTHS* out), cbCipherLengths (DWORD), dwFlags (DWORD)
r1, _, err := procSslLookupCipherLengths.Call(
uintptr(hSslProvider),
uintptr(dwProtocol),
uintptr(dwCipherSuite),
uintptr(dwKeyType),
uintptr(pCipherLengths),
uintptr(cbCipherLengths),
uintptr(dwFlags),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction SslLookupCipherLengths(
hSslProvider: NativeUInt; // NCRYPT_PROV_HANDLE
dwProtocol: DWORD; // DWORD
dwCipherSuite: DWORD; // DWORD
dwKeyType: DWORD; // DWORD
pCipherLengths: Pointer; // NCRYPT_SSL_CIPHER_LENGTHS* out
cbCipherLengths: DWORD; // DWORD
dwFlags: DWORD // DWORD
): Integer; stdcall;
external 'ncrypt.dll' name 'SslLookupCipherLengths';result := DllCall("ncrypt\SslLookupCipherLengths"
, "UPtr", hSslProvider ; NCRYPT_PROV_HANDLE
, "UInt", dwProtocol ; DWORD
, "UInt", dwCipherSuite ; DWORD
, "UInt", dwKeyType ; DWORD
, "Ptr", pCipherLengths ; NCRYPT_SSL_CIPHER_LENGTHS* out
, "UInt", cbCipherLengths ; DWORD
, "UInt", dwFlags ; DWORD
, "Int") ; return: HRESULT●SslLookupCipherLengths(hSslProvider, dwProtocol, dwCipherSuite, dwKeyType, pCipherLengths, cbCipherLengths, dwFlags) = DLL("ncrypt.dll", "int SslLookupCipherLengths(int, dword, dword, dword, void*, dword, dword)")
# 呼び出し: SslLookupCipherLengths(hSslProvider, dwProtocol, dwCipherSuite, dwKeyType, pCipherLengths, cbCipherLengths, dwFlags)
# hSslProvider : NCRYPT_PROV_HANDLE -> "int"
# dwProtocol : DWORD -> "dword"
# dwCipherSuite : DWORD -> "dword"
# dwKeyType : DWORD -> "dword"
# pCipherLengths : NCRYPT_SSL_CIPHER_LENGTHS* out -> "void*"
# cbCipherLengths : DWORD -> "dword"
# dwFlags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "ncrypt" fn SslLookupCipherLengths(
hSslProvider: usize, // NCRYPT_PROV_HANDLE
dwProtocol: u32, // DWORD
dwCipherSuite: u32, // DWORD
dwKeyType: u32, // DWORD
pCipherLengths: [*c]NCRYPT_SSL_CIPHER_LENGTHS, // NCRYPT_SSL_CIPHER_LENGTHS* out
cbCipherLengths: u32, // DWORD
dwFlags: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;proc SslLookupCipherLengths(
hSslProvider: uint, # NCRYPT_PROV_HANDLE
dwProtocol: uint32, # DWORD
dwCipherSuite: uint32, # DWORD
dwKeyType: uint32, # DWORD
pCipherLengths: ptr NCRYPT_SSL_CIPHER_LENGTHS, # NCRYPT_SSL_CIPHER_LENGTHS* out
cbCipherLengths: uint32, # DWORD
dwFlags: uint32 # DWORD
): int32 {.importc: "SslLookupCipherLengths", stdcall, dynlib: "ncrypt.dll".}pragma(lib, "ncrypt");
extern(Windows)
int SslLookupCipherLengths(
size_t hSslProvider, // NCRYPT_PROV_HANDLE
uint dwProtocol, // DWORD
uint dwCipherSuite, // DWORD
uint dwKeyType, // DWORD
NCRYPT_SSL_CIPHER_LENGTHS* pCipherLengths, // NCRYPT_SSL_CIPHER_LENGTHS* out
uint cbCipherLengths, // DWORD
uint dwFlags // DWORD
);ccall((:SslLookupCipherLengths, "ncrypt.dll"), stdcall, Int32,
(Csize_t, UInt32, UInt32, UInt32, Ptr{NCRYPT_SSL_CIPHER_LENGTHS}, UInt32, UInt32),
hSslProvider, dwProtocol, dwCipherSuite, dwKeyType, pCipherLengths, cbCipherLengths, dwFlags)
# hSslProvider : NCRYPT_PROV_HANDLE -> Csize_t
# dwProtocol : DWORD -> UInt32
# dwCipherSuite : DWORD -> UInt32
# dwKeyType : DWORD -> UInt32
# pCipherLengths : NCRYPT_SSL_CIPHER_LENGTHS* out -> Ptr{NCRYPT_SSL_CIPHER_LENGTHS}
# cbCipherLengths : DWORD -> UInt32
# dwFlags : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SslLookupCipherLengths(
uintptr_t hSslProvider,
uint32_t dwProtocol,
uint32_t dwCipherSuite,
uint32_t dwKeyType,
void* pCipherLengths,
uint32_t cbCipherLengths,
uint32_t dwFlags);
]]
local ncrypt = ffi.load("ncrypt")
-- ncrypt.SslLookupCipherLengths(hSslProvider, dwProtocol, dwCipherSuite, dwKeyType, pCipherLengths, cbCipherLengths, dwFlags)
-- hSslProvider : NCRYPT_PROV_HANDLE
-- dwProtocol : DWORD
-- dwCipherSuite : DWORD
-- dwKeyType : DWORD
-- pCipherLengths : NCRYPT_SSL_CIPHER_LENGTHS* out
-- cbCipherLengths : DWORD
-- dwFlags : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('ncrypt.dll');
const SslLookupCipherLengths = lib.func('__stdcall', 'SslLookupCipherLengths', 'int32_t', ['uintptr_t', 'uint32_t', 'uint32_t', 'uint32_t', 'void *', 'uint32_t', 'uint32_t']);
// SslLookupCipherLengths(hSslProvider, dwProtocol, dwCipherSuite, dwKeyType, pCipherLengths, cbCipherLengths, dwFlags)
// hSslProvider : NCRYPT_PROV_HANDLE -> 'uintptr_t'
// dwProtocol : DWORD -> 'uint32_t'
// dwCipherSuite : DWORD -> 'uint32_t'
// dwKeyType : DWORD -> 'uint32_t'
// pCipherLengths : NCRYPT_SSL_CIPHER_LENGTHS* out -> 'void *'
// cbCipherLengths : DWORD -> 'uint32_t'
// dwFlags : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ncrypt.dll", {
SslLookupCipherLengths: { parameters: ["usize", "u32", "u32", "u32", "pointer", "u32", "u32"], result: "i32" },
});
// lib.symbols.SslLookupCipherLengths(hSslProvider, dwProtocol, dwCipherSuite, dwKeyType, pCipherLengths, cbCipherLengths, dwFlags)
// hSslProvider : NCRYPT_PROV_HANDLE -> "usize"
// dwProtocol : DWORD -> "u32"
// dwCipherSuite : DWORD -> "u32"
// dwKeyType : DWORD -> "u32"
// pCipherLengths : NCRYPT_SSL_CIPHER_LENGTHS* out -> "pointer"
// cbCipherLengths : DWORD -> "u32"
// dwFlags : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SslLookupCipherLengths(
size_t hSslProvider,
uint32_t dwProtocol,
uint32_t dwCipherSuite,
uint32_t dwKeyType,
void* pCipherLengths,
uint32_t cbCipherLengths,
uint32_t dwFlags);
C, "ncrypt.dll");
// $ffi->SslLookupCipherLengths(hSslProvider, dwProtocol, dwCipherSuite, dwKeyType, pCipherLengths, cbCipherLengths, dwFlags);
// hSslProvider : NCRYPT_PROV_HANDLE
// dwProtocol : DWORD
// dwCipherSuite : DWORD
// dwKeyType : DWORD
// pCipherLengths : NCRYPT_SSL_CIPHER_LENGTHS* out
// cbCipherLengths : DWORD
// 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 SslLookupCipherLengths(
long hSslProvider, // NCRYPT_PROV_HANDLE
int dwProtocol, // DWORD
int dwCipherSuite, // DWORD
int dwKeyType, // DWORD
Pointer pCipherLengths, // NCRYPT_SSL_CIPHER_LENGTHS* out
int cbCipherLengths, // DWORD
int dwFlags // DWORD
);
}@[Link("ncrypt")]
lib Libncrypt
fun SslLookupCipherLengths = SslLookupCipherLengths(
hSslProvider : LibC::SizeT, # NCRYPT_PROV_HANDLE
dwProtocol : UInt32, # DWORD
dwCipherSuite : UInt32, # DWORD
dwKeyType : UInt32, # DWORD
pCipherLengths : NCRYPT_SSL_CIPHER_LENGTHS*, # NCRYPT_SSL_CIPHER_LENGTHS* out
cbCipherLengths : UInt32, # DWORD
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 SslLookupCipherLengthsNative = Int32 Function(UintPtr, Uint32, Uint32, Uint32, Pointer<Void>, Uint32, Uint32);
typedef SslLookupCipherLengthsDart = int Function(int, int, int, int, Pointer<Void>, int, int);
final SslLookupCipherLengths = DynamicLibrary.open('ncrypt.dll')
.lookupFunction<SslLookupCipherLengthsNative, SslLookupCipherLengthsDart>('SslLookupCipherLengths');
// hSslProvider : NCRYPT_PROV_HANDLE -> UintPtr
// dwProtocol : DWORD -> Uint32
// dwCipherSuite : DWORD -> Uint32
// dwKeyType : DWORD -> Uint32
// pCipherLengths : NCRYPT_SSL_CIPHER_LENGTHS* out -> Pointer<Void>
// cbCipherLengths : DWORD -> Uint32
// dwFlags : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SslLookupCipherLengths(
hSslProvider: NativeUInt; // NCRYPT_PROV_HANDLE
dwProtocol: DWORD; // DWORD
dwCipherSuite: DWORD; // DWORD
dwKeyType: DWORD; // DWORD
pCipherLengths: Pointer; // NCRYPT_SSL_CIPHER_LENGTHS* out
cbCipherLengths: DWORD; // DWORD
dwFlags: DWORD // DWORD
): Integer; stdcall;
external 'ncrypt.dll' name 'SslLookupCipherLengths';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SslLookupCipherLengths"
c_SslLookupCipherLengths :: CUIntPtr -> Word32 -> Word32 -> Word32 -> Ptr () -> Word32 -> Word32 -> IO Int32
-- hSslProvider : NCRYPT_PROV_HANDLE -> CUIntPtr
-- dwProtocol : DWORD -> Word32
-- dwCipherSuite : DWORD -> Word32
-- dwKeyType : DWORD -> Word32
-- pCipherLengths : NCRYPT_SSL_CIPHER_LENGTHS* out -> Ptr ()
-- cbCipherLengths : DWORD -> Word32
-- dwFlags : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let ssllookupcipherlengths =
foreign "SslLookupCipherLengths"
(size_t @-> uint32_t @-> uint32_t @-> uint32_t @-> (ptr void) @-> uint32_t @-> uint32_t @-> returning int32_t)
(* hSslProvider : NCRYPT_PROV_HANDLE -> size_t *)
(* dwProtocol : DWORD -> uint32_t *)
(* dwCipherSuite : DWORD -> uint32_t *)
(* dwKeyType : DWORD -> uint32_t *)
(* pCipherLengths : NCRYPT_SSL_CIPHER_LENGTHS* out -> (ptr void) *)
(* cbCipherLengths : DWORD -> 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 ("SslLookupCipherLengths" ssl-lookup-cipher-lengths :convention :stdcall) :int32
(h-ssl-provider :uint64) ; NCRYPT_PROV_HANDLE
(dw-protocol :uint32) ; DWORD
(dw-cipher-suite :uint32) ; DWORD
(dw-key-type :uint32) ; DWORD
(p-cipher-lengths :pointer) ; NCRYPT_SSL_CIPHER_LENGTHS* out
(cb-cipher-lengths :uint32) ; DWORD
(dw-flags :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SslLookupCipherLengths = Win32::API::More->new('ncrypt',
'int SslLookupCipherLengths(WPARAM hSslProvider, DWORD dwProtocol, DWORD dwCipherSuite, DWORD dwKeyType, LPVOID pCipherLengths, DWORD cbCipherLengths, DWORD dwFlags)');
# my $ret = $SslLookupCipherLengths->Call($hSslProvider, $dwProtocol, $dwCipherSuite, $dwKeyType, $pCipherLengths, $cbCipherLengths, $dwFlags);
# hSslProvider : NCRYPT_PROV_HANDLE -> WPARAM
# dwProtocol : DWORD -> DWORD
# dwCipherSuite : DWORD -> DWORD
# dwKeyType : DWORD -> DWORD
# pCipherLengths : NCRYPT_SSL_CIPHER_LENGTHS* out -> LPVOID
# cbCipherLengths : DWORD -> DWORD
# dwFlags : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。