Source Code/My Patch

PKCS#11 Header ํŒŒ์ผ ์ ์šฉ ํ•˜๊ธฐ

JayKim๐Ÿ™‚ 2023. 7. 7. 10:14

PKCS#11 ํ‘œ์ค€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ธ Cryptoki ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ธฐ๋Šฅ์„ ๊ฐœ๋ฐœ ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š”
OASIS ์—์„œ ์ œ๊ณตํ•˜๋Š” ํ—ค๋” ํŒŒ์ผ์„ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค.
PKCS#11์€ ๋ชจ๋“  ์ •์˜ ๊ฐ’์ด ํ‘œ์ค€ํ™” ๋˜์–ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์ด์— ๋Œ€ํ•œ ์ •์˜๋ฅผ OASIS์—์„œ ๋งŒ๋“ค์–ด์„œ ์ œ๊ณต ํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

๊ทธ๋Ÿผ ์ œ๊ณต ํ•˜๋Š” Header ํŒŒ์ผ์€ ๋‹ค์Œ 3๊ฐ€์ง€ ์ด๋‹ค.
์—ฌ๊ธฐ์„œ๋Š” ํ˜„์žฌ ๊ฐ€์žฅ ๋งŽ์ด ์‚ฌ์šฉ๋˜๊ณ  ์žˆ๋‹ค๊ณ  ์ƒ๊ฐ ๋˜๋Š” PKCS#11 ๋ฒ„์ „ 2.4 ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์„ค๋ช…ํ•œ๋‹ค.
์•„๋ž˜ ์ฃผ์†Œ๋กœ ๊ฐ€๋ฉด ๊ด€๋ จ ๋‚ด์šฉ์„ ์ฐธ์กฐ ํ•  ์ˆ˜ ์žˆ๋‹ค.

http://docs.oasis-open.org/pkcs11/pkcs11-base/v2.40/pkcs11-base-v2.40.html

 

PKCS #11 Cryptographic Token Interface Base Specification Version 2.40

 

docs.oasis-open.org

์ ์šฉํ•ด์•ผ ํ•  3๊ฐ€์ง€ ํŒŒ์ผ์€ ์•„๋ž˜ 3๊ฐ€์ง€ ํŒŒ์ผ์ด๋‹ค.

pkcs11.h
pkcs11t.h
pcks11f.h

์ด ํŒŒ์ผ๋“ค์„ ๋ฐ›์•„์„œ ์‚ฌ์šฉ ํ•œ๋‹ค. ํ•˜์ง€๋งŒ pkcs11.h ํŒŒ์ผ์„ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์— ๋งž๊ฒŒ ๋งž์ถ”์–ด ์ฃผ์–ด์•ผ ํ•œ๋‹ค.
ํฌ๊ฒŒ ๋งž์ถ”์–ด ์ฃผ๋Š” ๋ถ€๋ถ„์€ Windows ์™€ ๋‹ค๋ฅธ OS ๋‘๊ฐ€์ง€๋กœ ์ฒ˜๋ฆฌ๋ฅผ ํ•ด์ฃผ๋ฉด ์–ด๋””์—์„œ๋“  ์‚ฌ์šฉ ๊ฐ€๋Šฅ ํ•œ๋‹ค.
์‚ฌ์‹ค pkcs11.h ํŒŒ์ผ์— ์ฃผ์„์„ ์ฝ์–ด ๋ณด๋ฉด ์ž์„ธํ•œ ์„ค๋ช…์ด ์žˆ๋‹ค.

๊ทธ๋Ÿผ pkcs11.h ์— ์ถ”๊ฐ€ ํ•ด ์ฃผ๋Š” ๋ถ€๋ถ„์€ ํ—ค๋” ์•ž๊ณผ ๋ ๋ถ€๋ถ„์— ์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ์ ์šฉ ํ•˜์—ฌ ์‚ฌ์šฉ ํ•˜๋ฉด ๋œ๋‹ค.

/* ํ—ค๋” ์•ž ๋ถ€๋ถ„ ์ ์šฉ */
#if defined(_WIN32) || defined(CRYPTOKI_FORCE_WIN32)

/* There is a matching pop below.  */
#pragma pack(push, cryptoki, 1)

#define CK_PTR *

#define CK_DEFINE_FUNCTION(returnType, name) \
   returnType __declspec(dllexport) name

#define CK_DECLARE_FUNCTION(returnType, name) \
   returnType __declspec(dllimport) name

#define CK_DECLARE_FUNCTION_POINTER(returnType, name) \
   returnType __declspec(dllimport) (* name)

#define CK_CALLBACK_FUNCTION(returnType, name) \
   returnType (* name)

#else

#define CK_PTR *

#define CK_DEFINE_FUNCTION(returnType, name) \
   returnType name

#define CK_DECLARE_FUNCTION(returnType, name) \
   returnType name

#define CK_DECLARE_FUNCTION_POINTER(returnType, name) \
   returnType (* name)

#define CK_CALLBACK_FUNCTION(returnType, name) \
   returnType (* name)

#endif

#ifndef NULL_PTR
#define NULL_PTR 0
#endif



/* ํ—ค๋” ๋’ค ๋ถ€๋ถ„ ์ ์šฉ */

/* System dependencies.  */
#if defined(_WIN32) || defined(CRYPTOKI_FORCE_WIN32)
#pragma pack(pop, cryptoki)
#endif

์ด๋ ‡๊ฒŒ ์ ์šฉ์„ ํ•˜๊ฒŒ ๋˜๋ฉด ์‚ฌ์‹ค ๋ฐ”๋กœ cryptoki ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๊ฐœ๋ฐœ์„ ํ•˜๋ฉด ๋œ๋‹ค.
๊ทธ์™ธ ๋‹ค๋ฅธ ๋ถ€๋ถ„์€ ์†๋Œ€์ง€ ์•Š์•„๋„ ๋œ๋‹ค.
์‹ค์ œ ์‚ฌ์šฉ์‹œ์—๋Š” pkcs11.h ํ—ค๋” ํŒŒ์ผ์„ ์ธํด๋ฃจ๋“œ ํ•ด์„œ ์‚ฌ์šฉ ํ•˜๋ฉด ๋œ๋‹ค.

ํ•˜์ง€๋งŒ IDE ํˆด ์—์„œ pcks11f.h pkcs11t.h ํ—ค๋”๋ฅผ ์—ด์–ด ๋ณด๋ณ€ ๋ฌธ๋ฒ• ์˜ค๋ฅ˜ ์ฒ˜๋Ÿฌ ํ‘œ์‹œ ๋˜๊ธฐ๋„ ํ•˜๋Š”๋ฐ
(๋‚ด๊ฒฝ์šฐ Qt Creator์—์„œ๋Š” ๊ทธ๋ ‡๊ฒŒ ๋‚˜์˜จ๋‹ค. ๋‹ค๋ฅธ IDE ํˆด์€ ํ™•์ธ์ด ํ•„์š”ํ•˜๋‹ค)
์ด๊ฑด ์•„๋งˆ๋„ DEFINE ๊ฐ’์— ๋Œ€ํ•œ IDE์—์„œ ์ธ์‹์ด ์ž˜ ์•ˆ๋˜์–ด์„œ์ด์ง€ ์‚ฌ์šฉ์—๋Š” ๋ฌธ์ œ๊ฐ€ ์—†๋‹ค.

์ฐธ๊ณ ๋กœ ๋‚ด๊ฐ€ ์ ์šฉํ•œ pkcs11.h ํŒŒ์ผ์„ ์ฒจ๋ถ€ ํ•˜์˜€๋‹ค.

pkcs11.h
9.7 kB