Lines Matching full:pd
35 void osdp_compute_scbk(struct osdp_pd *pd, uint8_t *master_key, uint8_t *scbk) in osdp_compute_scbk() argument
39 memcpy(scbk, pd->sc.pd_client_uid, 8); in osdp_compute_scbk()
46 void osdp_compute_session_keys(struct osdp_pd *pd) in osdp_compute_session_keys() argument
49 struct osdp *ctx = pd_to_osdp(pd); in osdp_compute_session_keys()
52 if (ISSET_FLAG(pd, PD_FLAG_SC_USE_SCBKD)) { in osdp_compute_session_keys()
55 if (is_cp_mode(pd) && !ISSET_FLAG(pd, PD_FLAG_HAS_SCBK)) { in osdp_compute_session_keys()
56 osdp_compute_scbk(pd, ctx->sc_master_key, scbk); in osdp_compute_session_keys()
58 memcpy(scbk, pd->sc.scbk, 16); in osdp_compute_session_keys()
62 memset(pd->sc.s_enc, 0, 16); in osdp_compute_session_keys()
63 memset(pd->sc.s_mac1, 0, 16); in osdp_compute_session_keys()
64 memset(pd->sc.s_mac2, 0, 16); in osdp_compute_session_keys()
66 pd->sc.s_enc[0] = 0x01; in osdp_compute_session_keys()
67 pd->sc.s_enc[1] = 0x82; in osdp_compute_session_keys()
68 pd->sc.s_mac1[0] = 0x01; in osdp_compute_session_keys()
69 pd->sc.s_mac1[1] = 0x01; in osdp_compute_session_keys()
70 pd->sc.s_mac2[0] = 0x01; in osdp_compute_session_keys()
71 pd->sc.s_mac2[1] = 0x02; in osdp_compute_session_keys()
74 pd->sc.s_enc[i] = pd->sc.cp_random[i - 2]; in osdp_compute_session_keys()
75 pd->sc.s_mac1[i] = pd->sc.cp_random[i - 2]; in osdp_compute_session_keys()
76 pd->sc.s_mac2[i] = pd->sc.cp_random[i - 2]; in osdp_compute_session_keys()
79 osdp_encrypt(scbk, NULL, pd->sc.s_enc, 16); in osdp_compute_session_keys()
80 osdp_encrypt(scbk, NULL, pd->sc.s_mac1, 16); in osdp_compute_session_keys()
81 osdp_encrypt(scbk, NULL, pd->sc.s_mac2, 16); in osdp_compute_session_keys()
84 void osdp_compute_cp_cryptogram(struct osdp_pd *pd) in osdp_compute_cp_cryptogram() argument
87 memcpy(pd->sc.cp_cryptogram + 0, pd->sc.pd_random, 8); in osdp_compute_cp_cryptogram()
88 memcpy(pd->sc.cp_cryptogram + 8, pd->sc.cp_random, 8); in osdp_compute_cp_cryptogram()
89 osdp_encrypt(pd->sc.s_enc, NULL, pd->sc.cp_cryptogram, 16); in osdp_compute_cp_cryptogram()
110 int osdp_verify_cp_cryptogram(struct osdp_pd *pd) in osdp_verify_cp_cryptogram() argument
115 memcpy(cp_crypto + 0, pd->sc.pd_random, 8); in osdp_verify_cp_cryptogram()
116 memcpy(cp_crypto + 8, pd->sc.cp_random, 8); in osdp_verify_cp_cryptogram()
117 osdp_encrypt(pd->sc.s_enc, NULL, cp_crypto, 16); in osdp_verify_cp_cryptogram()
119 if (osdp_ct_compare(pd->sc.cp_cryptogram, cp_crypto, 16) != 0) { in osdp_verify_cp_cryptogram()
125 void osdp_compute_pd_cryptogram(struct osdp_pd *pd) in osdp_compute_pd_cryptogram() argument
128 memcpy(pd->sc.pd_cryptogram + 0, pd->sc.cp_random, 8); in osdp_compute_pd_cryptogram()
129 memcpy(pd->sc.pd_cryptogram + 8, pd->sc.pd_random, 8); in osdp_compute_pd_cryptogram()
130 osdp_encrypt(pd->sc.s_enc, NULL, pd->sc.pd_cryptogram, 16); in osdp_compute_pd_cryptogram()
133 int osdp_verify_pd_cryptogram(struct osdp_pd *pd) in osdp_verify_pd_cryptogram() argument
138 memcpy(pd_crypto + 0, pd->sc.cp_random, 8); in osdp_verify_pd_cryptogram()
139 memcpy(pd_crypto + 8, pd->sc.pd_random, 8); in osdp_verify_pd_cryptogram()
140 osdp_encrypt(pd->sc.s_enc, NULL, pd_crypto, 16); in osdp_verify_pd_cryptogram()
142 if (osdp_ct_compare(pd->sc.pd_cryptogram, pd_crypto, 16) != 0) { in osdp_verify_pd_cryptogram()
148 void osdp_compute_rmac_i(struct osdp_pd *pd) in osdp_compute_rmac_i() argument
151 memcpy(pd->sc.r_mac, pd->sc.cp_cryptogram, 16); in osdp_compute_rmac_i()
152 osdp_encrypt(pd->sc.s_mac1, NULL, pd->sc.r_mac, 16); in osdp_compute_rmac_i()
153 osdp_encrypt(pd->sc.s_mac2, NULL, pd->sc.r_mac, 16); in osdp_compute_rmac_i()
156 int osdp_decrypt_data(struct osdp_pd *pd, int is_cmd, uint8_t *data, int length) in osdp_decrypt_data() argument
165 memcpy(iv, is_cmd ? pd->sc.r_mac : pd->sc.c_mac, 16); in osdp_decrypt_data()
170 osdp_decrypt(pd->sc.s_enc, iv, data, length); in osdp_decrypt_data()
184 int osdp_encrypt_data(struct osdp_pd *pd, int is_cmd, uint8_t *data, int length) in osdp_encrypt_data() argument
194 memcpy(iv, is_cmd ? pd->sc.r_mac : pd->sc.c_mac, 16); in osdp_encrypt_data()
199 osdp_encrypt(pd->sc.s_enc, iv, data, pad_len); in osdp_encrypt_data()
204 int osdp_compute_mac(struct osdp_pd *pd, int is_cmd, in osdp_compute_mac() argument
223 memcpy(iv, is_cmd ? pd->sc.r_mac : pd->sc.c_mac, 16); in osdp_compute_mac()
226 osdp_encrypt(pd->sc.s_mac1, iv, buf, pad_len - 16); in osdp_compute_mac()
232 osdp_encrypt(pd->sc.s_mac2, iv, buf + pad_len - 16, 16); in osdp_compute_mac()
233 memcpy(is_cmd ? pd->sc.c_mac : pd->sc.r_mac, buf + pad_len - 16, 16); in osdp_compute_mac()
238 void osdp_sc_setup(struct osdp_pd *pd) in osdp_sc_setup() argument
241 bool preserve_scbk = is_pd_mode(pd) || ISSET_FLAG(pd, PD_FLAG_HAS_SCBK); in osdp_sc_setup()
244 memcpy(scbk, pd->sc.scbk, 16); in osdp_sc_setup()
246 memset(&pd->sc, 0, sizeof(struct osdp_secure_channel)); in osdp_sc_setup()
248 memcpy(pd->sc.scbk, scbk, 16); in osdp_sc_setup()
251 if (is_pd_mode(pd)) { in osdp_sc_setup()
252 pd->sc.pd_client_uid[0] = BYTE_0(pd->id.vendor_code); in osdp_sc_setup()
253 pd->sc.pd_client_uid[1] = BYTE_1(pd->id.vendor_code); in osdp_sc_setup()
254 pd->sc.pd_client_uid[2] = BYTE_0(pd->id.model); in osdp_sc_setup()
255 pd->sc.pd_client_uid[3] = BYTE_1(pd->id.version); in osdp_sc_setup()
256 pd->sc.pd_client_uid[4] = BYTE_0(pd->id.serial_number); in osdp_sc_setup()
257 pd->sc.pd_client_uid[5] = BYTE_1(pd->id.serial_number); in osdp_sc_setup()
258 pd->sc.pd_client_uid[6] = BYTE_2(pd->id.serial_number); in osdp_sc_setup()
259 pd->sc.pd_client_uid[7] = BYTE_3(pd->id.serial_number); in osdp_sc_setup()
261 osdp_fill_random(pd->sc.cp_random, 8); in osdp_sc_setup()