+ p3->even = 0; p3->odd = 0;\r
+ p4->even = 0; p4->odd = 0;\r
+ statelists[0].len = p3 - statelists[0].head.slhead;\r
+ statelists[1].len = p4 - statelists[1].head.slhead;\r
+ statelists[0].tail.sltail=--p3;\r
+ statelists[1].tail.sltail=--p4;\r
+\r
+ // the statelists now contain possible keys. The key we are searching for must be in the\r
+ // intersection of both lists. Create the intersection:\r
+ qsort(statelists[0].head.keyhead, statelists[0].len, sizeof(uint64_t), compar_int);\r
+ qsort(statelists[1].head.keyhead, statelists[1].len, sizeof(uint64_t), compar_int);\r
+\r
+ uint64_t *p5, *p6, *p7;\r
+ p5 = p7 = statelists[0].head.keyhead; \r
+ p6 = statelists[1].head.keyhead;\r
+ while (p5 <= statelists[0].tail.keytail && p6 <= statelists[1].tail.keytail) {\r
+ if (compar_int(p5, p6) == 0) {\r
+ *p7++ = *p5++;\r
+ p6++;\r
+ }\r
+ else {\r
+ while (compar_int(p5, p6) == -1) p5++;\r
+ while (compar_int(p5, p6) == 1) p6++;\r
+ }\r
+ }\r
+ statelists[0].len = p7 - statelists[0].head.keyhead;\r
+ statelists[0].tail.keytail=--p7;\r
+\r
+ memset(resultKey, 0, 6);\r
+ // The list may still contain several key candidates. Test each of them with mfCheckKeys\r
+ for (i = 0; i < statelists[0].len; i++) {\r
+ uint8_t keyBlock[6];\r
+ uint64_t key64;\r
+ crypto1_get_lfsr(statelists[0].head.slhead + i, &key64);\r
+ num_to_bytes(key64, 6, keyBlock);\r
+ key64 = 0;\r
+ if (!mfCheckKeys(statelists[0].blockNo, statelists[0].keyType, 1, keyBlock, &key64)) {\r
+ num_to_bytes(key64, 6, resultKey);\r
+ break;\r
+ }\r
+ }\r
+ \r
+ free(statelists[0].head.slhead);\r
+ free(statelists[1].head.slhead);\r
+ \r