- /* special case if qpoly is zero, search to end of range */
- if(!ptst(qpoly))
- rflags &= ~R_HAVEQ;
-
- /* if endianness not specified, try
- * little-endian then big-endian.
- * NB: crossed-endian algorithms will not be
- * searched.
- */
- /* scan against preset models */
- if(~uflags & C_FORCE) {
- pass = 0;
- Cnt = 0;
- do {
- psets = mcount();
-
- while(psets) {
- mbynum(&pset, --psets);
-
- /* skip if different width, or refin or refout don't match */
- if(plen(pset.spoly) != width[0] || (model.flags ^ pset.flags) & (P_REFIN | P_REFOUT))
- continue;
- /* skip if the preset doesn't match specified parameters */
- if(rflags & R_HAVEP && pcmp(&model.spoly, &pset.spoly))
- continue;
- if(rflags & R_HAVEI && psncmp(&model.init, &pset.init))
- continue;
- if(rflags & R_HAVEX && psncmp(&model.xorout, &pset.xorout))
- continue;
-
- //for additional args (not used yet, maybe future?)
- apoly = pclone(pset.xorout);
- if(pset.flags & P_REFOUT)
- prev(&apoly);
-
- for(qptr = apolys; qptr < pptr; ++qptr) {
- crc = pcrc(*qptr, pset.spoly, pset.init, apoly, 0);
- if(ptst(crc)) {
- pfree(&crc);
- break;
- } else
- pfree(&crc);
- }
- pfree(&apoly);
- if(qptr == pptr) {
-
- /* the selected model solved all arguments */
-
- mcanon(&pset);
-
- size_t size = (pset.name && *pset.name) ? strlen(pset.name) : 6;
- //PrintAndLog("Size: %d, %s, count: %d",size,pset.name, Cnt);
- char *tmp = calloc(size+1, sizeof(char));
- if (tmp == NULL){
- PrintAndLog("out of memory?");
- return 0;
- }
- width[Cnt] = width[0];
- memcpy(tmp, pset.name, size);
- Models[Cnt++] = tmp;
- *count = Cnt;
- uflags |= C_RESULT;
- }
- }
- mfree(&pset);