siv

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2022 License: MIT Imports: 6 Imported by: 4

README

Build Status GoDoc

siv

SIV-AES (rfc5297) implementation for Golang.

SIV was proposed by Phil Rogaway and Thomas Shrimpton. Synthetic Initialization Vector (SIV) Authenticated Encryption Using the Advanced Encryption Standard (AES) was proposed as a nonce-reuse misuse resistant Deterministic Authenticated Encryption mechanism in rfc5297.

Usage

  • Import siv into your source
go get github.com/ChandraNarreddy/siv
import "github.com/ChandraNarreddy/siv"
  • Create a Blockpair as -
pair, _ := siv.NewAesSIVBlockPair(key)

where key can be 256, 384 or 512 bit sized []byte array

  • Initialize SIV as -
siv, _ := siv.NewSIV(pair)
  • Wrap plaintext and additionalData using -
plainBytes := []byte(plainText)
additionalDataBytes := [][]byte{[]byte("first additional data"), []byte("second additional data")}
cipherBytes, _ := siv.Wrap(plainBytes, additionalDataBytes...)
  • Unwrap encrypted bytes -
plainBytes, failure := siv.Unwrap(cipherBytes, additionalDataBytes...)
if failure != nil {
  //Unwrap failed because of wrong {cipherBytes, additionalDataBytes... and key) combination
} else {
//do what you want to do with plainBytes here
}

Author

Chandrakanth Narreddy

Contributing

Please submit issues for suggestions. Pull requests are welcome too.

License

MIT License

Acknowledgments

  • Andreas Auernhammer for CMAC

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//ErrAesSIVGeneric indicates a generic error with AesSIV
	ErrAesSIVGeneric = errors.New("AES SIV Generic error: Something went wrong")
	//ErrSivWrapGeneric indicates that an error occurred during the Wrap() function of AesSIV
	ErrSivWrapGeneric = errors.New("Siv Wrap error: error wrapping the message")
	//ErrSivWrapUnsupportedPlaintext indicates that the plaintext supplied to the AesSIV wrap() function is longer than supported (size is platform specific)
	ErrSivWrapUnsupportedPlaintext = errors.New("Siv Wrap error: plaintext size is longer than supported")
	//ErrSivWrapUnsupportedAdditionalData indicates that the additionalData elements supplied exceed the maximum number supported
	ErrSivWrapUnsupportedAdditionalData = errors.New("Siv Wrap error: additionalData elements more than than supported")
	//ErrSivUnwrapGeneric indicates that an error occurred during unwrap() function of AesSIV
	ErrSivUnwrapGeneric = errors.New("Siv Unwrap error: error unwrapping the ciphertext")
	//ErrFailSivUnwrap indicates that the AesSIV unwrap() function failed for the combination of key, ciphertext and additionalData
	ErrFailSivUnwrap = errors.New("Siv Unwrap: Unwrapping the ciphertext failed")
	//ErrSivUnWrapSizeUnsupportedCiphertext indicates that the ciphertext supplied to the AesSIV unwrap() function is longer than supported (size is platform specific)
	ErrSivUnWrapSizeUnsupportedCiphertext = errors.New("Siv Unwrap error: ciphertext size is longer than supported")
	//ErrSivUnWrapUnsupportedAdditionalData indicates that the additionalData elements supplied exceed the maximum number supported
	ErrSivUnWrapUnsupportedAdditionalData = errors.New("Siv Unwrap error: additionalData elements more than than supported")
	//ErrSivUnWrapShortCipherLength indicates that the cipher text is too short
	ErrSivUnWrapShortCipherLength = errors.New("Siv Unwrap error: ciphertext is too short")
)
View Source
var (
	//ErrAesSIVinitKeySize indicates that the key supplied to create an AesSIVBlockPair is in unsupported
	ErrAesSIVinitKeySize = errors.New("Aes SIV Init error: Key size is unsupported")
	//ErrAesSIVinitGeneric indicates that an error occurred initiating an AesSIVBlockPair
	ErrAesSIVinitGeneric = errors.New("AES SIV Init error: Initializing AES SIV block failed")
)
View Source
var (
	//ErrAesSIVs2v indicates that the AesSIVs2v routine failed
	ErrAesSIVs2v = errors.New("AES SIV s2v error: s2v routine failed")
)
View Source
var ErrSiv = errors.New("NewSIV() error: error returning a new SIV implementation")

ErrSiv indicates that NewSIV() failed to return an SIV implementation

Functions

func NewAesSIVBlockPair

func NewAesSIVBlockPair(key []byte) (*aesSIVBlockPair, error)

NewAesSIVBlockPair function takes a 256, 384 or 512 bit key and returns an AesSIVBlockPair.

Types

type SIV

type SIV interface {
	//Wrap encrypts and authenticates the plaintext using SIV mode
	// Wrap (destination, plaintext, ...additionalData) (cipherText, error)
	Wrap(plaintext []byte, additionalData ...[]byte) ([]byte, error)
	//Unwrap
	//Unwrap(destination, ciphertext, ...associatedData) (plaintext, error)
	Unwrap(ciphertext []byte, additionalData ...[]byte) ([]byte, error)
	//KeySize() returns the key size of the SIV mode
	CMACBlockSize() int
	CTRBlockSize() int
}

SIV is the SIV operation mode for SIV proposed by Phil Rogaway and Thomas Shrimpton standardized as https://tools.ietf.org/html/rfc5297

func NewSIV

func NewSIV(sivpair sivBlockPair) (SIV, error)

NewSIV returns the given block cipher wrapped in SIV mode

Jump to

Keyboard shortcuts

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