}
struct header {
- unsigned char model[16];
+ char model[16];
uint32_t crc;
};
// Compute a CRC, using the POSIX 1003 definition
__externC cyg_uint32
-cyg_posix_crc32(unsigned char *s, int len);
+cyg_posix_crc32(void *s, int len);
// Gary S. Brown's 32 bit CRC
__externC cyg_uint32
-cyg_crc32(unsigned char *s, int len);
+cyg_crc32(void *s, int len);
// Gary S. Brown's 32 bit CRC, but accumulate the result from a
// previous CRC calculation
__externC cyg_uint32
-cyg_crc32_accumulate(cyg_uint32 crc, unsigned char *s, int len);
+cyg_crc32_accumulate(cyg_uint32 crc, void *s, int len);
// Ethernet FCS Algorithm
__externC cyg_uint32
-cyg_ether_crc32(unsigned char *s, int len);
+cyg_ether_crc32(void *s, int len);
// Ethernet FCS algorithm, but accumulate the result from a previous
// CRC calculation.
__externC cyg_uint32
-cyg_ether_crc32_accumulate(cyg_uint32 crc, unsigned char *s, int len);
+cyg_ether_crc32_accumulate(cyg_uint32 crc, void *s, int len);
// 16 bit CRC with polynomial x^16+x^12+x^5+1
__externC cyg_uint16
-cyg_crc16(unsigned char *s, int len);
+cyg_crc16(void *s, int len);
#endif // _SERVICES_CRC_CRC_H_
};
cyg_uint16
-cyg_crc16(unsigned char *buf, int len)
+cyg_crc16(void *ptr, int len)
{
+ unsigned char *buf = ptr;
int i;
cyg_uint16 cksum;
/* This is the standard Gary S. Brown's 32 bit CRC algorithm, but
accumulate the CRC into the result of a previous CRC. */
cyg_uint32
-cyg_crc32_accumulate(cyg_uint32 crc32val, unsigned char *s, int len)
+cyg_crc32_accumulate(cyg_uint32 crc32val, void *ptr, int len)
{
+ unsigned char *s = ptr;
int i;
for (i = 0; i < len; i++) {
/* This is the standard Gary S. Brown's 32 bit CRC algorithm */
cyg_uint32
-cyg_crc32(unsigned char *s, int len)
+cyg_crc32(void *s, int len)
{
return (cyg_crc32_accumulate(0,s,len));
}
result from a previous CRC calculation. This uses the Ethernet FCS
algorithm.*/
cyg_uint32
-cyg_ether_crc32_accumulate(cyg_uint32 crc32val, unsigned char *s, int len)
+cyg_ether_crc32_accumulate(cyg_uint32 crc32val, void *ptr, int len)
{
+ unsigned char *s = ptr;
int i;
if (s == 0) return 0L;
/* Return a 32-bit CRC of the contents of the buffer, using the
Ethernet FCS algorithm. */
cyg_uint32
-cyg_ether_crc32(unsigned char *s, int len)
+cyg_ether_crc32(void *s, int len)
{
return cyg_ether_crc32_accumulate(0,s,len);
}
};
static uint32_t crc32(uint32_t crc,
- const unsigned char *buf,
+ const void *data,
unsigned int len)
{
+ const uint8_t *buf = data;
+
crc = crc ^ 0xffffffffUL;
do {
crc = crc32_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8);
return crc ^ 0xffffffffUL;
}
-static void be_wr(unsigned char *buf, uint32_t val)
+static void be_wr(char *buf, uint32_t val)
{
buf[0] = (val >> 24) & 0xFFU;
buf[1] = (val >> 16) & 0xFFU;
int ret = 0;
const char *pathin;
const char *pathout;
- unsigned char *buffer;
+ char *buffer;
uint32_t sum;
size_t bufsize;
size_t bytes;
#define PART_NAME_LENGTH 16
typedef struct header {
- uint8_t magic[MAGIC_LENGTH];
- uint8_t version[256];
+ char magic[MAGIC_LENGTH];
+ char version[256];
u_int32_t crc;
u_int32_t pad;
} __attribute__ ((packed)) header_t;
typedef struct part {
- uint8_t magic[MAGIC_LENGTH];
- uint8_t name[PART_NAME_LENGTH];
+ char magic[MAGIC_LENGTH];
+ char name[PART_NAME_LENGTH];
uint8_t pad[12];
u_int32_t memaddr;
u_int32_t index;
}
}
-static uint32_t crc32buf(unsigned char *buf, size_t len)
+static uint32_t crc32buf(const void *buf, size_t len)
{
uint32_t crc = 0xFFFFFFFF;
+ const uint8_t *in = buf;
- for (; len; len--, buf++)
- crc = crc32[(uint8_t)crc ^ *buf] ^ (crc >> BPB);
+ for (; len; len--, in++)
+ crc = crc32[(uint8_t)crc ^ *in] ^ (crc >> BPB);
return ~crc;
}
void
-csum16_update(uint8_t *p, uint32_t len, struct csum_state *css)
+csum16_update(void *data, uint32_t len, struct csum_state *css)
{
+ uint8_t *p = data;
uint16_t t;
if (css->odd) {
}
void
-csum_update(uint8_t *p, uint32_t len, struct csum_state *css)
+csum_update(void *data, uint32_t len, struct csum_state *css)
{
+ uint8_t *p = data;
+
switch (css->size) {
case CSUM_TYPE_8:
csum8_update(p,len,css);
* routines to write data to the output file
*/
int
-write_out_data(FILE *outfile, uint8_t *data, size_t len,
+write_out_data(FILE *outfile, void *data, size_t len,
struct csum_state *css)
{
+ uint8_t *ptr = data;
+
errno = 0;
- fwrite(data, len, 1, outfile);
+ fwrite(ptr, len, 1, outfile);
if (errno) {
ERRS("unable to write output file");
return ERR_FATAL;
}
if (css) {
- csum_update(data, len, css);
+ csum_update(ptr, len, css);
}
return 0;
void
-csum16_update(uint8_t *p, uint32_t len, struct csum_state *css)
+csum16_update(void *data, uint32_t len, struct csum_state *css)
{
+ uint8_t *p = data;
uint16_t t;
if (css->odd) {
void
-csum_update(uint8_t *p, uint32_t len, struct csum_state *css)
+csum_update(void *data, uint32_t len, struct csum_state *css)
{
+ uint8_t *p = data;
+
switch (css->size) {
case CSUM_SIZE_8:
csum8_update(p,len,css);
* routines to write data to the output file
*/
int
-write_out_data(FILE *outfile, uint8_t *data, size_t len,
+write_out_data(FILE *outfile, void *data, size_t len,
struct csum_state *css)
{
+ uint8_t *ptr = data;
+
errno = 0;
- fwrite(data, len, 1, outfile);
+ fwrite(ptr, len, 1, outfile);
if (errno) {
ERRS("unable to write output file");
return ERR_FATAL;
}
if (css) {
- csum_update(data, len, css);
+ csum_update(ptr, len, css);
}
return 0;
* routines to write data to the output file
*/
int
-write_out_data(FILE *outfile, uint8_t *data, size_t len, uint32_t *crc)
+write_out_data(FILE *outfile, void *data, size_t len, uint32_t *crc)
{
+ uint8_t *ptr = data;
+
errno = 0;
- fwrite(data, len, 1, outfile);
+ fwrite(ptr, len, 1, outfile);
if (errno) {
errmsg(1,"unable to write output file");
return -1;
}
if (crc) {
- update_crc(data, len, crc);
+ update_crc(ptr, len, crc);
}
return 0;
uint8_t ih_type;
uint8_t ih_comp;
union {
- uint8_t ih_name[IH_NMLEN];
+ char ih_name[IH_NMLEN];
asus_t asus;
} tail;
} image_header_t;
MD5_Update(&ctx, (char *)&header->devname, sizeof(header->devname));
MD5_Update(&ctx, data, size);
- MD5_Final(header->digest, &ctx);
+ MD5_Final((unsigned char *)header->digest, &ctx);
}
int main(int argc, char *argv[])
MD5_Update(&ctx, (char *)&header->devname, sizeof(header->devname));
MD5_Update(&ctx, data, size);
- MD5_Final(header->digest, &ctx);
+ MD5_Final((unsigned char *)header->digest, &ctx);
}
int main(int argc, char *argv[])
void
-csum_update(uint8_t *p, uint32_t len, struct csum_state *css)
+csum_update(void *data, uint32_t len, struct csum_state *css)
{
+ uint8_t *p = data;
+
if (len == 0)
return;
* routines to write data to the output file
*/
int
-write_out_data(FILE *outfile, uint8_t *data, size_t len,
+write_out_data(FILE *outfile, void *data, size_t len,
struct csum_state *css)
{
+ uint8_t *ptr = data;
+
errno = 0;
- fwrite(data, len, 1, outfile);
+ fwrite(ptr, len, 1, outfile);
if (errno) {
ERR("unable to write output file");
return -1;
}
if (css) {
- csum_update(data, len, css);
+ csum_update(ptr, len, css);
}
return 0;
int
-write_out_data_align(FILE *outfile, uint8_t *data, size_t len, size_t align,
+write_out_data_align(FILE *outfile, void *data, size_t len, size_t align,
struct csum_state *css)
{
size_t padlen;
mh->count=0;
/* Build user data section */
- data = buf+sizeof(*mh);
+ data = (char *)buf + sizeof(*mh);
data += sprintf(data, "Vendor 1 %d", board->vendor);
*data++ = '\0';
data += sprintf(data, "Model 1 %d", BE16_TO_HOST(board->model));
ctx->state[4] += E;
}
-void sha1_update( sha1_context *ctx, uchar *input, uint length )
+void sha1_update( sha1_context *ctx, void *data, uint length )
{
+ uchar *input = data;
ulong left, fill;
if( ! length ) return;
* Core SHA-1 functions
*/
void sha1_starts( sha1_context *ctx );
-void sha1_update( sha1_context *ctx, uchar *input, uint length );
+void sha1_update( sha1_context *ctx, void *input, uint length );
void sha1_finish( sha1_context *ctx, uchar digest[20] );
/*
};
-uint32_t crc32(uint32_t crc, uint8_t *data, size_t len)
+uint32_t crc32(uint32_t crc, const void *data, size_t len)
{
+ const uint8_t *in = data;
+
while (len--)
- crc = (crc >> 8) ^ crc32tab[(crc ^ *data++) & 0xFF];
+ crc = (crc >> 8) ^ crc32tab[(crc ^ *in++) & 0xFF];
return crc;
}
static int is_hex_pattern;
-int xor_data(uint8_t *data, size_t len, const uint8_t *pattern, int p_len, int p_off)
+int xor_data(void *data, size_t len, const void *pattern, int p_len, int p_off)
{
- int offset = p_off;
+ const uint8_t *key = pattern;
+ uint8_t *d = data;
+
while (len--) {
- *data ^= pattern[offset];
- data++;
- offset = (offset + 1) % p_len;
+ *d ^= key[p_off];
+ d++;
+ p_off = (p_off + 1) % p_len;
}
- return offset;
+ return p_off;
}