static void cfb64_test(char key1[8], char iv[8], char in[23], char out[23]) { unsigned char k1[8], indata[23], outdata[23], outdata2[23], ansdata[23]; DES_key_schedule s1; DES_cblock ivdata; int num; memcpy(k1, key1, 8); memcpy(indata, in, 23); memcpy(ansdata, out, 23); DES_set_odd_parity(&k1); DES_set_key_unchecked(&k1, &s1); num = 0; memcpy(ivdata, iv, 8); DES_cfb64_encrypt(indata, outdata, 23, &s1, &ivdata, &num, 1); if (memcmp(outdata, ansdata, sizeof(ansdata)) != 0) errx(1, "cfb64: encrypt"); num = 0; memcpy(ivdata, iv, 8); DES_cfb64_encrypt(outdata, outdata2, 23, &s1, &ivdata, &num, 0); if (memcmp(indata, outdata2, sizeof(outdata2)) != 0) errx(1, "cfb64: decrypt"); }
static int cfb64_test(unsigned char *cfb_cipher) { DES_key_schedule ks; int err = 0, i, n; DES_set_key_checked(&cfb_key, &ks); memcpy(cfb_tmp, cfb_iv, sizeof(cfb_iv)); n = 0; DES_cfb64_encrypt(plain, cfb_buf1, 12, &ks, &cfb_tmp, &n, DES_ENCRYPT); DES_cfb64_encrypt(&(plain[12]), &(cfb_buf1[12]), sizeof(plain) - 12, &ks, &cfb_tmp, &n, DES_ENCRYPT); if (memcmp(cfb_cipher, cfb_buf1, sizeof(plain)) != 0) { err = 1; printf("cfb_encrypt encrypt error\n"); for (i = 0; i < 24; i += 8) printf("%s\n", pt(&(cfb_buf1[i]))); } memcpy(cfb_tmp, cfb_iv, sizeof(cfb_iv)); n = 0; DES_cfb64_encrypt(cfb_buf1, cfb_buf2, 17, &ks, &cfb_tmp, &n, DES_DECRYPT); DES_cfb64_encrypt(&(cfb_buf1[17]), &(cfb_buf2[17]), sizeof(plain) - 17, &ks, &cfb_tmp, &n, DES_DECRYPT); if (memcmp(plain, cfb_buf2, sizeof(plain)) != 0) { err = 1; printf("cfb_encrypt decrypt error\n"); for (i = 0; i < 24; i += 8) printf("%s\n", pt(&(cfb_buf2[i]))); } return (err); }
static int des_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) { DES_cfb64_encrypt(in, out, (long)inl, ctx->cipher_data, (DES_cblock *)ctx->iv, &ctx->num, ctx->encrypt); return 1; }
static int encrypt( char *key, char *msg, int size, char *res) { int n=0; DES_cblock key2; DES_key_schedule schedule; /* Prepare the key for use with DES_cfb64_encrypt */ memcpy( key2, key,8); DES_set_odd_parity( &key2 ); DES_set_key_checked( &key2, &schedule ); /* Encryption occurs here */ DES_cfb64_encrypt( ( unsigned char * ) msg, ( unsigned char * ) res, size, &schedule, &key2, &n, DES_ENCRYPT ); return size; }
char * Decrypt( char *Key, char *Msg, int size) { static char* Res; int n=0; DES_cblock Key2; DES_key_schedule schedule; Res = ( char * ) malloc( size ); /* Prepare the key for use with DES_cfb64_encrypt */ memcpy( Key2, Key,8); DES_set_odd_parity( &Key2 ); DES_set_key_checked( &Key2, &schedule ); /* Decryption occurs here */ DES_cfb64_encrypt( ( unsigned char * ) Msg, ( unsigned char * ) Res, size, &schedule, &Key2, &n, DES_DECRYPT ); return (Res); }
void _ossl_old_des_cfb64_encrypt(unsigned char *in, unsigned char *out, long length, des_key_schedule schedule, _ossl_old_des_cblock *ivec, int *num, int enc) { DES_cfb64_encrypt(in, out, length, (DES_key_schedule *)schedule, ivec, num, enc); }