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

BCryptAddContextFunctionProvider

関数
CNGコンテキストの関数にプロバイダーを追加する。
DLLbcrypt.dll呼出規約winapi

シグネチャ

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

NTSTATUS BCryptAddContextFunctionProvider(
    DWORD dwTable,
    LPCWSTR pszContext,
    DWORD dwInterface,
    LPCWSTR pszFunction,
    LPCWSTR pszProvider,
    DWORD dwPosition
);

パラメーター

名前方向説明
dwTableDWORDin対象の構成テーブルを示す値(CRYPT_LOCAL等)。
pszContextLPCWSTRin対象のコンテキスト名。
dwInterfaceDWORDin対象のインターフェイス識別子(暗号/署名等)。
pszFunctionLPCWSTRin関数(アルゴリズム)名。
pszProviderLPCWSTRin関連付けるプロバイダ名。
dwPositionDWORDinプロバイダ一覧内の挿入位置。CRYPT_PRIORITY_TOP/BOTTOM等。

戻り値の型: NTSTATUS

各言語での呼び出し定義

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

NTSTATUS BCryptAddContextFunctionProvider(
    DWORD dwTable,
    LPCWSTR pszContext,
    DWORD dwInterface,
    LPCWSTR pszFunction,
    LPCWSTR pszProvider,
    DWORD dwPosition
);
[DllImport("bcrypt.dll", ExactSpelling = true)]
static extern int BCryptAddContextFunctionProvider(
    uint dwTable,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] string pszContext,   // LPCWSTR
    uint dwInterface,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] string pszFunction,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string pszProvider,   // LPCWSTR
    uint dwPosition   // DWORD
);
<DllImport("bcrypt.dll", ExactSpelling:=True)>
Public Shared Function BCryptAddContextFunctionProvider(
    dwTable As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> pszContext As String,   ' LPCWSTR
    dwInterface As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> pszFunction As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> pszProvider As String,   ' LPCWSTR
    dwPosition As UInteger   ' DWORD
) As Integer
End Function
' dwTable : DWORD
' pszContext : LPCWSTR
' dwInterface : DWORD
' pszFunction : LPCWSTR
' pszProvider : LPCWSTR
' dwPosition : DWORD
Declare PtrSafe Function BCryptAddContextFunctionProvider Lib "bcrypt" ( _
    ByVal dwTable As Long, _
    ByVal pszContext As LongPtr, _
    ByVal dwInterface As Long, _
    ByVal pszFunction As LongPtr, _
    ByVal pszProvider As LongPtr, _
    ByVal dwPosition As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

BCryptAddContextFunctionProvider = ctypes.windll.bcrypt.BCryptAddContextFunctionProvider
BCryptAddContextFunctionProvider.restype = ctypes.c_int
BCryptAddContextFunctionProvider.argtypes = [
    wintypes.DWORD,  # dwTable : DWORD
    wintypes.LPCWSTR,  # pszContext : LPCWSTR
    wintypes.DWORD,  # dwInterface : DWORD
    wintypes.LPCWSTR,  # pszFunction : LPCWSTR
    wintypes.LPCWSTR,  # pszProvider : LPCWSTR
    wintypes.DWORD,  # dwPosition : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('bcrypt.dll')
BCryptAddContextFunctionProvider = Fiddle::Function.new(
  lib['BCryptAddContextFunctionProvider'],
  [
    -Fiddle::TYPE_INT,  # dwTable : DWORD
    Fiddle::TYPE_VOIDP,  # pszContext : LPCWSTR
    -Fiddle::TYPE_INT,  # dwInterface : DWORD
    Fiddle::TYPE_VOIDP,  # pszFunction : LPCWSTR
    Fiddle::TYPE_VOIDP,  # pszProvider : LPCWSTR
    -Fiddle::TYPE_INT,  # dwPosition : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "bcrypt")]
extern "system" {
    fn BCryptAddContextFunctionProvider(
        dwTable: u32,  // DWORD
        pszContext: *const u16,  // LPCWSTR
        dwInterface: u32,  // DWORD
        pszFunction: *const u16,  // LPCWSTR
        pszProvider: *const u16,  // LPCWSTR
        dwPosition: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("bcrypt.dll")]
public static extern int BCryptAddContextFunctionProvider(uint dwTable, [MarshalAs(UnmanagedType.LPWStr)] string pszContext, uint dwInterface, [MarshalAs(UnmanagedType.LPWStr)] string pszFunction, [MarshalAs(UnmanagedType.LPWStr)] string pszProvider, uint dwPosition);
"@
$api = Add-Type -MemberDefinition $sig -Name 'bcrypt_BCryptAddContextFunctionProvider' -Namespace Win32 -PassThru
# $api::BCryptAddContextFunctionProvider(dwTable, pszContext, dwInterface, pszFunction, pszProvider, dwPosition)
#uselib "bcrypt.dll"
#func global BCryptAddContextFunctionProvider "BCryptAddContextFunctionProvider" sptr, sptr, sptr, sptr, sptr, sptr
; BCryptAddContextFunctionProvider dwTable, pszContext, dwInterface, pszFunction, pszProvider, dwPosition   ; 戻り値は stat
; dwTable : DWORD -> "sptr"
; pszContext : LPCWSTR -> "sptr"
; dwInterface : DWORD -> "sptr"
; pszFunction : LPCWSTR -> "sptr"
; pszProvider : LPCWSTR -> "sptr"
; dwPosition : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "bcrypt.dll"
#cfunc global BCryptAddContextFunctionProvider "BCryptAddContextFunctionProvider" int, wstr, int, wstr, wstr, int
; res = BCryptAddContextFunctionProvider(dwTable, pszContext, dwInterface, pszFunction, pszProvider, dwPosition)
; dwTable : DWORD -> "int"
; pszContext : LPCWSTR -> "wstr"
; dwInterface : DWORD -> "int"
; pszFunction : LPCWSTR -> "wstr"
; pszProvider : LPCWSTR -> "wstr"
; dwPosition : DWORD -> "int"
; NTSTATUS BCryptAddContextFunctionProvider(DWORD dwTable, LPCWSTR pszContext, DWORD dwInterface, LPCWSTR pszFunction, LPCWSTR pszProvider, DWORD dwPosition)
#uselib "bcrypt.dll"
#cfunc global BCryptAddContextFunctionProvider "BCryptAddContextFunctionProvider" int, wstr, int, wstr, wstr, int
; res = BCryptAddContextFunctionProvider(dwTable, pszContext, dwInterface, pszFunction, pszProvider, dwPosition)
; dwTable : DWORD -> "int"
; pszContext : LPCWSTR -> "wstr"
; dwInterface : DWORD -> "int"
; pszFunction : LPCWSTR -> "wstr"
; pszProvider : LPCWSTR -> "wstr"
; dwPosition : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	bcrypt = windows.NewLazySystemDLL("bcrypt.dll")
	procBCryptAddContextFunctionProvider = bcrypt.NewProc("BCryptAddContextFunctionProvider")
)

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

extern "bcrypt" fn BCryptAddContextFunctionProvider(
    dwTable: u32, // DWORD
    pszContext: [*c]const u16, // LPCWSTR
    dwInterface: u32, // DWORD
    pszFunction: [*c]const u16, // LPCWSTR
    pszProvider: [*c]const u16, // LPCWSTR
    dwPosition: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;
proc BCryptAddContextFunctionProvider(
    dwTable: uint32,  # DWORD
    pszContext: WideCString,  # LPCWSTR
    dwInterface: uint32,  # DWORD
    pszFunction: WideCString,  # LPCWSTR
    pszProvider: WideCString,  # LPCWSTR
    dwPosition: uint32  # DWORD
): int32 {.importc: "BCryptAddContextFunctionProvider", stdcall, dynlib: "bcrypt.dll".}
pragma(lib, "bcrypt");
extern(Windows)
int BCryptAddContextFunctionProvider(
    uint dwTable,   // DWORD
    const(wchar)* pszContext,   // LPCWSTR
    uint dwInterface,   // DWORD
    const(wchar)* pszFunction,   // LPCWSTR
    const(wchar)* pszProvider,   // LPCWSTR
    uint dwPosition   // DWORD
);
ccall((:BCryptAddContextFunctionProvider, "bcrypt.dll"), stdcall, Int32,
      (UInt32, Cwstring, UInt32, Cwstring, Cwstring, UInt32),
      dwTable, pszContext, dwInterface, pszFunction, pszProvider, dwPosition)
# dwTable : DWORD -> UInt32
# pszContext : LPCWSTR -> Cwstring
# dwInterface : DWORD -> UInt32
# pszFunction : LPCWSTR -> Cwstring
# pszProvider : LPCWSTR -> Cwstring
# dwPosition : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t BCryptAddContextFunctionProvider(
    uint32_t dwTable,
    const uint16_t* pszContext,
    uint32_t dwInterface,
    const uint16_t* pszFunction,
    const uint16_t* pszProvider,
    uint32_t dwPosition);
]]
local bcrypt = ffi.load("bcrypt")
-- bcrypt.BCryptAddContextFunctionProvider(dwTable, pszContext, dwInterface, pszFunction, pszProvider, dwPosition)
-- dwTable : DWORD
-- pszContext : LPCWSTR
-- dwInterface : DWORD
-- pszFunction : LPCWSTR
-- pszProvider : LPCWSTR
-- dwPosition : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('bcrypt.dll');
const BCryptAddContextFunctionProvider = lib.func('__stdcall', 'BCryptAddContextFunctionProvider', 'int32_t', ['uint32_t', 'str16', 'uint32_t', 'str16', 'str16', 'uint32_t']);
// BCryptAddContextFunctionProvider(dwTable, pszContext, dwInterface, pszFunction, pszProvider, dwPosition)
// dwTable : DWORD -> 'uint32_t'
// pszContext : LPCWSTR -> 'str16'
// dwInterface : DWORD -> 'uint32_t'
// pszFunction : LPCWSTR -> 'str16'
// pszProvider : LPCWSTR -> 'str16'
// dwPosition : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("bcrypt.dll", {
  BCryptAddContextFunctionProvider: { parameters: ["u32", "buffer", "u32", "buffer", "buffer", "u32"], result: "i32" },
});
// lib.symbols.BCryptAddContextFunctionProvider(dwTable, pszContext, dwInterface, pszFunction, pszProvider, dwPosition)
// dwTable : DWORD -> "u32"
// pszContext : LPCWSTR -> "buffer"
// dwInterface : DWORD -> "u32"
// pszFunction : LPCWSTR -> "buffer"
// pszProvider : LPCWSTR -> "buffer"
// dwPosition : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t BCryptAddContextFunctionProvider(
    uint32_t dwTable,
    const uint16_t* pszContext,
    uint32_t dwInterface,
    const uint16_t* pszFunction,
    const uint16_t* pszProvider,
    uint32_t dwPosition);
C, "bcrypt.dll");
// $ffi->BCryptAddContextFunctionProvider(dwTable, pszContext, dwInterface, pszFunction, pszProvider, dwPosition);
// dwTable : DWORD
// pszContext : LPCWSTR
// dwInterface : DWORD
// pszFunction : LPCWSTR
// pszProvider : LPCWSTR
// dwPosition : 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 Bcrypt extends StdCallLibrary {
    Bcrypt INSTANCE = Native.load("bcrypt", Bcrypt.class);
    int BCryptAddContextFunctionProvider(
        int dwTable,   // DWORD
        WString pszContext,   // LPCWSTR
        int dwInterface,   // DWORD
        WString pszFunction,   // LPCWSTR
        WString pszProvider,   // LPCWSTR
        int dwPosition   // DWORD
    );
}
@[Link("bcrypt")]
lib Libbcrypt
  fun BCryptAddContextFunctionProvider = BCryptAddContextFunctionProvider(
    dwTable : UInt32,   # DWORD
    pszContext : UInt16*,   # LPCWSTR
    dwInterface : UInt32,   # DWORD
    pszFunction : UInt16*,   # LPCWSTR
    pszProvider : UInt16*,   # LPCWSTR
    dwPosition : 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 BCryptAddContextFunctionProviderNative = Int32 Function(Uint32, Pointer<Utf16>, Uint32, Pointer<Utf16>, Pointer<Utf16>, Uint32);
typedef BCryptAddContextFunctionProviderDart = int Function(int, Pointer<Utf16>, int, Pointer<Utf16>, Pointer<Utf16>, int);
final BCryptAddContextFunctionProvider = DynamicLibrary.open('bcrypt.dll')
    .lookupFunction<BCryptAddContextFunctionProviderNative, BCryptAddContextFunctionProviderDart>('BCryptAddContextFunctionProvider');
// dwTable : DWORD -> Uint32
// pszContext : LPCWSTR -> Pointer<Utf16>
// dwInterface : DWORD -> Uint32
// pszFunction : LPCWSTR -> Pointer<Utf16>
// pszProvider : LPCWSTR -> Pointer<Utf16>
// dwPosition : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function BCryptAddContextFunctionProvider(
  dwTable: DWORD;   // DWORD
  pszContext: PWideChar;   // LPCWSTR
  dwInterface: DWORD;   // DWORD
  pszFunction: PWideChar;   // LPCWSTR
  pszProvider: PWideChar;   // LPCWSTR
  dwPosition: DWORD   // DWORD
): Integer; stdcall;
  external 'bcrypt.dll' name 'BCryptAddContextFunctionProvider';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "BCryptAddContextFunctionProvider"
  c_BCryptAddContextFunctionProvider :: Word32 -> CWString -> Word32 -> CWString -> CWString -> Word32 -> IO Int32
-- dwTable : DWORD -> Word32
-- pszContext : LPCWSTR -> CWString
-- dwInterface : DWORD -> Word32
-- pszFunction : LPCWSTR -> CWString
-- pszProvider : LPCWSTR -> CWString
-- dwPosition : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let bcryptaddcontextfunctionprovider =
  foreign "BCryptAddContextFunctionProvider"
    (uint32_t @-> (ptr uint16_t) @-> uint32_t @-> (ptr uint16_t) @-> (ptr uint16_t) @-> uint32_t @-> returning int32_t)
(* dwTable : DWORD -> uint32_t *)
(* pszContext : LPCWSTR -> (ptr uint16_t) *)
(* dwInterface : DWORD -> uint32_t *)
(* pszFunction : LPCWSTR -> (ptr uint16_t) *)
(* pszProvider : LPCWSTR -> (ptr uint16_t) *)
(* dwPosition : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library bcrypt (t "bcrypt.dll"))
(cffi:use-foreign-library bcrypt)

(cffi:defcfun ("BCryptAddContextFunctionProvider" bcrypt-add-context-function-provider :convention :stdcall) :int32
  (dw-table :uint32)   ; DWORD
  (psz-context (:string :encoding :utf-16le))   ; LPCWSTR
  (dw-interface :uint32)   ; DWORD
  (psz-function (:string :encoding :utf-16le))   ; LPCWSTR
  (psz-provider (:string :encoding :utf-16le))   ; LPCWSTR
  (dw-position :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $BCryptAddContextFunctionProvider = Win32::API::More->new('bcrypt',
    'int BCryptAddContextFunctionProvider(DWORD dwTable, LPCWSTR pszContext, DWORD dwInterface, LPCWSTR pszFunction, LPCWSTR pszProvider, DWORD dwPosition)');
# my $ret = $BCryptAddContextFunctionProvider->Call($dwTable, $pszContext, $dwInterface, $pszFunction, $pszProvider, $dwPosition);
# dwTable : DWORD -> DWORD
# pszContext : LPCWSTR -> LPCWSTR
# dwInterface : DWORD -> DWORD
# pszFunction : LPCWSTR -> LPCWSTR
# pszProvider : LPCWSTR -> LPCWSTR
# dwPosition : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。