trivium

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

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

Go to latest
Published: Feb 25, 2017 License: MIT Imports: 0 Imported by: 2

README

trivium

GoDoc Build Status Coverage Status

A simple golang implementation of the lightweight trivium stream cipher.

DISCLAIMER: This package is purely for fun and makes no claim or waranty of security. Do not use this package to encrypt any sensitive information.

Trivium is a light weight stream cipher developed to be particularly efficient in hardware.

The trivium specification is http://www.ecrypt.eu.org/stream/p3ciphers/trivium/trivium_p3.pdf

This is a straighforward implementation based on the specification using SWAR calculations to calculate up to 64 bits at a time.

Documentation

Overview

Package trivium is a simple implementation of the light weight stream cipher trivium.

DISCLAIMER: This package is purely for fun and makes no claim or waranty of security. Do not use this package to encrypt any sensitive information.

Trivium is a light weight stream cipher developed to be particularly efficient in hardware.

The trivium specification is http://www.ecrypt.eu.org/stream/p3ciphers/trivium/trivium_p3.pdf

This is a straighforward implementation based on the specification using SWAR calculations to calculate up to 64 bits at a time.

Index

Examples

Constants

View Source
const (
	// KeyLength bytes in the key and IV, 10 bytes = 80 bits
	KeyLength = 10
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Trivium

type Trivium struct {
	// contains filtered or unexported fields
}

Trivium represents the 288-bit state of the Trivium cipher.

func NewTrivium

func NewTrivium(key, iv [KeyLength]byte) *Trivium

NewTrivium returns a Trivium cipher initialized with key and initialization value (IV). Both the key and IV are 80-bits (10 bytes). The initialization processes the cipher for 4*288 cycles to "warm-up" and attempt to eliminate and usable dependency on key and IV.

Example
var key = [10]byte{0x5F, 0xE5, 0x2A, 0x80, 0x75, 0xDA, 0x10, 0xAD, 0x46, 0xF0}
var iv = [10]byte{0xE3, 0x06, 0x9F, 0x49, 0xD4, 0x23, 0xBA, 0x6F, 0xF1, 0x14}
var trivium = NewTrivium(key, iv)
// note the key and iv are printed big-endian
fmt.Printf("key: %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n", key[9], key[8], key[7], key[6], key[5], key[4], key[3], key[2], key[1], key[0])
fmt.Printf("iv:  %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n", iv[9], iv[8], iv[7], iv[6], iv[5], iv[4], iv[3], iv[2], iv[1], iv[0])
fmt.Println("first 64 bytes of key stream:")
for j := 0; j < 4; j++ {
	for i := 0; i < 16; i++ {
		fmt.Printf("%02X", trivium.NextByte())
	}
	fmt.Println()
}
Output:

key: F046AD10DA75802AE55F
iv:  14F16FBA23D4499F06E3
first 64 bytes of key stream:
A4386C6D7624983FEA8DBE7314E5FE1F
9D102004C2CEC99AC3BFBF003A66433F
3089A98FAD8512C49D7AABC0639F90C5
FFED06F9D35AA8C86630E76A838E26D7

func (*Trivium) NextBit

func (t *Trivium) NextBit() uint64

NextBit gets the next bit from the Trivium stream.

func (*Trivium) NextBits

func (t *Trivium) NextBits(n uint) uint64

NextBits gets the next 1 to 63 bits from the Trivium stream.

func (*Trivium) NextByte

func (t *Trivium) NextByte() byte

NextByte returns the next byte of key stream with the MSB as the last bit produced. the first byte produced will have bits [76543210] of the keystream

func (*Trivium) NextBytes

func (t *Trivium) NextBytes(n uint) []byte

NextBytes returns the next 1 to 8 bytes of key stream with the MSB as the last bit produced. the first byte produced will have bits [76543210] of the keystream

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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