Giter Club home page Giter Club logo

rabaead's Introduction

rabaead

rabbit128 poly1305 aead cipher package for golang, this package implement aead (authenticated encryption with associated data) cipher with associated io chunk and io stream interfaces.

aead methods:

  • seal: seals a plaintext into the rabbit aead ciphertext. panic occurs if nonce len is not equal to IVXLen (8byte) or zero
  • open: opens a rabbit aead ciphertext. panic occurs if nonce len is not equal to IVXLen (8byte) or zero

seal

io interfaces:

  • chunkReader: read and open() data in chunks, there is 2byte + 16byte overhead per chunk. read data can be used safely. this reader has a chunk size in-memory buffer, large chunk size can make application to runs out of memory, thus this is most suitable for sliced data, like network data transmit and so..

  • chunkReader: seal() and write data in chunks, there is 2byte + 16byte overhead per chunk. this writer has a chunk size in-memory buffer, large chunk size can make application to runs out of memory, thus this is most suitable for sliced data, like network data transmit and so..

chunkio

  • streamReader: this reader open() and read aead ciphertext which have 16-byte poly1305 tag overhead. read data is unreliable until underlying reader returns EOF, after that Read return EOF or ErrAuthMsg if integrity of data has been compromised. in such a case, you need to unread data. a simple demonstration would be to delete or truncate the file if ErrAuthMsg is returned

  • streamWriter: this writer seal() and write aead plaintext which have 16-byte poly1305 tag overhead, running Close() is necessary in order to calculate and write tag at the end of the write.

how to use?

rabaead lives on both github and snix git services, you can simply import this package by using either import "snix.ir/rabaead" or import "github.com/sina-ghaderi/rabaead"

examples

check out _example directory which contains real-world use cases of rabaead cipher, in addition you may want to look at test unit files or package documentation at pkg.go.dev

// aead open() and seal() methods
func rabbitPoly1305() {
	key := []byte{
		0x01, 0x01, 0x01, 0x01,
		0x01, 0x01, 0x01, 0x01,
		0x01, 0x01, 0x01, 0x01,
		0x01, 0x01, 0x01, 0x01,
	}
	ivx := []byte{
		0x01, 0x01, 0x01, 0x01,
		0x01, 0x01, 0x01, 0x01,
	}
	buff := []byte("plain-text")
	aead, err := rabaead.NewAEAD(key)
	if err != nil {
		panic(err)
	}
	ctxt := aead.Seal([]byte{}, ivx, buff, nil)
	fmt.Printf("aead data: %x\n", ctxt)
	ptxt, err := aead.Open([]byte{}, ivx, ctxt, nil)
	if err != nil {
		panic(err)
	}
	fmt.Printf("plaintext: %s\n", string(ptxt))
}

licence and contribute

feel free to email me [email protected] if you want to contribute to this project. GNU General Public License v3

rabaead's People

Contributors

sina-ghaderi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.