DES(3)
okay so welcome to DES(3), bestie π this is the Library Functions Manual page for single and triple DES, and weβre gonna make it make sense without losing a single crumb. No cap. π«Ά
β¨ NAME β¨
setupDESstate, des_key_setup, block_cipher, desCBCencrypt, desCBCdecrypt, desECBencrypt, desECBdecrypt, des3CBCencrypt, des3CBCdecrypt, des3ECBencrypt, des3ECBdecrypt, key_setup, des56to64, des64to56, setupDES3state, triple_block_cipher β single and triple digital encryption standard. π
π§Ύ SYNOPSIS π§Ύ
#include <u.h>
#include <libc.h>
#include <mp.h>
#include <libsec.h>
void des_key_setup(uchar key[8], ulong schedule[32])
void block_cipher(ulong *schedule, uchar *data, int decrypting)
void setupDESstate(DESstate *s, uchar key[8], uchar *ivec)
void desCBCencrypt(uchar*, int, DESstate*)
void desCBCdecrypt(uchar*, int, DESstate*)
void desECBencrypt(uchar*, int, DESstate*)
void desECBdecrypt(uchar*, int, DESstate*)
void triple_block_cipher(ulong keys[3][32], uchar*, int)
void setupDES3state(DES3state *s, uchar key[3][8], uchar *ivec)
void des3CBCencrypt(uchar*, int, DES3state*)
void des3CBCdecrypt(uchar*, int, DES3state*)
void des3ECBencrypt(uchar*, int, DES3state*)
void des3ECBdecrypt(uchar*, int, DES3state*)
void key_setup(uchar[7], ulong[32])
void des56to64(uchar *k56, uchar *k64)
void des64to56(uchar *k64, uchar *k56)
π§ DESCRIPTION π§
πΈ the whole DES vibe
Digital Encryption Standard (DES) is a shared key or symmetric encryption sitch β youβre either using a 56 bit key for single DES or three 56 bit keys for triple des. The keys are encoded into 64 bits where every eight bit is parity. β¨
π§± block_cipher: the tiny but awkward engine
block_cipher is the basic DES function, bestie. It works on a block of 8 bytes, converting them in place. It takes a key schedule, a pointer to the block, and a flag indicating encrypting (0) or decrypting (1). The key schedule is created from the key using des_key_setup. π₯
Since it is a bit awkward, block_cipher is rarely called directly. Instead, one normally uses routines that encrypt larger buffers of data and which may chain the encryption state from one buffer to the next. These routines keep track of the state of the encryption using a DESstate structure that contains the key schedule and any chained state. setupDESstate sets up the DESstate structure using the key and an 8 byte initialization vector. π§Έ
π ECB vs CBC: the mode check
Electronic code book, using desECBencrypt and desECBdecrypt, is the less secure mode. The encryption of each 8 bytes does not depend on the encryption of any other. Hence the encryption is a substitution cipher using 64 bit characters. π
Cipher block chaining mode, using desCBCencrypt and desCBCdecrypt, is more secure. Every block encrypted depends on the initialization vector and all blocks encrypted before it. π¦
For both CBC and ECB modes, a stream of data can be encrypted as multiple buffers. However, all buffers except the last must be a multiple of 8 bytes to ensure successful decryption of the stream. Thatβs not a suggestion, bestie, itβs the rule. π
π§ triple DES corner
There are equivalent triple DES functions for each of the DES functions. The triple crew hanging out in the synopsis is setupDES3state, triple_block_cipher, des3CBCencrypt, des3CBCdecrypt, des3ECBencrypt, and des3ECBdecrypt. π
π°οΈ the old 56 bit / 7 byte key format
In the past Plan 9 used a 56 bit or 7 byte format for DES keys. To be compatible with the rest of the world, weβve abandoned this format. There are two functions: des56to64 and des64to56 to convert back and forth between the two formats. Also a key schedule can be set up from the 7 byte format using key_setup. π
πΎ SOURCE πΎ
/src/libsec β thatβs the source, bestie. π«Ά
π SEE ALSO π
thatβs the whole page π source: /src/libsec; manual/version: DES(3); date: the footer didnβt list one, so thereβs no date to report. bye bestie, go encrypt responsibly π
π¦ where this page comes from
- alpine 3.24: plan9port-doc 0_git20260208-r0 Β· LPL-1.02
- arch rolling: plan9port 20261021-2 Β· custom
- nixos 26.05: plan9port 0-unstable-2025-11-10
- nixos 26.05: plan9port-wayland 0-unstable-2025-11-26
- nixpkgs unstable: plan9port 0-unstable-2025-11-10
- nixpkgs unstable: plan9port-wayland 0-unstable-2025-11-26
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms