📄 objpin.c
字号:
/* ============================================================================ Project Name : jayaCard Module Name : proto/bios/odata/objpin.c Version : $Id: objpin.c,v 1.5 2004/01/11 09:56:31 dgil Exp $ Description: ISO7816-4 BIOS HELPER FUNCTIONS for PIN The Original Code is jayaCard code. The Initial Developer of the Original Code is Gilles Dumortier. Portions created by the Initial Developer are Copyright (C) 2002-2004 the Initial Developer. All Rights Reserved. Contributor(s): This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see http://www.gnu.org/licenses/gpl.html History Rev Description 100503 dgil wrote it from scratch ============================================================================*/#include "precomp.h"/* ============================================================================ check PIN format - see 7816-15 PIN format : C N P P P P P/F P/F P/F P/F P/F P/F P/F P/F F F C control field 0010 N pin length 0100 to 1100 P pin digit 0000 to 1001 P/F pin/filler determined by pin length F filler 1111 PIN must be in u.bBlock[JAYA_BCRYPTO_INPUT0] and following bytes ========================================================================= */void __bios_check_PIN_format(void){ LOCAL(jbyte,n); LOCAL(jbyte,i); #ifdef DEBUG /* fix this value - will be used to display the step of the check failing */ i=0; n=0; #endif LOG8("PIN","INPUT: %.2X %.2X %.2X %.2X %.2X %.2X %.2X %.2X ", u.bBlock[JAYA_BCRYPTO_INPUT0+0], u.bBlock[JAYA_BCRYPTO_INPUT0+1], u.bBlock[JAYA_BCRYPTO_INPUT0+2], u.bBlock[JAYA_BCRYPTO_INPUT0+3], u.bBlock[JAYA_BCRYPTO_INPUT0+4], u.bBlock[JAYA_BCRYPTO_INPUT0+5], u.bBlock[JAYA_BCRYPTO_INPUT0+6], u.bBlock[JAYA_BCRYPTO_INPUT0+7] ); /* check the control field */ if ((u.bBlock[JAYA_BCRYPTO_INPUT0+0]&0xF0)!=0x20) {invalid_pin: BIOS_SETERR(ERR_INVALID_PIN); LOG2("PIN","__bios_check_PIN_format(): pin invalid in step %d / %d",i,n); return; } /* check the pin length */ n = u.bBlock[JAYA_BCRYPTO_INPUT0+0] & 0x0F; if ((n<4) || (n>12)) goto invalid_pin; /* check each pin digit */ for (i=2;i<=14;) { LOG3("PIN","__bios_check_PIN_format(): step %d-%d / test: %.2X",i,n,u.bBlock[JAYA_BCRYPTO_INPUT0+(i>>1)]&0xF0); if (i<(n+2)) { /* check the pin digit */ if ((u.bBlock[JAYA_BCRYPTO_INPUT0+(i>>1)]&0xF0)>0x90) goto invalid_pin; } else { /* check the filler */ if ((u.bBlock[JAYA_BCRYPTO_INPUT0+(i>>1)]&0xF0)!=0xF0) goto invalid_pin; } i++; LOG3("PIN","__bios_check_PIN_format(): step %d-%d / test: %.2X",i,n,u.bBlock[JAYA_BCRYPTO_INPUT0+(i>>1)]&0x0F); if (i<(n+2)) { /* check the pin digit */ if ((u.bBlock[JAYA_BCRYPTO_INPUT0+(i>>1)]&0x0F)>0x09) goto invalid_pin; } else { /* check the filler */ if ((u.bBlock[JAYA_BCRYPTO_INPUT0+(i>>1)]&0x0F)!=0x0F) goto invalid_pin; } i++; } /* PIN format is ok */ LOG("PIN","__bios_check_PIN_format(): Pin format is valid.");}/* ============================================================================ verify PIN org PIN must be in r.bBlock[JAYA_BCRYPTO_KEYA] and following bytes cmp PIN must be in u.bBlock[JAYA_BCRYPTO_INPUT0] and following bytes secure: use the global semaphore ========================================================================= */void __bios_verify_PIN(void){ LOCAL(jbyte,diff); LOCAL(jbyte,i); LOG8("PIN","INPUT: %.2X %.2X %.2X %.2X %.2X %.2X %.2X %.2X ", u.bBlock[JAYA_BCRYPTO_INPUT0+0], u.bBlock[JAYA_BCRYPTO_INPUT0+1], u.bBlock[JAYA_BCRYPTO_INPUT0+2], u.bBlock[JAYA_BCRYPTO_INPUT0+3], u.bBlock[JAYA_BCRYPTO_INPUT0+4], u.bBlock[JAYA_BCRYPTO_INPUT0+5], u.bBlock[JAYA_BCRYPTO_INPUT0+6], u.bBlock[JAYA_BCRYPTO_INPUT0+7] ); LOG8("PIN","PIN : %.2X %.2X %.2X %.2X %.2X %.2X %.2X %.2X ", r.bBlock[JAYA_BCRYPTO_KEYA+0], r.bBlock[JAYA_BCRYPTO_KEYA+1], r.bBlock[JAYA_BCRYPTO_KEYA+2], r.bBlock[JAYA_BCRYPTO_KEYA+3], r.bBlock[JAYA_BCRYPTO_KEYA+4], r.bBlock[JAYA_BCRYPTO_KEYA+5], r.bBlock[JAYA_BCRYPTO_KEYA+6], r.bBlock[JAYA_BCRYPTO_KEYA+7] ); lasterr = ERR_AUTH_FAILURE; gGlobalSem++; diff = 0x00; for (i=0 ;i<8 ; i++) { diff |= (r.bBlock[JAYA_BCRYPTO_KEYA+i] ^ u.bBlock[JAYA_BCRYPTO_INPUT0+i]) ; } if (i!=8) { LOG("ATTACK","__bios_verify_PIN()"); HAL_HALT(); return; } gGlobalSem++; if (diff==0x00) { LOG("PIN","__bios_verify_PIN() : Pin are the same."); lasterr = SUCCESS; }}/* ========================================================================= That's all folks ! ========================================================================= */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -