-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsc_functions.h
More file actions
95 lines (76 loc) · 2.76 KB
/
sc_functions.h
File metadata and controls
95 lines (76 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
============================
= saada.benamar@gmail.com =
= plug-up international =
============================
*/
#include <stdio.h>
#include <string.h>
#include <openssl/rand.h>
#include <openssl/des.h>
/*
generate bytes challenge
*/
void generateChallenge(unsigned char *challenge,int chl_size);
/*
Verify that calculated card cryptogram is the same as that returned from the card
*/
int checkCardCryptogram(char *returnedCardCryptogram, char *computedCardCryptogram);
/*
Calculate card cryptogram
*/
void computeCardCryptogram(char *hostChallenge,char *cardChallenge, char *counter, char *s_encKey, char *cardCryptogram);
/*
Calculate host cryptogram
*/
void computeHostCryptogram(char *hostChallenge,char *cardChallenge,char *counter,char *s_encKey,char *hostCryptogram);
/*
Calculate retail MAC = command MAC = command integrity
*/
void computeRetailMac(const char *data, char *key, char *previousMac, char *retailMac);
/*
Modify CLA & Lc for command that will be MAC-ed
*/
void modifyCdeForMac(char * command, char *mCommand);
/*
Calculate full triple DES MAC used to calculate card & host cryptograms
*/
void computeFull3DesMac(char *data, char *key, char *full3DesMac);
/*
Calculate a session key
*/
void computeSessionKey(char *counter,char *keyConstant, char *masterKey, char *sessionKey);
/*
Form an initialize update command to be used as echange() function parameter
The length of init_up_apdu array shall be (13*2+1)
*/
void initializeUpdate(char *keysetId, char *hostChallenge, char* init_up_apdu);
/*
Form an external authenticate command to be used as echange() function parameter after it will be Mac-ed
*/
void externalAuthenticate(char *securityLevel, char *hostCryptogram, char *ext_auth_apdu);
/*
Form a diversified initialize update command to be used as echange() function parameter
The length of d_init_up_apdu array shall be (24*2+1)
*/
void diversifiedInitializeUpdate(char *keysetId, char *hostChallenge, char* masterKeyDiversifier, char* d_init_up_apdu);
/*
Form a mac-ed apdu. return current mac also.
*/
void macedCommand(char *cde, char *cmacKey, char *lastMac, char *currentMac, char *macedCde);
/*
Form a put key command
*/
int createPutKeyCommand(char *numKeyset, char *mode, char *sdekKey, char* gp_enc, char *gp_mac, char *gp_dek, char *keyUsage, char *keyAccess, char *putKeyCommand);
/*
Perform a triple des ecb encryption on 8 bytes data. Outputs 8 bytes encrypted data. (used in createPutKeyCommand())
*/
int tripleDES_ECB_encrypt(char *data, char *key, char *encrypted_data);
/*
Compute a Key Check Value
*/
int computeKCV(char *key, char *kcv);
/*
computes a 16-bytes diversified key from the given <16-bytes key> and the <16-bytes diversifier> parameters using 3-des-cbc algorithm.
*/
void computeDiversifiedKey(char *key, char *s_diversifier, char *divKey);