📄 stacrypt.c
字号:
/* *//* RETURN DESCRIPTION *//* Octetstring Pointer to allocated structure *//* NULL error *//* M_ETIME *//* M_ETEXT *//* *//* CALLED FUNCTIONS *//* check_sct_sc ERROR-Codes *//* ESIDUNK *//* ENOSHELL *//* EOPERR *//* EEMPTY *//* EMEMAVAIL *//* ECLERR *//* ESIDUNK *//* ERDERR *//* EINVARG *//* ETOOLONG *//* sw1/sw2 from SCT response *//* T1 - ERROR *//* *//* sct_interface ERROR-Codes *//* EINVARG *//* ETOOLONG *//* EMEMAVAIL *//* ESIDUNK *//* EPARMISSED *//* INVPAR *//* EINVINS *//* sw1/sw2 from SCT response *//* T1 - ERROR *//* sta_aux_bytestr_free *//* *//* err_analyse ERROR_Codes *//* ENOSHELL *//* EOPERR *//* EEMPTY *//* ECLERR *//* ESIDUNK *//* ERDERR *//* *//* *//* set_errmsg *//* *//*-------------------------------------------------------------*/OctetString *sca_get_rno(sct_id, rnd_len) int sct_id; unsigned int rnd_len;{ /*----------------------------------------------------------*/ /* Definitions */ /*----------------------------------------------------------*/ int rc, i; OctetString *ostring; /*----------------------------------------------------------*/ /* Statements */ /*----------------------------------------------------------*/ rc = 0; sca_errno = M_NOERR; sca_errmsg = NULL; sc_expect = FALSE; /* this function doesn't need a SC */#ifdef TEST fprintf(stdout, "\n***** STAMOD-Routine sca_get_rndo *****\n\n"); fprintf(stdout, "TRACE of the input parameters : \n"); fprintf(stdout, "sct_id : %d\n", sct_id); fprintf(stdout, "rnd_len : %d\n", rnd_len);#endif /*-----------------------------------------------------*/ /* call check_sct_sc */ /*-----------------------------------------------------*/ if (check_sct_sc(sct_id, sc_expect) == -1) return ((OctetString *) 0); /*-----------------------------------------------------*/ /* Prepare parameters for the SCT Interface */ /*-----------------------------------------------------*/ command = S_GET_RNO; request.rq_p1.lrno = rnd_len; /*-----------------------------------------------------*/ /* Call SCT Interface */ /*-----------------------------------------------------*/ rc = sct_interface(sct_id, command, &request, &response); if (rc < 0) { sca_errno = sct_errno; sca_errmsg = sct_errmsg; err_analyse(sct_id); return ((OctetString *) 0); } /*----------------------------------------------------------*/ /* Normal End generate Octetstring and Release response */ /*----------------------------------------------------------*/ if ((ostring = (OctetString *) malloc(sizeof(OctetString))) == NULL) { sca_errno = M_EMEMORY; set_errmsg(); sta_aux_bytestr_free(&response); return ((OctetString *) 0); } if ((ostring->octets = (char *) malloc(response.nbytes)) == NULL) { sca_errno = M_EMEMORY; set_errmsg(); free(ostring); sta_aux_bytestr_free(&response); return ((OctetString *) 0); } ostring->noctets = response.nbytes; for (i = 0; i < ostring->noctets; i++) *(ostring->octets + i) = *(response.bytes + i); sta_aux_bytestr_free(&response);#ifdef TEST fprintf(stdout, "TRACE of the output parameters : \n"); fprintf(stdout, "Octetstring : \n"); fprintf(stdout, " noctets : %d\n", ostring->noctets); fprintf(stdout, " octets : \n"); aux_fxdump(stdout, ostring->octets, ostring->noctets, 0); fprintf(stdout, "\n***** Normal end of sca_get_rno *****\n\n");#endif return (ostring);} /* end sca_get_rno *//*-------------------------------------------------------------*//* E N D O F P R O C E D U R E sca_get_rno *//*-------------------------------------------------------------*//*-------------------------------------------------------------*//* | GMD *//* +-----*//* PROC sca_del_user_key VERSION 1.0 *//* DATE Januar 1992 *//* BY U.Viebeg *//* *//* DESCRIPTION *//* Delete key within the specified SCT *//* *//* A smartcard is not expected. *//* *//* *//* IN DESCRIPTION *//* sct_id SCT identifier *//* *//* key_id Key-Id of the key to be deleted *//* *//* OUT *//* *//* *//* RETURN DESCRIPTION *//* 0 o.k *//* -1 error *//* EINVKID *//* *//* CALLED FUNCTIONS *//* check_sct_sc ERROR-Codes *//* ENOCARD *//* ESIDUNK *//* ENOSHELL *//* EOPERR *//* EEMPTY *//* EMEMAVAIL *//* ECLERR *//* ESIDUNK *//* ERDERR *//* EINVARG *//* ETOOLONG *//* sw1/sw2 from SCT response *//* T1 - ERROR *//* *//* get_sct_keyid ERROR-Codes *//* EINVKID *//* *//* sct_interface ERROR-Codes *//* EINVARG *//* ETOOLONG *//* EMEMAVAIL *//* ESIDUNK *//* EPARMISSED *//* INVPAR *//* EINVINS *//* sw1/sw2 from SCT response *//* T1 - ERROR *//* *//* err_analyse ERROR_Codes *//* ENOSHELL *//* EOPERR *//* EEMPTY *//* ECLERR *//* ESIDUNK *//* ERDERR *//* *//* set_errmsg *//* *//* sta_aux_bytestr_free *//* *//*-------------------------------------------------------------*/intsca_del_user_key(sct_id, key_id) int sct_id; KeyId *key_id;{ /*----------------------------------------------------------*/ /* Definitions */ /*----------------------------------------------------------*/ int i; int rc; char sct_keyid; /* char representation of the key_id */ /*----------------------------------------------------------*/ /* Statements */ /*----------------------------------------------------------*/ rc = 0; sca_errno = M_NOERR; sca_errmsg = NULL;#ifdef TEST fprintf(stdout, "\n***** STAMOD-Routine sca_del_user_key *********************************************\n\n"); fprintf(stdout, "input-parameters:\n"); fprintf(stdout, "sct_id: %d\n", sct_id); if (key_id->key_level == SC_MF) fprintf(stdout, "key_id: MF-level Key_No: "); if (key_id->key_level == SC_DF) fprintf(stdout, "key_id: DF-level Key_No: "); if (key_id->key_level == SC_SF) fprintf(stdout, "key_id: SF-level Key_No: "); if (key_id->key_level == SCT) fprintf(stdout, "key_id: SCT-level Key_No: "); fprintf(stdout, "%d\n", key_id->key_number); fprintf(stdout, "\n\n");#endif /*-----------------------------------------------------*/ /* Check input parameters */ /*-----------------------------------------------------*/ /*-----------------------------------------------------*/ /* check key_id and get keyid in char representation */ /*-----------------------------------------------------*/ if ((sct_keyid = get_sct_keyid(key_id)) == -1) return (-1); /*-----------------------------------------------------*/ /* A key on the smartcard cannot be deleted. */ /* If level = level on the smartcard */ /* then return (error) */ /*-----------------------------------------------------*/ if ((key_id->key_level == SC_MF) || (key_id->key_level == SC_DF) || (key_id->key_level == SC_SF)) { sca_errno = EINVKID; set_errmsg(); return (-1); } /*-----------------------------------------------------*/ /* call check_sct_sc */ /*-----------------------------------------------------*/ if (check_sct_sc(sct_id, FALSE) == -1) return (-1); /*-----------------------------------------------------*/ /* Prepare parameters for the SCT Interface */ /*-----------------------------------------------------*/ command = S_DEL_USER_KEY; request.rq_p1.kid = sct_keyid; /*-----------------------------------------------------*/ /* Call SCT Interface */ /*-----------------------------------------------------*/ rc = sct_interface(sct_id, command, &request, &response); if (rc < 0) { sca_errno = sct_errno; sca_errmsg = sct_errmsg; err_analyse(sct_id); return (-1); } /*-----------------------------------------------------*/ /* Normal End (Release storage) */ /*-----------------------------------------------------*/ sta_aux_bytestr_free(&response);#ifdef TEST fprintf(stdout, "\n***** Normal end of sca_del_user_key *********************************************\n\n");#endif return (sca_errno);} /* end sca_del_user_key *//*-------------------------------------------------------------*//* E N D O F P R O C E D U R E sca_del_user_key *//*-------------------------------------------------------------*/#ifdef ASSEMBLER/*-------------------------------------------------------------*//* | GMD *//* +-----*//* PROC sca_sign VERSION 1.0 *//* DATE Januar 1992 *//* BY U.Viebeg *//* *//* DESCRIPTION *//* Sign octetstring *//* *//* Smartcard must be inserted. *//* *//* Observe that: *//* If VERSION10 is defined *//* then the result of the hash-function is padded with *//* leading zeroes (X'00') to the modulus length. *//* *//* *//* IN DESCRIPTION *//* sct_id SCT identifier *//* *//* in_octets Octetstring of the data to be */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -