Beispiel #1
0
int main(int argc, char* argv[])
{
	char *text = "TESTWY";
	unsigned char plaintext[8], cipher[8] = {0}, buffor[8] = {0};
	memcpy(plaintext, text, 8);

	des_ctx *ctx = des_make_ctx((unsigned char*)text);
	printf("plaintext: "); print_hex(plaintext, 8);
	des_crypt(ctx, plaintext, cipher, DES_ENCRYPT);
	printf("cipher: "); print_hex(cipher, 8);
	des_crypt(ctx, cipher, buffor, DES_DECRYPT);
	printf("decrypted: "); print_hex(buffor, 8);
	return 0;
}
/* my_crypt returns malloc'ed data */
static char *my_crypt(const char *key, const char *salt)
{
	/* First, check if we are supposed to be using the MD5 replacement
	 * instead of DES...  */
	if (salt[0] == '$' && salt[1] == '1' && salt[2] == '$') {
		return md5_crypt(xzalloc(MD5_OUT_BUFSIZE), (unsigned char*)key, (unsigned char*)salt);
	}

	{
		if (!des_cctx)
			des_cctx = const_des_init();
		des_ctx = des_init(des_ctx, des_cctx);
		return des_crypt(des_ctx, xzalloc(DES_OUT_BUFSIZE), (unsigned char*)key, (unsigned char*)salt);
	}
}
Beispiel #3
0
/* my_crypt returns malloc'ed data */
static char *my_crypt(const char *key, const char *salt)
{
	/* MD5 or SHA? */
	if (salt[0] == '$' && salt[1] && salt[2] == '$') {
		if (salt[1] == '1')
			return md5_crypt(xzalloc(MD5_OUT_BUFSIZE), (unsigned char*)key, (unsigned char*)salt);
#if ENABLE_USE_BB_CRYPT_SHA
		if (salt[1] == '5' || salt[1] == '6')
			return sha_crypt((char*)key, (char*)salt);
#endif
	}

	if (!des_cctx)
		des_cctx = const_des_init();
	des_ctx = des_init(des_ctx, des_cctx);
	return des_crypt(des_ctx, xzalloc(DES_OUT_BUFSIZE), (unsigned char*)key, (unsigned char*)salt);
}
void desPerformOn(uint8_t *plainData) {
    uint8_t desSchedule_buffer[16][6];
    uint8_t encryptedDataBuffer_ptr[DES_BLOCK_SIZE];

    //set crypto mode
    CryptoMode_enum crypto_mode = ((g_Des_mode == DES_ENCRYPTION) ? ENCRYPT : DECRYPT);
    //setup buffer for keys
    des_key_setup(g_DES_KEY_ptr, desSchedule_buffer, crypto_mode);
    //apply to data
    des_crypt(plainData, encryptedDataBuffer_ptr, desSchedule_buffer);

    //replace plain data by encrypted data
    memcpy(plainData, encryptedDataBuffer_ptr, DES_BLOCK_SIZE);

    //debug print
    //for (int i=0; i<DES_BLOCK_SIZE;i++) printf("%02X ",plainData[i]);
}
Beispiel #5
0
char *crypt(const char *buf, const char *salt)
	{
	return(des_crypt(buf, salt));
	}