static void pdf_gen_xor(pdf_ctx *pc, const UINT8 nonce[8], UINT8 buf[8]) { /* 'ndx' indicates that we'll be using the 0th or 1st eight bytes * of the AES output. If last time around we returned the ndx-1st * element, then we may have the result in the cache already. */ #if (UMAC_OUTPUT_LEN == 4) #define LOW_BIT_MASK 3 #elif (UMAC_OUTPUT_LEN == 8) #define LOW_BIT_MASK 1 #elif (UMAC_OUTPUT_LEN > 8) #define LOW_BIT_MASK 0 #endif union { UINT8 tmp_nonce_lo[4]; UINT32 align; } t; #if LOW_BIT_MASK != 0 int ndx = nonce[7] & LOW_BIT_MASK; #endif memcpy(t.tmp_nonce_lo, nonce + 4, sizeof(t.tmp_nonce_lo)); t.tmp_nonce_lo[3] &= ~LOW_BIT_MASK; /* zero last bit */ if (memcmp(t.tmp_nonce_lo, pc->nonce + 1, sizeof(t.tmp_nonce_lo)) != 0 || memcmp(nonce, pc->nonce, sizeof(t.tmp_nonce_lo)) != 0) { memcpy(pc->nonce, nonce, sizeof(t.tmp_nonce_lo)); memcpy(pc->nonce + 4, t.tmp_nonce_lo, sizeof(t.tmp_nonce_lo)); aes_encryption(pc->nonce, pc->cache, pc->prf_key); } #if (UMAC_OUTPUT_LEN == 4) xor32(buf, 0, pc->cache, ndx); #elif (UMAC_OUTPUT_LEN == 8) xor64(buf, 0, pc->cache, ndx); #elif (UMAC_OUTPUT_LEN == 12) xor64(buf, 0, pc->cache, 0); xor32(buf, 2, pc->cache, 2); #elif (UMAC_OUTPUT_LEN == 16) xor64(buf, 0, pc->cache, 0); xor64(buf, 1, pc->cache, 1); #endif }
// this function calculate time spent to generate RNamount of random number in nanosecond long getRnGenTime (long RNamount) { struct timespec start; struct timespec end; clockid_t clockID = CLOCK_MONOTONIC; long i; clock_gettime(clockID, &start); for(i = 0; i < RNamount; i++) { // printf("\t%lu%s", (unsigned long) randomMT()%100, (i%7)==6 ? "\n" : ""); xor32(); } clock_gettime(clockID, &end); return (end.tv_nsec - start.tv_nsec); }