Advertisement
Guest User

Untitled

a guest
Dec 14th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 104.62 KB | None | 0 0
  1. #ifndef __MULTOS_H
  2. #define __MULTOS_H
  3.  
  4.  
  5. /*
  6. ** ----------------------------------------------------------------------------
  7. ** Copyright (C) 2012-2016
  8. ** MAOSCO Limited.
  9. **
  10. ** FILE NAME:       multos.h
  11. **
  12. ** DESCRIPTION:     Standard MULTOS API for SmartDeck.
  13. ** VERSION:         1.4
  14. **
  15. ** DISCLAIMER: This header file is provided "as is" and comes with no warranty
  16. ** or guarantee of correct operation. Anyone using functions from this file
  17. ** MUST independently ensure correct operation of applications containing calls
  18. ** to these functions.
  19. **
  20. ** CHANGES in 1.3:
  21. ** Added multosSetSelectCLSW, multosBlockLookupWord, multosGetProcessEvent, multosRejectProcessEvent
  22. ** multosRsaVerify, multosSetATSHistoricalCharacters, multosSetFCIFileRecord, multosInitialisePIN
  23. ** multosReadPIN, multosVerifyPIN, multosSetPINTryCounter, multosSetPINTryLimit, multosGetPINTryCount
  24. ** multosGetPINTryLimit, multosGetPINStatus, multosFlushPublic
  25. **
  26. ** Corrected parameter order (in macro) for multosBlockEncipherECB (ciphertext and plaintext params were inverted)
  27. **
  28. ** Added #defines for Process Events
  29. **
  30. ** CHANGES in 1.4:
  31. ** Added multosBlockShiftLeftVar, multosBlockShiftRightVar, multosBlockRotateLeft, multosBlockRotateRight,
  32. ** multosUpdateStaticSize
  33. **-----------------------------------------------------------------------------
  34. */
  35.  
  36. #define __SMARTWORKS    1
  37. #define __SMARTDECK     1
  38.  
  39. /*
  40. **=============================================================================
  41. ** Standard type names used by the C-API.
  42. **=============================================================================
  43. */
  44. typedef unsigned char BOOL;
  45. typedef unsigned char BYTE;
  46. typedef signed char SBYTE;
  47. typedef unsigned short WORD;
  48. typedef short SWORD;
  49. typedef unsigned long DWORD;
  50. typedef long SDWORD;
  51.  
  52. typedef void (*FN_PTR) (void);
  53.  
  54. #define TRUE    (1)
  55. #define FALSE   (0)
  56. #define NULL    (0)
  57.  
  58. #define MAX_BYTE    (255)
  59. #define MAX_WORD    (65535)
  60. #define MAX_DWORD   (4294967295)
  61.  
  62. /*
  63. ** Crypto algorithms
  64. */
  65. #define ALGORITHM_DES   (3)
  66. #define ALGORITHM_3DES  (4)
  67. #define ALGORITHM_SEED  (5)
  68. #define ALGORITHM_AES   (6)
  69. #define ALGORITHM_RSA   (7)
  70. #define ALGORITHM_COMP128   (8)
  71.  
  72. /*
  73. ** Possible application execution events
  74. */
  75. #define EVENT_APP_APDU                       0x00
  76. #define EVENT_SELECT_APDU                    0x01
  77. #define EVENT_AUTO_SELECT                    0x02
  78. #define EVENT_RESELECT_APDU                  0x03
  79. #define EVENT_DESELECT                       0x04
  80. #define EVENT_CREATE                         0x05
  81. #define EVENT_DELETE                         0x06
  82.  
  83. /*
  84. **=============================================================================
  85. ** Specific SmartWorks constants and macros.  Note that these do not form a
  86. ** part of the C-API.
  87. **=============================================================================
  88. */
  89. /* Support for N byte block arithmetic. */
  90. #define __BLOCKCAST(N) *(struct { BYTE __x[N]; }*)
  91.  
  92. /* OP N blocks at OP1 and OP2 and store in RES.  N and RES must be constants. */
  93. #define __BINARY_OPN(N, OP, RES, OP1, OP2) \
  94. do \
  95.     {  \
  96.   __push (__BLOCKCAST(N)(__typechk(BYTE *, OP1))); \
  97.   __push (__BLOCKCAST(N)(__typechk(BYTE *, OP2))); \
  98.   __code (OP, N);  \
  99.   __code (__POPN, N);  \
  100.   __code (__STORE, __typechk(BYTE *, RES), N); \
  101. } while (0)
  102.  
  103. /* OP N block */
  104. #define __UNARY_OPN(N, OP, V) \
  105.   __code(OP, V, N);
  106.  
  107. /* Internal system variables. */
  108. extern BYTE ProtocolFlags;
  109. extern BYTE ProtocolType;
  110. extern BYTE GetResponseCLA;
  111. extern BYTE GetResponseSW1;
  112. extern BYTE CLA;
  113. extern BYTE INS;
  114. extern BYTE P1;
  115. extern BYTE P2;
  116. extern BYTE P3;
  117. extern WORD P1P2;               /* P1 in MSB, P2 in LSB. */
  118. extern WORD Lc;
  119. extern WORD Le;
  120. extern WORD La;
  121. extern BYTE SW1;
  122. extern BYTE SW2;
  123. extern WORD SW12;               /* SW1 in MSB, SW2 in LSB. */
  124.  
  125. /* The values of each MULTOS instruction. */
  126. #define __SYSTEM    0x00
  127. #define __BRANCH    0x01
  128. #define __JUMP      0x02
  129. #define __CALL      0x03
  130. #define __STACK     0x04
  131. #define __PRIMRET   0x05
  132. #define __UNUSED    0x06
  133. #define __LOAD      0x07
  134. #define __STORE     0x08
  135. #define __LOADI     0x09
  136. #define __STOREI    0x0A
  137. #define __LOADA     0x0B
  138. #define __INDEX     0x0C
  139. #define __SETB      0x0D
  140. #define __CMPB      0x0E
  141. #define __ADDB      0x0F
  142. #define __SUBB      0x10
  143. #define __SETW      0x11
  144. #define __CMPW      0x12
  145. #define __ADDW      0x13
  146. #define __SUBW      0x14
  147. #define __CLEARN    0x15
  148. #define __TESTN     0x16
  149. #define __INCN      0x17
  150. #define __DECN      0x18
  151. #define __NOTN      0x19
  152. #define __CMPN      0x1A
  153. #define __ADDN      0x1B
  154. #define __SUBN      0x1C
  155. #define __ANDN      0x1D
  156. #define __ORN       0x1E
  157. #define __XORN      0x1F
  158.  
  159. #define __RET       0x20
  160. #define __POPB      0x21
  161. #define __POPW      0x22
  162. #define __POPN      0x23
  163. #define __PUSHB     0x24
  164. #define __PUSHW     0x25
  165. #define __PUSHZ     0x26
  166. #define __PRIM      0x27
  167.  
  168. /* The values of each set zero MULTOS primitive. */
  169. #define __PRIM_CHECK_CASE                           0x01
  170. #define __PRIM_RESET_WWT                            0x02
  171. #define __PRIM_LOAD_CCR                             0x05
  172. #define __PRIM_STORE_CCR                            0x06
  173. #define __PRIM_SET_ATR_FILE_RECORD                  0x07
  174. #define __PRIM_SET_ATR_HISTORICAL_CHARACTERS        0x08
  175. #define __PRIM_GET_MEMORY_RELIABILITY               0x09
  176. #define __PRIM_LOOKUP                               0x0A
  177. #define __PRIM_MEMORY_COMPARE                       0x0B
  178. #define __PRIM_MEMORY_COPY                          0x0C
  179. #define __PRIM_QUERY_INTERFACE_TYPE                 0x0D
  180. #define __PRIM_SET_ATS_HISTORICAL_CHARACTERS        0x0E
  181. #define __PRIM_MEMORY_COPY_NON_ATOMIC               0x0F
  182. #define __PRIM_CONTROL_AUTO_RESET_WWT               0x10
  183. #define __PRIM_SET_FCI_FILE_RECORD                  0x11
  184. #define __PRIM_CARD_UNBLOCK                         0x13
  185. #define __PRIM_LOOKUP_WORD                          0x14
  186. #define __PRIM_EXIT_TO_MULTOS_AND_RESTART           0x17
  187. #define __PRIM_DELEGATE                             0x80
  188. #define __PRIM_RESET_SESSION_DATA                   0x81
  189. #define __PRIM_CHECKSUM                             0x82
  190. #define __PRIM_CALL_CODELET                         0x83
  191. #define __PRIM_QUERY_CODELET                        0x84
  192. #define __PRIM_EXCHANGE_DATA                        0x85
  193. #define __PRIM_QUERY_CHANNEL                        0x86
  194. #define __PRIM_PLATFORM_OPTIMISED_CHECKSUM          0x89
  195. #define __PRIM_QUERY_ALGO                           0x8A
  196. #define __PRIM_DES_ECB_ENCIPHER                     0xC1
  197. #define __PRIM_MODULAR_MULTIPLICATION               0xC2
  198. #define __PRIM_MODULAR_REDUCTION                    0xC3
  199. #define __PRIM_GET_RANDOM_NUMBER                    0xC4
  200. #define __PRIM_DES_ECB_DECIPHER                     0xC5
  201. #define __PRIM_GENERATE_DES_CBC_SIGNATURE           0xC6
  202. #define __PRIM_GENERATE_TRIPLE_DES_CBC_SIGNATURE    0xC7
  203. #define __PRIM_MODULAR_EXPONENTIATION               0xC8
  204. #define __PRIM_MODULAR_EXPONENTIATION_CRT           0xC9
  205. #define __PRIM_SHA_1                                0xCA
  206. #define __PRIM_GSM_AUTHENTICATE                     0xCB
  207. #define __PRIM_SECURE_HASH                          0xCF
  208. #define __PRIM_ECC_ADDITION                         0xD0
  209. #define __PRIM_ECC_CONVERT_REPRESENTATION           0xD1
  210. #define __PRIM_ECC_EQUALITY_TEST                    0xD2
  211. #define __PRIM_ECC_INVERSE                          0xD3
  212. #define __PRIM_ECC_SCALAR_MULTIPLICATION            0xD4
  213. #define __PRIM_AES_ECB_DECIPHER                     0xD6
  214. #define __PRIM_AES_ECB_ENCIPHER                     0xD7
  215. #define __PRIM_3DES_ECB_DECIPHER                    0xD8
  216. #define __PRIM_3DES_ECB_ENCIPHER                    0xD9
  217. #define __PRIM_MODULAR_EXPONENTIATION_CRT_PROTECTED 0xDC
  218. #define __PRIM_SECURE_HASH_IV                       0xE4
  219. #define __PRIM_INITIALISE_PIN                       0xE5
  220. #define __PRIM_READ_PIN                             0xE6
  221. #define __PRIM_VERIFY_PIN                           0xE7
  222. #define __PRIM_GET_PROCESS_EVENT                    0xE8
  223. #define __PRIM_REJECT_PROCESS_EVENT                 0xE9
  224. #define __PRIM_RSA_VERIFY                           0xEB
  225. #define __PRIM_FLUSH_PUBLIC                         0xEC
  226.  
  227.  
  228. /* The values of each set one MULTOS primitive. */
  229. #define __PRIM_QUERY                                0x00   /* Range 0x00-0x03 */
  230. #define __PRIM_UPDATE_STATIC_SIZE                   0x04
  231. #define __PRIM_DIVIDEN                              0x08
  232. #define __PRIM_GET_DIR_FILE_RECORD                  0x09
  233. #define __PRIM_GET_FILE_CONTROL_INFORMATION         0x0A
  234. #define __PRIM_GET_MANUFACTURER_DATA                0x0B
  235. #define __PRIM_GET_MULTOS_DATA                      0x0C
  236. #define __PRIM_GET_PURSE_TYPE                       0x0D
  237. #define __PRIM_MEMORY_COPY_FIXED_LENGTH             0x0E
  238. #define __PRIM_MEMORY_COMPARE_FIXED_LENGTH          0x0F
  239. #define __PRIM_MULTIPLYN                            0x10
  240. #define __PRIM_ADD_BCDN                             0x11
  241. #define __PRIM_SUBTRACT_BCDN                        0x12
  242. #define __PRIM_MEMORY_COPY_NON_ATOMIC_FIXED_LENGTH  0x13
  243. #define __PRIM_CONVERT_BCD                          0x14
  244. #define __PRIM_PAD                                  0x15
  245. #define __PRIM_UNPAD                                0x16
  246. #define __PRIM_SET_TRANSACTION_PROTECTION           0x80
  247. #define __PRIM_GET_DELEGATOR_AID                    0x81
  248. #define __PRIM_SET_PIN_DATA                         0x85
  249. #define __PRIM_GET_PIN_DATA                         0x86
  250. #define __PRIM_GET_DATA                             0x87
  251. #define __PRIM_SET_PROTECTED_MEMORY_ACCESS          0x88
  252. #define __PRIM_GENERATE_ASYMMETRIC_HASH             0xC4
  253. #define __PRIM_ECC_VERIFY                           0xD1
  254. #define __PRIM_CONFIG_READ_BINARY                   0xDC
  255. #define __PRIM_COPY_ADDITIONAL_STATIC               0xDD
  256. #define __PRIM_FILL_ADDITIONAL_STATIC               0xDE
  257. #define __PRIM_GET_STATIC_SIZE                      0xDF
  258. #define __PRIM_SET_SILENT_MODE                      0xE3
  259. #define __PRIM_GEN_ECC_SIG                          0xE5
  260. #define __PRIM_VER_ECC_SIG                          0xE6
  261. #define __PRIM_GEN_ECC_PAIR                         0xE7
  262. #define __PRIM_ECCDH                                0xE8
  263. #define __PRIM_ECC_DEC                              0xE9
  264. #define __PRIM_ECC_ENC                              0xEA
  265.  
  266. /* The values of each set two MULTOS primitive. */
  267. #define __PRIM_BIT_MANIPULATE_BYTE                  0x01
  268. #define __PRIM_SHIFT_LEFT                           0x02
  269. #define __PRIM_SHIFT_RIGHT                          0x03
  270. #define __PRIM_SET_SELECT_SW                        0x04
  271. #define __PRIM_CARD_BLOCK                           0x05
  272. #define __PRIM_SET_SELECT_CL_SW                     0x06
  273. #define __PRIM_SHIFT_ROTATE                         0x07
  274. #define __PRIM_RETURN_FROM_CODELET                  0x80
  275. #define __PRIM_BLOCK_DECIPHER_ECB                   0xDA
  276. #define __PRIM_BLOCK_ENCIPHER_ECB                   0xDB
  277. #define __PRIM_GEN_RSA_KEYPAIR                      0xE0
  278.  
  279. /* The values of each set three MULTOS primitive. */
  280. #define __PRIM_BIT_MANIPULATE_WORD                  0x01
  281. #define __PRIM_CALL_EXTENSION_PRIMITIVE             0x80   /* Range 0x80-0x86 */
  282.  
  283. /*
  284. **=============================================================================
  285. ** MULTOS C-API variables.
  286. **=============================================================================
  287. */
  288. #define multosProtocolFlags     ProtocolFlags
  289. #define multosProtocolType      ProtocolType
  290. #define multosGetResponseCLA    GetResponseCLA
  291. #define multosGetResponseSW1    GetResponseSW1
  292. #define multosCLA               CLA
  293. #define multosINS               INS
  294. #define multosP1                P1
  295. #define multosP2                P2
  296. #define multosP3                P3
  297. #define multosP1P2              P1P2
  298. #define multosLc                Lc
  299. #define multosLe                Le
  300. #define multosLa                La
  301. #define multosSW1               SW1
  302. #define multosSW2               SW2
  303. #define multosSW12              SW12
  304.  
  305. /*
  306. **=============================================================================
  307. ** MULTOS C-API functions.
  308. **=============================================================================
  309. */
  310.  
  311. #define multosPrintf0(fmt)
  312. #define multosPrintf1(fmt, a)
  313. #define multosPrintf2(fmt, a, b)
  314. #define multosPrintf3(fmt, a, b, c)
  315. #define multosPrintf4(fmt, a, b, c, d)
  316.  
  317. /*
  318. **-----------------------------------------------------------------------------
  319. ** void multosAddBCD (const BYTE length,
  320. **                    BYTE *operand1,
  321. **                    BYTE *operand2,
  322. **                    BYTE *result)
  323. **-----------------------------------------------------------------------------
  324. */
  325. #ifdef __FUNCTION_PROTOTYPES
  326. void multosAddBCD (const BYTE length, BYTE *operand1, BYTE *operand2,
  327.                    BYTE *result);
  328. #else
  329. #define multosAddBCD(length, operand1, operand2, result) \
  330. do \
  331. { \
  332.     __push (__BLOCKCAST(length)(__typechk(BYTE *, operand1))); \
  333.     __push (__BLOCKCAST(length)(__typechk(BYTE *, operand2))); \
  334.     __code (__PRIM, __PRIM_ADD_BCDN, length); \
  335.     __code (__STORE, __typechk(BYTE *, result), length); \
  336. } while (0)
  337. #endif
  338.  
  339. /*
  340. **-----------------------------------------------------------------------------
  341. ** void multosAESECBDecipher (BYTE *cipherText,
  342. **                            BYTE *plainText,
  343.                               BYTE keyLength,
  344. **                            BYTE *key)
  345. **-----------------------------------------------------------------------------
  346. */
  347. #ifdef __FUNCTION_PROTOTYPES
  348. void multosAESECBDecipher (BYTE *cipherText, BYTE *plainText, BYTE keyLength,
  349.                            BYTE *key);
  350. #else
  351. #define multosAESECBDecipher(cipherText, plainText, keyLength, key) \
  352. do \
  353. { \
  354.     __push (__typechk(BYTE *, key)); \
  355.     __push (__typechk(BYTE, keyLength)); \
  356.     __push (__typechk(BYTE *, plainText)); \
  357.     __push (__typechk(BYTE *, cipherText)); \
  358.     __code (__PRIM, __PRIM_AES_ECB_DECIPHER); \
  359. } while (0)
  360. #endif
  361.  
  362. /*
  363. **-----------------------------------------------------------------------------
  364. ** void multosAESECBEncipher (BYTE *cipherText,
  365. **                            BYTE *plainText,
  366.                               BYTE keyLength,
  367. **                            BYTE *key)
  368. **-----------------------------------------------------------------------------
  369. */
  370. #ifdef __FUNCTION_PROTOTYPES
  371. void multosAESECBEncipher (BYTE *plainText, BYTE *cipherText, BYTE keyLength,
  372.                            BYTE *key);
  373. #else
  374. #define multosAESECBEncipher(plainText, cipherText, keyLength, key) \
  375. do \
  376. { \
  377.     __push (__typechk(BYTE *, key)); \
  378.     __push (__typechk(BYTE, keyLength)); \
  379.     __push (__typechk(BYTE *, cipherText)); \
  380.     __push (__typechk(BYTE *, plainText)); \
  381.     __code (__PRIM, __PRIM_AES_ECB_ENCIPHER); \
  382. } while (0)
  383. #endif
  384.  
  385. /*
  386. **-----------------------------------------------------------------------------
  387. ** void multosBlockAdd (const BYTE blockLength,
  388. **                      BYTE *block1,
  389. **                      BYTE *block2,
  390. **                      const BYTE *result)
  391. **-----------------------------------------------------------------------------
  392. */
  393. #ifdef __FUNCTION_PROTOTYPES
  394. void multosBlockAdd (const BYTE blockLength, BYTE *block1, BYTE *block2,
  395.                      const BYTE *result);
  396. #else
  397. #define multosBlockAdd(blockLength, block1, block2, result) \
  398.     __BINARY_OPN (blockLength, __ADDN, result, block1, block2)
  399. #endif
  400.  
  401. /*
  402. **-----------------------------------------------------------------------------
  403. ** void multosBlockAnd (const BYTE blockLength,
  404. **                      BYTE *block1,
  405. **                      BYTE *block2,
  406. **                      const BYTE *result)
  407. **-----------------------------------------------------------------------------
  408. */
  409. #ifdef __FUNCTION_PROTOTYPES
  410. void multosBlockAnd (const BYTE blockLength, BYTE *block1, BYTE *block2,
  411.                      const BYTE *result);
  412. #else
  413. #define multosBlockAnd(blockLength, block1, block2, result) \
  414.     __BINARY_OPN (blockLength, __ANDN, result, block1, block2)
  415. #endif
  416.  
  417. /*
  418. **-----------------------------------------------------------------------------
  419. ** void multosBlockCompare (WORD blockLength,
  420. **                          BYTE *block1,
  421. **                          BYTE *block2,
  422. **                          BYTE *result)
  423. **-----------------------------------------------------------------------------
  424. */
  425. #define MULTOS_BLOCK1_GT_BLOCK2     (0x00)
  426. #define MULTOS_BLOCK2_GT_BLOCK1     (0x08)
  427. #define MULTOS_BLOCK1_EQ_BLOCK2     (0x01)
  428. #ifdef __FUNCTION_PROTOTYPES
  429. void multosBlockCompare (WORD blockLength, BYTE *block1, BYTE *block2,
  430.                          BYTE *result);
  431. #else
  432. #define multosBlockCompare(blockLength, block1, block2, result) \
  433. do \
  434. { \
  435.     __push (__typechk(WORD, blockLength)); \
  436.     __push (/*__BLOCKCAST(blockLength)*/(__typechk(BYTE *, block1))); \
  437.     __push (/*__BLOCKCAST(blockLength)*/(__typechk(BYTE *, block2))); \
  438.     __code (__PRIM, __PRIM_MEMORY_COMPARE); \
  439.     __code (__PRIM, __PRIM_LOAD_CCR); \
  440.     __code (__PRIM, __PRIM_BIT_MANIPULATE_BYTE, 0x83, 0x09); \
  441.     __code (__STORE, __typechk(BOOL *, result), 1); \
  442. } while (0)
  443. #endif
  444.  
  445. /*
  446. **-----------------------------------------------------------------------------
  447. ** void multosBlockCompareFixedLength (BYTE blockLength,
  448. **                                     BYTE *block1,
  449. **                                     BYTE *block2,
  450. **                                     BYTE *result)
  451. **-----------------------------------------------------------------------------
  452. */
  453. #ifdef __FUNCTION_PROTOTYPES
  454. void multosBlockCompareFixedLength (BYTE blockLength, BYTE *block1,
  455.                                     BYTE *block2, BYTE *result);
  456. #else
  457. #define multosBlockCompareFixedLength(blockLength, block1, block2, result) \
  458. do \
  459. { \
  460.     __push (/*__BLOCKCAST(blockLength)*/(__typechk(BYTE *, block1))); \
  461.     __push (/*__BLOCKCAST(blockLength)*/(__typechk(BYTE *, block2))); \
  462.     __code (__PRIM, __PRIM_MEMORY_COMPARE_FIXED_LENGTH, blockLength); \
  463.     __code (__PRIM, __PRIM_LOAD_CCR); \
  464.     __code (__PRIM, __PRIM_BIT_MANIPULATE_BYTE, 0x83, 0x09); \
  465.     __code (__STORE, __typechk(BOOL *, result), 1); \
  466. } while (0)
  467. #endif
  468.  
  469. /*
  470. **-----------------------------------------------------------------------------
  471. ** void multosBlockClear (const BYTE blockLength,
  472. **                        const BYTE *block)
  473. **-----------------------------------------------------------------------------
  474. */
  475. #ifdef __FUNCTION_PROTOTYPES
  476. void multosBlockClear (const BYTE blockLength, const BYTE *block);
  477. #else
  478. #define multosBlockClear(blockLength, block) \
  479.     __UNARY_OPN (blockLength, __CLEARN, block)
  480. #endif
  481.  
  482. /*
  483. **-----------------------------------------------------------------------------
  484. ** void multosBlockCopy (WORD blockLength,
  485. **                       BYTE *blockSource,
  486. **                       BYTE *blockDest)
  487. **-----------------------------------------------------------------------------
  488. */
  489. #ifdef __FUNCTION_PROTOTYPES
  490. void multosBlockCopy (WORD blockLength, BYTE *blockSource, BYTE *blockDest);
  491. #else
  492. #define multosBlockCopy(blockLength, blockSource, blockDest) \
  493. do  \
  494. { \
  495.     __push (__typechk(WORD, blockLength)); \
  496.     __push (/*__BLOCKCAST(blockLength)*/(__typechk(BYTE *, blockDest))); \
  497.     __push (/*__BLOCKCAST(blockLength)*/(__typechk(BYTE *, blockSource))); \
  498.     __code (__PRIM, __PRIM_MEMORY_COPY); \
  499. } while (0)
  500. #endif
  501.  
  502. /*
  503. **-----------------------------------------------------------------------------
  504. ** void multosBlockCopyFixedLength (BYTE blockLength,
  505. **                                  BYTE *blockSource,
  506. **                                  BYTE *blockDest)
  507. **-----------------------------------------------------------------------------
  508. */
  509. #ifdef __FUNCTION_PROTOTYPES
  510. void multosBlockCopyFixedLength (BYTE blockLength, BYTE *blockSource,
  511.                                  BYTE *blockDest);
  512. #else
  513. #define multosBlockCopyFixedLength(blockLength, blockSource, blockDest) \
  514. do  \
  515. { \
  516.     __push (/*__BLOCKCAST(blockLength)*/(__typechk(BYTE *, blockDest))); \
  517.     __push (/*__BLOCKCAST(blockLength)*/(__typechk(BYTE *, blockSource))); \
  518.     __code (__PRIM, __PRIM_MEMORY_COPY_FIXED_LENGTH, blockLength); \
  519. } while (0)
  520. #endif
  521.  
  522. /*
  523. **-----------------------------------------------------------------------------
  524. ** void multosBlockCopyNonAtomic (WORD blockLength,
  525. **                                BYTE *blockSource,
  526. **                                BYTE *blockDest)
  527. **-----------------------------------------------------------------------------
  528. */
  529. #ifdef __FUNCTION_PROTOTYPES
  530. void multosBlockCopyNonAtomic (WORD blockLength, BYTE *blockSource,
  531.                                BYTE *blockDest);
  532. #else
  533. #define multosBlockCopyNonAtomic(blockLength, blockSource, blockDest) \
  534. do  \
  535. { \
  536.     __push (__typechk(WORD, blockLength)); \
  537.     __push (/*__BLOCKCAST(blockLength)*/(__typechk(BYTE *, blockDest))); \
  538.     __push (/*__BLOCKCAST(blockLength)*/(__typechk(BYTE *, blockSource))); \
  539.     __code (__PRIM, __PRIM_MEMORY_COPY_NON_ATOMIC); \
  540. } while (0)
  541. #endif
  542.  
  543. /*
  544. **-----------------------------------------------------------------------------
  545. ** void multosBlockCopyNonAtomicFixedLength (BYTE blockLength,
  546. **                                           BYTE *blockSource,
  547. **                                           BYTE *blockDest)
  548. **-----------------------------------------------------------------------------
  549. */
  550. #ifdef __FUNCTION_PROTOTYPES
  551. void multosBlockCopyNonAtomicFixedLength (BYTE blockLength, BYTE *blockSource,
  552.                                           BYTE *blockDest);
  553. #else
  554. #define multosBlockCopyNonAtomicFixedLength(blockLength, blockSource, blockDest) \
  555. do  \
  556. { \
  557.     __push (/*__BLOCKCAST(blockLength)*/(__typechk(BYTE *, blockDest))); \
  558.     __push (/*__BLOCKCAST(blockLength)*/(__typechk(BYTE *, blockSource))); \
  559.     __code (__PRIM, __PRIM_MEMORY_COPY_NON_ATOMIC_FIXED_LENGTH, blockLength); \
  560. } while (0)
  561. #endif
  562.  
  563. /*
  564. **-----------------------------------------------------------------------------
  565. ** void multosBlockDecipherCBC (const BYTE algorithm,
  566. **                              WORD inputLength,
  567. **                              BYTE *cipherText,
  568. **                              BYTE *plainText,
  569. **                              BYTE initialValueLength,
  570. **                              BYTE *initialValue,
  571. **                              BYTE keyLength,
  572. **                              BYTE *key)
  573. **-----------------------------------------------------------------------------
  574. */
  575. #ifdef __FUNCTION_PROTOTYPES
  576. void multosBlockDecipherCBC (const BYTE algorithm, WORD inputLength,
  577.                              BYTE *cipherText, BYTE *plainText,
  578.                              BYTE initialValueLength, BYTE *initialValue,
  579.                              BYTE keyLength, BYTE *key);
  580. #else
  581. #define multosBlockDecipherCBC(algorithm, inputLength, cipherText, plainText, initialValueLength, initialValue, keyLength, key) \
  582. do \
  583. { \
  584.     __push (__typechk(BYTE, initialValueLength)); \
  585.     __push (__typechk(BYTE *, initialValue)); \
  586.     __push (__typechk(WORD, inputLength)); \
  587.     __push (__typechk(BYTE *, key)); \
  588.     __push (__typechk(BYTE, keyLength)); \
  589.     __push (__typechk(BYTE *, plainText)); \
  590.     __push (__typechk(BYTE *, cipherText)); \
  591.     __code (__PRIM, __PRIM_BLOCK_DECIPHER_ECB, algorithm, 2); \
  592. } while (0)
  593. #endif
  594.  
  595. /*
  596. **-----------------------------------------------------------------------------
  597. ** void multosBlockDecipherECB (const BYTE algorithm,
  598. **                              WORD inputLength,
  599. **                              BYTE *cipherText,
  600. **                              BYTE *plainText,
  601. **                              BYTE keyLength,
  602. **                              BYTE *key)
  603. **-----------------------------------------------------------------------------
  604. */
  605. #ifdef __FUNCTION_PROTOTYPES
  606. void multosBlockDecipherECB (const BYTE algorithm, WORD inputLength,
  607.                              BYTE *cipherText, BYTE *plainText, BYTE keyLength,
  608.                              BYTE *key);
  609. #else
  610. #define multosBlockDecipherECB(algorithm, inputLength, cipherText, plainText, keyLength, key) \
  611. do \
  612. { \
  613.     __push (__typechk(WORD, inputLength)); \
  614.     __push (__typechk(BYTE *, key)); \
  615.     __push (__typechk(BYTE, keyLength)); \
  616.     __push (__typechk(BYTE *, plainText)); \
  617.     __push (__typechk(BYTE *, cipherText)); \
  618.     __code (__PRIM, __PRIM_BLOCK_DECIPHER_ECB, algorithm, 1); \
  619. } while (0)
  620. #endif
  621.  
  622. /*
  623. **-----------------------------------------------------------------------------
  624. ** void multosBlockDecrement (const BYTE blockLength,
  625. **                            const BYTE *block)
  626. **-----------------------------------------------------------------------------
  627. */
  628. #ifdef __FUNCTION_PROTOTYPES
  629. void multosBlockDecrement (const BYTE blockLength, const BYTE *block);
  630. #else
  631. #define multosBlockDecrement(blockLength, block) \
  632.     __UNARY_OPN (blockLength, __DECN, block);
  633. #endif
  634.  
  635. /*
  636. **-----------------------------------------------------------------------------
  637. ** void multosBlockDivide (const BYTE blockLength,
  638. **                         BYTE *numerator,
  639. **                         BYTE *denominator,
  640. **                         BYTE *quotient,
  641. **                         BYTE *remainder)
  642. **-----------------------------------------------------------------------------
  643. */
  644. #ifdef __FUNCTION_PROTOTYPES
  645. void multosBlockDivide (const BYTE blockLength, BYTE *numerator,
  646.                         BYTE *denominator, BYTE *quotient, BYTE *remainder);
  647. #else
  648. #define multosBlockDivide(blockLength, numerator, denominator, quotient, remainder) \
  649. do  \
  650. { \
  651.     __push (__BLOCKCAST(blockLength)(__typechk(BYTE *, numerator))); \
  652.     __push (__BLOCKCAST(blockLength)(__typechk(BYTE *, denominator))); \
  653.     __code (__PRIM, __PRIM_DIVIDEN, blockLength); \
  654.     __code (__STORE, __typechk(BYTE *, remainder), blockLength); \
  655.     __code (__STORE, __typechk(BYTE *, quotient), blockLength);     \
  656. } while (0)
  657. #endif
  658.  
  659. /*
  660. **-----------------------------------------------------------------------------
  661. ** void multosBlockEncipherCBC (const BYTE algorithm,
  662. **                              WORD blockLength,
  663. **                              BYTE *plainText,
  664. **                              BYTE *cipherText,
  665. **                              BYTE initialValueLength,
  666. **                              BYTE *initialValue,
  667. **                              BYTE keyLength,
  668. **                              BYTE *key)
  669. **-----------------------------------------------------------------------------
  670. */
  671. #ifdef __FUNCTION_PROTOTYPES
  672. void multosBlockEncipherCBC (const BYTE algorithm, WORD inputLength,
  673.                              BYTE *plainText, BYTE *cipherText,
  674.                              BYTE initialValueLength, BYTE *initialValue,
  675.                              BYTE keyLength, BYTE *key);
  676. #else
  677. #define multosBlockEncipherCBC(algorithm, inputLength, plainText, cipherText, initialValueLength, initialValue, keyLength, key) \
  678. do \
  679. { \
  680.     __push (__typechk(BYTE, initialValueLength)); \
  681.     __push (__typechk(BYTE *, initialValue)); \
  682.     __push (__typechk(WORD, inputLength)); \
  683.     __push (__typechk(BYTE *, key)); \
  684.     __push (__typechk(BYTE, keyLength)); \
  685.     __push (__typechk(BYTE *, cipherText)); \
  686.     __push (__typechk(BYTE *, plainText)); \
  687.     __code (__PRIM, __PRIM_BLOCK_ENCIPHER_ECB, algorithm, 2); \
  688. } while (0)
  689. #endif
  690.  
  691. /*
  692. **-----------------------------------------------------------------------------
  693. ** void multosBlockEncipherECB (const BYTE algorithm,
  694. **                              WORD blockLength,
  695. **                              BYTE *plainText,
  696. **                              BYTE *cipherText,
  697. **                              BYTE keyLength,
  698. **                              BYTE *key)
  699. **-----------------------------------------------------------------------------
  700. */
  701. #ifdef __FUNCTION_PROTOTYPES
  702. void multosBlockEncipherECB (const BYTE algorithm, WORD inputLength,
  703.                              BYTE *plainText, BYTE *cipherText, BYTE keyLength,
  704.                              BYTE *key);
  705. #else
  706. #define multosBlockEncipherECB(algorithm, inputLength, plainText, cipherText, keyLength, key) \
  707. do \
  708. { \
  709.     __push (__typechk(WORD, inputLength)); \
  710.     __push (__typechk(BYTE *, key)); \
  711.     __push (__typechk(BYTE, keyLength)); \
  712.     __push (__typechk(BYTE *, cipherText)); \
  713.     __push (__typechk(BYTE *, plainText)); \
  714.     __code (__PRIM, __PRIM_BLOCK_ENCIPHER_ECB, algorithm, 1); \
  715. } while (0)
  716. #endif
  717.  
  718. /*
  719. **-----------------------------------------------------------------------------
  720. ** void multosBlockIncrement (const BYTE blockLength,
  721. **                            const BYTE *block)
  722. **-----------------------------------------------------------------------------
  723. */
  724. #ifdef __FUNCTION_PROTOTYPES
  725. void multosBlockIncrement (const BYTE blockLength, const BYTE *block);
  726. #else
  727. #define multosBlockIncrement(blockLength, block) \
  728.     __UNARY_OPN (blockLength, __INCN, block);
  729. #endif
  730.  
  731. /*
  732. **-----------------------------------------------------------------------------
  733. ** void multosBlockInvert (const BYTE blockLength,
  734. **                         const BYTE *block)
  735. **-----------------------------------------------------------------------------
  736. */
  737. #ifdef __FUNCTION_PROTOTYPES
  738. void multosBlockInvert (const BYTE blockLength, const BYTE *block);
  739. #else
  740. #define multosBlockInvert(blockLength, block) \
  741.     __UNARY_OPN (blockLength, __NOTN, block);
  742. #endif
  743.  
  744. /*
  745. **-----------------------------------------------------------------------------
  746. ** void multosBlockLookup (BYTE value,
  747. **                         BYTE *block,
  748. **                         BYTE *result,
  749. **                         BOOL *byteFound)
  750. **-----------------------------------------------------------------------------
  751. */
  752. #ifdef __FUNCTION_PROTOTYPES
  753. void multosBlockLookup (BYTE value, BYTE *block, BYTE *result,
  754.                         BOOL *byteFound);
  755. #else
  756. #define multosBlockLookup(value, block, result, byteFound) \
  757. do  \
  758. { \
  759.     __push (__typechk(BYTE, value)); \
  760.     __push (__typechk(BYTE *, block)); \
  761.     __code (__PRIM, __PRIM_LOOKUP); \
  762.     __code (__STORE, __typechk(BYTE *, result), 1); \
  763.     __code (__PRIM, __PRIM_LOAD_CCR); \
  764.     __code (__PRIM, __PRIM_BIT_MANIPULATE_BYTE, 0x83, 0x01); \
  765.     __code (__STORE, __typechk(BOOL *, byteFound), 1); \
  766. } while (0)
  767. #endif
  768.  
  769. /*
  770. **-----------------------------------------------------------------------------
  771. ** void multosBlockMultiply (const BYTE blockLength,
  772. **                           BYTE *block1,
  773. **                           BYTE *block2,
  774. **                           BYTE *result)
  775. **-----------------------------------------------------------------------------
  776. */
  777. #ifdef __FUNCTION_PROTOTYPES
  778. void multosBlockMultiply (const BYTE blockLength, BYTE *block1, BYTE *block2,
  779.                           BYTE *result);
  780. #else
  781. #define multosBlockMultiply(blockLength, block1, block2, result) \
  782. do \
  783. { \
  784.     __push (__BLOCKCAST(blockLength)(__typechk(BYTE *, block1))); \
  785.     __push (__BLOCKCAST(blockLength)(__typechk(BYTE *, block2))); \
  786.     __code (__PRIM, __PRIM_MULTIPLYN, blockLength); \
  787.     __code (__STORE, __typechk(BYTE *, result), blockLength*2); \
  788. } while (0)
  789. #endif
  790.  
  791. /*
  792. **-----------------------------------------------------------------------------
  793. ** void multosBlockOr (const BYTE blockLength,
  794. **                     BYTE *block1,
  795. **                     BYTE *block2,
  796. **                     BYTE *result)
  797. **-----------------------------------------------------------------------------
  798. */
  799. #ifdef __FUNCTION_PROTOTYPES
  800. void multosBlockOr (const BYTE blockLength, BYTE *block1, BYTE *block2,
  801.                     BYTE *result);
  802. #else
  803. #define multosBlockOr(blockLength, block1, block2, result) \
  804.     __BINARY_OPN (blockLength, __ORN, result, block1, block2)
  805. #endif
  806.  
  807. /*
  808. **-----------------------------------------------------------------------------
  809. ** void multosBlockShiftLeft (const BYTE blockLength,
  810. **                            const BYTE numShiftBits,
  811. **                            BYTE *blockSource,
  812. **                            BYTE *blockDest)
  813. **-----------------------------------------------------------------------------
  814. */
  815. #ifdef __FUNCTION_PROTOTYPES
  816. void multosBlockShiftLeft (const BYTE blockLength, const BYTE numShiftBits,
  817.                            BYTE *blockSource, BYTE *blockDest);
  818. #else
  819. #define multosBlockShiftLeft(blockLength, numShiftBits, blockSource, blockDest) \
  820. do \
  821. { \
  822.     __push (__BLOCKCAST(blockLength)(__typechk(BYTE *, blockSource))); \
  823.     __code (__PRIM, __PRIM_SHIFT_LEFT, blockLength, numShiftBits); \
  824.     __code (__STORE, __typechk(BYTE *, blockDest), blockLength); \
  825. } while (0)
  826. #endif
  827.  
  828. /*
  829. **-----------------------------------------------------------------------------
  830. ** void multosBlockShiftRight (const BYTE blockLength,
  831. **                             const BYTE numShiftBits,
  832. **                             BYTE *blockSource,
  833. **                             BYTE *blockDest)
  834. **-----------------------------------------------------------------------------
  835. */
  836. #ifdef __FUNCTION_PROTOTYPES
  837. void multosBlockShiftRight (const BYTE blockLength, const BYTE numShiftBits,
  838.                             BYTE *blockSource, BYTE *blockDest);
  839. #else
  840. #define multosBlockShiftRight(blockLength, numShiftBits, blockSource, blockDest) \
  841. do \
  842. { \
  843.     __push (__BLOCKCAST(blockLength)(__typechk(BYTE *, blockSource))); \
  844.     __code (__PRIM, __PRIM_SHIFT_RIGHT, blockLength, numShiftBits); \
  845.     __code (__STORE, __typechk(BYTE *, blockDest), blockLength); \
  846. } while (0)
  847. #endif
  848.  
  849. /*
  850. **-----------------------------------------------------------------------------
  851. ** void multosBlockSubtract (const BYTE blockLength,
  852. **                          BYTE *block1,
  853. **                          BYTE *block2,
  854. **                          const BYTE *result)
  855. **-----------------------------------------------------------------------------
  856. */
  857. #ifdef __FUNCTION_PROTOTYPES
  858. void multosBlockSubtract (const BYTE blockLength, BYTE *block1, BYTE *block2,
  859.                          const BYTE *result);
  860. #else
  861. #define multosBlockSubtract(blockLength, block1, block2, result) \
  862.     __BINARY_OPN (blockLength, __SUBN, result, block1, block2)
  863. #endif
  864.  
  865. /*
  866. **-----------------------------------------------------------------------------
  867. ** void multosBlockTestZero (const BYTE blockLength,
  868. **                           const BYTE *block,
  869. **                           BOOL *isZero)
  870. **-----------------------------------------------------------------------------
  871. */
  872. #ifdef __FUNCTION_PROTOTYPES
  873. void multosBlockTestZero (const BYTE blockLength, const BYTE *block,
  874.                           BOOL *isZero);
  875. #else
  876. #define multosBlockTestZero(blockLength, block, isZero) \
  877. do  \
  878. { \
  879.     __UNARY_OPN (blockLength, __TESTN, block) \
  880.     __code (__PRIM, __PRIM_LOAD_CCR); \
  881.     __code (__PRIM, __PRIM_BIT_MANIPULATE_BYTE, 0x83, 0x01); \
  882.     __code (__STORE, __typechk(BOOL *, isZero), 1); \
  883. } while (0)
  884. #endif
  885.  
  886. /*
  887. **-----------------------------------------------------------------------------
  888. ** void multosBlockXor (const BYTE blockLength,
  889. **                      BYTE *block1,
  890. **                      BYTE *block2,
  891. **                      BYTE *result)
  892. **-----------------------------------------------------------------------------
  893. */
  894. #ifdef __FUNCTION_PROTOTYPES
  895. void multosBlockXor (const BYTE blockLength, BYTE *block1, BYTE *block2,
  896.                      BYTE *result);
  897. #else
  898. #define multosBlockXor(blockLength, block1, block2, result) \
  899.     __BINARY_OPN (blockLength, __XORN, result, block1, block2)
  900. #endif
  901.  
  902. /*
  903. **-----------------------------------------------------------------------------
  904. ** void multosCallCodelet (WORD codeletID,
  905. **                         WORD entryAddress)
  906. **-----------------------------------------------------------------------------
  907. */
  908. #ifdef __FUNCTION_PROTOTYPES
  909. void multosCallCodelet (WORD codeletID, WORD entryAddress);
  910. #else
  911. #define multosCallCodelet(codeletID, entryAddress) \
  912. do \
  913. { \
  914.     __push (__typechk(WORD, codeletID)); \
  915.     __push (__typechk(WORD, entryAddress)); \
  916.     __code (__PRIM, __PRIM_CALL_CODELET); \
  917. } while (0)
  918. #endif
  919.  
  920. /*
  921. **-----------------------------------------------------------------------------
  922. ** void multosCallExtensionPrimitive (const BYTE extensionNum,
  923. **                                    const BYTE primTypeLo,
  924. **                                    const BYTE primTypeHi,
  925. **                                    const BYTE paramByte)
  926. **-----------------------------------------------------------------------------
  927. */
  928. #ifdef __FUNCTION_PROTOTYPES
  929. void multosCallExtensionPrimitive (const BYTE extensionNum,
  930.                                    const BYTE primTypeLo, const BYTE primTypeHi,
  931.                                    const BYTE paramByte);
  932. #else
  933. #define multosCallExtensionPrimitive(extensionNum, primTypeLo, primTypeHi, paramByte) \
  934.     __code (__PRIM, __PRIM_CALL_EXTENSION_PRIMITIVE+extensionNum, primTypeLo, primTypeHi, paramByte)
  935. #endif
  936.  
  937. /*
  938. **-----------------------------------------------------------------------------
  939. ** void multosCardBlock (const BYTE offsetMAChi,
  940. **                       const BYTE offsetMAClo,
  941. **                       BOOL *cardBlockedOk)
  942. **-----------------------------------------------------------------------------
  943. */
  944. #ifdef __FUNCTION_PROTOTYPES
  945. void multosCardBlock (const BYTE offsetMAChi, const BYTE offsetMAClo,
  946.                       BOOL *cardBlockedOk);
  947. #else
  948. #define multosCardBlock(offsetMAChi, offsetMAClo, cardBlockedOk) \
  949. do \
  950. { \
  951.     __code (__PRIM, __PRIM_CARD_BLOCK, offsetMAChi, offsetMAClo); \
  952.     __code (__PRIM, __PRIM_LOAD_CCR); \
  953.     __code (__PRIM, __PRIM_BIT_MANIPULATE_BYTE, (0x83), 0x01); \
  954.     __code (__STORE, __typechk(BOOL *, cardBlockedOk), 1); \
  955. } while (0)
  956. #endif
  957.  
  958. /*
  959. **-----------------------------------------------------------------------------
  960. ** BOOL multosCheckCase (BYTE isoCase)
  961. **-----------------------------------------------------------------------------
  962. */
  963. BOOL CheckCase (BYTE isocase);
  964. #ifdef __FUNCTION_PROTOTYPES
  965. BOOL multosCheckCase (BYTE isoCase);
  966. #else
  967. #define multosCheckCase(isoCase) (BOOL)CheckCase(isoCase)
  968. #endif
  969.  
  970. /*
  971. **-----------------------------------------------------------------------------
  972. ** void multosChecksum (WORD blockLength,
  973. **                      BYTE *block,
  974. **                      DWORD *result)
  975. **-----------------------------------------------------------------------------
  976. */
  977. #ifdef __FUNCTION_PROTOTYPES
  978. void multosChecksum (WORD blockLength, BYTE *block, DWORD *result);
  979. #else
  980. #define multosChecksum(blockLength, block, result) \
  981. do \
  982. { \
  983.     __push (__typechk(WORD, blockLength)); \
  984.     __push (__typechk(BYTE *, block)); \
  985.     __code (__PRIM, __PRIM_CHECKSUM); \
  986.     __code (__STORE, __typechk(DWORD *, result), 4); \
  987. } while (0)
  988. #endif
  989.  
  990. /*
  991. **-----------------------------------------------------------------------------
  992. ** void multosControlAutoResetWWT (BOOL disable)
  993. **-----------------------------------------------------------------------------
  994. */
  995. #ifdef __FUNCTION_PROTOTYPES
  996. void multosControlAutoResetWWT (BOOL disable);
  997. #else
  998. #define multosControlAutoResetWWT(disable) \
  999. do \
  1000. { \
  1001.     __push (__typechk(BOOL, disable)); \
  1002.     __code (__PRIM, __PRIM_CONTROL_AUTO_RESET_WWT); \
  1003. } while (0)
  1004. #endif
  1005.  
  1006. /*
  1007. **-----------------------------------------------------------------------------
  1008. ** void multosConvertBCD (BYTE mode)
  1009. **-----------------------------------------------------------------------------
  1010. */
  1011. #define MULTOS_BCD_TO_BIN   (0x00)
  1012. #define MULTOS_BIN_TO_BCD   (0x01)
  1013. #ifdef __FUNCTION_PROTOTYPES
  1014. void multosConvertBCD (BYTE mode, BYTE srcLength, BYTE destLength, BYTE *src,
  1015.                        BYTE *dest, BOOL *convertedOK);
  1016. #else
  1017. #define multosConvertBCD(mode, srcLength, destLength, src, dest, convertedOK) \
  1018. do \
  1019. { \
  1020.     __push (__typechk(BYTE, destLength)); \
  1021.     __push (__typechk(BYTE, srcLength)); \
  1022.     __push (__typechk(BYTE *, dest)); \
  1023.     __push (__typechk(BYTE *, src)); \
  1024.     __code (__PRIM, __PRIM_CONVERT_BCD, mode); \
  1025.     __code (__PRIM, __PRIM_LOAD_CCR); \
  1026.     __code (__PRIM, __PRIM_BIT_MANIPULATE_BYTE, (0x83), 0x01); \
  1027.     __code (__STORE, __typechk(BOOL *, convertedOK), 1); \
  1028. } while (0)
  1029. #endif
  1030.  
  1031. /*
  1032. **-----------------------------------------------------------------------------
  1033. ** void multosDelegate (BYTE *aid)
  1034. **-----------------------------------------------------------------------------
  1035. */
  1036. #ifdef __FUNCTION_PROTOTYPES
  1037. void multosDelegate (BYTE *aid);
  1038. #else
  1039. #define multosDelegate(aid) \
  1040. do \
  1041. {\
  1042.     __push (__typechk(BYTE *, aid)); \
  1043.     __code (__PRIM, __PRIM_DELEGATE); \
  1044. } while (0)
  1045. #endif
  1046.  
  1047. /*
  1048. **-----------------------------------------------------------------------------
  1049. ** void multosDESECBDecipher (BYTE *cipherText,
  1050. **                            BYTE *plainText,
  1051. **                            BYTE key[8])
  1052. **-----------------------------------------------------------------------------
  1053. */
  1054. #ifdef __FUNCTION_PROTOTYPES
  1055. void multosDESECBDecipher (BYTE *cipherText, BYTE *plainText, BYTE key[8]);
  1056. #else
  1057. #define multosDESECBDecipher(cipherText, plainText, key) \
  1058. do \
  1059. { \
  1060.     __push (__typechk(BYTE *, key)); \
  1061.     __push (__typechk(BYTE *, plainText)); \
  1062.     __push (__typechk(BYTE *, cipherText));    \
  1063.     __code (__PRIM, __PRIM_DES_ECB_DECIPHER); \
  1064. } while (0)
  1065. #endif
  1066.  
  1067. /*
  1068. **-----------------------------------------------------------------------------
  1069. ** void multosDESECBEncipher (BYTE *plainText,
  1070. **                            BYTE *cipherText,
  1071. **                            BYTE key[8])
  1072. **-----------------------------------------------------------------------------
  1073. */
  1074. #ifdef __FUNCTION_PROTOTYPES
  1075. void multosDESECBEncipher (BYTE *plainText, BYTE *cipherText, BYTE key[8]);
  1076. #else
  1077. #define multosDESECBEncipher(plainText, cipherText, key) \
  1078. do \
  1079. { \
  1080.     __push (__typechk(BYTE *, key)); \
  1081.     __push (__typechk(BYTE *, cipherText)); \
  1082.     __push (__typechk(BYTE *, plainText)); \
  1083.     __code (__PRIM, __PRIM_DES_ECB_ENCIPHER); \
  1084. } while (0)
  1085. #endif
  1086.  
  1087. /*
  1088. **-----------------------------------------------------------------------------
  1089. ** void multosExchangeData (BYTE channelID,
  1090. **                          BYTE *data)
  1091. **-----------------------------------------------------------------------------
  1092. */
  1093. #ifdef __FUNCTION_PROTOTYPES
  1094. void multosExchangeData (BYTE channelID, BYTE *data);
  1095. #else
  1096. #define multosExchangeData(channelID, data) \
  1097. do \
  1098. { \
  1099.     __push (__typechk(BYTE, channelID)); \
  1100.     __push (__typechk(BYTE *, data)); \
  1101.     __code (__PRIM, __PRIM_EXCHANGE_DATA); \
  1102. } while (0)
  1103. #endif
  1104.  
  1105. /*
  1106. **-----------------------------------------------------------------------------
  1107. ** void multosExit (void)
  1108. **-----------------------------------------------------------------------------
  1109. */
  1110. #ifdef __FUNCTION_PROTOTYPES
  1111. void multosExit (void);
  1112. #else
  1113. #define multosExit() \
  1114.     __code (__SYSTEM, 4)
  1115. #endif
  1116.  
  1117. /*
  1118. **-----------------------------------------------------------------------------
  1119. ** void multosExitLa (const BYTE la)
  1120. **-----------------------------------------------------------------------------
  1121. */
  1122. #ifdef __FUNCTION_PROTOTYPES
  1123. void multosExitLa (const BYTE la);
  1124. #else
  1125. #define multosExitLa(la) \
  1126.     __code (__SYSTEM, 6, la)
  1127. #endif
  1128.  
  1129. /*
  1130. **-----------------------------------------------------------------------------
  1131. ** void multosExitSW (const WORD sw)
  1132. **-----------------------------------------------------------------------------
  1133. */
  1134. #ifdef __FUNCTION_PROTOTYPES
  1135. void multosExitSW (const WORD sw);
  1136. #else
  1137. #define multosExitSW(sw) \
  1138.     __code (__SYSTEM, 5, sw)
  1139. #endif
  1140.  
  1141. /*
  1142. **-----------------------------------------------------------------------------
  1143. ** void multosExitSWLa (const WORD sw,
  1144. **                      const BYTE la)
  1145. **-----------------------------------------------------------------------------
  1146. */
  1147. #ifdef __FUNCTION_PROTOTYPES
  1148. void multosExitSWLa (const WORD sw, const BYTE la);
  1149. #else
  1150. #define multosExitSWLa(sw, la) \
  1151.   __code (__SYSTEM, 7, sw, la)
  1152. #endif
  1153.  
  1154. /*
  1155. **-----------------------------------------------------------------------------
  1156. ** void multosExitToMultosAndRestart (void)
  1157. **-----------------------------------------------------------------------------
  1158. */
  1159. #ifdef __FUNCTION_PROTOTYPES
  1160. void multosExitToMultosAndRestart (void);
  1161. #else
  1162. #define multosExitToMultosAndRestart() \
  1163.     __code (__PRIM, __PRIM_EXIT_TO_MULTOS_AND_RESTART)
  1164. #endif
  1165.  
  1166. /*
  1167. **-----------------------------------------------------------------------------
  1168. ** void multosGenerateAsymmetricHash (WORD plainTextLength,
  1169. **                                    BYTE *plainText,
  1170. **                                    BYTE hash[16])
  1171. **-----------------------------------------------------------------------------
  1172. */
  1173. #ifdef __FUNCTION_PROTOTYPES
  1174. void multosGenerateAsymmetricHash (WORD plainTextLength, BYTE *plainText,
  1175.                                    BYTE hash[16]);
  1176. #else
  1177. #define multosGenerateAsymmetricHash(plainTextLength, plainText, hash) \
  1178. do \
  1179. { \
  1180.     __push (__typechk(WORD, plainTextLength)); \
  1181.     __push (__typechk(BYTE *, hash)); \
  1182.     __push (__typechk(BYTE *, plainText)); \
  1183.     __code (__PRIM, __PRIM_GENERATE_ASYMMETRIC_HASH, 0); \
  1184. } while (0)
  1185. #endif
  1186.  
  1187. /*
  1188. **-----------------------------------------------------------------------------
  1189. ** void multosGenerateAsymmetricHashIV (BYTE initialValue[16],
  1190. **                                      WORD plainTextlength,
  1191. **                                      BYTE *plainText,
  1192. **                                      BYTE hash[16])
  1193. **-----------------------------------------------------------------------------
  1194. */
  1195. #ifdef __FUNCTION_PROTOTYPES
  1196. void multosGenerateAsymmetricHashIV (BYTE initialValue[16],
  1197.                                      WORD plainTextlength, BYTE *plainText,
  1198.                                      BYTE hash[16]);
  1199. #else
  1200. #define multosGenerateAsymmetricHashIV(initialValue, plainTextlength, plainText, hash) \
  1201. do \
  1202. { \
  1203.     __push (__typechk(BYTE *, initialValue)); \
  1204.     __push (__typechk(WORD, plainTextlength)); \
  1205.     __push (__typechk(BYTE *, hash)); \
  1206.     __push (__typechk(BYTE *, plainText)); \
  1207.     __code (__PRIM, __PRIM_GENERATE_ASYMMETRIC_HASH, 1); \
  1208. } while (0)
  1209. #endif
  1210.  
  1211. /*
  1212. **-----------------------------------------------------------------------------
  1213. ** void multosGenerateDESCBCSignature (WORD plainTextLength,
  1214. **                                     BYTE *plainText,
  1215. **                                     BYTE initialValue[8],
  1216. **                                     BYTE key[8],
  1217. **                                     BYTE signature[8])
  1218. **-----------------------------------------------------------------------------
  1219. */
  1220. #ifdef __FUNCTION_PROTOTYPES
  1221. void multosGenerateDESCBCSignature (WORD plainTextLength, BYTE *plainText,
  1222.                                     BYTE initialValue[8], BYTE key[8],
  1223.                                     BYTE signature[8]);
  1224. #else
  1225. #define multosGenerateDESCBCSignature(plainTextLength, plainText, initialValue, key, signature) \
  1226. do \
  1227. { \
  1228.     __push (__typechk(WORD, plainTextLength)); \
  1229.     __push (__typechk(BYTE *, initialValue)); \
  1230.     __push (__typechk(BYTE *, key)); \
  1231.     __push (__typechk(BYTE *, signature)); \
  1232.     __push (__typechk(BYTE *, plainText)); \
  1233.     __code (__PRIM, __PRIM_GENERATE_DES_CBC_SIGNATURE); \
  1234. } while (0)
  1235. #endif
  1236.  
  1237. /*
  1238. **-----------------------------------------------------------------------------
  1239. ** void multosGenerateTripleDESCBCSignature (WORD plainTextLength,
  1240. **                                           BYTE *plainText,
  1241. **                                           BYTE initialValue[8],
  1242. **                                           BYTE keys[16],
  1243. **                                           BYTE signature[8])
  1244. **-----------------------------------------------------------------------------
  1245. */
  1246. #ifdef __FUNCTION_PROTOTYPES
  1247. void multosGenerateTripleDESCBCSignature (WORD plainTextLength, BYTE *plainText,
  1248.                                           BYTE initialValue[8], BYTE keys[16],
  1249.                                           BYTE signature[8]);
  1250. #else
  1251. #define multosGenerateTripleDESCBCSignature(plainTextLength, plainText, initialValue, keys, signature) \
  1252. do \
  1253. { \
  1254.     __push (__typechk(WORD, plainTextLength)); \
  1255.     __push (__typechk(BYTE *, initialValue)); \
  1256.     __push (__typechk(BYTE *, keys)); \
  1257.     __push (__typechk(BYTE *, signature)); \
  1258.     __push (__typechk(BYTE *, plainText)); \
  1259.     __code (__PRIM, __PRIM_GENERATE_TRIPLE_DES_CBC_SIGNATURE); \
  1260. } while (0)
  1261. #endif
  1262.  
  1263. /*
  1264. **-----------------------------------------------------------------------------
  1265. ** void multosGetData (const BYTE numDataBytes,
  1266. **                     BYTE *numCopied,
  1267. **                     BYTE *output)
  1268. **-----------------------------------------------------------------------------
  1269. */
  1270. #ifdef __FUNCTION_PROTOTYPES
  1271. void multosGetData (const BYTE numDataBytes, BYTE *numCopied, BYTE *output);
  1272. #else
  1273. #define multosGetData(numDataBytes, numCopied, output) \
  1274. do \
  1275. { \
  1276.     __push (__typechk(BYTE *, output));     \
  1277.     __code (__PRIM, __PRIM_GET_DATA, numDataBytes); \
  1278.     __code (__STORE, __typechk(BYTE *, numCopied), 1); \
  1279. } while (0)
  1280. #endif
  1281.  
  1282. /*
  1283. **-----------------------------------------------------------------------------
  1284. ** void multosGetDelegatorAID (const WORD aidLength,
  1285. **                             BYTE *aid,
  1286. **                             BOOL *notADelegate)
  1287. **-----------------------------------------------------------------------------
  1288. */
  1289. #ifdef __FUNCTION_PROTOTYPES
  1290. void multosGetDelegatorAID (const BYTE aidLength, BYTE *aid,
  1291.                             BOOL *notADelegate);
  1292. #else
  1293. #define multosGetDelegatorAID(aidLength, aid, notADelegate) \
  1294. do  \
  1295. { \
  1296.     __push (__typechk(BYTE *, aid)); \
  1297.     __code (__PRIM, __PRIM_GET_DELEGATOR_AID, aidLength); \
  1298.     __code (__PRIM, __PRIM_LOAD_CCR); \
  1299.     __code (__PRIM, __PRIM_BIT_MANIPULATE_BYTE, 0x83, 1); \
  1300.     __code (__STORE, __typechk(BYTE *, notADelegate), 1); \
  1301. } while (0)
  1302. #endif
  1303.  
  1304. /*
  1305. **-----------------------------------------------------------------------------
  1306. ** void multosGetDIRFileRecord (const BYTE dirRecordLength,
  1307. **                              BYTE recordNum,
  1308. **                              BYTE *numCopied,
  1309. **                              BYTE *output,
  1310. **                              BOOL *noRecordFound)
  1311. **-----------------------------------------------------------------------------
  1312. */
  1313. #ifdef __FUNCTION_PROTOTYPES
  1314. void multosGetDIRFileRecord (const BYTE dirRecordLength, BYTE recordNum,
  1315.                              BYTE *numCopied, BYTE *output,
  1316.                              BOOL *noRecordFound);
  1317. #else
  1318. #define multosGetDIRFileRecord(dirRecordLength, recordNum, numCopied, output, noRecordFound) \
  1319. do \
  1320. { \
  1321.     __push (__typechk(BYTE *, output)); \
  1322.     __push (__typechk(BYTE, recordNum)); \
  1323.     __code (__PRIM, __PRIM_GET_DIR_FILE_RECORD, dirRecordLength); \
  1324.     __code (__STORE, __typechk(BYTE *, numCopied), 1); \
  1325.     __code (__POPN, 3);    \
  1326.     __code (__PRIM, __PRIM_LOAD_CCR); \
  1327.     __code (__PRIM, __PRIM_BIT_MANIPULATE_BYTE, 0x83, 1); \
  1328.     __code (__STORE, __typechk(BYTE *, noRecordFound), 1); \
  1329. } while (0)
  1330. #endif
  1331.  
  1332. /*
  1333. **-----------------------------------------------------------------------------
  1334. ** void multosGetFileControlInformation (const BYTE fciRecordLength,
  1335. **                                       BYTE recordNum,
  1336. **                                       BYTE *numCopied,
  1337. **                                       BYTE *output,
  1338. **                                       BOOL *noRecordFound)
  1339. **-----------------------------------------------------------------------------
  1340. */
  1341. #ifdef __FUNCTION_PROTOTYPES
  1342. void multosGetFileControlInformation (const BYTE fciRecordLength,
  1343.                                       BYTE recordNum, BYTE *numCopied,
  1344.                                       BYTE *output, BOOL *noRecordFound);
  1345. #else
  1346. #define multosGetFileControlInformation(fciRecordLength, recordNum, numCopied, output, noRecordFound) \
  1347. do \
  1348. { \
  1349.     __push (__typechk(BYTE *, output)); \
  1350.     __push (__typechk(BYTE, recordNum)); \
  1351.     __code (__PRIM, __PRIM_GET_FILE_CONTROL_INFORMATION, fciRecordLength); \
  1352.     __code (__STORE, __typechk(BYTE *, numCopied), 1); \
  1353.     __code (__POPN, 3); \
  1354.     __code (__PRIM, __PRIM_LOAD_CCR); \
  1355.     __code (__PRIM, __PRIM_BIT_MANIPULATE_BYTE, 0x83, 1); \
  1356.     __code (__STORE, __typechk(BYTE *, noRecordFound), 1); \
  1357. } while (0)
  1358. #endif
  1359.  
  1360. /*
  1361. **-----------------------------------------------------------------------------
  1362. ** void multosGetManufacturerData (const BYTE numDataBytes,
  1363. **                                 BYTE *numCopied,
  1364. **                                 BYTE *output)
  1365. **-----------------------------------------------------------------------------
  1366. */
  1367. #ifdef __FUNCTION_PROTOTYPES
  1368. void multosGetManufacturerData (const BYTE numDataBytes, BYTE *numCopied,
  1369.                                 BYTE *output);
  1370. #else
  1371. #define multosGetManufacturerData(numDataBytes, numCopied, output) \
  1372. do \
  1373. { \
  1374.     __push (__typechk(BYTE *, output)); \
  1375.     __code (__PRIM, __PRIM_GET_MANUFACTURER_DATA, numDataBytes); \
  1376.     __code (__STORE, __typechk(BYTE *, numCopied), 1); \
  1377. } while (0)
  1378. #endif
  1379.  
  1380. /*
  1381. **-----------------------------------------------------------------------------
  1382. ** void multosGetMemoryReliability (BYTE *result)
  1383. **-----------------------------------------------------------------------------
  1384. */
  1385. #define MULTOS_MEMORY_RELIABLE     (0)
  1386. #define MULTOS_MEMORY_MARGINAL     (1)
  1387. #define MULTOS_MEMORY_UNRELIABLE   (8)
  1388. #ifdef __FUNCTION_PROTOTYPES
  1389. void multosGetMemoryReliability (BYTE *result);
  1390. #else
  1391. #define multosGetMemoryReliability(result) \
  1392. do \
  1393. { \
  1394.     __code (__PRIM, __PRIM_GET_MEMORY_RELIABILITY); \
  1395.     __code (__PRIM, __PRIM_LOAD_CCR); \
  1396.     __code (__PRIM, __PRIM_BIT_MANIPULATE_BYTE, 0x09, 1); \
  1397.     __code (__STORE, __typechk(BYTE *, result), 1);  \
  1398. } while (0)
  1399. #endif
  1400.  
  1401. /*
  1402. **-----------------------------------------------------------------------------
  1403. ** void multosGetMultosData (const BYTE numDataBytes,
  1404. **                           BYTE *numCopied,
  1405. **                           BYTE *output)
  1406. **-----------------------------------------------------------------------------
  1407. */
  1408. #ifdef __FUNCTION_PROTOTYPES
  1409. void multosGetMultosData (const BYTE numDataBytes, BYTE *numCopied,
  1410.                           BYTE *output);
  1411. #else
  1412. #define multosGetMultosData(numDataBytes, numCopied, output) \
  1413. do \
  1414. { \
  1415.     __push (__typechk(BYTE *, output));    \
  1416.     __code (__PRIM, __PRIM_GET_MULTOS_DATA, numDataBytes); \
  1417.     __code (__STORE, __typechk(BYTE *, numCopied), 1); \
  1418. } while (0)
  1419. #endif
  1420.  
  1421. /*
  1422. **-----------------------------------------------------------------------------
  1423. ** void multosGetRandomNumber (BYTE result[8])
  1424. **-----------------------------------------------------------------------------
  1425. */
  1426. #ifdef __FUNCTION_PROTOTYPES
  1427. void multosGetRandomNumber (BYTE result[8]);
  1428. #else
  1429. #define multosGetRandomNumber(result) \
  1430. do \
  1431. { \
  1432.   __code (__PRIM, __PRIM_GET_RANDOM_NUMBER); \
  1433.   __code (__STORE, __typechk(BYTE *, result), 8); \
  1434. } while (0)
  1435. #endif
  1436.  
  1437. /*
  1438. **-----------------------------------------------------------------------------
  1439. ** void multosIndex (BYTE blockLength,
  1440. **                   BYTE index,
  1441. **                   BYTE *baseAddr,
  1442. **                   BYTE *resultData)
  1443. **-----------------------------------------------------------------------------
  1444. */
  1445. #ifdef __FUNCTION_PROTOTYPES
  1446. void multosIndex (BYTE blockLength, BYTE index, BYTE *baseAddr,
  1447.                   BYTE *resultData);
  1448. #else
  1449. #define multosIndex(blockLength, index, baseAddr, resultData) \
  1450. do \
  1451. { \
  1452.     __push (__typechk (BYTE, index)); \
  1453.     __code (__INDEX, baseAddr, blockLength); \
  1454.     __code (__LOADI, blockLength); \
  1455.     __code (__STORE, __typechk(BYTE *, resultData), blockLength); \
  1456. } while (0)
  1457. #endif
  1458.  
  1459. /*
  1460. **-----------------------------------------------------------------------------
  1461. ** void multosModularExponentiation (WORD exponentLength,
  1462. **                                   WORD modulusLength,
  1463. **                                   BYTE *exponent,
  1464. **                                   BYTE *modulus,
  1465. **                                   BYTE *input,
  1466. **                                   BYTE *output)
  1467. **-----------------------------------------------------------------------------
  1468. */
  1469. #ifdef __FUNCTION_PROTOTYPES
  1470. void multosModularExponentiation (WORD exponentLength, WORD modulusLength,
  1471.                                   BYTE *exponent, BYTE *modulus, BYTE *input,
  1472.                                   BYTE *output);
  1473. #else
  1474. #define multosModularExponentiation(exponentLength, modulusLength, exponent, modulus, input, output) \
  1475. do \
  1476. { \
  1477.     __push (__typechk(WORD, exponentLength)); \
  1478.     __push (__typechk(WORD, modulusLength)); \
  1479.     __push (__typechk(BYTE *, exponent)); \
  1480.     __push (__typechk(BYTE *, modulus)); \
  1481.     __push (__typechk(BYTE *, input)); \
  1482.     __push (__typechk(BYTE *, output)); \
  1483.     __code (__PRIM, __PRIM_MODULAR_EXPONENTIATION); \
  1484. } while (0)
  1485. #endif
  1486.  
  1487. /*
  1488. **-----------------------------------------------------------------------------
  1489. ** void multosModularExponentiationCRT (WORD dpdqLength,
  1490. **                                      BYTE *dpdq,
  1491. **                                      BYTE *pqu,
  1492. **                                      BYTE *input,
  1493. **                                      BYTE *output)
  1494. **-----------------------------------------------------------------------------
  1495. */
  1496. #ifdef __FUNCTION_PROTOTYPES
  1497. void multosModularExponentiationCRT (WORD dpdqLength, BYTE *dpdq, BYTE *pqu,
  1498.                                      BYTE *input, BYTE *output);
  1499. #else
  1500. #define multosModularExponentiationCRT(dpdqLength, dpdq, pqu, input, output) \
  1501. do \
  1502. { \
  1503.     __push (__typechk(WORD, dpdqLength)); \
  1504.     __push (__typechk(BYTE *, dpdq)); \
  1505.     __push (__typechk(BYTE *, pqu)); \
  1506.     __push (__typechk(BYTE *, input)); \
  1507.     __push (__typechk(BYTE *, output));    \
  1508.     __code (__PRIM, __PRIM_MODULAR_EXPONENTIATION_CRT); \
  1509. } while (0)
  1510. #endif
  1511.  
  1512. /*
  1513. **-----------------------------------------------------------------------------
  1514. ** void multosModularExponentiationCRTProtected (WORD dpdqLength,
  1515. **                                               BYTE *dpdq,
  1516. **                                               BYTE *pqu,
  1517. **                                               BYTE *input,
  1518. **                                               BYTE *output)
  1519. **-----------------------------------------------------------------------------
  1520. */
  1521. #ifdef __FUNCTION_PROTOTYPES
  1522. void multosModularExponentiationCRTProtected (WORD dpdqLength, BYTE *dpdq,
  1523.                                               BYTE *pqu, BYTE *input,
  1524.                                               BYTE *output);
  1525. #else
  1526. #define multosModularExponentiationCRTProtected(dpdqLength, dpdq, pqu, input, output) \
  1527. do \
  1528. { \
  1529.     __push (__typechk(WORD, dpdqLength)); \
  1530.     __push (__typechk(BYTE *, dpdq)); \
  1531.     __push (__typechk(BYTE *, pqu)); \
  1532.     __push (__typechk(BYTE *, input)); \
  1533.     __push (__typechk(BYTE *, output));    \
  1534.     __code (__PRIM, __PRIM_MODULAR_EXPONENTIATION_CRT_PROTECTED); \
  1535. } while (0)
  1536. #endif
  1537.  
  1538. /*
  1539. **-----------------------------------------------------------------------------
  1540. ** void multosModularMultiplication (WORD modulusLength,
  1541. **                                   BYTE *modulus,
  1542. **                                   BYTE *block1,
  1543. **                                   BYTE *block2)
  1544. **-----------------------------------------------------------------------------
  1545. */
  1546. #ifdef __FUNCTION_PROTOTYPES
  1547. void multosModularMultiplication (WORD modulusLength, BYTE *modulus,
  1548.                                   BYTE *block1, BYTE *block2);
  1549. #else
  1550. #define multosModularMultiplication(modulusLength, modulus, block1, block2) \
  1551. do \
  1552. { \
  1553.     __push (__typechk(WORD, modulusLength)); \
  1554.     __push (__typechk(BYTE *, block1)); \
  1555.     __push (__typechk(BYTE *, block2)); \
  1556.     __push (__typechk(BYTE *, modulus)); \
  1557.     __code (__PRIM, __PRIM_MODULAR_MULTIPLICATION); \
  1558. } while (0)
  1559. #endif
  1560.  
  1561. /*
  1562. **-----------------------------------------------------------------------------
  1563. ** void multosModularReduction (WORD operandLength,
  1564. **                              WORD modulusLength,
  1565. **                              BYTE *operand,
  1566. **                              BYTE *modulus)
  1567. **-----------------------------------------------------------------------------
  1568. */
  1569. #ifdef __FUNCTION_PROTOTYPES
  1570. void multosModularReduction (WORD operandLength, WORD modulusLength,
  1571.                              BYTE *operand, BYTE *modulus);
  1572. #else
  1573. #define multosModularReduction(operandLength, modulusLength, operand, modulus) \
  1574. do \
  1575. { \
  1576.     __push (__typechk(WORD, operandLength)); \
  1577.     __push (__typechk(WORD, modulusLength)); \
  1578.     __push (__typechk(BYTE *, operand)); \
  1579.     __push (__typechk(BYTE *, modulus)); \
  1580.     __code (__PRIM, __PRIM_MODULAR_REDUCTION); \
  1581. } while (0)
  1582. #endif
  1583.  
  1584. /*
  1585. **-----------------------------------------------------------------------------
  1586. ** void multosPlatformOptimisedChecksum (WORD blockLength,
  1587. **                                       BYTE *block,
  1588. **                                       DWORD *result)
  1589. **-----------------------------------------------------------------------------
  1590. */
  1591. #ifdef __FUNCTION_PROTOTYPES
  1592. void multosPlatformOptimisedChecksum (WORD blockLength, BYTE *block,
  1593.                                       DWORD *result);
  1594. #else
  1595. #define multosPlatformOptimisedChecksum(blockLength, block, result) \
  1596. do \
  1597. { \
  1598.     __push (__typechk(WORD, blockLength)); \
  1599.     __push (__typechk(BYTE *, block)); \
  1600.     __code (__PRIM, __PRIM_PLATFORM_OPTIMISED_CHECKSUM); \
  1601.     __code (__STORE, __typechk(DWORD *, result), 4); \
  1602. } while (0)
  1603. #endif
  1604.  
  1605. /*
  1606. **-----------------------------------------------------------------------------
  1607. ** void multosQueryInterfaceType (BOOL *isContactless)
  1608. **
  1609. **-----------------------------------------------------------------------------
  1610. */
  1611. #ifdef __FUNCTION_PROTOTYPES
  1612. void multosQueryInterfaceType (BOOL *isContactless);
  1613. #else
  1614. #define multosQueryInterfaceType(isContactless) \
  1615. do \
  1616. { \
  1617.     __code (__PRIM, __PRIM_QUERY_INTERFACE_TYPE); \
  1618.     __code (__PRIM, __PRIM_LOAD_CCR); \
  1619.     __code (__PRIM, __PRIM_BIT_MANIPULATE_BYTE, 0x83, 1); \
  1620.     __code (__STORE, __typechk(BOOL *, isContactless), 1); \
  1621. } while (0)
  1622. #endif
  1623.  
  1624. /*
  1625. **-----------------------------------------------------------------------------
  1626. ** void multosQueryChannel (BYTE channelID,
  1627. **                          BOOL *channelSupported)
  1628. **-----------------------------------------------------------------------------
  1629. */
  1630. #ifdef __FUNCTION_PROTOTYPES
  1631. void multosQueryChannel (BYTE channelID, BOOL *channelSupported);
  1632. #else
  1633. #define multosQueryChannel(channelID, channelSupported) \
  1634. do \
  1635. { \
  1636.     __push (__typechk(BYTE, channelID)); \
  1637.     __code (__PRIM, __PRIM_QUERY_CHANNEL); \
  1638.     __code (__PRIM, __PRIM_LOAD_CCR); \
  1639.     __code (__PRIM, __PRIM_BIT_MANIPULATE_BYTE, 0x83, 1); \
  1640.     __code (__STORE, __typechk(BOOL *, channelSupported), 1); \
  1641. } while (0)
  1642. #endif
  1643.  
  1644. /*
  1645. **-----------------------------------------------------------------------------
  1646. ** void multosQueryCodelet (WORD codeletID,
  1647. **                          BOOL *codeletSupported)
  1648. **-----------------------------------------------------------------------------
  1649. */
  1650. #ifdef __FUNCTION_PROTOTYPES
  1651. void multosQueryCodelet (WORD codeletID, BOOL *codeletSupported);
  1652. #else
  1653. #define multosQueryCodelet(codeletID, codeletSupported) \
  1654. do \
  1655. { \
  1656.     __push (__typechk(WORD, codeletID)); \
  1657.     __code (__PRIM, __PRIM_QUERY_CODELET); \
  1658.     __code (__PRIM, __PRIM_LOAD_CCR); \
  1659.     __code (__PRIM, __PRIM_BIT_MANIPULATE_BYTE, 0x83, 1); \
  1660.     __code (__STORE, __typechk(BOOL *, codeletSupported), 1); \
  1661. } while (0);
  1662. #endif
  1663.  
  1664. /*
  1665. **-----------------------------------------------------------------------------
  1666. ** void multosQueryPrimitive (const BYTE setNum,
  1667. **                            const BYTE primitiveNum,
  1668. **                            BOOL *primitiveSupported)
  1669. **-----------------------------------------------------------------------------
  1670. */
  1671. #ifdef __FUNCTION_PROTOTYPES
  1672. void multosQueryPrimitive (const BYTE setNum, const BYTE primitiveNum,
  1673.                            BOOL *primitiveSupported);
  1674. #else
  1675. #define multosQueryPrimitive(setNum, primitiveNum, primitiveSupported) \
  1676. do  \
  1677. { \
  1678.     __code (__PRIM, __PRIM_QUERY + setNum, primitiveNum); \
  1679.     __code (__PRIM, __PRIM_LOAD_CCR); \
  1680.     __code (__PRIM, __PRIM_BIT_MANIPULATE_BYTE, 0x83, 1); \
  1681.     __code (__STORE, __typechk(BOOL *, primitiveSupported), 1); \
  1682. } while (0);
  1683. #endif
  1684.  
  1685. /*
  1686. **-----------------------------------------------------------------------------
  1687. ** void multosResetSessionData (void)
  1688. **-----------------------------------------------------------------------------
  1689. */
  1690. #ifdef __FUNCTION_PROTOTYPES
  1691. void multosResetSessionData (void);
  1692. #else
  1693. #define multosResetSessionData() \
  1694.   __code (__PRIM, __PRIM_RESET_SESSION_DATA)
  1695. #endif
  1696.  
  1697. /*
  1698. **-----------------------------------------------------------------------------
  1699. ** void multosResetWWT (void)
  1700. **-----------------------------------------------------------------------------
  1701. */
  1702. #ifdef __FUNCTION_PROTOTYPES
  1703. void multosResetWWT (void);
  1704. #else
  1705. #define multosResetWWT() \
  1706.     __code (__PRIM, __PRIM_RESET_WWT)
  1707. #endif
  1708.  
  1709. /*
  1710. **-----------------------------------------------------------------------------
  1711. ** void multosReturnFromCodelet (const BYTE numBytesIn,
  1712. **                               const BYTE numBytesOut)
  1713. **-----------------------------------------------------------------------------
  1714. */
  1715. #ifdef __FUNCTION_PROTOTYPES
  1716. void multosReturnFromCodelet (const BYTE numBytesIn, const BYTE numBytesOut);
  1717. #else
  1718. #define multosReturnFromCodelet(numBytesIn, numBytesOut) \
  1719.     __code (__PRIM, __PRIM_RETURN_FROM_CODELET, numBytesIn, numBytesOut)
  1720. #endif
  1721.  
  1722. /*
  1723. **-----------------------------------------------------------------------------
  1724. ** void multosSetATRFileRecord (BYTE *record,
  1725. **                              BYTE *numBytesWritten)
  1726. **-----------------------------------------------------------------------------
  1727. */
  1728. #ifdef __FUNCTION_PROTOTYPES
  1729. void multosSetATRFileRecord (BYTE *record, BYTE *numBytesWritten);
  1730. #else
  1731. #define multosSetATRFileRecord(record, numBytesWritten) \
  1732. do \
  1733. { \
  1734.     __push (__typechk(BYTE *, record)); \
  1735.     __code (__PRIM, __PRIM_SET_ATR_FILE_RECORD); \
  1736.     __code (__STORE, __typechk(BYTE *, numBytesWritten), 1); \
  1737. } while (0)
  1738. #endif
  1739.  
  1740. /*
  1741. **-----------------------------------------------------------------------------
  1742. ** void multosSetATRHistoricalCharacters (BYTE *input,
  1743. **                                        BYTE *numBytesWritten)
  1744. **-----------------------------------------------------------------------------
  1745. */
  1746. #ifdef __FUNCTION_PROTOTYPES
  1747. void multosSetATRHistoricalCharacters (BYTE *input, BYTE *numBytesWritten);
  1748. #else
  1749. #define multosSetATRHistoricalCharacters(input, numBytesWritten) \
  1750. do \
  1751. { \
  1752.     __push (__typechk(BYTE *, input)); \
  1753.     __code (__PRIM, __PRIM_SET_ATR_HISTORICAL_CHARACTERS); \
  1754.     __code (__STORE, __typechk(BYTE *, numBytesWritten), 1); \
  1755. } while (0)
  1756. #endif
  1757.  
  1758. /*
  1759. **-----------------------------------------------------------------------------
  1760. ** void multosSetProtectedMemoryAccess (const BYTE options)
  1761. **-----------------------------------------------------------------------------
  1762. */
  1763. #define MULTOS_PROTECTED_MEMORY_ACCESS_OFF  (0)
  1764. #define MULTOS_PROTECTED_MEMORY_ACCESS_ON   (1)
  1765. #ifdef __FUNCTION_PROTOTYPES
  1766. void multosSetProtectedMemoryAccess (const BYTE options);
  1767. #else
  1768. #define multosSetProtectedMemoryAccess(options) \
  1769.     __code(__PRIM, __PRIM_SET_PROTECTED_MEMORY_ACCESS, options)
  1770. #endif
  1771.  
  1772. /*
  1773. **-----------------------------------------------------------------------------
  1774. ** void multosSetTransactionProtection (const BYTE options)
  1775. **-----------------------------------------------------------------------------
  1776. */
  1777. #define MULTOS_TP_OFF_AND_DISCARD   (0)
  1778. #define MULTOS_TP_OFF_AND_COMMIT    (1)
  1779. #define MULTOS_TP_ON_AND_DISCARD    (2)
  1780. #define MULTOS_TP_ON_AND_COMMIT     (3)
  1781. #ifdef __FUNCTION_PROTOTYPES
  1782. void multosSetTransactionProtection (const BYTE options);
  1783. #else
  1784. #define multosSetTransactionProtection(options) \
  1785.     __code(__PRIM, __PRIM_SET_TRANSACTION_PROTECTION, options)
  1786. #endif
  1787.  
  1788. /*
  1789. **-----------------------------------------------------------------------------
  1790. ** void multosSetSelectSW (const BYTE sw1,
  1791. **                         const BYTE sw2)
  1792. **-----------------------------------------------------------------------------
  1793. */
  1794. /* Set SELECT SW codes */
  1795. #ifdef __FUNCTION_PROTOTYPES
  1796. void multosSetSelectSW (const BYTE sw1, const BYTE sw2);
  1797. #else
  1798. #define multosSetSelectSW(sw1, sw2) \
  1799.     __code (__PRIM, __PRIM_SET_SELECT_SW, sw1, sw2)
  1800. #endif
  1801.  
  1802. /*
  1803. **-----------------------------------------------------------------------------
  1804. ** void multosSHA1 (WORD messageLength,
  1805. **                  BYTE *message,
  1806. **                  BYTE *hash)
  1807. **-----------------------------------------------------------------------------
  1808. */
  1809. #ifdef __FUNCTION_PROTOTYPES
  1810. void multosSHA1 (WORD messageLength, BYTE *message, BYTE *hash);
  1811. #else
  1812. #define multosSHA1(messageLength, message, hash) \
  1813. do \
  1814. { \
  1815.     __push (__typechk(WORD, messageLength)); \
  1816.     __push (__typechk(BYTE *, hash)); \
  1817.     __push (__typechk(BYTE *, message)); \
  1818.     __code (__PRIM, __PRIM_SHA_1); \
  1819. } while (0)
  1820. #endif
  1821.  
  1822. /*
  1823. **-----------------------------------------------------------------------------
  1824. ** void multosSubtractBCD (const BYTE length,
  1825. **                         BYTE *operand1,
  1826. **                         BYTE *operand2,
  1827. **                         BYTE *result)
  1828. **-----------------------------------------------------------------------------
  1829. */
  1830. #ifdef __FUNCTION_PROTOTYPES
  1831. void multosSubtractBCD (const BYTE length, BYTE *operand1, BYTE *operand2,
  1832.                         BYTE *result);
  1833. #else
  1834. #define multosSubtractBCD(length, operand1, operand2, result) \
  1835. do \
  1836. { \
  1837.     __push (__BLOCKCAST(length)(__typechk(BYTE *, operand1))); \
  1838.     __push (__BLOCKCAST(length)(__typechk(BYTE *, operand2))); \
  1839.     __code (__PRIM, __PRIM_SUBTRACT_BCDN, length); \
  1840.     __code (__STORE, __typechk(BYTE *, result), length); \
  1841. } while (0)
  1842. #endif
  1843.  
  1844. /*--------------------- MULTOS 4.3 and 4.3.1 additions -----------------------*/
  1845. /*
  1846. **-----------------------------------------------------------------------------
  1847. ** void multosQueryCryptographicAlgorithm (BYTE algoId,
  1848. **                                         BOOL *isSupported)
  1849. ** algoId as defined by ALGORITHM_DES etc.
  1850. **-----------------------------------------------------------------------------
  1851. */
  1852. #ifdef __FUNCTION_PROTOTYPES
  1853. void multosQueryCryptographicAlgorithm (BYTE algoId,BOOL *isSupported);
  1854. #else
  1855. #define multosQueryCryptographicAlgorithm(algoId, isSupported) \
  1856. do \
  1857. { \
  1858.     __push (__typechk(BYTE, algoId)); \
  1859.     __code (__PRIM, __PRIM_QUERY_ALGO); \
  1860.     __code (__PRIM, __PRIM_LOAD_CCR); \
  1861.     __code (__PRIM, __PRIM_BIT_MANIPULATE_BYTE, 0x83, 1); \
  1862.     __code (__STORE, __typechk(BOOL *, isSupported), 1); \
  1863. } while (0)
  1864. #endif
  1865.  
  1866. /*
  1867. **-----------------------------------------------------------------------------
  1868. ** void multosSecureHash (WORD msgLen,
  1869. **                        WORD hashLen,
  1870. **                        BYTE *hashOut,
  1871. **                        BYTE *msgIn)
  1872. **-----------------------------------------------------------------------------
  1873. */
  1874. #ifdef __FUNCTION_PROTOTYPES
  1875. void multosSecureHash (WORD msgLen, WORD hashLen, BYTE *hashOut, BYTE *msgIn);
  1876. #else
  1877. #define multosSecureHash(msgLen, hashLen, hashOut, msgIn) \
  1878. do \
  1879. { \
  1880.     __push (__typechk(WORD, msgLen)); \
  1881.     __push (__typechk(WORD, hashLen)); \
  1882.     __push (__typechk(BYTE *, hashOut)); \
  1883.     __push (__typechk(BYTE *, msgIn)); \
  1884.     __code (__PRIM, __PRIM_SECURE_HASH); \
  1885. } while (0)
  1886. #endif
  1887.  
  1888. /*
  1889. **-----------------------------------------------------------------------------
  1890. ** void multosTripleDESECBDecipher (BYTE *cipherText,
  1891. **                            BYTE *plainText,
  1892. **                            BYTE keyLength,
  1893. **                            BYTE *key)
  1894. **-----------------------------------------------------------------------------
  1895. */
  1896. #ifdef __FUNCTION_PROTOTYPES
  1897. void multosTripleDESECBDecipher (BYTE *cipherText, BYTE *plainText, BYTE keyLength, BYTE *key);
  1898. #else
  1899. #define multosTripleDESECBDecipher(cipherText, plainText, keyLength, key) \
  1900. do \
  1901. { \
  1902.     __push (__typechk(BYTE *, key)); \
  1903.     __push (__typechk(BYTE, keyLength)); \
  1904.     __push (__typechk(BYTE *, plainText)); \
  1905.     __push (__typechk(BYTE *, cipherText)); \
  1906.     __code (__PRIM, __PRIM_3DES_ECB_DECIPHER); \
  1907. } while (0)
  1908. #endif
  1909.  
  1910. /*
  1911. **-----------------------------------------------------------------------------
  1912. ** void multosTripleDESECBEncipher (BYTE *cipherText,
  1913. **                            BYTE *plainText,
  1914. **                            BYTE keyLength,
  1915. **                            BYTE *key)
  1916. **-----------------------------------------------------------------------------
  1917. */
  1918. #ifdef __FUNCTION_PROTOTYPES
  1919. void multosTripleDESECBEncipher (BYTE *plainText, BYTE *cipherText, BYTE keyLength, BYTE *key);
  1920. #else
  1921. #define multosTripleDESECBEncipher(plainText, cipherText, keyLength, key) \
  1922. do \
  1923. { \
  1924.     __push (__typechk(BYTE *, key)); \
  1925.     __push (__typechk(BYTE, keyLength)); \
  1926.     __push (__typechk(BYTE *, cipherText)); \
  1927.     __push (__typechk(BYTE *, plainText)); \
  1928.     __code (__PRIM, __PRIM_3DES_ECB_ENCIPHER); \
  1929. } while (0)
  1930. #endif
  1931.  
  1932. /*
  1933. **-----------------------------------------------------------------------------
  1934. ** void multosPad (WORD msgLen,
  1935. **           BYTE *msg,
  1936. **           BYTE blockLen,
  1937. **           WORD *paddedMsgLen,
  1938. **           const BYTE padMethod)
  1939. ** padMethod = 0x01 : 0x80 followed by zero or more 0x00
  1940. ** padMethod = 0x02 : 0x80 followed by one or more 0x00
  1941. **-----------------------------------------------------------------------------
  1942. */
  1943. #ifdef __FUNCTION_PROTOTYPES
  1944. void multosPad (WORD msgLen,BYTE *msg,BYTE blockLen,WORD *paddedMsgLen,const BYTE padMethod);
  1945. #else
  1946. #define multosPad(msgLen, msg, blockLen, paddedMsgLen, padMethod) \
  1947. do \
  1948. { \
  1949.     __push (__typechk(BYTE, blockLen)); \
  1950.     __push (__typechk(WORD, msgLen)); \
  1951.     __push (__typechk(BYTE *, msg)); \
  1952.     __code (__PRIM, __PRIM_PAD, padMethod); \
  1953.     __code (__STORE, __typechk(WORD *, paddedMsgLen), 2); \
  1954. } while (0)
  1955. #endif
  1956.  
  1957. /*
  1958. **-----------------------------------------------------------------------------
  1959. ** void multosUnPad (WORD msgLen,
  1960. **           BYTE *msg,
  1961. **           WORD *unpaddedMsgLen,
  1962. **           const BYTE padMethod)
  1963. ** padMethod = 0x01 : 0x80 followed by zero or more 0x00
  1964. ** padMethod = 0x02 : 0x80 followed by one or more 0x00
  1965. **-----------------------------------------------------------------------------
  1966. */
  1967. #ifdef __FUNCTION_PROTOTYPES
  1968. void multosUnPad (WORD msgLen,BYTE *msg,WORD *unpaddedMsgLen,const BYTE padMethod);
  1969. #else
  1970. #define multosUnPad(msgLen, msg, unpaddedMsgLen, padMethod) \
  1971. do \
  1972. { \
  1973.     __push (__typechk(WORD, msgLen)); \
  1974.     __push (__typechk(BYTE *, msg)); \
  1975.     __code (__PRIM, __PRIM_UNPAD, padMethod); \
  1976.     __code (__STORE, __typechk(WORD *, unpaddedMsgLen), 2); \
  1977. } while (0)
  1978. #endif
  1979.  
  1980. /*
  1981. **-----------------------------------------------------------------------------
  1982. ** void multosSetSilentMode (const BYTE mode)
  1983. **-----------------------------------------------------------------------------
  1984. */
  1985. #ifdef __FUNCTION_PROTOTYPES
  1986. void multosSetSilentMode (const BYTE mode);
  1987. #else
  1988. #define multosSetSilentMode(mode) \
  1989. do \
  1990. { \
  1991.     __code (__PRIM, __PRIM_SET_SILENT_MODE, mode); \
  1992. } while (0)
  1993. #endif
  1994.  
  1995. /*
  1996. **-----------------------------------------------------------------------------
  1997. ** void multosCardUnBlock (BOOL *cardUnBlockedOk)
  1998. **-----------------------------------------------------------------------------
  1999. */
  2000. #ifdef __FUNCTION_PROTOTYPES
  2001. void multosCardUnBlock (BOOL *cardUnBlockedOk);
  2002. #else
  2003. #define multosCardUnBlock(cardUnBlockedOk) \
  2004. do \
  2005. { \
  2006.     __code (__PRIM, __PRIM_CARD_UNBLOCK); \
  2007.     __code (__PRIM, __PRIM_LOAD_CCR); \
  2008.     __code (__PRIM, __PRIM_BIT_MANIPULATE_BYTE, (0x83), 0x01); \
  2009.     __code (__STORE, __typechk(BOOL *, cardUnBlockedOk), 1); \
  2010. } while (0)
  2011. #endif
  2012.  
  2013. /*
  2014. **-----------------------------------------------------------------------------
  2015. ** void multosDeactivateAcceleratedRead (BOOL *success)
  2016. **-----------------------------------------------------------------------------
  2017. */
  2018. #ifdef __FUNCTION_PROTOTYPES
  2019. void multosDeactivateAcceleratedRead (BOOL *success);
  2020. #else
  2021. #define multosDeactivateAcceleratedRead(success) \
  2022. do \
  2023. { \
  2024.     __code (__PRIM, __PRIM_CONFIG_READ_BINARY, 0x00); \
  2025.     __code (__PRIM, __PRIM_LOAD_CCR); \
  2026.     __code (__PRIM, __PRIM_BIT_MANIPULATE_BYTE, (0x83), 0x01); \
  2027.     __code (__STORE, __typechk(BOOL *, success), 1); \
  2028. } while (0)
  2029. #endif
  2030.  
  2031. /*
  2032. **-----------------------------------------------------------------------------
  2033. ** void multosAcceleratedReadNoBAC (BYTE channel, BYTE* dataAddr, BOOL *success)
  2034. **-----------------------------------------------------------------------------
  2035. */
  2036. #ifdef __FUNCTION_PROTOTYPES
  2037. void multosAcceleratedReadNoBAC (BYTE channel, BYTE* dataAddr, BOOL *success);
  2038. #else
  2039. #define multosAcceleratedReadNoBAC(channel, dataAddr, success) \
  2040. do \
  2041. { \
  2042.     __push (__typechk(BYTE, channel)); \
  2043.     __push (__typechk(BYTE*, dataAddr)); \
  2044.     __code (__PRIM, __PRIM_CONFIG_READ_BINARY, 0x10); \
  2045.     __code (__PRIM, __PRIM_LOAD_CCR); \
  2046.     __code (__PRIM, __PRIM_BIT_MANIPULATE_BYTE, (0x83), 0x01); \
  2047.     __code (__STORE, __typechk(BOOL *, success), 1); \
  2048. } while (0)
  2049. #endif
  2050.  
  2051. /*
  2052. **-----------------------------------------------------------------------------
  2053. ** void multosAcceleratedReadBAC (BYTE* SSCAddr,
  2054. **                                BYTE* KeyMacAddr,
  2055. **                                BYTE* KeyEncAddr,
  2056. **                                BYTE channel,
  2057. **                                BYTE* dataAddr,
  2058. **                                BOOL optional,
  2059. **                                BOOL *success)
  2060. ** optional: false = Mandatory, true = Optional
  2061. **-----------------------------------------------------------------------------
  2062. */
  2063. #ifdef __FUNCTION_PROTOTYPES
  2064. void multosAcceleratedReadBAC (BYTE* SSCAddr, BYTE* KeyMacAddr, BYTE* KeyEncAddr, BYTE channel, BYTE* dataAddr, BOOL optional, BOOL *success);
  2065. #else
  2066. #define multosAcceleratedReadBAC(SSCAddr, KeyMacAddr, KeyEncAddr, channel, dataAddr, optional, success) \
  2067. do \
  2068. { \
  2069.     __push (__typechk(BYTE*, SSCAddr)); \
  2070.     __push (__typechk(BYTE*, KeyMacAddr)); \
  2071.     __push (__typechk(BYTE*, KeyEncAddr)); \
  2072.     __push (__typechk(BYTE, channel)); \
  2073.     __push (__typechk(BYTE*, dataAddr)); \
  2074.     if(optional) \
  2075.         __code (__PRIM, __PRIM_CONFIG_READ_BINARY, 0x11); \
  2076.     else \
  2077.         __code (__PRIM, __PRIM_CONFIG_READ_BINARY, 0x12); \
  2078.     __code (__PRIM, __PRIM_LOAD_CCR); \
  2079.     __code (__PRIM, __PRIM_BIT_MANIPULATE_BYTE, (0x83), 0x01); \
  2080.     __code (__STORE, __typechk(BOOL *, success), 1); \
  2081. } while (0)
  2082. #endif
  2083.  
  2084. /*
  2085. **-----------------------------------------------------------------------------
  2086. ** void multosAcceleratedReadBACLite ( BYTE* KeyEncAddr,
  2087. **                                BYTE channel,
  2088. **                                BYTE* dataAddr,
  2089. **                                BOOL optional,
  2090. **                                BOOL *success)
  2091. ** optional: false = Mandatory, true = Optional
  2092. **-----------------------------------------------------------------------------
  2093. */
  2094. #ifdef __FUNCTION_PROTOTYPES
  2095. void multosAcceleratedReadBACLite (BYTE* KeyEncAddr, BYTE channel, BYTE* dataAddr, BOOL optional, BOOL *success);
  2096. #else
  2097. #define multosAcceleratedReadBACLite(KeyEncAddr, channel, dataAddr, optional, success) \
  2098. do \
  2099. { \
  2100.     __push (__typechk(BYTE*, KeyEncAddr)); \
  2101.     __push (__typechk(BYTE, channel)); \
  2102.     __push (__typechk(BYTE*, dataAddr)); \
  2103.     if(optional) \
  2104.         __code (__PRIM, __PRIM_CONFIG_READ_BINARY, 0x13); \
  2105.     else \
  2106.         __code (__PRIM, __PRIM_CONFIG_READ_BINARY, 0x14); \
  2107.     __code (__PRIM, __PRIM_LOAD_CCR); \
  2108.     __code (__PRIM, __PRIM_BIT_MANIPULATE_BYTE, (0x83), 0x01); \
  2109.     __code (__STORE, __typechk(BOOL *, success), 1); \
  2110. } while (0)
  2111. #endif
  2112.  
  2113. /*
  2114. **-----------------------------------------------------------------------------
  2115. ** void multosGetStaticSize ( DWORD* value, BOOL *success )
  2116. **-----------------------------------------------------------------------------
  2117. */
  2118. #ifdef __FUNCTION_PROTOTYPES
  2119. void multosGetStaticSize ( DWORD* value, BOOL *success );
  2120. #else
  2121. #define multosGetStaticSize(value, success) \
  2122. do \
  2123. { \
  2124.     __code (__PRIM, __PRIM_GET_STATIC_SIZE, 0x00); \
  2125.     __code (__PRIM, __PRIM_LOAD_CCR); \
  2126.     __code (__PRIM, __PRIM_BIT_MANIPULATE_BYTE, (0x83), 0x01); \
  2127.     __code (__STORE, __typechk(BOOL *, success), 1); \
  2128.     if(*success) \
  2129.         __code (__STORE, __typechk(DWORD *,value), 4); \
  2130. } while (0)
  2131. #endif
  2132.  
  2133. /*
  2134. **-----------------------------------------------------------------------------
  2135. ** void multosGetStaticSizeHuge ( BYTE* value, BOOL *success )
  2136. **-----------------------------------------------------------------------------
  2137. */
  2138. #ifdef __FUNCTION_PROTOTYPES
  2139. void multosGetStaticSizeHuge ( BYTE* value, BOOL *success );
  2140. #else
  2141. #define multosGetStaticSizeHuge(value, success) \
  2142. do \
  2143. { \
  2144.     __code (__PRIM, __PRIM_GET_STATIC_SIZE, 0x01); \
  2145.     __code (__PRIM, __PRIM_LOAD_CCR); \
  2146.     __code (__PRIM, __PRIM_BIT_MANIPULATE_BYTE, (0x83), 0x01); \
  2147.     __code (__STORE, __typechk(BOOL *, success), 1); \
  2148.     if(*success) \
  2149.         __code (__STORE, __typechk(BYTE *,value), 8); \
  2150. } while (0)
  2151. #endif
  2152.  
  2153. /*
  2154. **-----------------------------------------------------------------------------
  2155. ** void multosGenerateRsaKeyPair ( const BYTE method, const BYTE mode, WORD keyLen,
  2156. ** WORD expLen, BYTE* expAddr, BYTE* dpdqpquAddr, BYTE* mAddr, WORD modLen, BOOL *success)
  2157. **-----------------------------------------------------------------------------
  2158. */
  2159. #ifdef __FUNCTION_PROTOTYPES
  2160. void multosGenerateRsaKeyPair ( const BYTE method, const BYTE mode, WORD keyLen, WORD expLen, BYTE* expAddr, BYTE* dpdqpquAddr, BYTE* mAddr, WORD modLen, BOOL *success);
  2161. #else
  2162. #define multosGenerateRsaKeyPair(method, mode, keyLen, expLen, expAddr, dpdqpquAddr, mAddr, modLen, success) \
  2163. do \
  2164. { \
  2165.     __push (__typechk(WORD, keyLen)); \
  2166.     __push (__typechk(WORD, expLen)); \
  2167.     __push (__typechk(BYTE*, expAddr)); \
  2168.     __push (__typechk(BYTE*, dpdqpquAddr)); \
  2169.     __push (__typechk(BYTE*, mAddr)); \
  2170.     __push (__typechk(WORD, modLen)); \
  2171.     __code (__PRIM, __PRIM_GEN_RSA_KEYPAIR, method, mode ); \
  2172.     __code (__PRIM, __PRIM_LOAD_CCR); \
  2173.     __code (__PRIM, __PRIM_BIT_MANIPULATE_BYTE, (0x83), 0x08); \
  2174.     __code (__STORE, __typechk(BOOL*, success), 1); \
  2175.     if(*success==8) \
  2176.         *success = FALSE; \
  2177.     else \
  2178.         *success = TRUE; \
  2179. } while (0)
  2180. #endif
  2181.  
  2182. /*
  2183. **-----------------------------------------------------------------------------
  2184. ** void multosGsmAuthenticate(BYTE* random, BYTE* key, BYTE* result)
  2185. **-----------------------------------------------------------------------------
  2186. */
  2187. #ifdef __FUNCTION_PROTOTYPES
  2188. void multosGsmAuthenticate(BYTE* random, BYTE* key, BYTE* result);
  2189. #else
  2190. #define multosGsmAuthenticate(random, key, result) \
  2191. do \
  2192. { \
  2193.     __push (__typechk(BYTE*, random)); \
  2194.     __push (__typechk(BYTE*, key)); \
  2195.     __push (__typechk(BYTE*, result)); \
  2196.     __code (__PRIM, __PRIM_GSM_AUTHENTICATE ); \
  2197. } while (0)
  2198. #endif
  2199.  
  2200. /*
  2201. **-----------------------------------------------------------------------------
  2202. multosCopyToAdditionalStatic(DWORD destAddr, BYTE* srcAddr, WORD toCopy, BYTE atomic)
  2203. **-----------------------------------------------------------------------------
  2204. */
  2205. #ifdef __FUNCTION_PROTOTYPES
  2206. void multosCopyToAdditionalStatic(DWORD destAddr, BYTE* srcAddr, WORD toCopy, BYTE atomic);
  2207. #else
  2208. #define multosCopyToAdditionalStatic(destAddr, srcAddr, toCopy, atomic) \
  2209. do \
  2210. { \
  2211.     __push (__typechk(WORD, toCopy)); \
  2212.     __push (__typechk(DWORD, destAddr)); \
  2213.     __push (__typechk(BYTE*, srcAddr)); \
  2214.     if(atomic) \
  2215.         __code (__PRIM, __PRIM_COPY_ADDITIONAL_STATIC, 0x80 ); \
  2216.     else \
  2217.         __code (__PRIM, __PRIM_COPY_ADDITIONAL_STATIC, 0x00 ); \
  2218. } while (0)
  2219. #endif
  2220.  
  2221. /*
  2222. **-----------------------------------------------------------------------------
  2223. multosCopyWithinAdditionalStatic(DWORD destAddr, DWORD srcAddr, DWORD toCopy, BYTE atomic)
  2224. **-----------------------------------------------------------------------------
  2225. */
  2226. #ifdef __FUNCTION_PROTOTYPES
  2227. void multosCopyWithinAdditionalStatic(DWORD destAddr, DWORD srcAddr, DWORD toCopy, BYTE atomic);
  2228. #else
  2229. #define multosCopyWithinAdditionalStatic(destAddr, srcAddr, toCopy, atomic) \
  2230. do \
  2231. { \
  2232.     __push (__typechk(DWORD, toCopy)); \
  2233.     __push (__typechk(DWORD, destAddr)); \
  2234.     __push (__typechk(DWORD, srcAddr)); \
  2235.     if(atomic) \
  2236.         __code (__PRIM, __PRIM_COPY_ADDITIONAL_STATIC, 0x82 ); \
  2237.     else \
  2238.         __code (__PRIM, __PRIM_COPY_ADDITIONAL_STATIC, 0x02 ); \
  2239. } while (0)
  2240. #endif
  2241.  
  2242. /*
  2243. **-----------------------------------------------------------------------------
  2244. multosCopyAdditionalToStatic(BYTE* destAddr, DWORD srcAddr, WORD toCopy, BYTE atomic)
  2245. **-----------------------------------------------------------------------------
  2246. */
  2247. #ifdef __FUNCTION_PROTOTYPES
  2248. void multosCopyAdditionalToStatic(BYTE* LONG destAddr, DWORD srcAddr, WORD toCopy, BYTE atomic);
  2249. #else
  2250. #define multosCopyAdditionalToStatic(destAddr, srcAddr, toCopy, atomic) \
  2251. do \
  2252. { \
  2253.     __push (__typechk(WORD, toCopy)); \
  2254.     __push (__typechk(BYTE*, destAddr)); \
  2255.     __push (__typechk(DWORD, srcAddr)); \
  2256.     if(atomic) \
  2257.         __code (__PRIM, __PRIM_COPY_ADDITIONAL_STATIC, 0x81 ); \
  2258.     else \
  2259.         __code (__PRIM, __PRIM_COPY_ADDITIONAL_STATIC, 0x01 ); \
  2260. } while (0)
  2261. #endif
  2262.  
  2263. /*
  2264. **-----------------------------------------------------------------------------
  2265. multosFillAdditionalStatic(DWORD destAddr, BYTE value, DWORD toFill, BYTE atomic)
  2266. **-----------------------------------------------------------------------------
  2267. */
  2268. #ifdef __FUNCTION_PROTOTYPES
  2269. void multosFillAdditionalStatic(DWORD destAddr, BYTE value, DWORD toFill, BYTE atomic);
  2270. #else
  2271. #define multosFillAdditionalStatic(destAddr, value, toFill, atomic) \
  2272. do \
  2273. { \
  2274.     __push (__typechk(BYTE, value)); \
  2275.     __push (__typechk(DWORD, toFill)); \
  2276.     __push (__typechk(DWORD, destAddr)); \
  2277.     if(atomic) \
  2278.         __code (__PRIM, __PRIM_FILL_ADDITIONAL_STATIC, 0x80 ); \
  2279.     else \
  2280.         __code (__PRIM, __PRIM_FILL_ADDITIONAL_STATIC, 0x00 ); \
  2281. } while (0)
  2282. #endif
  2283.  
  2284.  
  2285. /*
  2286. **-----------------------------------------------------------------------------
  2287. ** void multosSecureHashIV (WORD msgLen,                 // IN
  2288. **                        WORD hashLen,                  // IN
  2289. **                        BYTE *hashOut,                 // OUT
  2290. **                        BYTE *msgIn,                   // IN
  2291. **                        BYTE *intermediateHash,        // IN
  2292. **                        DWORD *numPrevHashedBytes,     // IN/OUT
  2293. **                        WORD *numMsgRemainder,         // IN/OUT
  2294. **                        WORD *msgRemainder             // IN/OUT
  2295. **-----------------------------------------------------------------------------
  2296. */
  2297. #ifdef __FUNCTION_PROTOTYPES
  2298. void multosSecureHashIV (WORD msgLen, WORD hashLen, BYTE *hashOut, BYTE *msgIn, BYTE *intermediateHash, DWORD *numPrevHashedBytes, WORD *numMsgRemainder, WORD *msgRemainder);
  2299. #else
  2300. #define multosSecureHashIV(msgLen, hashLen, hashOut, msgIn, intermediateHash, numPrevHashedBytes, numMsgRemainder, msgRemainder) \
  2301. do \
  2302. { \
  2303.     __push (__typechk(WORD, msgLen)); \
  2304.     __push (__typechk(WORD, hashLen)); \
  2305.     __push (__typechk(BYTE *, hashOut)); \
  2306.     __push (__typechk(BYTE *, msgIn)); \
  2307.     __push (__typechk(BYTE *, intermediateHash)); \
  2308.     __push (__typechk(DWORD *, numPrevHashedBytes)); \
  2309.     __push (__typechk(WORD, *numMsgRemainder)); \
  2310.     __push (__typechk(WORD, *msgRemainder)); \
  2311.     __code (__PRIM, __PRIM_SECURE_HASH_IV); \
  2312.     __code(__STORE, msgRemainder, 2); \
  2313.     __code(__STORE, numMsgRemainder, 2); \
  2314. } while (0)
  2315. #endif
  2316.  
  2317. /*
  2318. **-----------------------------------------------------------------------------
  2319. ** void multosEccGenerateKeyPair(BYTE *keyOut, BYTE *domain, const BYTE option, BOOL *success)
  2320. **-----------------------------------------------------------------------------
  2321. */
  2322. #ifdef __FUNCTION_PROTOTYPES
  2323. void multosEccGenerateKeyPair(BYTE *keyOut, BYTE *domain, const BYTE option, BOOL *success);
  2324. #else
  2325. #define multosEccGenerateKeyPair(keyOut, domain, option, success) \
  2326. do \
  2327. { \
  2328.     __push (__typechk(BYTE *, domain)); \
  2329.     __push (__typechk(BYTE *, keyOut)); \
  2330.     __code (__PRIM, __PRIM_GEN_ECC_PAIR, option); \
  2331.     __code (__PRIM, __PRIM_LOAD_CCR); \
  2332.     __code (__PRIM, __PRIM_BIT_MANIPULATE_BYTE, (0x80), 0x01); \
  2333.     __code (__STORE, __typechk(BOOL*, success), 1); \
  2334. } while (0)
  2335. #endif
  2336.  
  2337. /*
  2338. **-----------------------------------------------------------------------------
  2339. ** void multosEccGenerateSignature(BYTE *domainIn, BYTE *keyIn, BYTE *hashIn, BYTE *sigOut, const BYTE option, BOOL *success)
  2340. **-----------------------------------------------------------------------------
  2341. */
  2342. #ifdef __FUNCTION_PROTOTYPES
  2343. void multosEccGenerateSignature(BYTE *domainIn, BYTE *keyIn, BYTE *hashIn, BYTE *sigOut, const BYTE option, BOOL *success);
  2344. #else
  2345. #define multosEccGenerateSignature(domainIn, keyIn, hashIn, sigOut, option, success) \
  2346. do \
  2347. { \
  2348.     __push (__typechk(BYTE *, domainIn)); \
  2349.     __push(__typechk(BYTE *, keyIn)); \
  2350.     __push(__typechk(BYTE *, hashIn)); \
  2351.     __push(__typechk(BYTE *, sigOut)); \
  2352.     __code (__PRIM, __PRIM_GEN_ECC_SIG, option); \
  2353.     __code (__PRIM, __PRIM_LOAD_CCR); \
  2354.     __code (__PRIM, __PRIM_BIT_MANIPULATE_BYTE, (0x80), 0x01); \
  2355.     __code (__STORE, __typechk(BOOL*, success), 1); \
  2356. } while (0)
  2357. #endif
  2358.  
  2359. /*
  2360. **-----------------------------------------------------------------------------
  2361. ** void multosEccVerifySignature(BYTE *domainIn, BYTE *hashIn, BYTE *sigIn,
  2362. **                               BYTE *pubKeyIn, const BYTE option, BOOL *success)
  2363. **-----------------------------------------------------------------------------
  2364. */
  2365. #ifdef __FUNCTION_PROTOTYPES
  2366. void multosEccVerifySignature(BYTE *domainIn, BYTE *hashIn, BYTE *sigIn, BYTE *pubKeyIn, const BYTE option, BOOL *success);
  2367. #else
  2368. #define multosEccVerifySignature(domainIn, hashIn, sigIn, pubKeyIn, option, success) \
  2369. do \
  2370. { \
  2371.     __push(__typechk(BYTE *, domainIn)); \
  2372.     __push(__typechk(BYTE *, pubKeyIn)); \
  2373.     __push(__typechk(BYTE *, sigIn)); \
  2374.     __push(__typechk(BYTE *, hashIn)); \
  2375.     __code (__PRIM, __PRIM_VER_ECC_SIG, option); \
  2376.     __code (__PRIM, __PRIM_LOAD_CCR); \
  2377.     __code (__PRIM, __PRIM_BIT_MANIPULATE_BYTE, (0x80), 0x01); \
  2378.     __code (__STORE, __typechk(BOOL*, success), 1); \
  2379. } while (0)
  2380. #endif
  2381.  
  2382. /*
  2383. **-----------------------------------------------------------------------------
  2384. ** void multosEccDiffieHelman(BYTE *domainIn, BYTE *privateKeyIn, BYTE *publicKeyIn, BYTE *bufferOut, BYTE option, BOOL *success)
  2385. **-----------------------------------------------------------------------------
  2386. */
  2387. #ifdef __FUNCTION_PROTOTYPES
  2388. void multosEccDiffieHelman(BYTE *domainIn, BYTE *privateKeyIn, BYTE *publicKeyIn, BYTE *bufferOut, BYTE option, BOOL *success);
  2389. #else
  2390. #define multosEccDiffieHelman(domainIn, privateKeyIn, publicKeyIn, bufferOut, option, success) \
  2391. do \
  2392. { \
  2393.     __push(__typechk(BYTE *, domainIn)); \
  2394.     __push(__typechk(BYTE *, privateKeyIn)); \
  2395.     __push(__typechk(BYTE *, publicKeyIn)); \
  2396.     __push(__typechk(BYTE *, bufferOut)); \
  2397.     __code (__PRIM, __PRIM_ECCDH, option); \
  2398.     __code (__PRIM, __PRIM_LOAD_CCR); \
  2399.     __code (__PRIM, __PRIM_BIT_MANIPULATE_BYTE, (0x80), 0x01); \
  2400.     __code (__STORE, __typechk(BOOL*, success), 1); \
  2401. } while (0)
  2402. #endif
  2403.  
  2404. /*
  2405. **-----------------------------------------------------------------------------
  2406. ** void multosEccECIESEncipher(BYTE *domainIn, WORD msgLen, BYTE *publicKeyIn, BYTE *msgIn, BYTE *bufferOut, BYTE option, BOOL *success)
  2407. **-----------------------------------------------------------------------------
  2408. */
  2409. #ifdef __FUNCTION_PROTOTYPES
  2410. void multosEccECIESEncipher(BYTE *domainIn, WORD msgLen, BYTE *publicKeyIn, BYTE *msgIn, BYTE *bufferOut, BYTE option, BOOL *success);
  2411. #else
  2412. #define multosEccECIESEncipher(domainIn, msgLen, publicKeyIn, msgIn, bufferOut, option, success) \
  2413. do \
  2414. { \
  2415.     __push(__typechk(BYTE *, domainIn)); \
  2416.     __push(__typechk(WORD, msgLen)); \
  2417.     __push(__typechk(BYTE *, publicKeyIn)); \
  2418.     __push(__typechk(BYTE *, msgIn)); \
  2419.     __push(__typechk(BYTE *, bufferOut)); \
  2420.     __code (__PRIM, __PRIM_ECC_ENC, option); \
  2421.     __code (__PRIM, __PRIM_LOAD_CCR); \
  2422.     __code (__PRIM, __PRIM_BIT_MANIPULATE_BYTE, (0x80), 0x01); \
  2423.     __code (__STORE, __typechk(BOOL*, success), 1); \
  2424. } while (0)
  2425. #endif
  2426.  
  2427. /*
  2428. **-----------------------------------------------------------------------------
  2429. ** void multosEccECIESDecipher(BYTE *domainIn, WORD msgLen, BYTE *privateKeyIn, BYTE *msgIn, BYTE *bufferOut, BYTE option, BOOL *success)
  2430. **-----------------------------------------------------------------------------
  2431. */
  2432. #ifdef __FUNCTION_PROTOTYPES
  2433. void multosEccECIESDecipher(BYTE *domainIn, WORD msgLen, BYTE *privateKeyIn, BYTE *msgIn, BYTE *bufferOut, BYTE option, BOOL *success);
  2434. #else
  2435. #define multosEccECIESDecipher(domainIn, msgLen, privateKeyIn, msgIn, bufferOut, option, success) \
  2436. do \
  2437. { \
  2438.     __push(__typechk(BYTE *, domainIn)); \
  2439.     __push(__typechk(WORD, msgLen)); \
  2440.     __push(__typechk(BYTE *, privateKeyIn)); \
  2441.     __push(__typechk(BYTE *, msgIn)); \
  2442.     __push(__typechk(BYTE *, bufferOut)); \
  2443.     __code (__PRIM, __PRIM_ECC_DEC, option); \
  2444.     __code (__PRIM, __PRIM_LOAD_CCR); \
  2445.     __code (__PRIM, __PRIM_BIT_MANIPULATE_BYTE, (0x80), 0x01); \
  2446.     __code (__STORE, __typechk(BOOL*, success), 1); \
  2447. } while (0)
  2448. #endif
  2449.  
  2450. /*--------------------- MULTOS 4.3.2 and 4.4/4.5 additions -----------------------*/
  2451. /*
  2452. **-----------------------------------------------------------------------------
  2453. ** void multosSetSelectCLSW (const BYTE sw1,const BYTE sw2)
  2454. **-----------------------------------------------------------------------------
  2455. */
  2456. #ifdef __FUNCTION_PROTOTYPES
  2457. void multosSetSelectCLSW (const BYTE sw1,const BYTE sw2);
  2458. #else
  2459. #define multosSetSelectCLSW(sw1, sw2)                                         \
  2460.     __code (__PRIM, __PRIM_SET_SELECT_CL_SW, sw1, sw2)
  2461. #endif 
  2462.  
  2463. /*
  2464. *------------------------------------------------------------------------------
  2465. ** void multosBlockLookupWord (WORD value,
  2466. **                         WORD *block,
  2467. **                         WORD *result,
  2468. **                         BOOL *byteFound)
  2469. **-----------------------------------------------------------------------------
  2470. */
  2471. #ifdef __FUNCTION_PROTOTYPES
  2472. void multosBlockLookupWord (WORD value, WORD *block, WORD *result,
  2473.                         BYTE *wordFound);
  2474. #else
  2475. #define multosBlockLookupWord(value, block, result, wordFound) \
  2476. do  \
  2477. { \
  2478.     __push (__typechk(WORD, value)); \
  2479.     __push (__typechk(WORD *, block)); \
  2480.     __code (__PRIM, __PRIM_LOOKUP_WORD); \
  2481.     __code (__STORE, __typechk(WORD *, result), 2); \
  2482.     __code (__PRIM, __PRIM_LOAD_CCR); \
  2483.     __code (__PRIM, __PRIM_BIT_MANIPULATE_BYTE, 0x83, 0x09); \
  2484.     __code (__STORE, __typechk(BYTE *, wordFound), 1); \
  2485. } while (0)
  2486. #endif
  2487.  
  2488. /*
  2489. **-----------------------------------------------------------------------------
  2490. ** void multosGetProcessEvent (BYTE *event)
  2491. **-----------------------------------------------------------------------------
  2492. */
  2493. #ifdef __FUNCTION_PROTOTYPES
  2494. void multosGetProcessEvent (BYTE *event);
  2495. #else
  2496. #define multosGetProcessEvent(event) \
  2497. do \
  2498. { \
  2499.     __code (__PRIM, __PRIM_GET_PROCESS_EVENT); \
  2500.     __code (__STORE, __typechk (BYTE *, event), 1); \
  2501. } \
  2502. while (0)
  2503. #endif
  2504.  
  2505. /*
  2506. **-----------------------------------------------------------------------------
  2507. ** void multosRejectProcessEvent (void)
  2508. **-----------------------------------------------------------------------------
  2509. */
  2510. #ifdef __FUNCTION_PROTOTYPES
  2511. void multosRejectProcessEvent(void);
  2512. #else
  2513. #define multosRejectProcessEvent() \
  2514. do \
  2515. { \
  2516.     __code (__PRIM, __PRIM_REJECT_PROCESS_EVENT); \
  2517. } \
  2518. while (0)
  2519. #endif
  2520.  
  2521. /*
  2522. **-----------------------------------------------------------------------------
  2523. ** void multosRsaVerify (WORD exponentLength,
  2524. **                                   WORD modulusLength,
  2525. **                                   BYTE *exponent,
  2526. **                                   BYTE *modulus,
  2527. **                                   BYTE *input,
  2528. **                                   BYTE *output)
  2529. **-----------------------------------------------------------------------------
  2530. */
  2531. #ifdef __FUNCTION_PROTOTYPES
  2532. void multosRsaVerify (WORD exponentLength, WORD modulusLength,
  2533.                                   BYTE *exponent, BYTE *modulus, BYTE *input,
  2534.                                   BYTE *output);
  2535. #else
  2536. #define multosRsaVerify(exponentLength, modulusLength, exponent, modulus, input, output) \
  2537. do \
  2538. { \
  2539.     __push (__typechk(WORD, exponentLength)); \
  2540.     __push (__typechk(WORD, modulusLength)); \
  2541.     __push (__typechk(BYTE *, exponent)); \
  2542.     __push (__typechk(BYTE *, modulus)); \
  2543.     __push (__typechk(BYTE *, input)); \
  2544.     __push (__typechk(BYTE *, output)); \
  2545.     __code (__PRIM, __PRIM_RSA_VERIFY); \
  2546. } while (0)
  2547. #endif
  2548.  
  2549. /*
  2550. **-----------------------------------------------------------------------------
  2551. ** void multosSetATSHistoricalCharacters (BYTE *input,
  2552. **                                        BYTE *numBytesWritten)
  2553. **-----------------------------------------------------------------------------
  2554. */
  2555. #ifdef __FUNCTION_PROTOTYPES
  2556. void multosSetATSHistoricalCharacters (BYTE *input, BYTE *numBytesWritten);
  2557. #else
  2558. #define multosSetATSHistoricalCharacters(input, numBytesWritten) \
  2559. do \
  2560. { \
  2561.     __push (__typechk(BYTE *, input)); \
  2562.     __code (__PRIM, __PRIM_SET_ATS_HISTORICAL_CHARACTERS); \
  2563.     __code (__STORE, __typechk(BYTE *, numBytesWritten), 1); \
  2564. } while (0)
  2565. #endif
  2566.  
  2567.  
  2568. /*
  2569. **-----------------------------------------------------------------------------
  2570. ** void multosSetFCIFileRecord (BYTE *record,
  2571. **                              BYTE *numBytesWritten)
  2572. **-----------------------------------------------------------------------------
  2573. */
  2574. #ifdef __FUNCTION_PROTOTYPES
  2575. void multosSetFCIFileRecord (BYTE *record, BYTE *numBytesWritten);
  2576. #else
  2577. #define multosSetFCIFileRecord(record, numBytesWritten) \
  2578. do \
  2579. { \
  2580.     __push (__typechk(BYTE *, record)); \
  2581.     __code (__PRIM, __PRIM_SET_FCI_FILE_RECORD); \
  2582.     __code (__STORE, __typechk(BYTE *, numBytesWritten), 1); \
  2583. } while (0)
  2584. #endif
  2585.  
  2586. /*
  2587. **-----------------------------------------------------------------------------
  2588. ** void multosInitialisePIN (BYTE *initDataAddr)
  2589. **
  2590. ** initDataAddr is a 15 data block formatted as follows
  2591. ** - PIN Reference Data [8]
  2592. ** - PIN Length [1]
  2593. ** - PIN Try Counter [1]
  2594. ** - PIN Try Limit [1]
  2595. ** - MULTOS Checkum [4]
  2596. **-----------------------------------------------------------------------------
  2597. */
  2598. #ifdef __FUNCTION_PROTOTYPES
  2599. void multosInitialisePIN (BYTE *initDataAddr);
  2600. #else
  2601. #define multosInitialisePIN(initDataAddr) \
  2602. do \
  2603. { \
  2604.     __push (__typechk(BYTE *, initDataAddr)); \
  2605.     __code (__PRIM, __PRIM_INITIALISE_PIN); \
  2606. } while (0)
  2607. #endif
  2608.  
  2609. /*
  2610. **-----------------------------------------------------------------------------
  2611. ** void multosReadPIN (BYTE *outAddr, BYTE *pinLength)
  2612. **-----------------------------------------------------------------------------
  2613. */
  2614. #ifdef __FUNCTION_PROTOTYPES
  2615. void multosReadPIN (BYTE *outAddr, BYTE *pinLength);
  2616. #else
  2617. #define multosReadPIN(outAddr, pinLength) \
  2618. do \
  2619. { \
  2620.     __push (__typechk(BYTE *, outAddr)); \
  2621.     __code (__PRIM, __PRIM_READ_PIN); \
  2622.     __code (__STORE, __typechk(BYTE *, pinLength), 1); \
  2623. } while (0)
  2624. #endif
  2625.  
  2626. /*
  2627. **-----------------------------------------------------------------------------
  2628. ** void multosVerifyPIN (BYTE pinLen, BYTE *pinAddr, WORD *status)
  2629. **-----------------------------------------------------------------------------
  2630. */
  2631. #ifdef __FUNCTION_PROTOTYPES
  2632. void multosVerifyPIN (BYTE pinLen, BYTE *pinAddr, WORD *status);
  2633. #else
  2634. #define multosVerifyPIN(pinLen, pinAddr, status) \
  2635. do \
  2636. { \
  2637.     __push (__typechk(BYTE, pinLen)); \
  2638.     __push (__typechk(BYTE *, pinAddr)); \
  2639.     __code (__PRIM, __PRIM_VERIFY_PIN); \
  2640.     __code (__STORE, __typechk(WORD *, status), 2); \
  2641. } while (0)
  2642. #endif
  2643.  
  2644. /*
  2645. **-----------------------------------------------------------------------------
  2646. ** void multosSetPINTryCounter (BYTE ptc)
  2647. **-----------------------------------------------------------------------------
  2648. */
  2649. #ifdef __FUNCTION_PROTOTYPES
  2650. void multosSetPINTryCounter (BYTE ptc);
  2651. #else
  2652. #define multosSetPINTryCounter(ptc) \
  2653. do \
  2654. { \
  2655.     __push (__typechk(BYTE, ptc)); \
  2656.     __code (__PRIM, __PRIM_SET_PIN_DATA, 0x00); \
  2657. } while (0)
  2658. #endif
  2659.  
  2660. /*
  2661. **-----------------------------------------------------------------------------
  2662. ** void multosSetPINTryLimit (BYTE ptl)
  2663. **-----------------------------------------------------------------------------
  2664. */
  2665. #ifdef __FUNCTION_PROTOTYPES
  2666. void multosSetPINTryLimit (BYTE ptl);
  2667. #else
  2668. #define multosSetPINTryLimit(ptl) \
  2669. do \
  2670. { \
  2671.     __push (__typechk(BYTE, ptl)); \
  2672.     __code (__PRIM, __PRIM_SET_PIN_DATA, 0x01); \
  2673. } while (0)
  2674. #endif
  2675.  
  2676. /*
  2677. **-----------------------------------------------------------------------------
  2678. ** void multosGetPINTryCounter (BYTE *ptc)
  2679. **-----------------------------------------------------------------------------
  2680. */
  2681. #ifdef __FUNCTION_PROTOTYPES
  2682. void multosGetPINTryCounter (BYTE *ptc);
  2683. #else
  2684. #define multosGetPINTryCounter(ptc) \
  2685. do \
  2686. { \
  2687.     __code (__PRIM, __PRIM_GET_PIN_DATA, 0x00); \
  2688.     __code (__STORE, __typechk(BYTE *, ptc), 1); \
  2689. } while (0)
  2690. #endif
  2691.  
  2692. /*
  2693. **-----------------------------------------------------------------------------
  2694. ** void multosGetPINTryLimit (BYTE *ptl)
  2695. **-----------------------------------------------------------------------------
  2696. */
  2697. #ifdef __FUNCTION_PROTOTYPES
  2698. void multosGetPINTryLimit (BYTE *ptl);
  2699. #else
  2700. #define multosGetPINTryLimit(ptl) \
  2701. do \
  2702. { \
  2703.     __code (__PRIM, __PRIM_GET_PIN_DATA, 0x01); \
  2704.     __code (__STORE, __typechk(BYTE *, ptl), 1); \
  2705. } while (0)
  2706. #endif
  2707.  
  2708. /*
  2709. **-----------------------------------------------------------------------------
  2710. ** void multosGetPINStatus(BYTE *status)
  2711. **-----------------------------------------------------------------------------
  2712. */
  2713. #ifdef __FUNCTION_PROTOTYPES
  2714. void multosGetPINStatus (BYTE *status);
  2715. #else
  2716. #define multosGetPINStatus(status) \
  2717. do \
  2718. { \
  2719.     __code (__PRIM, __PRIM_GET_PIN_DATA, 0x02); \
  2720.     __code (__STORE, __typechk(BYTE *, status), 1); \
  2721. } while (0)
  2722. #endif
  2723.  
  2724. /*
  2725. **-----------------------------------------------------------------------------
  2726. ** void multosFlushPublic (WORD blockSize, BOOL *LaFlag)
  2727. ** LaFlag is set to 1 if La > 0
  2728. **-----------------------------------------------------------------------------
  2729. */
  2730. #ifdef __FUNCTION_PROTOTYPES
  2731. void multosFlushPublic (WORD blockSize, BOOL *LaFlag);
  2732. #else
  2733. #define multosFlushPublic(blockSize, LaFlag) \
  2734. do \
  2735. { \
  2736.     __push (__typechk(WORD, blockSize)); \
  2737.     __code (__PRIM, __PRIM_FLUSH_PUBLIC); \
  2738.     __code (__PRIM, __PRIM_LOAD_CCR); \
  2739.     __code (__PRIM, __PRIM_BIT_MANIPULATE_BYTE, 0x83, 0x01); \
  2740.     __code (__STORE, __typechk(BOOL *, LaFlag), 1); \
  2741. } while (0)
  2742. #endif
  2743.  
  2744. /*--------------------- MULTOS 4.5.1 additions -----------------------*/
  2745.  
  2746. /*
  2747. **-----------------------------------------------------------------------------
  2748. ** void multosBlockShiftLeftVar (WORD num_bits, WORD data_len, BYTE *data_addr)
  2749. ** void multosBlockShiftRightVar               "
  2750. ** void multosBlockRotateLeft                  "
  2751. ** void multosBlockRotateRight                 "
  2752. **-----------------------------------------------------------------------------
  2753. */
  2754. #ifdef __FUNCTION_PROTOTYPES
  2755. void multosBlockShiftLeftVar (WORD num_bits, WORD data_len, BYTE *data_addr);
  2756. #else
  2757. #define multosBlockShiftLeftVar(numBits,dataLen,dataAddr) \
  2758. do \
  2759. { \
  2760.     __push (__typechk(WORD, numBits)); \
  2761.     __push (__typechk(WORD, dataLen)); \
  2762.     __push (__typechk(BYTE*, dataAddr)); \
  2763.     __code (__PRIM, __PRIM_SHIFT_ROTATE, 1, 1); \
  2764. } while (0)
  2765. #endif
  2766. #ifdef __FUNCTION_PROTOTYPES
  2767. void multosBlockShiftRightVar (WORD num_bits, WORD data_len, BYTE *data_addr);
  2768. #else
  2769. #define multosBlockShiftRightVar(numBits,dataLen,dataAddr) \
  2770. do \
  2771. { \
  2772.     __push (__typechk(WORD, numBits)); \
  2773.     __push (__typechk(WORD, dataLen)); \
  2774.     __push (__typechk(BYTE*, dataAddr)); \
  2775.     __code (__PRIM, __PRIM_SHIFT_ROTATE, 1, 2); \
  2776. } while (0)
  2777. #endif
  2778. #ifdef __FUNCTION_PROTOTYPES
  2779. void multosBlockRotateLeft (WORD num_bits, WORD data_len, BYTE *data_addr);
  2780. #else
  2781. #define multosBlockRotateLeft(numBits,dataLen,dataAddr) \
  2782. do \
  2783. { \
  2784.     __push (__typechk(WORD, numBits)); \
  2785.     __push (__typechk(WORD, dataLen)); \
  2786.     __push (__typechk(BYTE*, dataAddr)); \
  2787.     __code (__PRIM, __PRIM_SHIFT_ROTATE, 2, 1); \
  2788. } while (0)
  2789. #endif
  2790. #ifdef __FUNCTION_PROTOTYPES
  2791. void multosBlockRotateRight (WORD num_bits, WORD data_len, BYTE *data_addr);
  2792. #else
  2793. #define multosBlockRotateRight(numBits,dataLen,dataAddr) \
  2794. do \
  2795. { \
  2796.     __push (__typechk(WORD, numBits)); \
  2797.     __push (__typechk(WORD, dataLen)); \
  2798.     __push (__typechk(BYTE*, dataAddr)); \
  2799.     __code (__PRIM, __PRIM_SHIFT_ROTATE, 2, 2); \
  2800. } while (0)
  2801. #endif
  2802.  
  2803. /*
  2804. **-----------------------------------------------------------------------------
  2805. ** void multosUpdateStaticSize (DWORD length,                            
  2806. **                              BYTE *result)
  2807. **-----------------------------------------------------------------------------
  2808. */
  2809. #ifdef __FUNCTION_PROTOTYPES
  2810. void multosUpdateStaticSize (DWORD length, BYTE * result);
  2811. #else
  2812. #define multosUpdateStaticSize(length, result) \
  2813. do \
  2814. { \
  2815.     __push (__typechk(DWORD, length)); \
  2816.     __code (__PRIM, __PRIM_UPDATE_STATIC_SIZE, 0); \
  2817.     __code (__STORE, __typechk(BYTE *, result), 1); \
  2818. } while (0)
  2819. #endif
  2820.  
  2821. #endif // #ifndef MULTOS_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement