int toHex(byte *digest, char *digestHex, int numBytes) { int i = 0; // assume MSB first for digest for( i = 0; i < numBytes; i++ ) { digestHex[2*i] = hexToAscii((digest[i] & 0xF0) >> 4); digestHex[2*i + 1] = hexToAscii((digest[i] & 0xF)); } digestHex[2*i] = '\0'; return(numBytes * 2 + 1); }
void DAPLUGCALL Daplug_totp(DaplugDongle *dpd, int keyVersion, int options, char *div1, char *div2, char* inData, char* outData){ char tmp[MAX_REAL_DATA_SIZE*2+1]=""; if(!(options & OTP_6_DIGIT) && !(options & OTP_7_DIGIT) && !(options & OTP_8_DIGIT)){ fprintf(stderr,"\ntotp(): Invalid option for Daplug_totp !\n"); return; } if(strlen(inData)/2 != 0 && strlen(inData)/2 != 8){ fprintf(stderr,"\ntotp(): Invalid data for Daplug_totp !\n"); return; } hmac_sha1(dpd, keyVersion, options, div1, div2, inData, tmp); hexToAscii(tmp,outData); }
int main(int argc, char* argv[]) { char *p; if ( argc==1 ) { usage(); return(1); } /* split by : */ p = (char*) strtok ( argv[1],":"); while (p != NULL) { printf("%c", hexToAscii(p) ); p = (char*) strtok (NULL, ":"); } printf("\n"); return(0); }