static void scam_decrypt_packet(uint8_t *packet, uint32_t packetLength, uint8_t *key, uint32_t dataLength, uint32_t dataOffset, uint8_t *xorOffset) { uint8_t tmpKey[8], iv[8]; uint32_t i; memcpy(tmpKey, key, 8); memset(iv, 0, 8); for(i=0; i<packetLength; i++) { tmpKey[*xorOffset] ^= packet[i]; *xorOffset = (*xorOffset + 1) & 7; } des_cbc_decrypt(packet + dataOffset, iv, key, dataLength); memcpy(key, tmpKey, 8); }
bool Des::Decrypt(const char *szInput, char *szOutput) { int i = 0; int inlen = strlen(szInput); int datalen = 0; if(inlen <= 8 || inlen > 512) return false; i = 0; char src[MAX_LEN] = {0}; while(i < inlen) { int len = 0; int hi = map_index(szInput[i], len); i += len; int lo = map_index(szInput[i], len); i += len; if(hi == 99 || lo == 99) return false; src[datalen++] = hi * 0x10 + lo; } des_key_setup(GET_32BIT_MSB_FIRST(key8), GET_32BIT_MSB_FIRST(key8 + 4), &crkey); unsigned char dest[256] = {0}; des_cbc_decrypt(dest, (unsigned char *)src, datalen, &crkey); sprintf(szOutput, "%s", dest); //memset(key, 0, 8); //memset(map, 0, 256); return true; }
void cipher_decrypt(CipherContext * context, unsigned char *dest, const unsigned char *src, unsigned int len) { switch (context->type) { case SSH_CIPHER_NONE: memcpy(dest, src, len); break; #ifdef WITH_IDEA case SSH_CIPHER_IDEA: idea_cfb_decrypt(&context->u.idea.key, context->u.idea.iv, dest, src, len); break; #endif /* WITH_IDEA */ #ifdef WITH_DES case SSH_CIPHER_DES: des_cbc_decrypt(&context->u.des.key, context->u.des.iv, dest, src, len); break; #endif /* WITH_DES */ case SSH_CIPHER_3DES: des_3cbc_decrypt(&context->u.des3.key1, context->u.des3.iv1, &context->u.des3.key2, context->u.des3.iv2, &context->u.des3.key3, context->u.des3.iv3, dest, src, len); break; #ifdef WITH_ARCFOUR case SSH_CIPHER_ARCFOUR: arcfour_decrypt(&context->u.arcfour, dest, src, len); break; #endif /* WITH_ARCFOUR */ #ifdef WITH_BLOWFISH case SSH_CIPHER_BLOWFISH: blowfish_cbc_decrypt(&context->u.blowfish, dest, src, len); break; #endif /* WITH_BLOWFISH */ default: fatal("cipher_decrypt: unknown cipher: %d", context->type); } }
static void des_decrypt_blk(unsigned char *blk, int len) { des_cbc_decrypt(blk, blk, len, cskeys); }
static void des_3cbc_decrypt(unsigned char *dest, const unsigned char *src, unsigned int len, DESContext *scheds) { des_cbc_decrypt(dest, src, len, &scheds[2]); des_cbc_encrypt(dest, src, len, &scheds[1]); des_cbc_decrypt(dest, src, len, &scheds[0]); }
//! \brief Main example doing DES encryption/decryption. int main( void ) { uint8_t i; board_init(); sleepmgr_init(); bool success = true; /* Example of how to use Single DES encryption and decryption functions. */ des_encrypt(data, single_ans, keys); des_decrypt(single_ans, single_ans, keys); /* Check if decrypted answer is equal to plaintext. */ for (i = 0; i < DES_BLOCK_LENGTH ; i++ ){ if (data[i] != single_ans[i]){ success = false; break; } } if (success){ /* Example of how to use 3DES encryption and decryption functions. */ des_3des_encrypt(data, single_ans, keys); des_3des_decrypt(single_ans, single_ans, keys); /* Check if decrypted answer is equal to plaintext. */ for (i = 0; i < DES_BLOCK_LENGTH ; i++ ){ if (data[i] != single_ans[i]){ success = false; break; } } } if (success){ /* Example of how to use DES Cipher Block Chaining encryption and * decryption functions. */ des_cbc_encrypt(data_block, cipher_block_ans, keys, init, true, DES_BLOCK_COUNT); des_cbc_decrypt(cipher_block_ans, block_ans, keys, init, true, DES_BLOCK_COUNT); /* Check if decrypted answer is equal to plaintext. */ for (i = 1; i < (DES_BLOCK_LENGTH * DES_BLOCK_COUNT); i++ ){ if (data_block[i] != block_ans[i]){ success = false; break; } } } /* Indicate final result by lighting LED. */ if (success) { /* If the example ends up here every thing is ok. */ ioport_set_pin_low(LED0_GPIO); } else { /* If the example ends up here something is wrong. */ ioport_set_pin_low(LED1_GPIO); } while (true) { /* Go to sleep. */ sleepmgr_enter_sleep(); } }