ホーム › Security.Cryptography › GenerateDerivedKey
GenerateDerivedKey
関数ラベルとノンスから派生鍵を生成する。
シグネチャ
// infocardapi.dll
#include <windows.h>
HRESULT GenerateDerivedKey(
INFORMATIONCARD_CRYPTO_HANDLE* hCrypto,
DWORD cbLabel,
BYTE* pLabel,
DWORD cbNonce,
BYTE* pNonce,
DWORD derivedKeyLength,
DWORD offset,
LPCWSTR algId,
DWORD* pcbKey,
BYTE** ppKey
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hCrypto | INFORMATIONCARD_CRYPTO_HANDLE* | in |
| cbLabel | DWORD | in |
| pLabel | BYTE* | in |
| cbNonce | DWORD | in |
| pNonce | BYTE* | in |
| derivedKeyLength | DWORD | in |
| offset | DWORD | in |
| algId | LPCWSTR | in |
| pcbKey | DWORD* | out |
| ppKey | BYTE** | out |
戻り値の型: HRESULT
各言語での呼び出し定義
// infocardapi.dll
#include <windows.h>
HRESULT GenerateDerivedKey(
INFORMATIONCARD_CRYPTO_HANDLE* hCrypto,
DWORD cbLabel,
BYTE* pLabel,
DWORD cbNonce,
BYTE* pNonce,
DWORD derivedKeyLength,
DWORD offset,
LPCWSTR algId,
DWORD* pcbKey,
BYTE** ppKey
);[DllImport("infocardapi.dll", ExactSpelling = true)]
static extern int GenerateDerivedKey(
IntPtr hCrypto, // INFORMATIONCARD_CRYPTO_HANDLE*
uint cbLabel, // DWORD
IntPtr pLabel, // BYTE*
uint cbNonce, // DWORD
IntPtr pNonce, // BYTE*
uint derivedKeyLength, // DWORD
uint offset, // DWORD
[MarshalAs(UnmanagedType.LPWStr)] string algId, // LPCWSTR
out uint pcbKey, // DWORD* out
IntPtr ppKey // BYTE** out
);<DllImport("infocardapi.dll", ExactSpelling:=True)>
Public Shared Function GenerateDerivedKey(
hCrypto As IntPtr, ' INFORMATIONCARD_CRYPTO_HANDLE*
cbLabel As UInteger, ' DWORD
pLabel As IntPtr, ' BYTE*
cbNonce As UInteger, ' DWORD
pNonce As IntPtr, ' BYTE*
derivedKeyLength As UInteger, ' DWORD
offset As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPWStr)> algId As String, ' LPCWSTR
<Out> ByRef pcbKey As UInteger, ' DWORD* out
ppKey As IntPtr ' BYTE** out
) As Integer
End Function' hCrypto : INFORMATIONCARD_CRYPTO_HANDLE*
' cbLabel : DWORD
' pLabel : BYTE*
' cbNonce : DWORD
' pNonce : BYTE*
' derivedKeyLength : DWORD
' offset : DWORD
' algId : LPCWSTR
' pcbKey : DWORD* out
' ppKey : BYTE** out
Declare PtrSafe Function GenerateDerivedKey Lib "infocardapi" ( _
ByVal hCrypto As LongPtr, _
ByVal cbLabel As Long, _
ByVal pLabel As LongPtr, _
ByVal cbNonce As Long, _
ByVal pNonce As LongPtr, _
ByVal derivedKeyLength As Long, _
ByVal offset As Long, _
ByVal algId As LongPtr, _
ByRef pcbKey As Long, _
ByVal ppKey As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GenerateDerivedKey = ctypes.windll.infocardapi.GenerateDerivedKey
GenerateDerivedKey.restype = ctypes.c_int
GenerateDerivedKey.argtypes = [
ctypes.c_void_p, # hCrypto : INFORMATIONCARD_CRYPTO_HANDLE*
wintypes.DWORD, # cbLabel : DWORD
ctypes.POINTER(ctypes.c_ubyte), # pLabel : BYTE*
wintypes.DWORD, # cbNonce : DWORD
ctypes.POINTER(ctypes.c_ubyte), # pNonce : BYTE*
wintypes.DWORD, # derivedKeyLength : DWORD
wintypes.DWORD, # offset : DWORD
wintypes.LPCWSTR, # algId : LPCWSTR
ctypes.POINTER(wintypes.DWORD), # pcbKey : DWORD* out
ctypes.c_void_p, # ppKey : BYTE** out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('infocardapi.dll')
GenerateDerivedKey = Fiddle::Function.new(
lib['GenerateDerivedKey'],
[
Fiddle::TYPE_VOIDP, # hCrypto : INFORMATIONCARD_CRYPTO_HANDLE*
-Fiddle::TYPE_INT, # cbLabel : DWORD
Fiddle::TYPE_VOIDP, # pLabel : BYTE*
-Fiddle::TYPE_INT, # cbNonce : DWORD
Fiddle::TYPE_VOIDP, # pNonce : BYTE*
-Fiddle::TYPE_INT, # derivedKeyLength : DWORD
-Fiddle::TYPE_INT, # offset : DWORD
Fiddle::TYPE_VOIDP, # algId : LPCWSTR
Fiddle::TYPE_VOIDP, # pcbKey : DWORD* out
Fiddle::TYPE_VOIDP, # ppKey : BYTE** out
],
Fiddle::TYPE_INT)#[link(name = "infocardapi")]
extern "system" {
fn GenerateDerivedKey(
hCrypto: *mut INFORMATIONCARD_CRYPTO_HANDLE, // INFORMATIONCARD_CRYPTO_HANDLE*
cbLabel: u32, // DWORD
pLabel: *mut u8, // BYTE*
cbNonce: u32, // DWORD
pNonce: *mut u8, // BYTE*
derivedKeyLength: u32, // DWORD
offset: u32, // DWORD
algId: *const u16, // LPCWSTR
pcbKey: *mut u32, // DWORD* out
ppKey: *mut *mut u8 // BYTE** out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("infocardapi.dll")]
public static extern int GenerateDerivedKey(IntPtr hCrypto, uint cbLabel, IntPtr pLabel, uint cbNonce, IntPtr pNonce, uint derivedKeyLength, uint offset, [MarshalAs(UnmanagedType.LPWStr)] string algId, out uint pcbKey, IntPtr ppKey);
"@
$api = Add-Type -MemberDefinition $sig -Name 'infocardapi_GenerateDerivedKey' -Namespace Win32 -PassThru
# $api::GenerateDerivedKey(hCrypto, cbLabel, pLabel, cbNonce, pNonce, derivedKeyLength, offset, algId, pcbKey, ppKey)#uselib "infocardapi.dll"
#func global GenerateDerivedKey "GenerateDerivedKey" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; GenerateDerivedKey varptr(hCrypto), cbLabel, varptr(pLabel), cbNonce, varptr(pNonce), derivedKeyLength, offset, algId, varptr(pcbKey), varptr(ppKey) ; 戻り値は stat
; hCrypto : INFORMATIONCARD_CRYPTO_HANDLE* -> "sptr"
; cbLabel : DWORD -> "sptr"
; pLabel : BYTE* -> "sptr"
; cbNonce : DWORD -> "sptr"
; pNonce : BYTE* -> "sptr"
; derivedKeyLength : DWORD -> "sptr"
; offset : DWORD -> "sptr"
; algId : LPCWSTR -> "sptr"
; pcbKey : DWORD* out -> "sptr"
; ppKey : BYTE** out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "infocardapi.dll" #cfunc global GenerateDerivedKey "GenerateDerivedKey" var, int, var, int, var, int, int, wstr, var, var ; res = GenerateDerivedKey(hCrypto, cbLabel, pLabel, cbNonce, pNonce, derivedKeyLength, offset, algId, pcbKey, ppKey) ; hCrypto : INFORMATIONCARD_CRYPTO_HANDLE* -> "var" ; cbLabel : DWORD -> "int" ; pLabel : BYTE* -> "var" ; cbNonce : DWORD -> "int" ; pNonce : BYTE* -> "var" ; derivedKeyLength : DWORD -> "int" ; offset : DWORD -> "int" ; algId : LPCWSTR -> "wstr" ; pcbKey : DWORD* out -> "var" ; ppKey : BYTE** out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "infocardapi.dll" #cfunc global GenerateDerivedKey "GenerateDerivedKey" sptr, int, sptr, int, sptr, int, int, wstr, sptr, sptr ; res = GenerateDerivedKey(varptr(hCrypto), cbLabel, varptr(pLabel), cbNonce, varptr(pNonce), derivedKeyLength, offset, algId, varptr(pcbKey), varptr(ppKey)) ; hCrypto : INFORMATIONCARD_CRYPTO_HANDLE* -> "sptr" ; cbLabel : DWORD -> "int" ; pLabel : BYTE* -> "sptr" ; cbNonce : DWORD -> "int" ; pNonce : BYTE* -> "sptr" ; derivedKeyLength : DWORD -> "int" ; offset : DWORD -> "int" ; algId : LPCWSTR -> "wstr" ; pcbKey : DWORD* out -> "sptr" ; ppKey : BYTE** out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT GenerateDerivedKey(INFORMATIONCARD_CRYPTO_HANDLE* hCrypto, DWORD cbLabel, BYTE* pLabel, DWORD cbNonce, BYTE* pNonce, DWORD derivedKeyLength, DWORD offset, LPCWSTR algId, DWORD* pcbKey, BYTE** ppKey) #uselib "infocardapi.dll" #cfunc global GenerateDerivedKey "GenerateDerivedKey" var, int, var, int, var, int, int, wstr, var, var ; res = GenerateDerivedKey(hCrypto, cbLabel, pLabel, cbNonce, pNonce, derivedKeyLength, offset, algId, pcbKey, ppKey) ; hCrypto : INFORMATIONCARD_CRYPTO_HANDLE* -> "var" ; cbLabel : DWORD -> "int" ; pLabel : BYTE* -> "var" ; cbNonce : DWORD -> "int" ; pNonce : BYTE* -> "var" ; derivedKeyLength : DWORD -> "int" ; offset : DWORD -> "int" ; algId : LPCWSTR -> "wstr" ; pcbKey : DWORD* out -> "var" ; ppKey : BYTE** out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT GenerateDerivedKey(INFORMATIONCARD_CRYPTO_HANDLE* hCrypto, DWORD cbLabel, BYTE* pLabel, DWORD cbNonce, BYTE* pNonce, DWORD derivedKeyLength, DWORD offset, LPCWSTR algId, DWORD* pcbKey, BYTE** ppKey) #uselib "infocardapi.dll" #cfunc global GenerateDerivedKey "GenerateDerivedKey" intptr, int, intptr, int, intptr, int, int, wstr, intptr, intptr ; res = GenerateDerivedKey(varptr(hCrypto), cbLabel, varptr(pLabel), cbNonce, varptr(pNonce), derivedKeyLength, offset, algId, varptr(pcbKey), varptr(ppKey)) ; hCrypto : INFORMATIONCARD_CRYPTO_HANDLE* -> "intptr" ; cbLabel : DWORD -> "int" ; pLabel : BYTE* -> "intptr" ; cbNonce : DWORD -> "int" ; pNonce : BYTE* -> "intptr" ; derivedKeyLength : DWORD -> "int" ; offset : DWORD -> "int" ; algId : LPCWSTR -> "wstr" ; pcbKey : DWORD* out -> "intptr" ; ppKey : BYTE** out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
infocardapi = windows.NewLazySystemDLL("infocardapi.dll")
procGenerateDerivedKey = infocardapi.NewProc("GenerateDerivedKey")
)
// hCrypto (INFORMATIONCARD_CRYPTO_HANDLE*), cbLabel (DWORD), pLabel (BYTE*), cbNonce (DWORD), pNonce (BYTE*), derivedKeyLength (DWORD), offset (DWORD), algId (LPCWSTR), pcbKey (DWORD* out), ppKey (BYTE** out)
r1, _, err := procGenerateDerivedKey.Call(
uintptr(hCrypto),
uintptr(cbLabel),
uintptr(pLabel),
uintptr(cbNonce),
uintptr(pNonce),
uintptr(derivedKeyLength),
uintptr(offset),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(algId))),
uintptr(pcbKey),
uintptr(ppKey),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction GenerateDerivedKey(
hCrypto: Pointer; // INFORMATIONCARD_CRYPTO_HANDLE*
cbLabel: DWORD; // DWORD
pLabel: Pointer; // BYTE*
cbNonce: DWORD; // DWORD
pNonce: Pointer; // BYTE*
derivedKeyLength: DWORD; // DWORD
offset: DWORD; // DWORD
algId: PWideChar; // LPCWSTR
pcbKey: Pointer; // DWORD* out
ppKey: Pointer // BYTE** out
): Integer; stdcall;
external 'infocardapi.dll' name 'GenerateDerivedKey';result := DllCall("infocardapi\GenerateDerivedKey"
, "Ptr", hCrypto ; INFORMATIONCARD_CRYPTO_HANDLE*
, "UInt", cbLabel ; DWORD
, "Ptr", pLabel ; BYTE*
, "UInt", cbNonce ; DWORD
, "Ptr", pNonce ; BYTE*
, "UInt", derivedKeyLength ; DWORD
, "UInt", offset ; DWORD
, "WStr", algId ; LPCWSTR
, "Ptr", pcbKey ; DWORD* out
, "Ptr", ppKey ; BYTE** out
, "Int") ; return: HRESULT●GenerateDerivedKey(hCrypto, cbLabel, pLabel, cbNonce, pNonce, derivedKeyLength, offset, algId, pcbKey, ppKey) = DLL("infocardapi.dll", "int GenerateDerivedKey(void*, dword, void*, dword, void*, dword, dword, char*, void*, void*)")
# 呼び出し: GenerateDerivedKey(hCrypto, cbLabel, pLabel, cbNonce, pNonce, derivedKeyLength, offset, algId, pcbKey, ppKey)
# hCrypto : INFORMATIONCARD_CRYPTO_HANDLE* -> "void*"
# cbLabel : DWORD -> "dword"
# pLabel : BYTE* -> "void*"
# cbNonce : DWORD -> "dword"
# pNonce : BYTE* -> "void*"
# derivedKeyLength : DWORD -> "dword"
# offset : DWORD -> "dword"
# algId : LPCWSTR -> "char*"
# pcbKey : DWORD* out -> "void*"
# ppKey : BYTE** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。