Originally Posted by
jimblumberg
Show how you are trying to call your function. Plus post the complete error message exactly as it appears in your development environment. And show how BLOWFISH_CONTEXT is defined.
Jim
This is the message from the build log:
Code:
-------------- Build: Debug in blow ---------------
Compiling: main.c
C:\Users\Clint Sharp\Documents\C Programs\blow\main.c: In function 'main':
C:\Users\Clint Sharp\Documents\C Programs\blow\main.c:32: warning: passing argument 1 of 'strlen' makes pointer from integer without a cast
c:\program files (x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/../../../../include/string.h:49: note: expected 'const char *' but argument is of type 'long unsigned int'
C:\Users\Clint Sharp\Documents\C Programs\blow\main.c:59: warning: passing argument 2 of 'BlowfishInitialize' makes pointer from integer without a cast
C:\Users\Clint Sharp\Documents\C Programs\blow\blow.h:19: note: expected 'long unsigned int *' but argument is of type 'long unsigned int'
Linking console executable: bin\Debug\blow.exe
Output size is 52.83 KB
Process terminated with status 0 (0 minutes, 0 seconds)
0 errors, 2 warnings
here is a portion of main.c:
Code:
int main (int argc, char *argv[]) {
BLOWFISH_CONTEXT context;
unsigned long input_key = strtoul(argv[1], NULL, 16);
int key_length = strlen(input_key);
int rc;
char buff[BUFF_SIZE];
rc = getLine ("Enter string> ", buff, sizeof(buff));
if (rc == NO_INPUT) {
printf ("No input\n");
return 1;
}
if (rc == TOO_LONG) {
printf ("Input too long\n");
return 1;
}
char *plaintext_string = buff;
int plaintext_length = strlen(plaintext_string);
unsigned char ciphertext_buffer[BUFF_SIZE];
unsigned char *ciphertext_string = &ciphertext_buffer[0];
int ciphertext_length = 0;
unsigned long message_left;
unsigned long message_right;
int block_len;
BlowfishInitialize(&context, input_key, key_length);
Here is blow.h
Code:
#define BLOW_H_INCLUDED
#define MAXKEYBYTES 56
#define N 16
#define OK 0
#define NO_INPUT 1
#define TOO_LONG 2
#define BUFF_SIZE 256
typedef struct {
unsigned long P[16 + 2];
unsigned long S[4][256];
} BLOWFISH_CONTEXT;
unsigned long F(BLOWFISH_CONTEXT *context, unsigned long x);
void BlowfishEncrypt(BLOWFISH_CONTEXT *context, unsigned long *xl, unsigned long *xr);
void BlowfishDecrypt(BLOWFISH_CONTEXT *context, unsigned long *xl, unsigned long *xr);
void BlowfishInitialize(BLOWFISH_CONTEXT *context, unsigned long *input_key, int key_length);
#endif // BLOW_H_INCLUDED
Here is blow_context.c
Code:
#include "blow.h"
unsigned long F(BLOWFISH_CONTEXT *context, unsigned long x) {
unsigned short a, b, c, d;
unsigned long y;
d = x & 0x00FF;
x >>= 8;
c = x & 0x00FF;
x >>= 8;
b = x & 0x00FF;
x >>= 8;
a = x & 0x00FF;
y = context->S[0][a] + context->S[1][b];
y = y ^ context->S[2][c];
y = y + context->S[3][d];
return y;
}
And all of blow_initialize.c
Code:
#include "blow.h"
#include "boxes.h"
void BlowfishInitialize(BLOWFISH_CONTEXT *context, unsigned long *input_key, int key_length) {
int i, j, k;
unsigned long data, data_left, data_right;
for (i = 0; i < 4; i++) {
for (j = 0; j < 256; j++)
context->S[i][j] = S_BOX[i][j];
}
j = 0;
for (i = 0; i < N + 2; ++i) {
data = 0x00000000;
for (k = 0; k < 4; ++k) {
data = (data << 8) | input_key[j];
j = j + 1;
if (j >= key_length)
j = 0;
}
context->P[i] = P_BOX[i] ^ data;
}
data_left = 0x00000000;
data_right = 0x00000000;
for (i = 0; i < N + 2; i += 2) {
BlowfishEncrypt(context, &data_left, &data_right);
context->P[i] = data_left;
context->P[i + 1] = data_right;
}
for (i = 0; i < 4; ++i) {
for (j = 0; j < 256; j += 2) {
BlowfishEncrypt(context, &data_left, &data_right);
context->S[i][j] = data_left;
context->S[i][j + 1] = data_right;
}
}
}
Thanks for your help thus far.