crypto tool: use host htonl

This commit is contained in:
schneider 2011-08-03 00:57:09 +02:00
parent 0aadf3fba8
commit 8b2dba5997
2 changed files with 9 additions and 25 deletions

View File

@ -130,7 +130,7 @@ int main(int argc, char *argv[]) {
if (verbose)
fprintf(stderr,"file size=%d\n", filesize);
int words = (filesize+3)/sizeof(uint32_t);
int words = (((filesize+3)/sizeof(uint32_t)+3)/4)*4;
int bytes = sizeof(uint32_t)*words;
if (verbose)
@ -152,6 +152,7 @@ int main(int argc, char *argv[]) {
fprintf(stderr,"Signing: ");
memset(buf, 0, bytes);
int cnt = fread(buf,sizeof(*buf),filesize,fp);
cnt = 0;
uint32_t mac[4];
xxtea_cbcmac(mac, (uint32_t*)buf, words, k);
@ -165,18 +166,18 @@ int main(int argc, char *argv[]) {
}
if (fwrite(buf,sizeof(*buf),bytes,ofp) != bytes){
fprintf(stderr, "Error: write failed\n");
fprintf(stderr, "Error: file write failed\n");
exit(253);
}
if (fwrite(mac,sizeof(*mac),4,ofp) != 4*sizeof(*mac)){
fprintf(stderr, "Error: write failed\n");
if (fwrite(mac,sizeof(*mac),4,ofp) != 4){
fprintf(stderr, "Error: mac write failed\n");
exit(253);
}
if(verbose) fprintf(stderr,".\n");
}
if( encrypt ){
int cnt, block;
int cnt, block=0;
if (verbose)
fprintf(stderr,"Encrypting: ");

View File

@ -3,32 +3,15 @@
* BSD Licence
*
* btea function is from
* <https://secure.wikimedia.org/wikipedia/en/wiki/XXTEA#Reference_code>
* <https://secure.wikim
* edia.org/wikipedia/en/wiki/XXTEA#Reference_code>
*
* (c) by Sec <sec@42.org> 6/2011
*/
#include <stdint.h>
#include "xxtea.h"
#ifdef SAFE
uint32_t htonl(uint32_t v)
{
uint32_t r=0;
r |= (v>> 0)&0xFF; r<<=8;
r |= (v>> 8)&0xFF; r<<=8;
r |= (v>>16)&0xFF; r<<=8;
r |= (v>>24)&0xFF;
return r;
}
#else
uint32_t htonl(uint32_t v){
__asm("rev %[value], %[value];" \
: [value] "+r" (v) : );
return v;
};
#endif
#include <arpa/inet.h>
void htonlp(uint32_t *v, uint8_t n)
{