present

package module
v0.0.0-...-797caef Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2021 License: MIT Imports: 3 Imported by: 0

README

PRESENT.go

This is a fork based which allows to set an adjustable number of rounds for research purposes. This is obviously INSECURE when used without the default number of rounds, which is 31. You properly may not want to use this, but rather the original if you do not need a "broken" cipher for research.

About

Go implementation of the PRESENT ultra-lightweight block cipher as defined by Bogdanov et al. [1].

Not to be confused with the Go presentation tool package and command.

Usage

This package implements the cipher.Block interface from crypto/cipher, so it can be used with the block cipher modes implemented there, just like the crypto/aes package.

Example

One of the test vectors from the PRESENT paper:

package main

import (
	"encoding/hex"
	"fmt"
	"log"

	"github.com/Nirusu/PRESENT.go"
)

func encodeHex(data []byte) string {
	dst := make([]byte, hex.EncodedLen(len(data)))
	hex.Encode(dst, data)
	return string(dst)
}

func main() {
	key := make([]byte, 10)
	fmt.Printf("%-10s : %s\n", "Key", encodeHex(key))
	cipher, err := present.NewCipher(key, 31) // Adjust 31 to choose how many rounds you want to use
	if err != nil {
		log.Fatal(err)
	}
	plaintext := make([]byte, 8)
	fmt.Printf("%-10s : %s\n", "Plaintext", encodeHex(plaintext))
	ciphertext := make([]byte, 8)
	cipher.Encrypt(ciphertext, plaintext)
	fmt.Printf("%-10s : %s\n", "Ciphertext", encodeHex(ciphertext))
}

Output:

Key        : 00000000000000000000
Plaintext  : 0000000000000000
Ciphertext : 5579c1387b228445

References

  1. Bogdanov A. et al. (2007) PRESENT: An Ultra-Lightweight Block Cipher. In: Paillier P., Verbauwhede I. (eds) Cryptographic Hardware and Embedded Systems - CHES 2007. CHES 2007. Lecture Notes in Computer Science, vol 4727. Springer, Berlin, Heidelberg (pdf)

Documentation

Overview

Package present implements the ultra-lightweight block cipher PRESENT as defined by Bogdanov et al. [1].

1. Bogdanov A. et al. (2007) PRESENT: An Ultra-Lightweight Block Cipher. In: Paillier P., Verbauwhede I. (eds) Cryptographic Hardware and Embedded Systems - CHES 2007. CHES 2007. Lecture Notes in Computer Science, vol 4727. Springer, Berlin, Heidelberg

Index

Constants

View Source
const BlockSize = 8

BlockSize is the PRESENT block size in bytes.

Variables

This section is empty.

Functions

func NewCipher

func NewCipher(key []byte, rounds int) (b cipher.Block, err error)

NewCipher creates a new cipher.Block. The argument should be the PRESENT key, which is either 10 or 16 bytes long for key lengths of 80 bits and 128 bits respectively.

Types

type KeySizeError

type KeySizeError int

KeySizeError represents an invalid PRESENT key length.

func (KeySizeError) Error

func (k KeySizeError) Error() string

Jump to

Keyboard shortcuts

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