def _crc16_checksum(bytes):
    """Returns the CRC-16 checksum of bytearray bytes

    Ported from Java implementation at: http://introcs.cs.princeton.edu/java/61data/CRC16CCITT.java.html

    Initial value changed to 0x0000 to match Stellar configuration.
    """
    crc = 0
    polynomial = 4129
    for byte in bytes:
        for i in range(8):
            bit = byte >> 7 - i & 1 == 1
            c15 = crc >> 15 & 1 == 1
            crc <<= 1
            if c15 ^ bit:
                crc ^= polynomial
    return crc & 65535
