def checksum(buffer, checkA, checkB):
    """
    8-bit Fletcher algorithm for packet integrity checksum. Refer to [1] 
    (section 32.4 UBX Checksum, pages 135 - 136).
    Inputs:
        buffer - They byte buffer to compute the checksum over.
        checkA - The first part of the reference checksum to compare the 
                 computed value to.
        checkB - The second part of the reference checksum to compare the 
                 computed value to.         
    Outputs:
        valid - Boolean flag indicating whether or not packet checksum matches
                reference checksum.
        buffer_checkA - First part of checksum computed from input buffer.
        buffer_checkB - Second part of checksum computed from input buffer.
    """
    # Compute buffer checksum
    buffer_checkA = 0
    buffer_checkB = 0
    for byte in buffer:
        buffer_checkA = buffer_checkA + byte
        buffer_checkB = buffer_checkB + buffer_checkA
    buffer_checkA = buffer_checkA & 0xFF
    buffer_checkB = buffer_checkB & 0xFF
        
    # Compare to packet provided checksum
    valid = True
    if checkA != buffer_checkA or checkB != buffer_checkB:
        valid = False
        
    return valid, buffer_checkA, buffer_checkB