DES crypto functions

Functions
DES crypto functions

## Functions
void | DES_set_odd_parity (DES_cblock *key)
int HC_DEPRECATED | DES_check_key_parity (DES_cblock *key)
int | DES_is_weak_key (DES_cblock *key)
int HC_DEPRECATED | DES_set_key (DES_cblock *key, DES_key_schedule *ks)
int | DES_set_key_unchecked (DES_cblock *key, DES_key_schedule *ks)
int | DES_set_key_checked (DES_cblock *key, DES_key_schedule *ks)
int | DES_key_sched (DES_cblock *key, DES_key_schedule *ks)
void | DES_encrypt (uint32_t u[2], DES_key_schedule *ks, int encp)
void | DES_ecb_encrypt (DES_cblock *input, DES_cblock *output, DES_key_schedule *ks, int encp)
void | DES_cbc_encrypt (const void *in, void *out, long length, DES_key_schedule *ks, DES_cblock *iv, int encp)
void | DES_pcbc_encrypt (const void *in, void *out, long length, DES_key_schedule *ks, DES_cblock *iv, int encp)
void | DES_ecb3_encrypt (DES_cblock *input, DES_cblock *output, DES_key_schedule *ks1, DES_key_schedule *ks2, DES_key_schedule *ks3, int encp)
void | DES_ede3_cbc_encrypt (const void *in, void *out, long length, DES_key_schedule *ks1, DES_key_schedule *ks2, DES_key_schedule *ks3, DES_cblock *iv, int encp)
void | DES_cfb64_encrypt (const void *in, void *out, long length, DES_key_schedule *ks, DES_cblock *iv, int *num, int encp)
uint32_t | DES_cbc_cksum (const void *in, DES_cblock *output, long length, DES_key_schedule *ks, DES_cblock *iv)
void | DES_string_to_key (const char *str, DES_cblock *key)
int HC_DEPRECATED | DES_new_random_key (DES_cblock *key)
void HC_DEPRECATED | DES_init_random_number_generator (DES_cblock *seed)
void HC_DEPRECATED | DES_random_key (DES_cblock *key)

## Detailed Description

See the DES - Data Encryption Standard crypto interface for description and examples.

## Function Documentation

## ◆ DES_cbc_cksum()

uint32_t DES_cbc_cksum | ( | const void * | in,
|  | DES_cblock * | output,
|  | long | length,
|  | DES_key_schedule * | ks,
|  | DES_cblock * | iv
| ) |  |

Crete a checksum using DES in CBC encryption mode. This mode is only used for Kerberos 4, and it should stay that way.

The IV must always be diffrent for diffrent input data blocks.

Parameters

  in | data to checksum
  output | the checksum
  length | length of data
  ks | key schedule to use
  iv | initial vector to use

## ◆ DES_cbc_encrypt()

void DES_cbc_encrypt | ( | const void * | in,
|  | void * | out,
|  | long | length,
|  | DES_key_schedule * | ks,
|  | DES_cblock * | iv,
|  | int | encp
| ) |  |

Encrypt/decrypt a block using DES in Chain Block Cipher mode (cbc).

The IV must always be diffrent for diffrent input data blocks.

Parameters

  in | data to encrypt
  out | data to encrypt
  length | length of data
  ks | key schedule to use
  iv | initial vector to use
  encp | if non zero, encrypt. if zero, decrypt.

## ◆ DES_cfb64_encrypt()

void DES_cfb64_encrypt | ( | const void * | in,
|  | void * | out,
|  | long | length,
|  | DES_key_schedule * | ks,
|  | DES_cblock * | iv,
|  | int * | num,
|  | int | encp
| ) |  |

Encrypt/decrypt using DES in cipher feedback mode with 64 bit feedback.

The IV must always be diffrent for diffrent input data blocks.

Parameters

  in | data to encrypt
  out | data to encrypt
  length | length of data
  ks | key schedule to use
  iv | initial vector to use
  num | offset into in cipher block encryption/decryption stop last time.
  encp | if non zero, encrypt. if zero, decrypt.

## ◆ DES_check_key_parity()

int HC_DEPRECATED DES_check_key_parity | ( | DES_cblock * | key | ) |

Check if the key have correct parity.

Parameters

  key | key to check the parity.

Returns
  1 on success, 0 on failure.

## ◆ DES_ecb3_encrypt()

void DES_ecb3_encrypt | ( | DES_cblock * | input,
|  | DES_cblock * | output,
|  | DES_key_schedule * | ks1,
|  | DES_key_schedule * | ks2,
|  | DES_key_schedule * | ks3,
|  | int | encp
| ) |  |

Encrypt/decrypt a block using triple DES using EDE mode, encrypt/decrypt/encrypt.

Parameters

  input | data to encrypt
  output | data to encrypt
  ks1 | key schedule to use
  ks2 | key schedule to use
  ks3 | key schedule to use
  encp | if non zero, encrypt. if zero, decrypt.

## ◆ DES_ecb_encrypt()

void DES_ecb_encrypt | ( | DES_cblock * | input,
|  | DES_cblock * | output,
|  | DES_key_schedule * | ks,
|  | int | encp
| ) |  |

Encrypt/decrypt a block using DES.

Parameters

  input | data to encrypt
  output | data to encrypt
  ks | key schedule to use
  encp | if non zero, encrypt. if zero, decrypt.

## ◆ DES_ede3_cbc_encrypt()

void DES_ede3_cbc_encrypt | ( | const void * | in,
|  | void * | out,
|  | long | length,
|  | DES_key_schedule * | ks1,
|  | DES_key_schedule * | ks2,
|  | DES_key_schedule * | ks3,
|  | DES_cblock * | iv,
|  | int | encp
| ) |  |

Encrypt/decrypt using Triple DES in Chain Block Cipher mode (cbc).

The IV must always be diffrent for diffrent input data blocks.

Parameters

  in | data to encrypt
  out | data to encrypt
  length | length of data
  ks1 | key schedule to use
  ks2 | key schedule to use
  ks3 | key schedule to use
  iv | initial vector to use
  encp | if non zero, encrypt. if zero, decrypt.

## ◆ DES_encrypt()

void DES_encrypt | ( | uint32_t | u[2],
|  | DES_key_schedule * | ks,
|  | int | encp
| ) |  |

Encrypt/decrypt a block using DES. Also called ECB mode

Parameters

  u | data to encrypt
  ks | key schedule to use
  encp | if non zero, encrypt. if zero, decrypt.

## ◆ DES_init_random_number_generator()

void HC_DEPRECATED DES_init_random_number_generator | ( | DES_cblock * | seed | ) |

Seed the random number generator. Deprecated, use RAND - random number

Parameters

  seed | a seed to seed that random number generate with.

## ◆ DES_is_weak_key()

int DES_is_weak_key | ( | DES_cblock * | key | ) |

Checks if the key is any of the weaks keys that makes DES attacks trival.

Parameters

  key | key to check.

Returns
  1 if the key is weak, 0 otherwise.

## ◆ DES_key_sched()

int DES_key_sched | ( | DES_cblock * | key,
|  | DES_key_schedule * | ks
| ) |  |

Compatibility function for eay libdes, works just like DES_set_key_checked().

Parameters

  key | a key to initialize the key schedule with.
  ks | a key schedule to initialize.

Returns
  0 on success, -1 on invalid parity, -2 on weak key.

## ◆ DES_new_random_key()

int HC_DEPRECATED DES_new_random_key | ( | DES_cblock * | key | ) |

Generate a random des key using a random block, fixup parity and skip weak keys.

Parameters

  key | is set to a random key.

Returns
  0 on success, non zero on random number generator failure.

## ◆ DES_pcbc_encrypt()

void DES_pcbc_encrypt | ( | const void * | in,
|  | void * | out,
|  | long | length,
|  | DES_key_schedule * | ks,
|  | DES_cblock * | iv,
|  | int | encp
| ) |  |

Encrypt/decrypt a block using DES in Propagating Cipher Block Chaining mode. This mode is only used for Kerberos 4, and it should stay that way.

The IV must always be diffrent for diffrent input data blocks.

Parameters

  in | data to encrypt
  out | data to encrypt
  length | length of data
  ks | key schedule to use
  iv | initial vector to use
  encp | if non zero, encrypt. if zero, decrypt.

## ◆ DES_random_key()

void HC_DEPRECATED DES_random_key | ( | DES_cblock * | key | ) |

Generate a random key, deprecated since it doesn't return an error code, use DES_new_random_key().

Parameters

  key | is set to a random key.

## ◆ DES_set_key()

int HC_DEPRECATED DES_set_key | ( | DES_cblock * | key,
|  | DES_key_schedule * | ks
| ) |  |

Setup a des key schedule from a key. Deprecated function, use DES_set_key_unchecked() or DES_set_key_checked() instead.

Parameters

  key | a key to initialize the key schedule with.
  ks | a key schedule to initialize.

Returns
  0 on success

## ◆ DES_set_key_checked()

int DES_set_key_checked | ( | DES_cblock * | key,
|  | DES_key_schedule * | ks
| ) |  |

Just like DES_set_key_unchecked() except checking that the key is not weak for or have correct parity.

Parameters

  key | a key to initialize the key schedule with.
  ks | a key schedule to initialize.

Returns
  0 on success, -1 on invalid parity, -2 on weak key.

## ◆ DES_set_key_unchecked()

int DES_set_key_unchecked | ( | DES_cblock * | key,
|  | DES_key_schedule * | ks
| ) |  |

Setup a des key schedule from a key. The key is no longer needed after this transaction and can cleared.

Does NOT check that the key is weak for or have wrong parity.

Parameters

  key | a key to initialize the key schedule with.
  ks | a key schedule to initialize.

Returns
  0 on success

## ◆ DES_set_odd_parity()

void DES_set_odd_parity | ( | DES_cblock * | key | ) |

Set the parity of the key block, used to generate a des key from a random key. See DES key generation.

Parameters

  key | key to fixup the parity for.

## ◆ DES_string_to_key()

void DES_string_to_key | ( | const char * | str,
|  | DES_cblock * | key
| ) |  |

Convert a string to a DES key. Use something like PKCS5_PBKDF2_HMAC_SHA1() to create key from passwords.

Parameters

  str | The string to convert to a key
  key | the resulting key