DES_CRYPT(3)

πŸ’– DES_CRYPT(3) πŸ’–

okay bestie, welcome to the DES crypt page β€” it lives in the Library Functions Manual and it's literally all about fast DES encryption. yes, that DES. the Data Encryption Standard one. buckle up πŸŽ€


✨ NAME ✨

des_crypt, ecb_crypt, cbc_crypt, des_setparity β€” fast DES encryption πŸ’…


✨ SYNOPSIS ✨

#include <rpc/des_crypt.h>

int
ecb_crypt(char *key, char *data, unsigned datalen, unsigned mode);

int
cbc_crypt(char *key, char *data, unsigned datalen, unsigned mode,
    char *ivec);

void
des_setparity(char *key);

✨ DESCRIPTION ✨

so ecb_crypt() and cbc_crypt() are the ones implementing the NBS DES (Data Encryption Standard) πŸ¦‹. these routines are faster and more general purpose than crypt(3), no cap. and here's the slay part β€” they can also utilize DES hardware if it's available. main character energy fr.

  • ecb_crypt() encrypts in ECB (Electronic Code Book) mode, which encrypts blocks of data independently.
  • cbc_crypt() encrypts in CBC (Cipher Block Chaining) mode, which chains together successive blocks. CBC mode protects against insertions, deletions and substitutions of blocks. also, regularities in the clear text will not appear in the cipher text. iconic behaviour honestly ✨

here's how you actually use these routines, bestie, pay attention:

  • the first argument, key, is the 8-byte encryption key with parity. to set the key's parity β€” which for DES is in the low bit of each byte β€” use des_setparity().
  • the second argument, data, contains the data to be encrypted or decrypted.
  • the third argument, datalen, is the length in bytes of data, and it must be a multiple of 8. like, mandatory. do not play with this one πŸ™ˆ
  • the fourth argument, mode, is formed by OR'ing together some things:
    • for the encryption direction, OR in either DES_ENCRYPT or DES_DECRYPT.
    • for software versus hardware encryption, OR in either DES_HW or DES_SW.
    • if DES_HW is specified, and there is no hardware, then the encryption is performed in software and the routine returns DESERR_NOHWDEVICE. so it still works, it's just doing it the software way 😌
  • for cbc_crypt(), the ivec argument is the 8-byte initialization vector for the chaining. it gets updated to the next initialization vector upon return. so it's giving... in-and-out, and it remembers where it left off πŸ’…

✨ ERRORS ✨

  • [DESERR_NONE] β€” no error. we love a clean run 🫢
  • [DESERR_NOHWDEVICE] β€” encryption succeeded, but done in software instead of the requested hardware. (it ate, just not the way you asked πŸ’€)
  • [DESERR_HWERR] β€” an error occurred in the hardware or driver.
  • [DESERR_BADPARAM] β€” bad argument to routine. bestie. check your args.

given a result status stat, the macro DES_FAILED(stat) is false only for the first two statuses. so if you're checking for failure, that's your vibe check right there πŸ‘‘


✨ AVAILABILITY ✨

the ecb_crypt(), cbc_crypt(), and des_setparity() functions are part of libtirpc πŸ’œ


✨ SEE ALSO ✨


✨ RESTRICTIONS ✨

these routines are not available in RPCSRC 4.0. this information is provided to describe the DES interface expected by Secure RPC.

so yeah, not available there. don't come for me, that's just the facts 🌸


mwah πŸ’‹ that's the whole page. this one shipped out with Debian, dated October 6, 1987 β€” yeah, an actual vintage. periodt. πŸ‘‘πŸ’–

πŸ“¦ where this page comes from