intel / intel-ipsec-mb

Intel(R) Multi-Buffer Crypto for IPSec
BSD 3-Clause "New" or "Revised" License
292 stars 88 forks source link

Possible cut-n-paste typo in snow3g_test.c #57

Closed ColinIanKing closed 4 years ago

ColinIanKing commented 4 years ago

Static analysis found a potential problem. I'm not 100% sure if this is a false positive or not, but I thought I should report it anyhow.

In function validate_snow3g_f8_1_bitblock():

616                /*check against the ciphertext in the vector against the
617                 * encrypted plaintext*/

   original: midBuff looks like the original copy.

618                if (membitcmp(midBuff, dstBuff, bit_len, 4) != 0) {
619                        printf("Test5:snow3g_f8_1_bitbuffer(Enc) buffer:%d "
620                               "size:%d offset:4\n", i, bit_len);
621                        snow3g_hexdump("Actual:", &midBuff[0],
622                                       (length * 8 + 4 + 7) / 8);
623                        snow3g_hexdump("Expected:", &dstBuff[0],
624                                       (length * 8 + 4 + 7) / 8);
625                        goto snow3g_f8_1_buffer_bit_exit;
626                }
627                printf(".");
628
629                /*Validate Decrypt*/
630                if (job_api)
631                        submit_uea2_jobs(mb_mgr, (uint8_t **)&pKeySched,
632                                         &pIV, &dstBufBefPad, &midBufBefPad,
633                                         &bit_len, &head_offset,
634                                         IMB_DIR_DECRYPT, 1);
635                else
636                        IMB_SNOW3G_F8_1_BUFFER_BIT(mb_mgr, pKeySched, pIV,
637                                                   /*midBuff*/ dstBuff,
638                                                   /*dstBuff*/ midBuff,
639                                                   bit_len, head_offset);
640

   CID 99586 (#1 of 1): Copy-paste error (COPY_PASTE_ERROR)
copy_paste_error: midBuff looks like a copy-paste error.
   Should it say dstBuff instead?

641                if (membitcmp(midBuff /*dstBuff*/, srcBuff, bit_len, 4) != 0) {
642                        printf("Test6: snow3g_f8_1_bitbuffer(Dec) buffer:%d "
643                               "size:%d offset:4\n", i, bit_len);
644                        snow3g_hexdump("Actual:", &dstBuff[0],
645                                       (length * 8 + 4 + 7) / 8);
646                        snow3g_hexdump("Expected:", &srcBuff[0],
647                                       (length * 8 + 4 + 7) / 8);
648                        goto snow3g_f8_1_buffer_bit_exit;
649                }
pablodelara commented 4 years ago

Thanks for reporting this, @ColinIanKing. Actually, I think midBuff is correct there (I will remove the comments), what doesn't look right is the dstBuff in line 644. Will fix that.