/* wordswap32.c is a tool to word swap RSA signatures for the BSP. BSP requres signatures to be placed in to the binaries with least significant word first. Keys and signatures must follow this format. For the LE binaries the signatures must also be endian swapped which can be achieved by using sswap32.c tool in a pipe with this tool. */ #include #include #define BLOCK_SIZE 0x100 unsigned char data[BLOCK_SIZE]; unsigned char out_data[BLOCK_SIZE]; int main(int argc, char * argv[]) { FILE * input; FILE * output; size_t read_count; size_t write_count; unsigned long * walker; unsigned long * out_walker; /* uncomment this if compiling on cygwin */ #if 0 if(-1 == setmode(fileno(stdin), O_BINARY)){ perror("Cannot set stdin to binary mode"); return -1; } if(-1 == setmode(fileno(stdout), O_BINARY)){ perror("Cannot set stdout to binary mode"); return -1; } #endif if((read_count != 0x80) && (0x100 != read_count)){ fprintf(stderr, "Input size must be 128 or 256 bytes! %d\n", read_count); return -1; } if(read_count != 0){ walker = (unsigned long*)data + (read_count / 4) - 1; out_walker = (unsigned long*)out_data; while(walker >= (unsigned long*)data) { *out_walker = *walker; out_walker++; walker--; } write_count = fwrite(out_data, 1, read_count, stdout); if(read_count != write_count){ perror("Unable to write data"); return -1; } } return 0; }