08 November 2019 1 1K Report

Hello Everyone,

I want to calculate CRC-16/X-25 for my APDU tranmission. I have a C code that calculates CRC-16/CCITT-FALSE, But I don't know what exactly is the difference between these two algorithms/protocols and how to calculate CRC-16/X-25?

I have used the following online calculator (https://crccalc.com/), and the values are fine, but I want to write a C program for that.

And one more thing is that what is RefIn and RefOut parameters given in the above mentioned link, because these two are the only things that are different in these two algorithms.

The C code I am using for CRC-16/CCITT-FALSE is given below:

#include

#define CRC_POLYNOMIAL 0x1021

#define USHORT_TOPBIT 0x8000

short crc_ret;

// function initialisation

unsigned short crc16(const char *buf, unsigned int buf_len)

{

unsigned short ret = 0xFFFF; // Initial Value

int bit = 8;

do {

if (!buf) {

break;

}

unsigned int i = 0;

for (i=0; i> 8));

for (bit = 8; bit > 0; --bit)

{

if (ret & USHORT_TOPBIT)

ret = (unsigned short)((ret >> 1) ^ CRC_POLYNOMIAL);

else

ret = (unsigned short)(ret >> 1);

}

}

} while (0);

return ret;

}

Can someone please guide me, what changes do I need to make so that it can also work with CRC-16/X-25?

Thank you

More Raza Javed's questions See All
Similar questions and discussions