Beispiel #1
0
// Authenticates just one arbitrarily sized chunk of data
void HMACOnce(const unsigned char* key, const uint8_t klen, 
              const unsigned char* data, int len) {
  HMACInit(key, klen);
  while (len>=0) {
    HMACBlock(data, len>SHA1_BLOCKSIZE?SHA1_BLOCKSIZE:len);
    len -= SHA1_BLOCKSIZE;
    data += SHA1_BLOCKSIZE;
  }
  HMACDone();
}
Beispiel #2
0
	void 				JIG_Task								(void)					{
	 static int bytes_out = 0, bytes_in = 0;
     Endpoint_SelectEndpoint(2);
     if (Endpoint_IsReadWriteAllowed()) {
		Endpoint_Read_Stream_LE  (&jig_challenge_res[bytes_out], 8, NO_STREAM_CALLBACK) ;		
        Endpoint_ClearOUT();
		bytes_out += 8;
		if (bytes_out >= 64) {			
			//prepare the response (by guess?)
			jig_challenge_res[1]--;
			jig_challenge_res[3]++;
			jig_challenge_res[6]++;
			HMACBlock(&jig_challenge_res[CHALLENGE_INDEX],20);
			
			USB_USBTask(); //just in case
			HMACDone();
			jig_challenge_res[7] = jig_id[0];
			jig_challenge_res[8] = jig_id[1];
			int i;
			for( i = 0; i < 20; i++)
				jig_challenge_res[9+i] = hmacdigest[i];
			state = p5_challenged;
			expire = 50; // was 90
		}
	 }
     Endpoint_SelectEndpoint(1);
     if (Endpoint_IsReadWriteAllowed() && state == p5_challenged && expire == 0) {
		if ( bytes_in < 64) {
			Endpoint_Write_PStream_LE(&jig_challenge_res[bytes_in], 8, NO_STREAM_CALLBACK);
			Endpoint_ClearIN();
			bytes_in += 8;
			if ( bytes_in >= 64) {
				state = p5_responded;
				expire = 50;
			}
		}
	 }
	}