summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-12-06 01:39:33 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2014-12-06 01:39:33 +0100
commit6533e74370acfa51653608b1dc5e1292c72970c9 (patch)
treedbd3b13cb10df6f341a82a5a449fcf5a4b9d9b66
parenta583bb24fb23728c9c4ed6c6c573d526ab654c49 (diff)
downloadcrypto-6533e74370acfa51653608b1dc5e1292c72970c9.zip
crypto-6533e74370acfa51653608b1dc5e1292c72970c9.tar.gz
remove extra spaces
-rw-r--r--aes.c4
-rw-r--r--blowfish.c14
-rw-r--r--crypto_buffer.c10
-rw-r--r--crypto_buffer_get.c2
-rw-r--r--crypto_buffer_put.c4
-rw-r--r--cryptot.c52
-rw-r--r--des.c32
-rw-r--r--douint.c4
-rw-r--r--ipv4_scan.c2
-rw-r--r--md4.c4
-rw-r--r--md5.c6
-rw-r--r--sha1.c4
-rw-r--r--sha256.c26
-rw-r--r--sha512.c30
-rw-r--r--socket_accept.c2
-rw-r--r--socket_bind.c2
-rw-r--r--socket_conn.c4
-rw-r--r--socket_local.c2
-rw-r--r--socket_remote.c2
-rw-r--r--test_crypto_api.c54
-rw-r--r--test_crypto_buffer.c16
-rw-r--r--twofish.c22
-rw-r--r--uint16_unpack.c8
-rw-r--r--x86cpuid.c8
24 files changed, 157 insertions, 157 deletions
diff --git a/aes.c b/aes.c
index b067505..4426cb5 100644
--- a/aes.c
+++ b/aes.c
@@ -1063,7 +1063,7 @@ void aes_encrypt(void *cx, u8 *dst, const u8 *src)
rk[3];
PUTU32(dst + 12, s3);
}
-
+
void aes_decrypt(void *cx, u8 *dst, const u8 *src)
{
struct aes_ctx *ctx = cx;
@@ -1331,7 +1331,7 @@ void rijndaelEncryptRound(const u32 rk[/*4*(Nr + 1)*/], int Nr, u8 block[16], in
(Te4[(s1 >> 8) & 0xff] & 0x0000ff00) ^
(Te4[(s2 ) & 0xff] & 0x000000ff) ^
rk[3];
-
+
s0 = t0;
s1 = t1;
s2 = t2;
diff --git a/blowfish.c b/blowfish.c
index dd22cff..1487ed1 100644
--- a/blowfish.c
+++ b/blowfish.c
@@ -1,11 +1,11 @@
-/*
+/*
* Cryptographic API.
*
* Blowfish Cipher Algorithm, by Bruce Schneier.
* http://www.counterpane.com/blowfish.html
- *
+ *
* Adapated from Kerneli implementation.
- *
+ *
* Copyright (c) Herbert Valerio Riedel <hvr@hvrlab.org>
* Copyright (c) Kyle McMartin <kyle@debian.org>
* Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
@@ -288,7 +288,7 @@ static const u32 bf_sbox[256 * 4] = {
0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6,
};
-/*
+/*
* Round loop unrolling macros, S is a pointer to a S-Box array
* organized in 4 unsigned longs at a row.
*/
@@ -304,7 +304,7 @@ static const u32 bf_sbox[256 * 4] = {
/*
* The blowfish encipher, processes 64-bit blocks.
- * NOTE: This function MUSTN'T respect endianess
+ * NOTE: This function MUSTN'T respect endianess
*/
static __inline void encrypt_block(struct blowfish_ctx *bctx, u32 *dst, u32 *src)
{
@@ -383,7 +383,7 @@ void blowfish_decrypt(void *ctx, u8 *dst, const u8 *src)
out_blk[1] = cpu_to_be32(yl);
}
-/*
+/*
* Calculates the blowfish S and P boxes for encryption and decryption.
*/
int blowfish_setkey(void *ctx, const u8 *key, unsigned int keylen, u32 *flags)
@@ -431,7 +431,7 @@ int blowfish_setkey(void *ctx, const u8 *key, unsigned int keylen, u32 *flags)
S[count + 1] = data[1];
}
}
-
+
/* Bruce says not to bother with the weak key check. */
return 0;
}
diff --git a/crypto_buffer.c b/crypto_buffer.c
index d17e805..5d7cadb 100644
--- a/crypto_buffer.c
+++ b/crypto_buffer.c
@@ -9,12 +9,12 @@ int crypto_buffer_init(crypto_buffer *s, int fd, operation op, u32 blocks, int t
{
int ret;
int size;
-
+
if(blocks<3) return -1; /* magic + info + data */
-
+
s->fd = fd;
s->op = op;
-
+
if(type & BLOWFISH){
size = BF_BLOCK_SIZE;
ret = blowfish_setkey((struct blowfish_ctx*)&s->ctx, key, key_len, 0);
@@ -49,7 +49,7 @@ int crypto_buffer_init(crypto_buffer *s, int fd, operation op, u32 blocks, int t
if(ret!=0) return -1;
if((U32_MAX / size) < blocks) return -1;
-
+
s->block_size = size;
s->e_len = size * blocks; /* TODO check overflow */
s->data_st.bytes = s->data_st.strlen = 0;
@@ -71,7 +71,7 @@ int crypto_buffer_init(crypto_buffer *s, int fd, operation op, u32 blocks, int t
s->e_ptr = s->e_buffer + (size << 1);
s->e_len -= (size << 1);
}
-/*
+/*
fprintf(stderr,"e_buffer : %x\n",s->e_buffer);
fprintf(stderr,"e_data : %x\n",s->e_data);
fprintf(stderr,"e_ptr : %x\n",s->e_ptr);
diff --git a/crypto_buffer_get.c b/crypto_buffer_get.c
index 33e99f0..b2b5ad8 100644
--- a/crypto_buffer_get.c
+++ b/crypto_buffer_get.c
@@ -111,7 +111,7 @@ static int eatinfo(crypto_buffer *s, u8* start)
static int getthis(crypto_buffer *s, u8 *buf, u32 len)
{
int available;
-
+
available = s->c_end - s->c_ptr;
if (len > available) len = available;
memcpy(buf, s->c_ptr, len);
diff --git a/crypto_buffer_put.c b/crypto_buffer_put.c
index 74f30a0..35c7730 100644
--- a/crypto_buffer_put.c
+++ b/crypto_buffer_put.c
@@ -61,14 +61,14 @@ int crypto_buffer_put(crypto_buffer *s,const u8 *buf,u32 len)
register u8* e_ptr;
register u8* e_end;
u32 free;
-
+
free = s->c_end - s->c_ptr;
if (len > free) {
if(free){
memcpy(s->c_ptr, buf, free);
buf += free;
len -= free;
- }
+ }
/* now c_buffer is full */
e_ptr = s->e_ptr;
e_end = s->e_end;
diff --git a/cryptot.c b/cryptot.c
index da565e1..719de40 100644
--- a/cryptot.c
+++ b/cryptot.c
@@ -41,7 +41,7 @@ static void connect_to_dist(int sock, struct cryptot_st *data, int verbose)
if(!recv(sock,buf,2,0)){
fprintf(stderr,"%s : rejected (because of -S option ?).\n",PROG_NAME); exit(1);
}
- if(strncmp(buf,"OK",2)) {
+ if(strncmp(buf,"OK",2)) {
fprintf(stderr,"%s : protocol error (middle man ?).\n",PROG_NAME); exit(1);
}
if(verbose)fprintf(stderr,"%s : connected.\n",PROG_NAME);
@@ -67,7 +67,7 @@ static int wait_connection(int sock, struct cryptot_st *data, int verbose)
PROG_NAME, NIPQUAD(data->local_ip),data->local_port);
client = socket_accept4(sock,peer_ip,&peer_port);
if(client<0){ fprintf(stderr,"%s socket_accept error : ",PROG_NAME); perror(""); exit(1); }
-
+
if(data->check_accept){
if(peer_port != data->src_port || memcmp(data->src_ip,peer_ip,4)){
fprintf(stderr,"%s : REFUSE connection from %03d.%03d.%03d.%03d:%d.\n",
@@ -100,7 +100,7 @@ static void do_stats(struct cryptot_st *data, struct timespec *s0, struct timesp
if(nbr> 1024){ nbr/=1024; unit=kb;}
if(nbr> 1024){ nbr/=1024; unit=mb;}
if(nbr> 1024){ nbr/=1024; unit=gb;}
-
+
time = (float)(s1->tv_sec - s0->tv_sec)+((float)(s1->tv_nsec-s0->tv_nsec))/1E9;
if (data->cipher & BLOWFISH) { cipher ="blowfish"; size = data->blocks*BF_BLOCK_SIZE;}
else if (data->cipher & TWOFISH) { cipher ="twofish"; size = data->blocks*TF_BLOCK_SIZE; }
@@ -123,8 +123,8 @@ static void usage(void)
fprintf(stderr,"\tThis program is distributed in the hope that it will be useful,\n");
fprintf(stderr,"\tbut WITHOUT ANY WARRANTY; without even the implied warranty of\n");
fprintf(stderr,"\tMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n");
- fprintf(stderr,"\tGNU General Public License for more details.\n\n");
-
+ fprintf(stderr,"\tGNU General Public License for more details.\n\n");
+
fprintf(stderr,"usage : %s [-v] [-x] [-c cipher] [-n nbr_blocks]\n"
" [-s [ip]:[port]] [-d [ip]:[port]] [-b [ip]:[port]] [-S [ip]:[port]] key\n",PROG_NAME);
fprintf(stderr,"\t\t-v : verbose mode (statistics)\n");
@@ -206,14 +206,14 @@ static void resolve_ip(char *ip)
fprintf(stderr,"%s error ",PROG_NAME);
perror("gethostname "); exit(1);
}
- if((hp = gethostbyname(hostname))==NULL){
+ if((hp = gethostbyname(hostname))==NULL){
fprintf(stderr,"%s : can't resolve %s, ",PROG_NAME,hostname);
herror("\tgethostbyname "); exit(1);
}
memcpy(ip,hp->h_addr,4);
}
}
-
+
/* if ip is 0:0:0:0 use localhost, bind to ip/port call listen if required */
static int bind_to(char *ip, int port, int listen)
@@ -221,16 +221,16 @@ static int bind_to(char *ip, int port, int listen)
int socket;
if((socket = socket_tcp(1))==-1) { fprintf(stderr,"%s error in ",PROG_NAME); perror("socket_tcp "); exit(1); }
-
+
if(socket_bind4(socket,ip,port)==-1) {
fprintf(stderr,"%s : unable to bind to %03d.%03d.%03d.%03d:%d",PROG_NAME,NIPQUAD(*ip),port);
perror("\tsocket_bind "); exit(1);
}
-
+
if(listen) if(socket_listen(socket,20)==-1) {
fprintf(stderr,"%s error in ",PROG_NAME); perror("socket_listen "); exit(1);
}
-
+
return socket;
}
@@ -239,7 +239,7 @@ static char* allocate_buffer(unsigned int cipher, unsigned int *blocks, unsigned
{
char *buffer = NULL;
int tmp = *blocks;
-
+
if(tmp==-1){
if(cipher & BLOWFISH) tmp = BUFFER_LENGTH/BF_BLOCK_SIZE;
else if(cipher & TWOFISH) tmp = BUFFER_LENGTH/TF_BLOCK_SIZE;
@@ -270,7 +270,7 @@ static void c_encrypt(struct cryptot_st *data, int verbose)
register unsigned int reg = 0;
register unsigned int size = data->size;
register u8 *buffer = (u8*)data->buffer;
-
+
operation op;
int input, output;
crypto_buffer c_buffer;
@@ -325,7 +325,7 @@ static void c_encrypt(struct cryptot_st *data, int verbose)
}
}
shutdown(reg,SHUT_RDWR);
- close(reg); /* close client socket */
+ close(reg); /* close client socket */
}
crypto_buffer_flush(&c_buffer);
if(ret==-1){ fprintf(stderr,"%s read error ",PROG_NAME); perror(""); exit(1); }
@@ -342,7 +342,7 @@ static void c_decrypt(struct cryptot_st *data, int verbose)
register unsigned int reg = 0;
register unsigned int size = data->size;
register u8 *buffer = (u8*)data->buffer;
-
+
operation op;
int input, output;
crypto_buffer c_buffer;
@@ -392,7 +392,7 @@ static void c_decrypt(struct cryptot_st *data, int verbose)
fprintf(stderr,"%s send error ",PROG_NAME); perror(""); exit(1);
}
}
-
+
}
if(input!=0) { shutdown(input,SHUT_RDWR); close(input); } /* close client socket */
if(ret==-1){ fprintf(stderr,"%s read error ",PROG_NAME); perror(""); exit(1); }
@@ -418,20 +418,20 @@ int main(int argc, char **argv)
unsigned int verbose = 0;
char bind_ip[4];
unsigned int bind_port;
-
+
/* crypto */
struct cryptot_st data;
init_data(&data);
bind_ip[0] = bind_ip[1] = bind_ip[2] = bind_ip[3] = 0;
bind_port = DEFAULT_PORT;
-
+
if(!--argc) usage();
++argv;
while(argc--){
if((*argv)[0]=='-'){
if((*argv)[1]=='v') verbose = 1;
-
+
else if((*argv)[1]=='x') data.cipher|=DECRYPT;
else if((*argv)[1]=='n') {
@@ -440,7 +440,7 @@ int main(int argc, char **argv)
if(!ret || (*argv)[ret]) argument_error('n',1);
data.blocks = (unsigned int)param;
}
-
+
else if((*argv)[1]=='c') {
if(!argc--) argument_error('c',0);
if(*(*(++argv))=='h') usage_cipher();
@@ -448,7 +448,7 @@ int main(int argc, char **argv)
if(!ret || (*argv)[ret])argument_error('c',1);
change_cipher(&data.cipher,param);
}
-
+
else if((*argv)[1]=='s') {
if(!argc--) argument_error('s',0);
ret=ipv4_scan(*(++argv),data.local_ip);
@@ -459,7 +459,7 @@ int main(int argc, char **argv)
if(*(tmp+ret)) argument_error('s',1);
data.in_fd = -1;
}
-
+
else if((*argv)[1]=='b') {
if(!argc--) argument_error('b',0);
ret=ipv4_scan(*(++argv),bind_ip);
@@ -469,7 +469,7 @@ int main(int argc, char **argv)
if(ret) bind_port = (unsigned int)param;
if(*(tmp+ret)) argument_error('b',1);
}
-
+
else if((*argv)[1]=='d') {
if(!argc--) argument_error('d',0);
ret=ipv4_scan(*(++argv),data.dist_ip);
@@ -480,7 +480,7 @@ int main(int argc, char **argv)
if(*(tmp+ret)) argument_error('d',1);
data.out_fd = -1;
}
-
+
else if((*argv)[1]=='S') {
if(!argc--) argument_error('S',0);
ret=ipv4_scan(*(++argv),data.src_ip);
@@ -502,7 +502,7 @@ int main(int argc, char **argv)
if(data.in_fd != 0) resolve_ip(data.local_ip);
if(data.out_fd != 1){ resolve_ip(data.dist_ip); resolve_ip(bind_ip); }
if(data.in_fd != 0 && data.check_accept) resolve_ip(data.src_ip);
-
+
/* if input AND output have been changed, check that local != bind AND local != distant */
if(data.in_fd != 0 && data.out_fd != 1){
if(data.local_port == bind_port && !memcmp(data.local_ip,bind_ip,4)){
@@ -517,7 +517,7 @@ int main(int argc, char **argv)
if(data.in_fd != 0) data.in_fd = bind_to(data.local_ip, data.local_port, 1); /* bind and listen */
if(data.out_fd != 1) data.out_fd = bind_to(bind_ip, bind_port, 0); /* bind */
-
+
data.buffer = allocate_buffer(data.cipher, &data.blocks, &data.size); /* allocate buffer and set blocks & size */
#ifdef _DEBUG_
@@ -554,7 +554,7 @@ int main(int argc, char **argv)
}
else fprintf(stderr,"%s : writing to stdout\n",PROG_NAME);
}
-
+
if(data.cipher&DECRYPT){
c_decrypt(&data,verbose);
}
diff --git a/des.c b/des.c
index 52df628..e5ce820 100644
--- a/des.c
+++ b/des.c
@@ -1,4 +1,4 @@
-/*
+/*
* Cryptographic API.
*
* DES & Triple DES EDE Cipher Algorithms.
@@ -9,7 +9,7 @@
* scatterlist interface. Changed LGPL to GPL per section 3 of the LGPL.
*
* Copyright (c) 1992 Dana L. How.
- * Copyright (c) Raimar Falke <rf13@inf.tu-dresden.de>
+ * Copyright (c) Raimar Falke <rf13@inf.tu-dresden.de>
* Copyright (c) Gisle Slensminde <gisle@ii.uib.no>
* Copyright (C) 2001 Niels Mller.
* Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
@@ -260,7 +260,7 @@ static const u8 parity[] = {
static void des_small_fips_encrypt(u32 *expkey, u8 *dst, const u8 *src)
{
u32 x, y, z;
-
+
x = src[7];
x <<= 8;
x |= src[6];
@@ -632,7 +632,7 @@ static void des_small_fips_encrypt(u32 *expkey, u8 *dst, const u8 *src)
static void des_small_fips_decrypt(u32 *expkey, u8 *dst, const u8 *src)
{
u32 x, y, z;
-
+
x = src[7];
x <<= 8;
x |= src[6];
@@ -1020,7 +1020,7 @@ static int setkey(u32 *expkey, const u8 *key, unsigned int keylen, u32 *flags)
n |= parity[key[6]]; n <<= 4;
n |= parity[key[7]];
w = 0x88888888L;
-
+
if ((*flags & CRYPTO_TFM_REQ_WEAK_KEY)
&& !((n - (w >> 3)) & w)) { /* 1 in 10^10 keys passes this test */
if (n < 0x41415151) {
@@ -1076,7 +1076,7 @@ static int setkey(u32 *expkey, const u8 *key, unsigned int keylen, u32 *flags)
}
}
}
-
+
goto not_weak;
weak:
*flags |= CRYPTO_TFM_RES_WEAK_KEY;
@@ -1089,7 +1089,7 @@ not_weak:
n = 56;
b0 = bits0;
b1 = bits1;
-
+
do {
w = (256 | *key++) << 2;
do {
@@ -1099,11 +1099,11 @@ not_weak:
b0[n] = 4 & w;
} while ( w >= 16 );
} while ( n );
-
+
/* put the bits in the correct places */
n = 16;
k = rotors;
-
+
do {
w = (b1[k[ 0 ]] | b0[k[ 1 ]]) << 4;
w |= (b1[k[ 2 ]] | b0[k[ 3 ]]) << 2;
@@ -1121,7 +1121,7 @@ not_weak:
w |= (b1[k[20 ]] | b0[k[21 ]]) << 2;
w |= b1[k[22 ]] | b0[k[23 ]];
expkey[0] = w;
-
+
w = (b1[k[ 0+24]] | b0[k[ 1+24]]) << 4;
w |= (b1[k[ 2+24]] | b0[k[ 3+24]]) << 2;
w |= b1[k[ 4+24]] | b0[k[ 5+24]];
@@ -1137,7 +1137,7 @@ not_weak:
w |= (b1[k[18+24]] | b0[k[19+24]]) << 4;
w |= (b1[k[20+24]] | b0[k[21+24]]) << 2;
w |= b1[k[22+24]] | b0[k[23+24]];
-
+
ROR(w, 4, 28); /* could be eliminated */
expkey[1] = w;
@@ -1163,7 +1163,7 @@ void des_decrypt(void *ctx, u8 *dst, const u8 *src)
des_small_fips_decrypt(((struct des_ctx *)ctx)->expkey, dst, src);
}
-/*
+/*
* RFC2451:
*
* For DES-EDE3, there is no known need to reject weak or
@@ -1182,27 +1182,27 @@ int des3_ede_setkey(void *ctx, const u8 *key,
unsigned int i, off;
struct des3_ede_ctx *dctx = ctx;
- if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE) &&
+ if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE) &&
memcmp(&key[DES_KEY_SIZE], &key[DES_KEY_SIZE * 2],
DES_KEY_SIZE))) {
*flags |= CRYPTO_TFM_RES_BAD_KEY_SCHED;
return -1;
}
-
+
for (i = 0, off = 0; i < 3; i++, off += DES_EXPKEY_WORDS,
key += DES_KEY_SIZE) {
int ret = setkey(&dctx->expkey[off], key, DES_KEY_SIZE, flags);
if (ret < 0)
return ret;
- }
+ }
return 0;
}
void des3_ede_encrypt(void *ctx, u8 *dst, const u8 *src)
{
struct des3_ede_ctx *dctx = ctx;
-
+
des_small_fips_encrypt(dctx->expkey, dst, src);
des_small_fips_decrypt(&dctx->expkey[DES_EXPKEY_WORDS], dst, dst);
des_small_fips_encrypt(&dctx->expkey[DES_EXPKEY_WORDS * 2], dst, dst);
diff --git a/douint.c b/douint.c
index bccf4a9..92c55bc 100644
--- a/douint.c
+++ b/douint.c
@@ -5,7 +5,7 @@ int main(void)
unsigned int ui;
unsigned long ul;
unsigned long long ull;
-
+
printf("#ifndef _UINT_H\n#define _UINT_H\n\n");
printf(" /* This file was auto-generated. Do not edit! */\n\n");
/* u8 */
@@ -45,7 +45,7 @@ int main(void)
}
}
printf("#define U32_MAX 0xFFFFFFFF\n\n");
-
+
/* u64 */
ui = 1<<31;
ui += ui; ui += ui; ui += ui; ui += ui; ui += ui; ui += ui; ui += ui; ui += ui;
diff --git a/ipv4_scan.c b/ipv4_scan.c
index b4906c0..061692b 100644
--- a/ipv4_scan.c
+++ b/ipv4_scan.c
@@ -6,7 +6,7 @@ unsigned int ipv4_scan(const char *s,char ip[4])
unsigned int i;
unsigned int len;
unsigned long u;
-
+
len = 0;
i = scan_ulong(s,&u); if (!i) return 0; ip[0] = u; s += i; len += i;
if (*s != '.') return 0; ++s; ++len;
diff --git a/md4.c b/md4.c
index 00477de..21c5e89 100644
--- a/md4.c
+++ b/md4.c
@@ -1,4 +1,4 @@
-/*
+/*
* Cryptographic API.
*
* MD4 Message Digest Algorithm (RFC1320).
@@ -43,7 +43,7 @@ static __inline u32 H(u32 x, u32 y, u32 z)
{
return x ^ y ^ z;
}
-
+
#define ROUND1(a,b,c,d,k,s) (a = lshift(a + F(b,c,d) + k, s))
#define ROUND2(a,b,c,d,k,s) (a = lshift(a + G(b,c,d) + k + (u32)0x5A827999,s))
#define ROUND3(a,b,c,d,k,s) (a = lshift(a + H(b,c,d) + k + (u32)0x6ED9EBA1,s))
diff --git a/md5.c b/md5.c
index a366d99..1f5281d 100644
--- a/md5.c
+++ b/md5.c
@@ -1,4 +1,4 @@
-/*
+/*
* Cryptographic API.
*
* MD5 Message Digest Algorithm (RFC1321).
@@ -8,10 +8,10 @@
*
* Copyright (c) Cryptoapi developers.
* Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
- *
+ *
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
+ * Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
*/
diff --git a/sha1.c b/sha1.c
index 2a928fb..6c6fa3e 100644
--- a/sha1.c
+++ b/sha1.c
@@ -13,7 +13,7 @@
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
+ * Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
*/
@@ -176,7 +176,7 @@ void sha1_final(void* ctx, u8 *out)
sha1_update(sctx, padding, padlen);
/* Append length */
- sha1_update(sctx, bits, sizeof bits);
+ sha1_update(sctx, bits, sizeof bits);
/* Store state in digest */
for (i = j = 0; i < 5; i++, j += 4) {
diff --git a/sha256.c b/sha256.c
index ce13e22..fa99505 100644
--- a/sha256.c
+++ b/sha256.c
@@ -42,13 +42,13 @@ static void sha_compress(struct sha256_ctx *md)
{
u32 S[8], W[64], t0, t1;
int i;
-
+
/* copy state into S */
for (i = 0; i < 8; i++)
S[i] = md->state[i];
-
+
/* copy the state into 512-bits into W[0..15] */
- for (i = 0; i < 16; i++)
+ for (i = 0; i < 16; i++)
W[i] = (((unsigned long) md->buf[(4 * i) + 0]) << 24) |
(((unsigned long) md->buf[(4 * i) + 1]) << 16) |
(((unsigned long) md->buf[(4 * i) + 2]) << 8) |
@@ -57,7 +57,7 @@ static void sha_compress(struct sha256_ctx *md)
/* fill W[16..63] */
for (i = 16; i < 64; i++)
W[i] = Gamma1(W[i - 2]) + W[i - 7] + Gamma0(W[i - 15]) + W[i - 16];
-
+
/* Compress */
for (i = 0; i < 64; i++) {
t0 = S[7] + Sigma1(S[4]) + Ch(S[4], S[5], S[6]) + K[i] + W[i];
@@ -71,7 +71,7 @@ static void sha_compress(struct sha256_ctx *md)
S[1] = S[0];
S[0] = t0 + t1;
}
-
+
/* feedback */
for (i = 0; i < 8; i++)
md->state[i] += S[i];
@@ -111,38 +111,38 @@ void sha256_final(void *ctx, u8 *hash)
{
struct sha256_ctx *md = ctx;
int i;
-
+
/* increase the length of the message */
md->length += md->curlen * 8;
-
+
/* append the '1' bit */
md->buf[md->curlen++] = 0x80;
-
+
/* if the length is currenlly above 56 bytes we append zeros
* then compress. Then we can fall back to padding zeros and length
* encoding like normal.
*/
-
+
if (md->curlen >= 56) {
for (; md->curlen < 64;)
md->buf[md->curlen++] = 0;
sha_compress(md);
md->curlen = 0;
}
-
+
/* pad upto 56 bytes of zeroes */
for (; md->curlen < 56;)
md->buf[md->curlen++] = 0;
-
+
/* since all messages are under 2^32 bits we mark the top bits zero */
for (i = 56; i < 60; i++)
md->buf[i] = 0;
-
+
/* append length */
for (i = 60; i < 64; i++)
md->buf[i] = (md->length >> ((63 - i) * 8)) & 255;
sha_compress(md);
-
+
/* copy output */
for (i = 0; i < 32; i++)
hash[i] = (md->state[i >> 2] >> (((3 - i) & 3) << 3)) & 255;
diff --git a/sha512.c b/sha512.c
index 7373467..189c2a7 100644
--- a/sha512.c
+++ b/sha512.c
@@ -126,9 +126,9 @@ sha512_transform(u64 *state, const u8 *input)
}
/* load the state into our registers */
- a=state[0]; b=state[1]; c=state[2]; d=state[3];
- e=state[4]; f=state[5]; g=state[6]; h=state[7];
-
+ a=state[0]; b=state[1]; c=state[2]; d=state[3];
+ e=state[4]; f=state[5]; g=state[6]; h=state[7];
+
/* now iterate */
for (i=0; i<80; i+=8) {
t1 = h + e1(e) + Ch(e,f,g) + sha512_K[i ] + W[i ];
@@ -148,9 +148,9 @@ sha512_transform(u64 *state, const u8 *input)
t1 = a + e1(f) + Ch(f,g,h) + sha512_K[i+7] + W[i+7];
t2 = e0(b) + Maj(b,c,d); e+=t1; a=t1+t2;
}
-
- state[0] += a; state[1] += b; state[2] += c; state[3] += d;
- state[4] += e; state[5] += f; state[6] += g; state[7] += h;
+
+ state[0] += a; state[1] += b; state[2] += c; state[3] += d;
+ state[4] += e; state[5] += f; state[6] += g; state[7] += h;
/* erase our data */
a = b = c = d = e = f = g = h = t1 = t2 = 0;
@@ -198,7 +198,7 @@ sha512_update(void *ctx, const u8 *data, unsigned int len)
/* Compute number of bytes mod 128 */
index = (unsigned int)((sctx->count[0] >> 3) & 0x7F);
-
+
/* Update number of bits */
if ((sctx->count[0] += (len << 3)) < (len << 3)) {
if ((sctx->count[1] += 1) < 1)
@@ -206,9 +206,9 @@ sha512_update(void *ctx, const u8 *data, unsigned int len)
sctx->count[3]++;
sctx->count[1] += (len >> 29);
}
-
+
part_len = 128 - index;
-
+
/* Transform as many times as possible. */
if (len >= part_len) {
memcpy(&sctx->buf[index], data, part_len);
@@ -230,7 +230,7 @@ void
sha512_final(void *ctx, u8 *hash)
{
struct sha512_ctx *sctx = ctx;
-
+
static u8 padding[128] = { 0x80, };
u32 t;
@@ -247,22 +247,22 @@ sha512_final(void *ctx, u8 *hash)
bits[15] = t; t>>=8;
bits[14] = t; t>>=8;
bits[13] = t; t>>=8;
- bits[12] = t;
+ bits[12] = t;
t = sctx->count[1];
bits[11] = t; t>>=8;
bits[10] = t; t>>=8;
bits[9 ] = t; t>>=8;
- bits[8 ] = t;
+ bits[8 ] = t;
t = sctx->count[2];
bits[7 ] = t; t>>=8;
bits[6 ] = t; t>>=8;
bits[5 ] = t; t>>=8;
- bits[4 ] = t;
+ bits[4 ] = t;
t = sctx->count[3];
bits[3 ] = t; t>>=8;
bits[2 ] = t; t>>=8;
bits[1 ] = t; t>>=8;
- bits[0 ] = t;
+ bits[0 ] = t;
/* Pad out to 112 mod 128. */
index = (sctx->count[0] >> 3) & 0x7f;
@@ -284,7 +284,7 @@ sha512_final(void *ctx, u8 *hash)
hash[j+1] = (char)t2 & 0xff; t2>>=8;
hash[j ] = (char)t2 & 0xff;
}
-
+
/* Zeroize sensitive information. */
memset(sctx, 0, sizeof(struct sha512_ctx));
}
diff --git a/socket_accept.c b/socket_accept.c
index 61de070..5a993d8 100644
--- a/socket_accept.c
+++ b/socket_accept.c
@@ -17,6 +17,6 @@ int socket_accept4(int s,char ip[4],u16 *port)
memcpy(ip,(char *) &sa.sin_addr,4);
u16_unpack_big((char *) &sa.sin_port,port);
-
+
return fd;
}
diff --git a/socket_bind.c b/socket_bind.c
index 5a6a0a0..b31f673 100644
--- a/socket_bind.c
+++ b/socket_bind.c
@@ -8,7 +8,7 @@
int socket_bind4(int s,char ip[4],u16 port)
{
struct sockaddr_in sa;
-
+
memset(&sa,0,sizeof sa);
sa.sin_family = AF_INET;
u16_pack_big((char *) &sa.sin_port,port);
diff --git a/socket_conn.c b/socket_conn.c
index 0d3b7f9..f7317d3 100644
--- a/socket_conn.c
+++ b/socket_conn.c
@@ -10,12 +10,12 @@
int socket_connect4(int s,const char ip[4],u16 port)
{
struct sockaddr_in sa;
-
+
memset(&sa,0,sizeof sa);
sa.sin_family = AF_INET;
u16_pack_big((char *) &sa.sin_port,port);
memcpy((char *) &sa.sin_addr,ip,4);
-
+
return connect(s,(struct sockaddr *) &sa,sizeof sa);
}
diff --git a/socket_local.c b/socket_local.c
index b676ee5..7ad6dcf 100644
--- a/socket_local.c
+++ b/socket_local.c
@@ -9,7 +9,7 @@ int socket_local4(int s,char ip[4],u16 *port)
{
struct sockaddr_in sa;
unsigned int dummy = sizeof sa;
-
+
if (getsockname(s,(struct sockaddr *) &sa,&dummy) == -1) return -1;
memcpy(ip,(char *) &sa.sin_addr,4);
u16_unpack_big((char *) &sa.sin_port,port);
diff --git a/socket_remote.c b/socket_remote.c
index 7ea339a..da77e4c 100644
--- a/socket_remote.c
+++ b/socket_remote.c
@@ -9,7 +9,7 @@ int socket_remote4(int s,char ip[4],u16 *port)
{
struct sockaddr_in sa;
unsigned int dummy = sizeof sa;
-
+
if (getpeername(s,(struct sockaddr *) &sa,&dummy) == -1) return -1;
memcpy(ip,(char *) &sa.sin_addr,4);
u16_unpack_big((char *) &sa.sin_port,port);
diff --git a/test_crypto_api.c b/test_crypto_api.c
index 5a20c77..8ff9758 100644
--- a/test_crypto_api.c
+++ b/test_crypto_api.c
@@ -17,7 +17,7 @@
int main(void)
{
int i,j;
-
+
struct blowfish_ctx bf_ctx;
struct twofish_ctx tf_ctx;
struct aes_ctx a_ctx;
@@ -29,7 +29,7 @@ int main(void)
struct sha256_ctx sha256;
struct sha512_ctx sha512;
u32 flags;
-
+
u8 key[]="9_&pass/#word%_0";
const u8 phrase[64] = "this#is/only|a?test,@nothing%more&nothing~less 0123456789 voila";
@@ -43,13 +43,13 @@ int main(void)
const u8 T1[64] = "123456";
const u8 T2[64] = "789101";
-
- printf("crypto api tests\n");
- printf("\n\tused phrase : '%s'\n\tlength : %d\n\n",phrase,strlen((char*)phrase));
-
+
+ printf("crypto api tests\n");
+ printf("\n\tused phrase : '%s'\n\tlength : %zu\n\n",phrase,strlen((char*)phrase));
+
memset(encrypt,0,sizeof(encrypt));
memset(encrypt,0,sizeof(decrypt));
-
+
/* test blowfish */
printf("_Blwofish: A 64-Bit Block Cipher_ by Bruce Schneier...\n");
if(blowfish_setkey(&bf_ctx, key, strlen((char*)key), &flags)!=0){
@@ -66,7 +66,7 @@ int main(void)
}
printf("\n\tdecrypted => '%s'\n\n",decrypt);
assert(memcmp(phrase,decrypt,64)==0);
-
+
memset(encrypt,0,sizeof(encrypt));
memset(encrypt,0,sizeof(decrypt));
@@ -86,7 +86,7 @@ int main(void)
blowfish_decrypt(&bf_ctx, decrypt+strlen((char*)T1), encrypt+BF_BLOCK_SIZE);
printf("\n\tdecrypted => '%s'\n\n",decrypt);
assert(memcmp(decrypt,"123456789101",12)==0);
-
+
memset(encrypt,0,sizeof(encrypt));
memset(encrypt,0,sizeof(decrypt));
@@ -98,7 +98,7 @@ int main(void)
fprintf(stderr,"twofish_setkey error.\n");
_exit(1);
}
-
+
for(i=0; i<sizeof(phrase)/TF_BLOCK_SIZE; i++){
twofish_encrypt(&tf_ctx, encrypt, phrase+i*TF_BLOCK_SIZE);
twofish_decrypt(&tf_ctx, decrypt+i*TF_BLOCK_SIZE, encrypt);
@@ -110,7 +110,7 @@ int main(void)
printf("\n");
printf("\n\tdecrypted => '%s'\n\n",decrypt);
assert(memcmp(phrase,decrypt,64)==0);
-
+
memset(encrypt,0,sizeof(encrypt));
memset(encrypt,0,sizeof(decrypt));
@@ -130,7 +130,7 @@ int main(void)
twofish_decrypt(&bf_ctx, decrypt+strlen((char*)T1), encrypt+TF_BLOCK_SIZE);
printf("\n\tdecrypted => '%s'\n\n",decrypt);
assert(memcmp(decrypt,"123456789101",12)==0);
-
+
memset(encrypt,0,sizeof(encrypt));
memset(encrypt,0,sizeof(decrypt));
@@ -141,7 +141,7 @@ int main(void)
fprintf(stderr,"aes_setkey error.\n");
_exit(1);
}
-
+
for(i=0; i<sizeof(phrase)/AES_BLOCK_SIZE; i++){
aes_encrypt(&a_ctx, encrypt, phrase+i*AES_BLOCK_SIZE);
aes_decrypt(&a_ctx, decrypt+i*AES_BLOCK_SIZE, encrypt);
@@ -153,7 +153,7 @@ int main(void)
printf("\n");
printf("\n\tdecrypted => '%s'\n\n",decrypt);
assert(memcmp(phrase,decrypt,64)==0);
-
+
memset(encrypt,0,sizeof(encrypt));
memset(encrypt,0,sizeof(decrypt));
@@ -173,17 +173,17 @@ int main(void)
aes_decrypt(&a_ctx, decrypt+strlen((char*)T1), encrypt+AES_BLOCK_SIZE);
printf("\n\tdecrypted => '%s'\n\n",decrypt);
assert(memcmp(decrypt,"123456789101",12)==0);
-
+
memset(encrypt,0,sizeof(encrypt));
memset(encrypt,0,sizeof(decrypt));
-
+
/* test des */
printf("_des \n");
if(des_setkey(&d_ctx, key, strlen((char*)key),&flags)!=0){
fprintf(stderr,"des_setkey error.\n");
_exit(1);
}
-
+
for(i=0; i<sizeof(phrase)/DES_BLOCK_SIZE; i++){
des_encrypt(&d_ctx, encrypt, phrase+i*DES_BLOCK_SIZE);
des_decrypt(&d_ctx, decrypt+i*DES_BLOCK_SIZE, encrypt);
@@ -195,7 +195,7 @@ int main(void)
printf("\n");
printf("\n\tdecrypted => '%s'\n\n",decrypt);
assert(memcmp(phrase,decrypt,64)==0);
-
+
memset(encrypt,0,sizeof(encrypt));
memset(encrypt,0,sizeof(decrypt));
@@ -215,7 +215,7 @@ int main(void)
des_decrypt(&d_ctx, decrypt+strlen((char*)T1), encrypt+DES_BLOCK_SIZE);
printf("\n\tdecrypted => '%s'\n\n",decrypt);
assert(memcmp(decrypt,"123456789101",12)==0);
-
+
memset(encrypt,0,sizeof(encrypt));
memset(encrypt,0,sizeof(decrypt));
@@ -225,7 +225,7 @@ int main(void)
fprintf(stderr,"des_setkey error.\n");
_exit(1);
}
-
+
for(i=0; i<sizeof(phrase)/DES3_EDE_BLOCK_SIZE; i++){
des3_ede_encrypt(&d3_ctx, encrypt, phrase+i*DES3_EDE_BLOCK_SIZE);
des3_ede_decrypt(&d3_ctx, decrypt+i*DES3_EDE_BLOCK_SIZE, encrypt);
@@ -237,7 +237,7 @@ int main(void)
printf("\n");
printf("\n\tdecrypted => '%s'\n\n",decrypt);
assert(memcmp(phrase,decrypt,64)==0);
-
+
memset(encrypt,0,sizeof(encrypt));
memset(encrypt,0,sizeof(decrypt));
@@ -257,7 +257,7 @@ int main(void)
des3_ede_decrypt(&d3_ctx, decrypt+strlen((char*)T1), encrypt+DES3_EDE_BLOCK_SIZE);
printf("\n\tdecrypted => '%s'\n\n",decrypt);
assert(memcmp(decrypt,"123456789101",12)==0);
-
+
memset(encrypt,0,sizeof(encrypt));
memset(encrypt,0,sizeof(decrypt));
@@ -271,7 +271,7 @@ int main(void)
for(i=0; i<MD4_DIGEST_SIZE; i++)
printf("%02x",md4_hash[i]);
printf("\n\n");
-
+
/* md5 */
printf("MD5: one way hash with a %d bits output digest.\n",MD5_DIGEST_SIZE);
md5_init(&md5);
@@ -282,7 +282,7 @@ int main(void)
for(i=0; i<MD5_DIGEST_SIZE; i++)
printf("%02x",md5_hash[i]);
printf("\n\n");
-
+
/* sha1 */
printf("SHA1: one way hash with a %d bits output digest.\n",SHA1_DIGEST_SIZE);
sha1_init(&sha1);
@@ -293,7 +293,7 @@ int main(void)
for(i=0; i<SHA1_DIGEST_SIZE; i++)
printf("%02x",sha1_hash[i]);
printf("\n\n");
-
+
/* sha256 */
printf("SHA256: one way hash with a %d bits output digest.\n",SHA256_DIGEST_SIZE);
sha256_init(&sha256);
@@ -304,7 +304,7 @@ int main(void)
for(i=0; i<SHA256_DIGEST_SIZE; i++)
printf("%02x",sha256_hash[i]);
printf("\n\n");
-
+
/* sha512 */
printf("SHA512: one way hash with a %d bits output digest.\n",SHA512_DIGEST_SIZE);
sha512_init(&sha512);
@@ -320,6 +320,6 @@ int main(void)
printf("\n\n");
printf("tests ok\n");
-
+
return 0;
}
diff --git a/test_crypto_buffer.c b/test_crypto_buffer.c
index 25e6c93..aeae892 100644
--- a/test_crypto_buffer.c
+++ b/test_crypto_buffer.c
@@ -29,7 +29,7 @@ int main(void)
close(fd);
printf("file written\n");
memset(decrypted,0,64);
-
+
/* read */
fd = open("./crypto_file",O_RDONLY);
if(fd == -1) return -1;
@@ -40,7 +40,7 @@ int main(void)
close(fd);
assert(memcmp(phrase,decrypted,5)==0);
memset(decrypted,0,64);
-
+
/* write */
fd = open("./crypto_file",O_WRONLY|O_CREAT|O_TRUNC,0644);
if(fd == -1) return -1;
@@ -100,7 +100,7 @@ int main(void)
close(fd);
assert(memcmp(phrase,decrypted,64)==0);
memset(decrypted,0,64);
-
+
/* write */
fd = open("./crypto_file",O_WRONLY|O_CREAT|O_TRUNC,0644);
if(fd == -1) return -1;
@@ -114,7 +114,7 @@ int main(void)
close(fd);
printf("file written\n");
memset(decrypted,0,64);
-
+
/* read */
fd = open("./crypto_file",O_RDONLY);
if(fd == -1) return -1;
@@ -152,7 +152,7 @@ int main(void)
close(fd);
printf("file written\n");
memset(decrypted,0,64);
-
+
/* read */
fd = open("./crypto_file",O_RDONLY);
if(fd == -1) return -1;
@@ -177,7 +177,7 @@ int main(void)
close(fd);
assert(memcmp(phrase,decrypted,64)==0);
memset(decrypted,0,64);
-
+
/* write */
fd = open("./crypto_file",O_WRONLY|O_CREAT|O_TRUNC,0644);
if(fd == -1) return -1;
@@ -191,7 +191,7 @@ int main(void)
close(fd);
printf("file written\n");
memset(decrypted,0,64);
-
+
/* read */
fd = open("./crypto_file",O_RDONLY);
if(fd == -1) return -1;
@@ -202,7 +202,7 @@ int main(void)
close(fd);
assert(memcmp(phrase,decrypted,64)==0);
memset(decrypted,0,64);
-
+
/* read */
fd = open("./crypto_file",O_RDONLY);
if(fd == -1) return -1;
diff --git a/twofish.c b/twofish.c
index 0900c00..accff46 100644
--- a/twofish.c
+++ b/twofish.c
@@ -9,7 +9,7 @@
* Ported to CryptoAPI by Colin Slater <hoho@tacomeat.net>
*
* The original author has disclaimed all copyright interest in this
- * code and thus put it in the public domain. The subsequent authors
+ * code and thus put it in the public domain. The subsequent authors
* have put this under the GNU General Public License.
*
* This program is free software; you can redistribute it and/or modify
@@ -21,7 +21,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
@@ -629,7 +629,7 @@ static const u8 calc_sb_tbl[512] = {
/* Perform the key setup. */
int twofish_setkey(void *cx, const u8 *key, unsigned int key_len, u32 *flags)
{
-
+
struct twofish_ctx *ctx = cx;
int i, j, k;
@@ -788,7 +788,7 @@ void twofish_encrypt(void *cx, u8 *out, const u8 *in)
/* The four 32-bit chunks of the text. */
u32 a, b, c, d;
-
+
/* Temporaries used by the round function. */
u32 x, y;
@@ -797,7 +797,7 @@ void twofish_encrypt(void *cx, u8 *out, const u8 *in)
INPACK (1, b, 1);
INPACK (2, c, 2);
INPACK (3, d, 3);
-
+
/* Encryption Feistel cycles. */
ENCCYCLE (0);
ENCCYCLE (1);
@@ -807,32 +807,32 @@ void twofish_encrypt(void *cx, u8 *out, const u8 *in)
ENCCYCLE (5);
ENCCYCLE (6);
ENCCYCLE (7);
-
+
/* Output whitening and unpacking. */
OUTUNPACK (0, c, 4);
OUTUNPACK (1, d, 5);
OUTUNPACK (2, a, 6);
OUTUNPACK (3, b, 7);
-
+
}
/* Decrypt one block. in and out may be the same. */
void twofish_decrypt(void *cx, u8 *out, const u8 *in)
{
struct twofish_ctx *ctx = cx;
-
+
/* The four 32-bit chunks of the text. */
u32 a, b, c, d;
-
+
/* Temporaries used by the round function. */
u32 x, y;
-
+
/* Input whitening and packing. */
INPACK (0, c, 4);
INPACK (1, d, 5);
INPACK (2, a, 6);
INPACK (3, b, 7);
-
+
/* Encryption Feistel cycles. */
DECCYCLE (7);
DECCYCLE (6);
diff --git a/uint16_unpack.c b/uint16_unpack.c
index 3821853..9b04821 100644
--- a/uint16_unpack.c
+++ b/uint16_unpack.c
@@ -3,19 +3,19 @@
__inline void u16_unpack(const char s[2],u16 *u)
{
u16 result;
-
+
result = (unsigned char) s[1]; result <<= 8;
result += (unsigned char) s[0];
-
+
*u = result;
}
__inline void u16_unpack_big(const char s[2],u16 *u)
{
u16 result;
-
+
result = (unsigned char) s[0]; result <<= 8;
result += (unsigned char) s[1];
-
+
*u = result;
}
diff --git a/x86cpuid.c b/x86cpuid.c
index 7cdd87b..809a111 100644
--- a/x86cpuid.c
+++ b/x86cpuid.c
@@ -12,9 +12,9 @@ int main()
int i;
int j;
char c;
-
+
signal(SIGILL,nope);
-
+
x[0] = 0;
x[1] = 0;
x[2] = 0;
@@ -32,8 +32,8 @@ int main()
putchar(c);
}
}
-
+
printf("-%08x-%08x\n",y[0],y[3]);
-
+
return 0;
}