SEC_LoadE2EE API for Telium Tetra: schVar_def.h Source File

Telium Tetra SEC Load E2EE API

SEC_LoadE2EE API for Telium Tetra  1.12.1
Lib API
schVar_def.h
Go to the documentation of this file.
1 /***
2  * Copyright (c) 2001 Sagem Monetel SA, rue claude Chappe,
3  * 07503 Guilherand-Granges, France, All Rights Reserved.
4  *
5  * Sagem Monetel SA has intellectual property rights relating
6  * to the technology embodied in this software. In particular,
7  * and without limitation, these intellectual property rights
8  * may include one or more patents.
9  *
10  * This software is distributed under licenses restricting
11  * its use, copying, distribution, and decompilation.
12  * No part of this software may be reproduced in any form
13  * by any means without prior written authorization of
14  * Sagem Monetel.
15  *
16  * @Title: SCHVAR_DEF.H
17  * @Description: Definitions for schemes package
18  * @Reference:
19  * @Comment:
20  *
21  * @author
22  * @version
23  * @Comment:
24  * @date: 2003/09/05
25  *
26  * @author
27  * @version
28  * @Comment: Adding T_HEADER_RESULT
29  * @date: 2006/08/17
30  *
31  * @author
32  * @version
33  * @Comment: Adding ID_SCH_RANDOM, NAM_SCH_RANDOM
34  * @date: 2006/09/04
35  *
36  * @author
37  * @version
38  * @Comment: Adding Specific MAC_ICV Scheme, TLV Mac Key in DUKPT secret area
39  * @date: 2006/12/04
40  */
41 
42 #ifndef _SCH_VAR_DEF_H
43 #define _SCH_VAR_DEF_H
44 
46 /*
47  Global definitions
48  */
49 #define DES_KEY_SIZE 8
50 #define TDES_KEY_SIZE 16
51 #define TRANSACTION_FIELD_SIZE 5
52 #define PIN_BLOC_SIZE 8
53 #define PAN_BLOC_SIZE 8
54 #define TDES_16_KEY_SIZE TDES_KEY_SIZE
55 #define TDES_24_KEY_SIZE 24
56 
57 #define TAG_SIZE 4
58 #define LEN_SIZE 4
59 #define ANSWER_HEADER_SIZE (TAG_SIZE + LEN_SIZE)
60 #define RETURN_CODE_SIZE 4
61 #define BUFFER_SIZE 32
63 #define MIN_PIN_CODE_SIZE 4
64 #define MAX_PIN_CODE_SIZE 12
65 #define MAX_PIN_AREA_SIZE 20
66 #define MAX_DATA_SIZE 1024
68 #define SEND_COMPLETED COM_FIN_EMI
70 #define MAX_SCH_REC_TIMEOUT 10
72 /*
73  Definitions for ISO9564
74  */
75 #define ISO9564_F0_DES 1
76 #define ISO9564_F0_TDES 2
77 #define ISO9564_F1_DES 3
78 #define ISO9564_F1_TDES 4
79 #define ISO9564_F3_DES 5
80 #define ISO9564_F3_TDES 6
81 #define ISO9564_F2_DES 7
82 #define ISO9564_F2_TDES 8
83 #define ISO9564_F2_OTHER 9
84 #define ISO9564_F0_F8_DES 10
85 #define ISO9564_F0_F8_TDES 11
86 #define ISO9564_F3_F8_DES 12
87 #define ISO9564_F3_F8_TDES 13
88 #define ISO9564_F0_TDES_24 14
89 #define ISO9564_F1_TDES_24 15
90 #define ISO9564_F2_TDES_24 16
91 #define ISO9564_F3_TDES_24 17
93 #define AA (0x10101010)
94 #define CONTROL_FIELD_3 0x30
96 #define ID_SCH_ISO9564 0x40020000
98 #define TAG_ISO9564_0 0x40020000
99 #define TAG_ISO9564_1 0x40020001
100 #define TAG_ISO9564_2 0x40020002
101 #define TAG_ISO9564_3 0x40020003
103 /*
104  Definitions for DUKPT
105  */
106 #define ID_SCH_DUKPT_DES 0x40020100
107 #define TAG_DUKPT 0x40020100
108 #define TAG_DUKPT_INITIALISATION 0x40020101
109 #define TAG_DUKPT_LOAD 0x40020102
110 #define TAG_DUKPT_TRANSACTION 0x40020103
111 #define TAG_DUKPT_CANCEL 0x40020104
113 #define DUKPT_INITIAL_KEY_CREATION 1
114 #define DUKPT_LOAD_KEY 2
115 #define DUKPT_LOAD_KSN 3
116 #define DUKPT_LOAD_KSN_CREATE 3+0x10000
117 #define DUKPT_ENCRYPT_PIN 4
118 #define DUKPT_ENCRYPT_PIN_F3 5
119 #define DUKPT_CANCEL_KEYS 6
120 #define DUKPT_GET_CURRENT_STATE 7
121 #define DUKPT_LOAD_RIGHT_PART_DERIVATION_KEY 8
122 #define DUKPT_LOAD_LEFT_PART_DERIVATION_KEY 9
123 #define DUKPT_LOAD_RIGHT_PART_KEY 10
124 #define DUKPT_LOAD_LEFT_PART_KEY 11
125 #define DUKPT_LOAD_CIPHERED_DERIVATION_KEY 12
126 #define DUKPT_LOAD_CIPHERED_INITIAL_KEY 13
127 #define DUKPT_CREATE_KEYS 14
128 #define DUKPT_GET_CURRENT_SMID 15
129 #define DUKPT_KCV_INITIALKEY 16
130 #define DUKPT_KCV_DERIVKEY 17
131 #define DUKPT_MAC_VERIFY 18
132 #define DUKPT_MAC_COMPUTE 19
133 #define DUKPT_ENCRYPT_DATABLOCK 20
134 #define DUKPT_ENCRYPT_DATABLOCK_F3 21
135 #define DUKPT_ENCRYPT_DATA_ECB 22
136 #define DUKPT_ENCRYPT_DATA_CBC 23
137 #define DUKPT_ENCRYPT_DATA_EXT_ECB 24
138 #define DUKPT_DECRYPT_DATA_EXT_ECB 25
139 #define DUKPT_ENCRYPT_DATA_EXT_CBC 26
140 #define DUKPT_DECRYPT_DATA_EXT_CBC 27
142 #define NB_DUKPT_KEYS 21
143 #define DUKPT_SMID_SIZE 10
144 #define DUKPT_DATA_SIZE 512
146 #define DUKPT_IN_FUNCTION 0
147 #define DUKPT_NOT_IN_FUNCTION 1
148 #define DUKPT_KSN_NOT_REC 2
149 #define DUKPT_INIT_KEY_NOT_REC 3
150 #define DUKPT_END_OF_LIFE (-110)
152 #define ID_SCH_DUKPT_TDES 0x40020200
153 #define TAG_DUKPT_TDES 0x40020200
154 #define TAG_TDUKPT 0x40020200
155 #define TAG_TDUKPT_INITIALISATION 0x40020201
156 #define TAG_TDUKPT_LOAD 0x40020202
157 #define TAG_TDUKPT_TRANSACTION 0x40020203
158 #define TAG_TDUKPT_CANCEL 0x40020204
160 #define INC_AUTO_MODE 0
161 #define INC_FORCED_MODE 1
163 /*
164  Temporary definitions (do not use)
165  */
166 #define ID_SCH_INIT_PIN_CODE 0x40020300
167 #define ID_SCH_INIT_KEYS_ISO9564 0x40020400
168 #define ID_SCH_INIT_KEY_DUKPT 0x40020500
169 #define ID_SCH_INIT_KEY_TDUKPT 0x40020600
171 #define ID_SCR_KEY_DES_ISO9564 0x40022000
172 #define ID_SCR_KEY_TDES_ISO9564 0x40022100
173 #define ID_SCR_KEY_OTHER_ISO9564 0x40022200
174 #define ID_SCR_KEY_DES_DUKPT 0x40022300
175 #define ID_SCR_KEY_TDES_DUKPT 0x40022400
176 #define ID_SCR_KEY 0x40022400
179 /*
180  Definitions for LOAD DATA
181  */
182 #define NAM_SCH_LOAD_DATA ("SchLoadData")
183 #define ID_SCH_LOAD_DATA 0x40020400
184 #define TAG_LOAD_DATA 0x40020400
186 #define DATA_NO_CIPHER 0x00000000
187 #define CLEAR_DATA_MODE 0x00000000
188 #define DATA_DES_CIPHER 0x01000000
189 #define DES_CIPHERED_MODE 0x01000000
190 #define DATA_TDES_CIPHER 0x02000000
191 #define TDES_CIPHERED_MODE DATA_TDES_CIPHER
192 #define CREATE_AREA 0x03000000
193 #define CREATE_AREA_FULLBL1 0x04000000
195 #define DATA_TDES_16_CIPHER DATA_TDES_CIPHER
196 #define TDES_16_CIPHERED_MODE DATA_TDES_CIPHER
197 #define DATA_TDES_24_CIPHER 0x05000000
198 #define TDES_24_CIPHERED_MODE DATA_TDES_24_CIPHER
199 #define AES_128_CIPHERED_MODE 0x06000000
200 #define AES_192_CIPHERED_MODE 0x07000000
201 #define AES_256_CIPHERED_MODE 0x08000000
203 #define OFFCET_MASTER_KEY 0x000003FF
204 #define OFFSET_MASTER_KEY 0x000003FF
206 #define NAM_SCH_LOAD_KEYTLV ("SloadKeyTlv")
207 #define ID_SCH_LOAD_KEYTLV 0x40020403
209 /*
210  Definitions for PIN CODE entry
211  */
212 #define NAM_SCH_GET_PIN ("SchGetPin")
213 #define ID_SCH_GET_PIN 0x40020500
216 #define HID_KEY_PIN_CODE '*'
217 #define C_GET_PIN_AUTO_VAL_MODE 0x01
218 #define C_GET_PIN_NO_FCT_KEY 0x80
219 #define C_GET_PIN_T_ANN_MODE 0x40
220 /*
221  Definitions for CIPHER or DECIPHER DATA
222  */
223 #define NAM_SCH_CIPHER_DATA ("SchCipherDa")
224 #define ID_SCH_CIPHER_DATA 0x40020600
225 #define TAG_CIPHER_DATA 0x40020600
227 #define DATA_DES_DECIPHER 0x04000000
228 #define DATA_TDES_DECIPHER 0x08000000
229 #define DATA_TDES_24_CIPHER_BIS 0x60000000
230 #define DATA_TDES_24_DECIPHER 0x09000000
231 #define DATA_DES_CIPHER_ICV 0x10000000
232 #define DATA_TDES_CIPHER_ICV 0x20000000
233 #define DATA_TDES_24_CIPHER_ICV 0x30000000
234 #define DATA_DES_DECIPHER_ICV 0x40000000
235 #define DATA_TDES_DECIPHER_ICV 0x80000000
236 #define DATA_TDES_24_DECIPHER_ICV 0x50000000
237 #define DATA_DES_CIPHER_OFB 0x05000000
238 #define DATA_TDES_CIPHER_OFB 0x06000000
239 #define DATA_TDES_24_CIPHER_OFB 0x07000000
240 #define DATA_MAC_ICV 0x90000000
242 /*
243  Definitions for other PIN entry scheme
244  */
245 #define SCH_PIN_ENTRY_NAME ("SchPinEntry")
246 #define ID_SCH_PIN_ENTRY 0x40020700
248 // Sound level
249 #define LOW 1
250 #define MIDDLE_LOW 2
251 #define MIDDLE 3
252 #define MIDDLE_HIGH 4
253 #define HIGH 5
255 // Note definitions
256 #define C 0
257 #define C_SHARP 1
258 #define D 2
259 #define D_SHARP 3
260 #define E 4
261 #define F 5
262 #define F_SHARP 6
263 #define G 7
264 #define G_SHARP 8
265 #define A 9
266 #define A_SHARP 10
267 #define B 11
269 /*
270  Definitions for FREE SECRET AREA
271  */
272 #define NAM_SCH_FREE_SECRET ("SchFree")
273 #define ID_SCH_FREE_SECRET 0x40020800
275 /*
276  Definitions for SchXOR
277  */
278 #define NAM_SCH_XOR ("SchXOR")
279 #define ID_SCH_XOR 0x40030200
280 #define TAG_XOR ID_SCH_XOR
282 /*
283  Definitions for Sch_Random
284  */
285 #define NAM_SCH_RANDOM ("Sch_Random")
286 #define ID_SCH_RANDOM 0x40030100
288 /*
289  Definitions for MAC_ICVDU Scheme
290  */
291 #define NAM_SCH_MAC_ICVDU ("SchMacIcvDu")
292 #define ID_SCH_MAC_ICVDU 0x40020A00
293 #define TAG_MAC_ICVDU ID_SCH_MAC_ICVDU
295 /* Value for parameter 1 : 16 bits high */
296 #define OP_MAC_ICV_DES 0x90000000
297 #define OP_MAC_ICV_TDES 0xA0000000
299 /* Value for parameter 1 : 16 bits low */
300 #define MAC_VERIFY 0x0001
301 #define MAC_COMPUTE 0x0002
304 /* ENmEntryGEN
305  * Definitions for ENmEntryGEN Scheme
306  */
307 #define NAM_SCH_ENMENTRY ("ENmEntryGEN")
308 #define ID_SCH_ENMENTRY 0x40030850
309 #define TAG_ENMENTRYGEN ID_SCH_ENMENTRY
311 /* Parameters to call the Scheme */
312 
317 #define C_DECAL_FIRSTTIMEOUT 16
318 #define C_MSK_FIRSTTIMEOUT 0xFFFF
319 
320 #define C_DECAL_INTERTIMEOUT 0
321 #define C_MSK_INTERTIMEOUT 0xFFFF
322 
328 #define C_MSK_NUM (1 << 0)
329 #define C_MSK_VAL (1 << 1)
330 #define C_MSK_CORR (1 << 2)
331 #define C_MSK_ANN (1 << 3)
332 #define C_MSK_F (1 << 4)
333 #define C_MSK_POINT (1 << 5)
334 #define C_MSK_STAR (1 << 6)
335 #define C_MSK_UP (1 << 7)
336 #define C_MSK_SK2 (1 << 8)
337 #define C_MSK_SK3 (1 << 9)
338 #define C_MSK_DOWN (1 << 10)
339 #define C_MSK_SK1 (1 << 11)
340 #define C_MSK_SK4 (1 << 12)
341 
347 #define C_DECAL_MESSHEAD 24
348 #define C_MSK_MESSHEAD 0xFF
349 
350 #define C_DECAL_LINEHEAD 16
351 #define C_MSK_LINEHEAD 0xFF
352 
353 #define C_DECAL_COLHEAD 8
354 #define C_MSK_COLHEAD 0xFF
355 
356 #define C_DECAL_MODE 0
357 #define C_MSK_MODE 0xFF
358 
359 
360 #define C_NUMGEN_MODE_TEXT 0
361 #define C_NUMGEN_MODE_GRAPH 1
362 
364 
369 #define C_DECAL_MESSFOOT 24
370 #define C_MSK_MESSFOOT 0xFF
371 
372 #define C_DECAL_LINEFOOT 16
373 #define C_MSK_LINEFOOT 0xFF
374 
375 #define C_DECAL_COLFOOT 8
376 #define C_MSK_COLFOOT 0xFF
377 
378 #define C_DECAL_EXTRA 0
379 #define C_MSK_EXTRA 0xFF
380 
383 #define C_EXTRA_LENGTH_PARAM 25 /* parameters exchanged via IAPP (without the signed buffeur)*/
384 
386 #define C_MESSAGE_BUFFER_MAX_SIZE 14000
387 
390 #define C_NUM_MESS_LENGTH 60
391 
393 
397 /*
398  Error codes (for all schemes)
399  */
400 #define ERR_ID_NOT_FOUND (-1024)
401 #define ERR_PIN_CODE_NOT_FOUND (-1025)
402 #define ERR_BAD_PIN_CODE_LEN (-1026)
403 #define ERR_BAD_IAPP_OPERATION (-1027)
404 #define ERR_UNKNOW_FORMAT (-1028)
405 #define ERR_DUKPT_END_OF_LIFE (-1029)
406 #define ERR_BAD_ACTION_TYPE (-1030)
408 #define ERR_ENTRY_CANCELED (-1031)
409 #define ERR_TIMEOUT (-1032)
410 #define ERR_BAD_IHM_OPERATION (-1033)
412 #define ERR_SYSTEME_ERROR (-1034)
413 #define ERR_SYSTEM (-1034)
415 #define ERR_BAD_PARAM (-1035)
417 #define ERR_MAC_VERIFY (-1036)
418 #define ERR_MAC_KEY (-1037)
420 #define ERR_DUKPT_NOT_IN_FUNCTION (-1038)
421 #define ERR_DIFFERENCE (-1039)
423 #define C_ERR_BAD_MESS_NO (-2901)
424 #define C_ERR_BAD_MESS_IAPP (-2902)
425 #define C_ERR_BAD_SIGN_CARD (-2903)
426 #define C_ERR_BAD_SIGN (-2904)
427 #define C_ERR_BAD_BUFFER_FORMAT (-2905)
428 #define C_ERR_BAD_MODE (-2906)
429 #define C_ERR_BUFFER_SIZE (-2907)
430 #define C_ERR_ECHO_CHAR (-2908)
431 #define C_ERR_CURRENCY_CODE (-2909)
432 #define C_ERR_FILE_NAME_PREFIX (-2910)
434 #define SCH_ERROR_SCHEME (-5000)
435 #define SCH_ERROR_LIBRARY (-6000)
439 
441 typedef struct{
442  unsigned int tag;
443  unsigned int id;
444  unsigned int len;
445  unsigned int usage;
446  unsigned char key[DES_KEY_SIZE];
447 }T_MAC_KDES;
448 
449 typedef struct{
450  unsigned int tag;
451  unsigned int id;
452  unsigned int len;
453  unsigned int usage;
454  unsigned char key[TDES_KEY_SIZE];
455 }T_MAC_KTDES;
456 
457 /*
458  New types (for all schemes)
459  */
460 typedef struct {
461  unsigned char PinCode[MAX_PIN_CODE_SIZE];
462  int PinLen;
463  unsigned char Rfu[4];
464 } T_PIN_CODE_AREA;
465 
466 typedef struct {
467  int CardNumber1;
468  int CardNumber2;
469  unsigned char Key[TDES_KEY_SIZE];
470 } T_TDES_KEY_AREA;
471 
472 typedef struct {
473  int CardNumber1;
474  int CardNumber2;
475  unsigned char Key[DES_KEY_SIZE];
476 } T_DES_KEY_AREA;
477 
478 typedef struct {
479  int CardNumber1;
480  int CardNumber2;
481  unsigned char Key[TDES_KEY_SIZE];
482  unsigned char Rfu[104];
483 } T_ISO9564_TDES_KEY_AREA;
484 
485 typedef struct {
486  int CardNumber1;
487  int CardNumber2;
488  unsigned char Key[DES_KEY_SIZE];
489  unsigned char Rfu[112];
490 } T_ISO9564_DES_KEY_AREA;
491 
492 typedef struct {
493  int CardNumber1;
494  int CardNumber2;
495  unsigned char PinBloc[PIN_BLOC_SIZE];
496  unsigned char Rfu[1000];
497 } T_ISO9564_2_OTHER_AREA;
498 
499 typedef struct {
500  int Tag;
501  int Len;
502  int ReturnCode;
503  unsigned char Answer[BUFFER_SIZE];
504 } T_ISO9564_RESULT;
505 
506 #ifndef __OEM_S_H
507 #ifndef __CRYPTO_DEF_H
508 #ifndef __CRYPTO_DEF_H_INCLUDED__
509 typedef struct {
510  unsigned char Key[DES_KEY_SIZE];
511  unsigned short Check;
512 } T_DUKPT_KEY;
513 
514 typedef struct{
515  unsigned char Key[TDES_KEY_SIZE];
516  unsigned short Check;
517 } T_DUKPT_TDES_KEY;
518 
519 #endif
520 #endif
521 #endif
522 
523 typedef struct {
524  int CardNumber1;
525  int CardNumber2;
526  int CurrentState;
527  T_DUKPT_KEY keys[NB_DUKPT_KEYS];
528  unsigned char Smid[DUKPT_SMID_SIZE];
529  unsigned char DerivationKey[TDES_KEY_SIZE];
530  unsigned char InitialKey[DES_KEY_SIZE];
531  T_MAC_KDES MacKey;
532  unsigned char Rfu[760-sizeof(T_MAC_KDES)];
533 } T_DUKPT_DES_SECRET_AREA;
534 
535 typedef struct {
536  int Tag;
537  int Len;
538  int ReturnCode;
539  unsigned char TransactionSmid[DUKPT_SMID_SIZE];
540  unsigned char TransactionPinBloc[PIN_BLOC_SIZE];
541 } T_DUKPT_RESULT;
542 
543 typedef struct {
544  int Tag;
545  int Len;
546  int ReturnCode;
547  unsigned char TransactionSmid[DUKPT_SMID_SIZE];
548  unsigned char CipheredData[DUKPT_DATA_SIZE];
549 } T_DUKPT_DATA_RESULT;
550 
551 typedef struct {
552  int CardNumber1;
553  int CardNumber2;
554  int CurrentState;
555  T_DUKPT_TDES_KEY keys[NB_DUKPT_KEYS];
556  unsigned char Smid[DUKPT_SMID_SIZE];
557  unsigned char DerivationKey[TDES_KEY_SIZE];
558  unsigned char InitialKey[TDES_KEY_SIZE];
559  T_MAC_KTDES MacKey;
560  unsigned char Rfu[572-sizeof(T_MAC_KTDES)];
561 } T_DUKPT_TDES_SECRET_AREA;
562 
563 typedef struct {
564  int CardNumber1;
565  int CardNumber2;
566  unsigned char Keys[1008];
567 } T_SECRET_AREA;
568 
569 typedef struct {
570  int Tag;
571  int Len;
572  int ReturnCode;
573 } T_LOAD_DATA_RESULT;
574 
575 typedef struct {
576  int Tag;
577  int Len;
578  int ReturnCode;
579  unsigned char BufferOut[MAX_DATA_SIZE];
580 } T_CIPHER_DATA_RESULT;
581 
582 
583 
584 
585 typedef struct {
586  unsigned char Echo;
587  unsigned char EchoChar;
588  unsigned char Line;
589  unsigned char Column;
590 } T_ECHO_INFO;
591 
592 typedef union {
593  int i;
594  T_ECHO_INFO c;
595 } U_ECHO_INFO;
596 
597 
598 typedef struct {
599  unsigned char Rfu;
600  unsigned char BipOn;
601  unsigned char MinDigit;
602  unsigned char MaxDigit;
603 } T_KEY_INFO;
604 
605 typedef union {
606  int i;
607  T_KEY_INFO c;
608 } U_KEY_INFO;
609 
610 
611 typedef struct {
612  unsigned short InterTimeout;
613  unsigned short GlobalTimeout;
614 } T_TIMEOUT_INFO;
615 
616 typedef union {
617  int i;
618  T_TIMEOUT_INFO s;
619 } U_TIMEOUT_INFO;
620 
621 
622 typedef struct {
623  unsigned char ErrorNote;
624  unsigned char ErrorLevel;
625  unsigned char NormalNote;
626  unsigned char NormalLevel;
627 } T_BIP_INFO;
628 
629 typedef union {
630  int i;
631  T_BIP_INFO c;
632 } U_BIP_INFO;
633 
634 
635 typedef struct {
636  int Tag;
637  int Len;
638  int ReturnCode;
639 } T_PIN_ENTRY_RESULT;
640 
641 typedef struct {
642  int Tag;
643  int Len;
644  int ReturnCode;
645 } T_XOR_RESULT;
646 
647 typedef struct {
648  int Tag;
649  int Len;
650  int ReturnCode;
651 } T_HEADER_RESULT;
653 
654 #endif
Ingenico