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

CMSG_CNG_CONTENT_DECRYPT_INFO

構造体
サイズx64: 88 バイト / x86: 44 バイト

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

フィールド

フィールドサイズx64x86説明
cbSizeDWORD4+0+0この構造体のサイズをバイト単位で格納します。
ContentEncryptionAlgorithmCRYPT_ALGORITHM_IDENTIFIER24/12+8+4メッセージの内容の暗号化に使用されるアルゴリズムと、それに関連するパラメーターを指定する CRYPT_ALGORITHM_IDENTIFIER 構造体です。
pfnAllocPFN_CMSG_ALLOC8/4+32+16更新されるメンバーのためにメモリを割り当てるために使用される、インストール可能関数へのポインターです。
pfnFreePFN_CMSG_FREE8/4+40+20pfnAlloc によって割り当てられたメモリを解放するために使用される、インストール可能関数へのポインターです。
hNCryptKeyNCRYPT_KEY_HANDLE8/4+48+24PFN_CMSG_CNG_IMPORT_KEY_TRANS 関数の pKeyTransDecryptPara パラメーターまたは pKeyAgreeDecryptPara パラメーターに含まれる CEK の復号に使用する、CNG 秘密キー のハンドルです。DecryptPara 構造体には変換された HCRYPTPROV ハンドルが格納されている場合があるため、コールバック関数はその構造体に含まれるキーではなく、このキーを使用しなければなりません。
pbContentEncryptKeyBYTE*8/4+56+28hNCryptKey メンバーを使用して、PFN_CMSG_CNG_IMPORT_KEY_TRANS 関数は pKeyTransDecryptPara パラメーター内の CEK を復号してこのメンバーを更新し、PFN_CMSG_CNG_IMPORT_KEY_AGREE 関数は pKeyAgreeDecryptPara パラメーター内の EncryptedKey を復号してこのメンバーを更新しなければなりません。このメンバーのメモリは pfnAlloc メンバーを使用して割り当てなければなりません。PFN_CMSG_CNG_IMPORT_CONTENT_ENCRYPT_KEY 関数は、これらのバイトをシークレットとして使用して hCNGContentEncryptKey メンバーを生成します。エラーが発生した場合でも、割り当てたメモリは pfnFree メンバーを使用して解放し、0 でクリアしなければなりません。
cbContentEncryptKeyDWORD4+64+32PFN_CMSG_CNG_IMPORT_KEY_TRANS 関数または PFN_CMSG_CNG_IMPORT_KEY_AGREE 関数は、上記の pbContentEncryptKey メンバーのサイズ (バイト単位) でこのメンバーを更新しなければなりません。
hCNGContentEncryptKeyBCRYPT_KEY_HANDLE8/4+72+36PFN_CMSG_CNG_IMPORT_CONTENT_ENCRYPT_KEY 関数は、コンテンツの復号に使用する、生成された BCRYPT_KEY_HANDLE でこのメンバーを更新しなければなりません。エラーが発生した場合でも、このハンドルは BCryptDestroyKey 関数を使用して解放しなければなりません。
pbCNGContentEncryptKeyObjectBYTE*8/4+80+40PFN_CMSG_CNG_IMPORT_CONTENT_ENCRYPT_KEY 関数は、hCNGContentEncryptKey メンバーに関連付けるために pfnAlloc メンバーで割り当てたメモリで、このメンバーを更新しなければなりません。エラーが発生した場合でも、割り当てたメモリは pfnFree メンバーを使用して解放し、0 でクリアしなければなりません。

公式ドキュメント

CMSG_CNG_CONTENT_DECRYPT_INFO 構造体は、Cryptography API: Next Generation (CNG) のコンテンツ暗号化キー (CEK) のインポートおよび復号のために、CryptMsgControlオブジェクト識別子 (OID) インストール可能関数との間で受け渡される関連情報をすべて格納します。CryptMsgControl 関数は、この構造体を使用して次の関数を呼び出します。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での定義

#include <windows.h>

// CRYPT_INTEGER_BLOB  (x64 16 / x86 8 バイト)
typedef struct CRYPT_INTEGER_BLOB {
    DWORD cbData;
    BYTE* pbData;
} CRYPT_INTEGER_BLOB;

// CRYPT_ALGORITHM_IDENTIFIER  (x64 24 / x86 12 バイト)
typedef struct CRYPT_ALGORITHM_IDENTIFIER {
    LPSTR pszObjId;
    CRYPT_INTEGER_BLOB Parameters;
} CRYPT_ALGORITHM_IDENTIFIER;

// CMSG_CNG_CONTENT_DECRYPT_INFO  (x64 88 / x86 44 バイト)
typedef struct CMSG_CNG_CONTENT_DECRYPT_INFO {
    DWORD cbSize;
    CRYPT_ALGORITHM_IDENTIFIER ContentEncryptionAlgorithm;
    PFN_CMSG_ALLOC pfnAlloc;
    PFN_CMSG_FREE pfnFree;
    NCRYPT_KEY_HANDLE hNCryptKey;
    BYTE* pbContentEncryptKey;
    DWORD cbContentEncryptKey;
    BCRYPT_KEY_HANDLE hCNGContentEncryptKey;
    BYTE* pbCNGContentEncryptKeyObject;
} CMSG_CNG_CONTENT_DECRYPT_INFO;
using System;
using System.Runtime.InteropServices;

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

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct CRYPT_ALGORITHM_IDENTIFIER
{
    public IntPtr pszObjId;
    public CRYPT_INTEGER_BLOB Parameters;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct CMSG_CNG_CONTENT_DECRYPT_INFO
{
    public uint cbSize;
    public CRYPT_ALGORITHM_IDENTIFIER ContentEncryptionAlgorithm;
    public IntPtr pfnAlloc;
    public IntPtr pfnFree;
    public UIntPtr hNCryptKey;
    public IntPtr pbContentEncryptKey;
    public uint cbContentEncryptKey;
    public IntPtr hCNGContentEncryptKey;
    public IntPtr pbCNGContentEncryptKeyObject;
}
Imports System.Runtime.InteropServices

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

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure CRYPT_ALGORITHM_IDENTIFIER
    Public pszObjId As IntPtr
    Public Parameters As CRYPT_INTEGER_BLOB
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure CMSG_CNG_CONTENT_DECRYPT_INFO
    Public cbSize As UInteger
    Public ContentEncryptionAlgorithm As CRYPT_ALGORITHM_IDENTIFIER
    Public pfnAlloc As IntPtr
    Public pfnFree As IntPtr
    Public hNCryptKey As UIntPtr
    Public pbContentEncryptKey As IntPtr
    Public cbContentEncryptKey As UInteger
    Public hCNGContentEncryptKey As IntPtr
    Public pbCNGContentEncryptKeyObject As IntPtr
End Structure
import ctypes
from ctypes import wintypes

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

class CRYPT_ALGORITHM_IDENTIFIER(ctypes.Structure):
    _fields_ = [
        ("pszObjId", ctypes.c_void_p),
        ("Parameters", CRYPT_INTEGER_BLOB),
    ]

class CMSG_CNG_CONTENT_DECRYPT_INFO(ctypes.Structure):
    _fields_ = [
        ("cbSize", wintypes.DWORD),
        ("ContentEncryptionAlgorithm", CRYPT_ALGORITHM_IDENTIFIER),
        ("pfnAlloc", ctypes.c_void_p),
        ("pfnFree", ctypes.c_void_p),
        ("hNCryptKey", ctypes.c_size_t),
        ("pbContentEncryptKey", ctypes.c_void_p),
        ("cbContentEncryptKey", wintypes.DWORD),
        ("hCNGContentEncryptKey", ctypes.c_void_p),
        ("pbCNGContentEncryptKeyObject", ctypes.c_void_p),
    ]
#[repr(C)]
pub struct CRYPT_INTEGER_BLOB {
    pub cbData: u32,
    pub pbData: *mut core::ffi::c_void,
}

#[repr(C)]
pub struct CRYPT_ALGORITHM_IDENTIFIER {
    pub pszObjId: *mut core::ffi::c_void,
    pub Parameters: CRYPT_INTEGER_BLOB,
}

#[repr(C)]
pub struct CMSG_CNG_CONTENT_DECRYPT_INFO {
    pub cbSize: u32,
    pub ContentEncryptionAlgorithm: CRYPT_ALGORITHM_IDENTIFIER,
    pub pfnAlloc: *mut core::ffi::c_void,
    pub pfnFree: *mut core::ffi::c_void,
    pub hNCryptKey: usize,
    pub pbContentEncryptKey: *mut core::ffi::c_void,
    pub cbContentEncryptKey: u32,
    pub hCNGContentEncryptKey: *mut core::ffi::c_void,
    pub pbCNGContentEncryptKeyObject: *mut core::ffi::c_void,
}
import "golang.org/x/sys/windows"

type CRYPT_INTEGER_BLOB struct {
	cbData uint32
	pbData uintptr
}

type CRYPT_ALGORITHM_IDENTIFIER struct {
	pszObjId uintptr
	Parameters CRYPT_INTEGER_BLOB
}

type CMSG_CNG_CONTENT_DECRYPT_INFO struct {
	cbSize uint32
	ContentEncryptionAlgorithm CRYPT_ALGORITHM_IDENTIFIER
	pfnAlloc uintptr
	pfnFree uintptr
	hNCryptKey uintptr
	pbContentEncryptKey uintptr
	cbContentEncryptKey uint32
	hCNGContentEncryptKey uintptr
	pbCNGContentEncryptKeyObject uintptr
}
type
  CRYPT_INTEGER_BLOB = record
    cbData: DWORD;
    pbData: Pointer;
  end;

  CRYPT_ALGORITHM_IDENTIFIER = record
    pszObjId: Pointer;
    Parameters: CRYPT_INTEGER_BLOB;
  end;

  CMSG_CNG_CONTENT_DECRYPT_INFO = record
    cbSize: DWORD;
    ContentEncryptionAlgorithm: CRYPT_ALGORITHM_IDENTIFIER;
    pfnAlloc: Pointer;
    pfnFree: Pointer;
    hNCryptKey: NativeUInt;
    pbContentEncryptKey: Pointer;
    cbContentEncryptKey: DWORD;
    hCNGContentEncryptKey: Pointer;
    pbCNGContentEncryptKeyObject: Pointer;
  end;
const CRYPT_INTEGER_BLOB = extern struct {
    cbData: u32,
    pbData: ?*anyopaque,
};

const CRYPT_ALGORITHM_IDENTIFIER = extern struct {
    pszObjId: ?*anyopaque,
    Parameters: CRYPT_INTEGER_BLOB,
};

const CMSG_CNG_CONTENT_DECRYPT_INFO = extern struct {
    cbSize: u32,
    ContentEncryptionAlgorithm: CRYPT_ALGORITHM_IDENTIFIER,
    pfnAlloc: ?*anyopaque,
    pfnFree: ?*anyopaque,
    hNCryptKey: usize,
    pbContentEncryptKey: ?*anyopaque,
    cbContentEncryptKey: u32,
    hCNGContentEncryptKey: ?*anyopaque,
    pbCNGContentEncryptKeyObject: ?*anyopaque,
};
type
  CRYPT_INTEGER_BLOB {.bycopy.} = object
    cbData: uint32
    pbData: pointer

  CRYPT_ALGORITHM_IDENTIFIER {.bycopy.} = object
    pszObjId: pointer
    Parameters: CRYPT_INTEGER_BLOB

  CMSG_CNG_CONTENT_DECRYPT_INFO {.bycopy.} = object
    cbSize: uint32
    ContentEncryptionAlgorithm: CRYPT_ALGORITHM_IDENTIFIER
    pfnAlloc: pointer
    pfnFree: pointer
    hNCryptKey: uint
    pbContentEncryptKey: pointer
    cbContentEncryptKey: uint32
    hCNGContentEncryptKey: pointer
    pbCNGContentEncryptKeyObject: pointer
struct CRYPT_INTEGER_BLOB
{
    uint cbData;
    void* pbData;
}

struct CRYPT_ALGORITHM_IDENTIFIER
{
    void* pszObjId;
    CRYPT_INTEGER_BLOB Parameters;
}

struct CMSG_CNG_CONTENT_DECRYPT_INFO
{
    uint cbSize;
    CRYPT_ALGORITHM_IDENTIFIER ContentEncryptionAlgorithm;
    void* pfnAlloc;
    void* pfnFree;
    size_t hNCryptKey;
    void* pbContentEncryptKey;
    uint cbContentEncryptKey;
    void* hCNGContentEncryptKey;
    void* pbCNGContentEncryptKeyObject;
}

HSP用 定義

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

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x86 レイアウト)
; CMSG_CNG_CONTENT_DECRYPT_INFO サイズ: 44 バイト(x86)
dim st, 11    ; 4byte整数×11(構造体サイズ 44 / 4 切り上げ)
; cbSize : DWORD (+0, 4byte)  st.0 = 値  /  値 = st.0   (lpoke/lpeek も可)
; ContentEncryptionAlgorithm : CRYPT_ALGORITHM_IDENTIFIER (+4, 12byte)  varptr(st)+4 を基点に操作(12byte:入れ子/配列)
; pfnAlloc : PFN_CMSG_ALLOC (+16, 4byte)  st.4 = 値  /  値 = st.4   (lpoke/lpeek も可)
; pfnFree : PFN_CMSG_FREE (+20, 4byte)  st.5 = 値  /  値 = st.5   (lpoke/lpeek も可)
; hNCryptKey : NCRYPT_KEY_HANDLE (+24, 4byte)  st.6 = 値  /  値 = st.6   (lpoke/lpeek も可)
; pbContentEncryptKey : BYTE* (+28, 4byte)  st.7 = 値  /  値 = st.7   (lpoke/lpeek も可)
; cbContentEncryptKey : DWORD (+32, 4byte)  st.8 = 値  /  値 = st.8   (lpoke/lpeek も可)
; hCNGContentEncryptKey : BCRYPT_KEY_HANDLE (+36, 4byte)  st.9 = 値  /  値 = st.9   (lpoke/lpeek も可)
; pbCNGContentEncryptKeyObject : BYTE* (+40, 4byte)  st.10 = 値  /  値 = st.10   (lpoke/lpeek も可)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; CMSG_CNG_CONTENT_DECRYPT_INFO サイズ: 88 バイト(x64)
dim st, 22    ; 4byte整数×22(構造体サイズ 88 / 4 切り上げ)
; cbSize : DWORD (+0, 4byte)  st.0 = 値  /  値 = st.0   (lpoke/lpeek も可)
; ContentEncryptionAlgorithm : CRYPT_ALGORITHM_IDENTIFIER (+8, 24byte)  varptr(st)+8 を基点に操作(24byte:入れ子/配列)
; pfnAlloc : PFN_CMSG_ALLOC (+32, 8byte)  qpoke st,32,値 / qpeek(st,32)  ※IronHSPのみ。3.7/3.8は lpoke st,32,下位 : lpoke st,36,上位
; pfnFree : PFN_CMSG_FREE (+40, 8byte)  qpoke st,40,値 / qpeek(st,40)  ※IronHSPのみ。3.7/3.8は lpoke st,40,下位 : lpoke st,44,上位
; hNCryptKey : NCRYPT_KEY_HANDLE (+48, 8byte)  qpoke st,48,値 / qpeek(st,48)  ※IronHSPのみ。3.7/3.8は lpoke st,48,下位 : lpoke st,52,上位
; pbContentEncryptKey : BYTE* (+56, 8byte)  qpoke st,56,値 / qpeek(st,56)  ※IronHSPのみ。3.7/3.8は lpoke st,56,下位 : lpoke st,60,上位
; cbContentEncryptKey : DWORD (+64, 4byte)  st.16 = 値  /  値 = st.16   (lpoke/lpeek も可)
; hCNGContentEncryptKey : BCRYPT_KEY_HANDLE (+72, 8byte)  qpoke st,72,値 / qpeek(st,72)  ※IronHSPのみ。3.7/3.8は lpoke st,72,下位 : lpoke st,76,上位
; pbCNGContentEncryptKeyObject : BYTE* (+80, 8byte)  qpoke st,80,値 / qpeek(st,80)  ※IronHSPのみ。3.7/3.8は lpoke st,80,下位 : lpoke st,84,上位
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global CRYPT_INTEGER_BLOB
    #field int cbData
    #field intptr pbData
#endstruct

#defstruct global CRYPT_ALGORITHM_IDENTIFIER
    #field intptr pszObjId
    #field CRYPT_INTEGER_BLOB Parameters
#endstruct

#defstruct global CMSG_CNG_CONTENT_DECRYPT_INFO
    #field int cbSize
    #field CRYPT_ALGORITHM_IDENTIFIER ContentEncryptionAlgorithm
    #field intptr pfnAlloc
    #field intptr pfnFree
    #field intptr hNCryptKey
    #field intptr pbContentEncryptKey
    #field int cbContentEncryptKey
    #field intptr hCNGContentEncryptKey
    #field intptr pbCNGContentEncryptKeyObject
#endstruct

stdim st, CMSG_CNG_CONTENT_DECRYPT_INFO        ; NSTRUCT 変数を確保
st->cbSize = 100
mes "cbSize=" + st->cbSize