#!/usr/bin/perl use strict; use warnings; use Digest::CRC; my $crc = qq(f0b8); print qq(target crc =$crc\n); my $msg = qq(8792ebfe26cc130030c20011c89f23c8); $msg = pack( 'H32', $msg ); my $ctx = Digest::CRC->new(width=>16, init=>0xffff, xorout=>0xffff, refout=>0, poly=>0x8408, refin=>1, cont=>1); $ctx->add($msg); my $crc2 = $ctx->hexdigest; print qq( crc = $crc2\n); #### #!/usr/bin/perl use strict; use warnings; # https://github.com/Yubico/yubico-c/blob/master/test-vectors.txt # https://github.com/Yubico/yubico-c/blob/master/ykcrc.c # (yubikey_crc16) my $plaintext = qq(8792ebfe26cc130030c20011c89f23c8); print qq(p=$plaintext\n); my $crc = &yubi_crc($plaintext, 16); print qq(yubi crc = ),$crc,qq( "),sprintf("0x%02x", $crc),qq("\n); print qq(target = 61624 "0xf0b8"\n); exit ( 0 ); sub yubi_crc { my ( $otp, $size ) = ( @_ ); my $crc = 0xffff; # while ( $size-- ) { my $byte = hex( substr( $otp, 0, 2, '' ) ); $crc = $crc ^ ( $byte & 0xff ); for ( my $i = 0; $i < 8; $i++) { my $n = $crc & 1; $crc = $crc >> 1; $crc = $crc ^ 0x8408 if ( $n != 0 ); } } return ( $crc ); }