Hi,
I've made a test program. I have an unstable output with keys/data in the magic option. With other data/keys the output is stable (doc option). Does someone has a reason for it? The source has been made for an linux environment. Best regards, Wim
/* ** Include files */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <termios.h> #include <unistd.h> #include <time.h> #include <openssl/des.h> #include <fcntl.h> #include <errno.h> #define BUFSIZE 350 #define MAGIC 1 #define DOC 2 static const unsigned char initVector[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; // The initialization vector static unsigned char skC1[8]; static unsigned char skC2[8]; static unsigned char in[BUFSIZE]={0}; static unsigned char out[BUFSIZE]={0}; /*---------------------------------------------------------------------------*/ static void debugHexPrint(unsigned char *tag, unsigned char *data, unsigned int size) { unsigned int i; printf("%s: ", tag); for(i=0;i<size;i++) printf("%02X ", *(data+i)); printf("\n"); } /*---------------------------------------------------------------------------*/ int main(int argc, char *argv[]) { des_key_schedule kSched1, kSched2; des_cblock iv; int i; struct timeval start, stop; int inSize; int outSize; int result; int type; if (argc < 2) { printf(" testdes V01.00\n"); printf(" use: \"testdes magic\" or \"testdes doc\"\n"); return 0; } for(i=0;i<argc;i++) { if (!strcmp(argv[i],"magic")) type = MAGIC; if (!strcmp(argv[i],"doc")) type = DOC; } printf("Encrypt message\n\r"); memset(in,0,sizeof(in)); memset(out,0,sizeof(out)); if (type == MAGIC) { printf("MAGIC\n"); memcpy(skC1, "\x0A\xBE\x32\x6C\x63\x79\x4C\x70", 8); memcpy(skC2, "\xC0\x60\xBA\xA2\xE6\xDB\x83\x95", 8); inSize = 16; memcpy(in,"\x01\x02\x03\x04\x05\x06\x07\x08\x80\x00\x00\x00\x00\x00\x00\x00", inSize); } if (type == DOC) { printf("DOC\n"); memcpy(skC1, "\x97\x9e\xc1\x3b\x1c\xbf\xe9\xdc", 8); memcpy(skC2, "\xd0\x1a\xb0\xfe\xd3\x07\xea\xe5", 8); inSize = 16; memcpy(in, "\x21\x0B\x01\x05\x40\xAA\x00\x00\x20\x80\x00\x00\x00\x00\x00\x00", inSize); } i = inSize; DES_set_key_checked(&skC1, &kSched1); // set the key schedule DES_set_key_checked(&skC2, &kSched2); // set the key schedule memcpy(iv,initVector,sizeof(initVector)); // set the initialization vector memset(out, 0, BUFSIZE); des_ede2_cbc_encrypt(in, out, (long)inSize, kSched1, kSched2, &iv, DES_ENCRYPT); debugHexPrint(" skC1: ", skC1, 8); debugHexPrint(" skC2: ", skC2, 8); debugHexPrint(" IN : ", in, inSize); debugHexPrint(" OUT : ", out, inSize); debugHexPrint(" IV : ", (char *)&iv, sizeof(iv)); printf(" Encrypt message done\n\r"); return 0; }