/* tsum.c */
/*
 * Written by Gavan Fantom gavan A T netbsd D O T <non profit organisation> 
 * 
 * Takes a kernel on standard in and produces the required checksum
 * on standard out.  This should be appeneded to the kernel which is
 * provided to the T1500 via dhcp
 *
 * This notice was added by James Mulcahy, May 02005.
 ***/

#include <stdio.h>

void putword(unsigned int w)
{
    putchar(w & 0xff);
    putchar((w >> 8) & 0xff);
    putchar((w >> 16) & 0xff);
    putchar((w >> 24) & 0xff);
}

int main(void)
{
    unsigned int s = 0;
    unsigned int p = 0;
    unsigned int n = 0;
    int c;

    while ((c = getchar()) != EOF)
    {
        s += c;
        p ^= c<<n;
        n+=8;
        if (n >= 32) n = 0;
    }
    fprintf(stderr,"s = %x, p = %x\n", s, p);

    putword(p);
    putword(s);

    return 0;
}
