Cleanup / comment dead code

This commit is contained in:
Charles-Edouard de la Vergne 2024-03-13 14:06:40 +01:00
parent cc8de8eb97
commit ae8d1f7607
No known key found for this signature in database
GPG Key ID: F12296941B7BB9C6
4 changed files with 14 additions and 34 deletions

View File

@ -379,7 +379,6 @@ int gpg_apdu_put_data(unsigned int ref) {
case 0x93: case 0x93:
len_q = l; len_q = l;
break; break;
break;
case 0x94: case 0x94:
case 0x95: case 0x95:
case 0x96: case 0x96:
@ -1007,12 +1006,7 @@ int gpg_apdu_put_key_data(unsigned int ref) {
sw = SW_CONDITIONS_NOT_SATISFIED; sw = SW_CONDITIONS_NOT_SATISFIED;
break; break;
} }
if (len != GPG_IO_BUFFER_LENGTH) {
sw = SW_CONDITIONS_NOT_SATISFIED;
break;
}
PRINTF("[DATA] - put_key_data: key len: %d\n", len);
gpg_io_discard(0); gpg_io_discard(0);
CX_CHECK(cx_aes_no_throw(&keyenc, CX_CHECK(cx_aes_no_throw(&keyenc,
CX_DECRYPT | CX_CHAIN_CBC | CX_PAD_ISO9797M2 | CX_LAST, CX_DECRYPT | CX_CHAIN_CBC | CX_PAD_ISO9797M2 | CX_LAST,
@ -1021,7 +1015,6 @@ int gpg_apdu_put_key_data(unsigned int ref) {
G_gpg_vstate.work.io_buffer, G_gpg_vstate.work.io_buffer,
&ksz)); &ksz));
if (len != ksz) { if (len != ksz) {
PRINTF("[DATA] - put_key_data: Wrong aes output len: %d / %d\n", len, ksz);
sw = SW_WRONG_DATA; sw = SW_WRONG_DATA;
break; break;
} }

View File

@ -249,7 +249,6 @@ int gpg_dispatch() {
/* --- SELECT --- */ /* --- SELECT --- */
case INS_SELECT: case INS_SELECT:
return gpg_apdu_select(); return gpg_apdu_select();
break;
/* --- ACTIVATE/TERMINATE FILE --- */ /* --- ACTIVATE/TERMINATE FILE --- */
case INS_ACTIVATE_FILE: case INS_ACTIVATE_FILE:
@ -258,17 +257,14 @@ int gpg_dispatch() {
gpg_install(STATE_ACTIVATE); gpg_install(STATE_ACTIVATE);
} }
return SW_OK; return SW_OK;
break;
case INS_TERMINATE_DF: case INS_TERMINATE_DF:
gpg_io_discard(0); gpg_io_discard(0);
if (gpg_pin_is_verified(PIN_ID_PW3) || (N_gpg_pstate->PW3.counter == 0)) { if (gpg_pin_is_verified(PIN_ID_PW3) || (N_gpg_pstate->PW3.counter == 0)) {
gpg_install(STATE_TERMINATE); gpg_install(STATE_TERMINATE);
return SW_OK; return SW_OK;
break;
} }
return SW_CONDITIONS_NOT_SATISFIED; return SW_CONDITIONS_NOT_SATISFIED;
break;
} }
/* Other commands allowed if not terminated */ /* Other commands allowed if not terminated */
@ -283,12 +279,6 @@ int gpg_dispatch() {
} }
switch (G_gpg_vstate.io_ins) { switch (G_gpg_vstate.io_ins) {
#ifdef GPG_DEBUG_APDU
case 0x42:
sw = debug_apdu();
break;
#endif
case INS_EXIT: case INS_EXIT:
os_sched_exit(0); os_sched_exit(0);
sw = SW_OK; sw = SW_OK;

View File

@ -219,7 +219,7 @@ static int gpg_gen_ecc_kyey(gpg_key_t *keygpg, uint8_t *name) {
nvm_write(&G_gpg_vstate.kslot->sig_count, &reset_cnt, sizeof(unsigned int)); nvm_write(&G_gpg_vstate.kslot->sig_count, &reset_cnt, sizeof(unsigned int));
gpg_io_clear(); gpg_io_clear();
return SW_OK; error = SW_OK;
end: end:
return error; return error;
@ -256,7 +256,7 @@ static int gpg_read_ecc_kyey(gpg_key_t *keygpg) {
keygpg->pub_key.ecfp.W_len, keygpg->pub_key.ecfp.W_len,
(unsigned char *) &keygpg->pub_key.ecfp.W); (unsigned char *) &keygpg->pub_key.ecfp.W);
} }
return SW_OK; error = SW_OK;
end: end:
return error; return error;

View File

@ -31,12 +31,13 @@ const unsigned char C_MAGIC[8] = {'G', 'P', 'G', 'C', 'A', 'R', 'D', '3'};
// secp256r1 / NIST P256 /ansi-x9.62 : 1.2.840.10045.3.1.7 // secp256r1 / NIST P256 /ansi-x9.62 : 1.2.840.10045.3.1.7
const unsigned char C_OID_SECP256R1[8] = {0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x07}; const unsigned char C_OID_SECP256R1[8] = {0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x07};
/*
//secp384r1 / NIST P384 /ansi-x9.62 :1.3.132.0.34 /* Unsupported (yet) Curves
// secp384r1 / NIST P384 /ansi-x9.62 :1.3.132.0.34
const unsigned char C_OID_SECP384R1[5] = { const unsigned char C_OID_SECP384R1[5] = {
0x2B, 0x81, 0x04, 0x00 , 0x22 0x2B, 0x81, 0x04, 0x00 , 0x22
}; };
//secp521r1 / NIST P521 /ansi-x9.62 : 1.3.132.0.35 // secp521r1 / NIST P521 /ansi-x9.62 : 1.3.132.0.35
const unsigned char C_OID_SECP521R1[5] = { const unsigned char C_OID_SECP521R1[5] = {
0x2B, 0x81, 0x04, 0x00, 0x23 0x2B, 0x81, 0x04, 0x00, 0x23
}; };
@ -44,20 +45,20 @@ const unsigned char C_OID_SECP521R1[5] = {
// secp256k1: 1.3.132.0.10 // secp256k1: 1.3.132.0.10
const unsigned char C_OID_SECP256K1[5] = {0x2B, 0x81, 0x04, 0x00, 0x0A}; const unsigned char C_OID_SECP256K1[5] = {0x2B, 0x81, 0x04, 0x00, 0x0A};
/* /* Unsupported (yet) Curves
//brainpool 256t1: 1.3.36.3.3.2.8.1.1.8 // brainpool 256t1: 1.3.36.3.3.2.8.1.1.8
const unsigned char C_OID_BRAINPOOL256T1[9] = { const unsigned char C_OID_BRAINPOOL256T1[9] = {
0x2B,0x24,0x03,0x03,0x02,0x08,0x01,0x01,0x07 0x2B,0x24,0x03,0x03,0x02,0x08,0x01,0x01,0x07
}; };
//brainpool 256r1: 1.3.36.3.3.2.8.1.1.7 // brainpool 256r1: 1.3.36.3.3.2.8.1.1.7
const unsigned char C_OID_BRAINPOOL256R1[9] = { const unsigned char C_OID_BRAINPOOL256R1[9] = {
0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x08 0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x08
}; };
//brainpool 384r1: 1.3.36.3.3.2.8.1.1.11 // brainpool 384r1: 1.3.36.3.3.2.8.1.1.11
const unsigned char C_OID_BRAINPOOL384R1[9] = { const unsigned char C_OID_BRAINPOOL384R1[9] = {
0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x0B 0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x0B
}; };
//brainpool 512r1: 1.3.36.3.3.2.8.1.1.13 // brainpool 512r1: 1.3.36.3.3.2.8.1.1.13
const unsigned char C_OID_BRAINPOOL512R1[9] = { const unsigned char C_OID_BRAINPOOL512R1[9] = {
0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x0D 0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x0D
}; };
@ -98,16 +99,14 @@ unsigned int gpg_oid2curve(unsigned char *oid, unsigned int len) {
if ((len == sizeof(C_OID_SECP256K1)) && (memcmp(oid, C_OID_SECP256K1, len) == 0)) { if ((len == sizeof(C_OID_SECP256K1)) && (memcmp(oid, C_OID_SECP256K1, len) == 0)) {
return CX_CURVE_SECP256K1; return CX_CURVE_SECP256K1;
} }
/* /* Unsupported (yet) Curves
if ( (len == sizeof(C_OID_SECP384R1)) && (memcmp(oid, C_OID_SECP384R1, len)==0) ) { if ( (len == sizeof(C_OID_SECP384R1)) && (memcmp(oid, C_OID_SECP384R1, len)==0) ) {
return CX_CURVE_SECP384R1; return CX_CURVE_SECP384R1;
} }
if ( (len == sizeof(C_OID_SECP521R1)) && (memcmp(oid, C_OID_SECP521R1, len)==0) ) { if ( (len == sizeof(C_OID_SECP521R1)) && (memcmp(oid, C_OID_SECP521R1, len)==0) ) {
return CX_CURVE_SECP521R1; return CX_CURVE_SECP521R1;
} }
*/
/*
if ( (len == sizeof(C_OID_BRAINPOOL256T1)) && (memcmp(oid, C_OID_BRAINPOOL256T1, len)==0) ) { if ( (len == sizeof(C_OID_BRAINPOOL256T1)) && (memcmp(oid, C_OID_BRAINPOOL256T1, len)==0) ) {
return CX_CURVE_BrainPoolP256T1; return CX_CURVE_BrainPoolP256T1;
} }
@ -142,7 +141,7 @@ unsigned char *gpg_curve2oid(unsigned int cv, unsigned int *len) {
*len = sizeof(C_OID_SECP256K1); *len = sizeof(C_OID_SECP256K1);
return (unsigned char *) PIC(C_OID_SECP256K1); return (unsigned char *) PIC(C_OID_SECP256K1);
/* /* Unsupported (yet) Curves
case CX_CURVE_SECP384R1: case CX_CURVE_SECP384R1:
*len = sizeof(C_OID_SECP384R1); *len = sizeof(C_OID_SECP384R1);
return (unsigned char*)PIC(C_OID_SECP384R1); return (unsigned char*)PIC(C_OID_SECP384R1);
@ -150,9 +149,7 @@ unsigned char *gpg_curve2oid(unsigned int cv, unsigned int *len) {
case CX_CURVE_SECP521R1: case CX_CURVE_SECP521R1:
*len = sizeof(C_OID_SECP521R1); *len = sizeof(C_OID_SECP521R1);
return (unsigned char*)PIC(C_OID_SECP521R1); return (unsigned char*)PIC(C_OID_SECP521R1);
*/
/*
case CX_CURVE_BrainPoolP256R1: case CX_CURVE_BrainPoolP256R1:
*len = sizeof(C_OID_SECP256R1); *len = sizeof(C_OID_SECP256R1);
return (unsigned char*)PIC(C_OID_SECP256R1); return (unsigned char*)PIC(C_OID_SECP256R1);
@ -455,7 +452,7 @@ void gpg_install(unsigned char app_state) {
nvm_write((void *) (&N_gpg_pstate->config_pin), G_gpg_vstate.work.io_buffer, 1); nvm_write((void *) (&N_gpg_pstate->config_pin), G_gpg_vstate.work.io_buffer, 1);
gpg_activate_pinpad(3); gpg_activate_pinpad(3);
// default key template: RSA 2048) // default key template
for (int s = 0; s < GPG_KEYS_SLOTS; s++) { for (int s = 0; s < GPG_KEYS_SLOTS; s++) {
gpg_install_slot((gpg_key_slot_t *) &N_gpg_pstate->keys[s]); gpg_install_slot((gpg_key_slot_t *) &N_gpg_pstate->keys[s]);
} }