des

package module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 10, 2023 License: MIT Imports: 5 Imported by: 0

README

des-avx

Go Reference

Package des-avx implements the Data Encryption Standard (DES) as described in chapter 7.4 of Handbook of Applied Cryptography, 1997. DES proceeds in 16 rounds, processing 64-bit plaintext blocks into 64-bit ciphertext blocks using a 56-bit key. This implementation utilises x86 AVX extensions to work on multiple blocks of plaintext simultaneously.

Documentation

Overview

Package des-avx implements the Data Encryption Standard (DES) as described in chapter 7.4 of Handbook of Applied Cryptography, 1997. DES proceeds in 16 rounds, processing 64-bit plaintext blocks into 64-bit ciphertext blocks using a 56-bit key. This implementation utilises x86 AVX extensions to work on multiple blocks of plaintext simultaneously.

Example
// The length of plaintext must be a multiple of 8
plaintext := []byte("exampleplaintext")
ciphertext := make([]byte, len(plaintext))

// DES keys must be 8 bytes
key, _ := hex.DecodeString("deadbeefdeadc0de")
des.NewDESECBEncrypter(key).CryptBlocks(ciphertext, plaintext)  // Encrypt
des.NewDESECBDecrypter(key).CryptBlocks(ciphertext, ciphertext) // Decrypt

// DES3 keys must be 24 bytes
key, _ = hex.DecodeString("deadbeefdeadc0defeedbabef00dbabebaadf00dbaaaaaad")
des.NewDES3ECBEncrypter(key).CryptBlocks(ciphertext, ciphertext) // Encrypt
des.NewDES3ECBDecrypter(key).CryptBlocks(ciphertext, ciphertext) // Decrypt

fmt.Println(string(ciphertext)) 
Output:

exampleplaintext

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrAVXSupport = errors.New("des-avx: AVX2 support required")
	ErrKeySize    = errors.New("des-avx: invalid key size")
	ErrInputSize  = errors.New("des-avx: invalid input size")
	ErrInternal   = errors.New("des-avx: something unexpected happened")
)

Functions

func NewDES3ECBDecrypter

func NewDES3ECBDecrypter(key []byte) cipher.BlockMode

NewDES3ECBDecrypter returns a cipher.BlockMode which decrypts messages using DES3 in electronic coodebook mode. The key should be 24 bytes long, its its effective size however, is only 168 bits as the least significant bit from each byte is ignored.

func NewDES3ECBEncrypter

func NewDES3ECBEncrypter(key []byte) cipher.BlockMode

NewDES3ECBEncrypter returns a cipher.BlockMode which encrypts messages using DES3 in electronic coodebook mode. The key should be 24 bytes long, its effective size however, is only 168 bits as the least significant bit from each byte is ignored.

func NewDESECBDecrypter

func NewDESECBDecrypter(key []byte) cipher.BlockMode

NewDESECBDecrypter returns a cipher.BlockMode which decrypts messages using DES in electronic coodebook mode. The key should be 8 bytes long, however, its effective size is only 56 bits as the least significant bit from each byte is ignored.

func NewDESECBEncrypter

func NewDESECBEncrypter(key []byte) cipher.BlockMode

NewDESECBEncrypter returns a cipher.BlockMode which encrypts messages using DES in electronic coodebook mode. The key should be 8 bytes long, its effective size however, is only 56 bits as the least significant bit from each byte is ignored.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL