present

package module
v0.0.0-...-3a4450f Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2018 License: MIT Imports: 3 Imported by: 1

README

PRESENT.go

GoDoc Build Status codecov Go Report Card

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/yi-jiayu/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)
	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) (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