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

CMSG_CTRL_KEY_AGREE_DECRYPT_PARA

構造体
サイズx64: 64 バイト / x86: 36 バイト

サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。

フィールド

フィールドサイズx64x86説明
cbSizeDWORD4+0+0この構造体のサイズ(バイト単位)。
Anonymous_Anonymous_e__Union8/4+8+4復号に使うレガシーCSPまたはCNG鍵ハンドルを保持する共用体。
dwKeySpecDWORD4+16+8使用する鍵の種別(AT_KEYEXCHANGE等)。
pKeyAgreeCMSG_KEY_AGREE_RECIPIENT_INFO*8/4+24+12復号対象の鍵共有受信者情報へのポインタ。
dwRecipientIndexDWORD4+32+16復号対象とする受信者のインデックス(0始まり)。
dwRecipientEncryptedKeyIndexDWORD4+36+20受信者内の暗号化鍵配列のインデックス(0始まり)。
OriginatorPublicKeyCRYPT_BIT_BLOB24/12+40+24鍵導出に使う送信者の公開鍵を格納するビット列BLOB。

共用体: _Anonymous_e__Union x64 8B / x86 4B

フィールドサイズx64x86
hCryptProvUINT_PTR8/4+0+0
hNCryptKeyNCRYPT_KEY_HANDLE8/4+0+0

各言語での定義

#include <windows.h>

// CRYPT_BIT_BLOB  (x64 24 / x86 12 バイト)
typedef struct CRYPT_BIT_BLOB {
    DWORD cbData;
    BYTE* pbData;
    DWORD cUnusedBits;
} CRYPT_BIT_BLOB;

// CMSG_CTRL_KEY_AGREE_DECRYPT_PARA  (x64 64 / x86 36 バイト)
typedef struct CMSG_CTRL_KEY_AGREE_DECRYPT_PARA {
    DWORD cbSize;
    _Anonymous_e__Union Anonymous;
    DWORD dwKeySpec;
    CMSG_KEY_AGREE_RECIPIENT_INFO* pKeyAgree;
    DWORD dwRecipientIndex;
    DWORD dwRecipientEncryptedKeyIndex;
    CRYPT_BIT_BLOB OriginatorPublicKey;
} CMSG_CTRL_KEY_AGREE_DECRYPT_PARA;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct CRYPT_BIT_BLOB
{
    public uint cbData;
    public IntPtr pbData;
    public uint cUnusedBits;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct CMSG_CTRL_KEY_AGREE_DECRYPT_PARA
{
    public uint cbSize;
    public _Anonymous_e__Union Anonymous;
    public uint dwKeySpec;
    public IntPtr pKeyAgree;
    public uint dwRecipientIndex;
    public uint dwRecipientEncryptedKeyIndex;
    public CRYPT_BIT_BLOB OriginatorPublicKey;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure CRYPT_BIT_BLOB
    Public cbData As UInteger
    Public pbData As IntPtr
    Public cUnusedBits As UInteger
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure CMSG_CTRL_KEY_AGREE_DECRYPT_PARA
    Public cbSize As UInteger
    Public Anonymous As _Anonymous_e__Union
    Public dwKeySpec As UInteger
    Public pKeyAgree As IntPtr
    Public dwRecipientIndex As UInteger
    Public dwRecipientEncryptedKeyIndex As UInteger
    Public OriginatorPublicKey As CRYPT_BIT_BLOB
End Structure
import ctypes
from ctypes import wintypes

class CRYPT_BIT_BLOB(ctypes.Structure):
    _fields_ = [
        ("cbData", wintypes.DWORD),
        ("pbData", ctypes.c_void_p),
        ("cUnusedBits", wintypes.DWORD),
    ]

class CMSG_CTRL_KEY_AGREE_DECRYPT_PARA(ctypes.Structure):
    _fields_ = [
        ("cbSize", wintypes.DWORD),
        ("Anonymous", _Anonymous_e__Union),
        ("dwKeySpec", wintypes.DWORD),
        ("pKeyAgree", ctypes.c_void_p),
        ("dwRecipientIndex", wintypes.DWORD),
        ("dwRecipientEncryptedKeyIndex", wintypes.DWORD),
        ("OriginatorPublicKey", CRYPT_BIT_BLOB),
    ]
#[repr(C)]
pub struct CRYPT_BIT_BLOB {
    pub cbData: u32,
    pub pbData: *mut core::ffi::c_void,
    pub cUnusedBits: u32,
}

#[repr(C)]
pub struct CMSG_CTRL_KEY_AGREE_DECRYPT_PARA {
    pub cbSize: u32,
    pub Anonymous: _Anonymous_e__Union,
    pub dwKeySpec: u32,
    pub pKeyAgree: *mut core::ffi::c_void,
    pub dwRecipientIndex: u32,
    pub dwRecipientEncryptedKeyIndex: u32,
    pub OriginatorPublicKey: CRYPT_BIT_BLOB,
}
import "golang.org/x/sys/windows"

type CRYPT_BIT_BLOB struct {
	cbData uint32
	pbData uintptr
	cUnusedBits uint32
}

type CMSG_CTRL_KEY_AGREE_DECRYPT_PARA struct {
	cbSize uint32
	Anonymous _Anonymous_e__Union
	dwKeySpec uint32
	pKeyAgree uintptr
	dwRecipientIndex uint32
	dwRecipientEncryptedKeyIndex uint32
	OriginatorPublicKey CRYPT_BIT_BLOB
}
type
  CRYPT_BIT_BLOB = record
    cbData: DWORD;
    pbData: Pointer;
    cUnusedBits: DWORD;
  end;

  CMSG_CTRL_KEY_AGREE_DECRYPT_PARA = record
    cbSize: DWORD;
    Anonymous: _Anonymous_e__Union;
    dwKeySpec: DWORD;
    pKeyAgree: Pointer;
    dwRecipientIndex: DWORD;
    dwRecipientEncryptedKeyIndex: DWORD;
    OriginatorPublicKey: CRYPT_BIT_BLOB;
  end;
const CRYPT_BIT_BLOB = extern struct {
    cbData: u32,
    pbData: ?*anyopaque,
    cUnusedBits: u32,
};

const CMSG_CTRL_KEY_AGREE_DECRYPT_PARA = extern struct {
    cbSize: u32,
    Anonymous: _Anonymous_e__Union,
    dwKeySpec: u32,
    pKeyAgree: ?*anyopaque,
    dwRecipientIndex: u32,
    dwRecipientEncryptedKeyIndex: u32,
    OriginatorPublicKey: CRYPT_BIT_BLOB,
};
type
  CRYPT_BIT_BLOB {.bycopy.} = object
    cbData: uint32
    pbData: pointer
    cUnusedBits: uint32

  CMSG_CTRL_KEY_AGREE_DECRYPT_PARA {.bycopy.} = object
    cbSize: uint32
    Anonymous: _Anonymous_e__Union
    dwKeySpec: uint32
    pKeyAgree: pointer
    dwRecipientIndex: uint32
    dwRecipientEncryptedKeyIndex: uint32
    OriginatorPublicKey: CRYPT_BIT_BLOB
struct CRYPT_BIT_BLOB
{
    uint cbData;
    void* pbData;
    uint cUnusedBits;
}

struct CMSG_CTRL_KEY_AGREE_DECRYPT_PARA
{
    uint cbSize;
    _Anonymous_e__Union Anonymous;
    uint dwKeySpec;
    void* pKeyAgree;
    uint dwRecipientIndex;
    uint dwRecipientEncryptedKeyIndex;
    CRYPT_BIT_BLOB OriginatorPublicKey;
}

HSP用 定義

HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x86 レイアウト)
; CMSG_CTRL_KEY_AGREE_DECRYPT_PARA サイズ: 36 バイト(x86)
dim st, 9    ; 4byte整数×9(構造体サイズ 36 / 4 切り上げ)
; cbSize : DWORD (+0, 4byte)  st.0 = 値  /  値 = st.0   (lpoke/lpeek も可)
; Anonymous : _Anonymous_e__Union (+4, 4byte)  varptr(st)+4 を基点に操作(4byte:入れ子/配列)
; dwKeySpec : DWORD (+8, 4byte)  st.2 = 値  /  値 = st.2   (lpoke/lpeek も可)
; pKeyAgree : CMSG_KEY_AGREE_RECIPIENT_INFO* (+12, 4byte)  varptr(st)+12 を基点に操作(4byte:入れ子/配列)
; dwRecipientIndex : DWORD (+16, 4byte)  st.4 = 値  /  値 = st.4   (lpoke/lpeek も可)
; dwRecipientEncryptedKeyIndex : DWORD (+20, 4byte)  st.5 = 値  /  値 = st.5   (lpoke/lpeek も可)
; OriginatorPublicKey : CRYPT_BIT_BLOB (+24, 12byte)  varptr(st)+24 を基点に操作(12byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; CMSG_CTRL_KEY_AGREE_DECRYPT_PARA サイズ: 64 バイト(x64)
dim st, 16    ; 4byte整数×16(構造体サイズ 64 / 4 切り上げ)
; cbSize : DWORD (+0, 4byte)  st.0 = 値  /  値 = st.0   (lpoke/lpeek も可)
; Anonymous : _Anonymous_e__Union (+8, 8byte)  varptr(st)+8 を基点に操作(8byte:入れ子/配列)
; dwKeySpec : DWORD (+16, 4byte)  st.4 = 値  /  値 = st.4   (lpoke/lpeek も可)
; pKeyAgree : CMSG_KEY_AGREE_RECIPIENT_INFO* (+24, 8byte)  varptr(st)+24 を基点に操作(8byte:入れ子/配列)
; dwRecipientIndex : DWORD (+32, 4byte)  st.8 = 値  /  値 = st.8   (lpoke/lpeek も可)
; dwRecipientEncryptedKeyIndex : DWORD (+36, 4byte)  st.9 = 値  /  値 = st.9   (lpoke/lpeek も可)
; OriginatorPublicKey : CRYPT_BIT_BLOB (+40, 24byte)  varptr(st)+40 を基点に操作(24byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global CRYPT_BIT_BLOB
    #field int cbData
    #field intptr pbData
    #field int cUnusedBits
#endstruct

#defstruct global CMSG_CTRL_KEY_AGREE_DECRYPT_PARA
    #field int cbSize
    #field byte Anonymous 8
    #field int dwKeySpec
    #field intptr pKeyAgree
    #field int dwRecipientIndex
    #field int dwRecipientEncryptedKeyIndex
    #field CRYPT_BIT_BLOB OriginatorPublicKey
#endstruct

stdim st, CMSG_CTRL_KEY_AGREE_DECRYPT_PARA        ; NSTRUCT 変数を確保
st->cbSize = 100
mes "cbSize=" + st->cbSize
; ※union フィールドは byte 列で確保(NSTRUCT は union 非対応)。必要に応じ手動でアクセス。