des

Imports

Imports #

"internal/byteorder"
"sync"
"crypto/cipher"
"crypto/internal/fips140/alias"
"crypto/internal/fips140only"
"errors"
"internal/byteorder"
"strconv"

Constants & Variables

BlockSize const #

The DES block size in bytes.

const BlockSize = 8

expansionFunction var #

Used to expand an input block of 32 bits, producing an output block of 48 bits.

var expansionFunction = [48]byte{...}

feistelBox var #

feistelBox[s][16*i+j] contains the output of permutationFunction for sBoxes[s][i][j] << 4*(7-s)

var feistelBox [8][64]uint32

feistelBoxOnce var #

var feistelBoxOnce sync.Once

finalPermutation var #

Used to perform a final permutation of a 4-bit preoutput block. This is the inverse of initialPermutation

var finalPermutation = [64]byte{...}

initialPermutation var #

Used to perform an initial permutation of a 64-bit input block.

var initialPermutation = [64]byte{...}

ksRotations var #

Size of left rotation per round in each half of the key schedule

var ksRotations = [16]uint8{...}

permutationFunction var #

Yields a 32-bit output from a 32-bit input

var permutationFunction = [32]byte{...}

permutedChoice1 var #

Used in the key schedule to select 56 bits from a 64-bit input.

var permutedChoice1 = [56]byte{...}

permutedChoice2 var #

Used in the key schedule to produce each subkey by selecting 48 bits from the 56-bit input

var permutedChoice2 = [48]byte{...}

sBoxes var #

8 S-boxes composed of 4 rows and 16 columns Used in the DES cipher function

var sBoxes = [8][4][16]uint8{...}

Type Aliases

KeySizeError type #

type KeySizeError int

Structs

desCipher struct #

desCipher is an instance of DES encryption.

type desCipher struct {
subkeys [16]uint64
}

tripleDESCipher struct #

A tripleDESCipher is an instance of TripleDES encryption.

type tripleDESCipher struct {
cipher1 desCipher
cipher2 desCipher
cipher3 desCipher
}

Functions

BlockSize method #

func (c *tripleDESCipher) BlockSize() int

BlockSize method #

func (c *desCipher) BlockSize() int

Decrypt method #

func (c *tripleDESCipher) Decrypt(dst []byte, src []byte)

Decrypt method #

func (c *desCipher) Decrypt(dst []byte, src []byte)

Encrypt method #

func (c *desCipher) Encrypt(dst []byte, src []byte)

Encrypt method #

func (c *tripleDESCipher) Encrypt(dst []byte, src []byte)

Error method #

func (k KeySizeError) Error() string

NewCipher function #

NewCipher creates and returns a new [cipher.Block].

func NewCipher(key []byte) (cipher.Block, error)

NewTripleDESCipher function #

NewTripleDESCipher creates and returns a new [cipher.Block].

func NewTripleDESCipher(key []byte) (cipher.Block, error)

cryptBlock function #

func cryptBlock(subkeys []uint64, dst []byte, src []byte, decrypt bool)

feistel function #

DES Feistel function. feistelBox must be initialized via feistelBoxOnce.Do(initFeistelBox) first.

func feistel(l uint32, r uint32, k0 uint64, k1 uint64) (lout uint32, rout uint32)

generateSubkeys method #

creates 16 56-bit subkeys from the original key.

func (c *desCipher) generateSubkeys(keyBytes []byte)

initFeistelBox function #

func initFeistelBox()

ksRotate function #

creates 16 28-bit blocks rotated according to the rotation schedule.

func ksRotate(in uint32) (out []uint32)

permuteBlock function #

general purpose function to perform DES block permutations.

func permuteBlock(src uint64, permutation []uint8) (block uint64)

permuteFinalBlock function #

permuteFinalBlock is equivalent to the permutation defined by finalPermutation.

func permuteFinalBlock(block uint64) uint64

permuteInitialBlock function #

permuteInitialBlock is equivalent to the permutation defined by initialPermutation.

func permuteInitialBlock(block uint64) uint64

unpack function #

Expand 48-bit input to 64-bit, with each 6-bit block padded by extra two bits at the top. By doing so, we can have the input blocks (four bits each), and the key blocks (six bits each) well-aligned without extra shifts/rotations for alignments.

func unpack(x uint64) uint64

Generated with Arrow