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

CertCompareIntegerBlob

関数
2つの整数BLOBの値を符号付きで比較する。
DLLCRYPT32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL CertCompareIntegerBlob(
    CRYPT_INTEGER_BLOB* pInt1,
    CRYPT_INTEGER_BLOB* pInt2
);

パラメーター

名前方向説明
pInt1CRYPT_INTEGER_BLOB*in比較対象の 1 つ目の整数を格納する CRYPT_INTEGER_BLOB 構造体へのポインターです。
pInt2CRYPT_INTEGER_BLOB*in比較対象の 2 つ目の整数を格納する CRYPT_INTEGER_BLOB 構造体へのポインターです。

戻り値の型: BOOL

公式ドキュメント

CertCompareIntegerBlob 関数は、2 つの整数 BLOB を比較し、それらが等しい数値を表しているかどうかを判定します。

戻り値

整数 BLOB の表現が同一であり、関数が成功した場合、関数は 0 以外の値 (TRUE) を返します。

関数が失敗した場合は 0 (FALSE) を返します。拡張エラー情報を取得するには、 GetLastError を呼び出してください。

解説(Remarks)

比較を行う前に、正の数からは値が 0x00 の上位バイトが削除されます。ここでの正とは、次の 0 以外のバイトの最上位ビットがセットされていないことを意味します。

負の数からは値が 0xFF の上位バイトが削除されます。ここでの負とは、次の 0xFF 以外のバイトの最上位ビットがセットされていることを意味します。これにより、次の表に示すように、その整数の一意な表現が得られます。

元のバイト列 簡約後の形式
0xFFFFFF88 0xFF88
0xFF23 0xFF23
0x007F 0x7F
0x00000080 0x80

複数バイトの整数は リトルエンディアン として扱われます。最下位バイトは pbData[0] です。最上位バイトは pbData[cbData - 1] であり、つまり 0xFFFFFF88 は 4 バイトとして次のように格納されます。

{0x88, 0xFF, 0xFF, 0xFF}

この関数を使用する例については、 C プログラムの例: CertOIDToAlgId と CertCompareIntegerBlob の使用 を参照してください。

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

各言語での呼び出し定義

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

BOOL CertCompareIntegerBlob(
    CRYPT_INTEGER_BLOB* pInt1,
    CRYPT_INTEGER_BLOB* pInt2
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("CRYPT32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool CertCompareIntegerBlob(
    IntPtr pInt1,   // CRYPT_INTEGER_BLOB*
    IntPtr pInt2   // CRYPT_INTEGER_BLOB*
);
<DllImport("CRYPT32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CertCompareIntegerBlob(
    pInt1 As IntPtr,   ' CRYPT_INTEGER_BLOB*
    pInt2 As IntPtr   ' CRYPT_INTEGER_BLOB*
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' pInt1 : CRYPT_INTEGER_BLOB*
' pInt2 : CRYPT_INTEGER_BLOB*
Declare PtrSafe Function CertCompareIntegerBlob Lib "crypt32" ( _
    ByVal pInt1 As LongPtr, _
    ByVal pInt2 As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CertCompareIntegerBlob = ctypes.windll.crypt32.CertCompareIntegerBlob
CertCompareIntegerBlob.restype = wintypes.BOOL
CertCompareIntegerBlob.argtypes = [
    ctypes.c_void_p,  # pInt1 : CRYPT_INTEGER_BLOB*
    ctypes.c_void_p,  # pInt2 : CRYPT_INTEGER_BLOB*
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('CRYPT32.dll')
CertCompareIntegerBlob = Fiddle::Function.new(
  lib['CertCompareIntegerBlob'],
  [
    Fiddle::TYPE_VOIDP,  # pInt1 : CRYPT_INTEGER_BLOB*
    Fiddle::TYPE_VOIDP,  # pInt2 : CRYPT_INTEGER_BLOB*
  ],
  Fiddle::TYPE_INT)
#[link(name = "crypt32")]
extern "system" {
    fn CertCompareIntegerBlob(
        pInt1: *mut CRYPT_INTEGER_BLOB,  // CRYPT_INTEGER_BLOB*
        pInt2: *mut CRYPT_INTEGER_BLOB  // CRYPT_INTEGER_BLOB*
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("CRYPT32.dll", SetLastError = true)]
public static extern bool CertCompareIntegerBlob(IntPtr pInt1, IntPtr pInt2);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CRYPT32_CertCompareIntegerBlob' -Namespace Win32 -PassThru
# $api::CertCompareIntegerBlob(pInt1, pInt2)
#uselib "CRYPT32.dll"
#func global CertCompareIntegerBlob "CertCompareIntegerBlob" sptr, sptr
; CertCompareIntegerBlob varptr(pInt1), varptr(pInt2)   ; 戻り値は stat
; pInt1 : CRYPT_INTEGER_BLOB* -> "sptr"
; pInt2 : CRYPT_INTEGER_BLOB* -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "CRYPT32.dll"
#cfunc global CertCompareIntegerBlob "CertCompareIntegerBlob" var, var
; res = CertCompareIntegerBlob(pInt1, pInt2)
; pInt1 : CRYPT_INTEGER_BLOB* -> "var"
; pInt2 : CRYPT_INTEGER_BLOB* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL CertCompareIntegerBlob(CRYPT_INTEGER_BLOB* pInt1, CRYPT_INTEGER_BLOB* pInt2)
#uselib "CRYPT32.dll"
#cfunc global CertCompareIntegerBlob "CertCompareIntegerBlob" var, var
; res = CertCompareIntegerBlob(pInt1, pInt2)
; pInt1 : CRYPT_INTEGER_BLOB* -> "var"
; pInt2 : CRYPT_INTEGER_BLOB* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	crypt32 = windows.NewLazySystemDLL("CRYPT32.dll")
	procCertCompareIntegerBlob = crypt32.NewProc("CertCompareIntegerBlob")
)

// pInt1 (CRYPT_INTEGER_BLOB*), pInt2 (CRYPT_INTEGER_BLOB*)
r1, _, err := procCertCompareIntegerBlob.Call(
	uintptr(pInt1),
	uintptr(pInt2),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function CertCompareIntegerBlob(
  pInt1: Pointer;   // CRYPT_INTEGER_BLOB*
  pInt2: Pointer   // CRYPT_INTEGER_BLOB*
): BOOL; stdcall;
  external 'CRYPT32.dll' name 'CertCompareIntegerBlob';
result := DllCall("CRYPT32\CertCompareIntegerBlob"
    , "Ptr", pInt1   ; CRYPT_INTEGER_BLOB*
    , "Ptr", pInt2   ; CRYPT_INTEGER_BLOB*
    , "Int")   ; return: BOOL
●CertCompareIntegerBlob(pInt1, pInt2) = DLL("CRYPT32.dll", "bool CertCompareIntegerBlob(void*, void*)")
# 呼び出し: CertCompareIntegerBlob(pInt1, pInt2)
# pInt1 : CRYPT_INTEGER_BLOB* -> "void*"
# pInt2 : CRYPT_INTEGER_BLOB* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "crypt32" fn CertCompareIntegerBlob(
    pInt1: [*c]CRYPT_INTEGER_BLOB, // CRYPT_INTEGER_BLOB*
    pInt2: [*c]CRYPT_INTEGER_BLOB // CRYPT_INTEGER_BLOB*
) callconv(std.os.windows.WINAPI) i32;
proc CertCompareIntegerBlob(
    pInt1: ptr CRYPT_INTEGER_BLOB,  # CRYPT_INTEGER_BLOB*
    pInt2: ptr CRYPT_INTEGER_BLOB  # CRYPT_INTEGER_BLOB*
): int32 {.importc: "CertCompareIntegerBlob", stdcall, dynlib: "CRYPT32.dll".}
pragma(lib, "crypt32");
extern(Windows)
int CertCompareIntegerBlob(
    CRYPT_INTEGER_BLOB* pInt1,   // CRYPT_INTEGER_BLOB*
    CRYPT_INTEGER_BLOB* pInt2   // CRYPT_INTEGER_BLOB*
);
ccall((:CertCompareIntegerBlob, "CRYPT32.dll"), stdcall, Int32,
      (Ptr{CRYPT_INTEGER_BLOB}, Ptr{CRYPT_INTEGER_BLOB}),
      pInt1, pInt2)
# pInt1 : CRYPT_INTEGER_BLOB* -> Ptr{CRYPT_INTEGER_BLOB}
# pInt2 : CRYPT_INTEGER_BLOB* -> Ptr{CRYPT_INTEGER_BLOB}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t CertCompareIntegerBlob(
    void* pInt1,
    void* pInt2);
]]
local crypt32 = ffi.load("crypt32")
-- crypt32.CertCompareIntegerBlob(pInt1, pInt2)
-- pInt1 : CRYPT_INTEGER_BLOB*
-- pInt2 : CRYPT_INTEGER_BLOB*
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('CRYPT32.dll');
const CertCompareIntegerBlob = lib.func('__stdcall', 'CertCompareIntegerBlob', 'int32_t', ['void *', 'void *']);
// CertCompareIntegerBlob(pInt1, pInt2)
// pInt1 : CRYPT_INTEGER_BLOB* -> 'void *'
// pInt2 : CRYPT_INTEGER_BLOB* -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("CRYPT32.dll", {
  CertCompareIntegerBlob: { parameters: ["pointer", "pointer"], result: "i32" },
});
// lib.symbols.CertCompareIntegerBlob(pInt1, pInt2)
// pInt1 : CRYPT_INTEGER_BLOB* -> "pointer"
// pInt2 : CRYPT_INTEGER_BLOB* -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t CertCompareIntegerBlob(
    void* pInt1,
    void* pInt2);
C, "CRYPT32.dll");
// $ffi->CertCompareIntegerBlob(pInt1, pInt2);
// pInt1 : CRYPT_INTEGER_BLOB*
// pInt2 : CRYPT_INTEGER_BLOB*
// 構造体/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 Crypt32 extends StdCallLibrary {
    Crypt32 INSTANCE = Native.load("crypt32", Crypt32.class);
    boolean CertCompareIntegerBlob(
        Pointer pInt1,   // CRYPT_INTEGER_BLOB*
        Pointer pInt2   // CRYPT_INTEGER_BLOB*
    );
}
@[Link("crypt32")]
lib LibCRYPT32
  fun CertCompareIntegerBlob = CertCompareIntegerBlob(
    pInt1 : CRYPT_INTEGER_BLOB*,   # CRYPT_INTEGER_BLOB*
    pInt2 : CRYPT_INTEGER_BLOB*   # CRYPT_INTEGER_BLOB*
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef CertCompareIntegerBlobNative = Int32 Function(Pointer<Void>, Pointer<Void>);
typedef CertCompareIntegerBlobDart = int Function(Pointer<Void>, Pointer<Void>);
final CertCompareIntegerBlob = DynamicLibrary.open('CRYPT32.dll')
    .lookupFunction<CertCompareIntegerBlobNative, CertCompareIntegerBlobDart>('CertCompareIntegerBlob');
// pInt1 : CRYPT_INTEGER_BLOB* -> Pointer<Void>
// pInt2 : CRYPT_INTEGER_BLOB* -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function CertCompareIntegerBlob(
  pInt1: Pointer;   // CRYPT_INTEGER_BLOB*
  pInt2: Pointer   // CRYPT_INTEGER_BLOB*
): BOOL; stdcall;
  external 'CRYPT32.dll' name 'CertCompareIntegerBlob';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "CertCompareIntegerBlob"
  c_CertCompareIntegerBlob :: Ptr () -> Ptr () -> IO CInt
-- pInt1 : CRYPT_INTEGER_BLOB* -> Ptr ()
-- pInt2 : CRYPT_INTEGER_BLOB* -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let certcompareintegerblob =
  foreign "CertCompareIntegerBlob"
    ((ptr void) @-> (ptr void) @-> returning int32_t)
(* pInt1 : CRYPT_INTEGER_BLOB* -> (ptr void) *)
(* pInt2 : CRYPT_INTEGER_BLOB* -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library crypt32 (t "CRYPT32.dll"))
(cffi:use-foreign-library crypt32)

(cffi:defcfun ("CertCompareIntegerBlob" cert-compare-integer-blob :convention :stdcall) :int32
  (p-int1 :pointer)   ; CRYPT_INTEGER_BLOB*
  (p-int2 :pointer))   ; CRYPT_INTEGER_BLOB*
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $CertCompareIntegerBlob = Win32::API::More->new('CRYPT32',
    'BOOL CertCompareIntegerBlob(LPVOID pInt1, LPVOID pInt2)');
# my $ret = $CertCompareIntegerBlob->Call($pInt1, $pInt2);
# pInt1 : CRYPT_INTEGER_BLOB* -> LPVOID
# pInt2 : CRYPT_INTEGER_BLOB* -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目
使用する型