cryptoinfra

module
v0.0.0-...-e4cc500 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2019 License: MIT

README

cryptoinfra

Cryptography Infrastructure

Non-Goals:

Goals:

  • A file/wire format to deploy ciphers orthogonally yet transparently.
    • CBC mode and similar Block-Modes
    • AEAD modes
    • Stream ciphers

Parts

Format 2

Why Format 2? Where is Format 1? Why is there no Format 1?

Because the developement of Format 1 utterly failed, before it was even started.

GoDoc

package main

import "github.com/mad-day/cryptoinfra/format2"
import "fmt"
import "bytes"
import "crypto/aes"
import "crypto/cipher"

type dummy struct{}
func (dummy) StartEncryption() (*format2.Preamble,*format2.CipherObject,error) {
	b,_ := aes.NewCipher([]byte("1234567890abcdef"))
	enc := cipher.NewCBCEncrypter(b,[]byte("1234567890abcdef"))
	return &format2.Preamble{Opaque:[]byte("1234567890abcdef"),PK_Algo:"/",Encoding:"aes"},&format2.CipherObject{Block:enc},nil
}
func (dummy) StartDecryption(p *format2.Preamble) (*format2.CipherObject,error) {
	b,_ := aes.NewCipher([]byte("1234567890abcdef"))
	enc := cipher.NewCBCDecrypter(b,[]byte("1234567890abcdef"))
	return &format2.CipherObject{Block:enc},nil
}

func main() {
	buf := new(bytes.Buffer)
	{
		wr,err := format2.NewWriter(buf,dummy{})
		if err!=nil { fmt.Println(err); return }
		fmt.Println(fmt.Fprintln(wr,"Hello World!"))
		wr.Close()
	}
	fmt.Printf("%q\n",buf.Bytes())
	buf2 := new(bytes.Buffer)
	{
		rd,err := format2.NewReader(buf,dummy{})
		if err!=nil { fmt.Println(err); return }
		buf2.ReadFrom(rd)
	}
	fmt.Printf("%q\n",buf2.Bytes())
}
Ciphersuite 2

Why Ciphersuite 2? Whats about Ciphersuite 1?

Because "Ciphersuite 1" was unfinished crap.

GoDoc

package main

import "github.com/mad-day/cryptoinfra/format2"
import "fmt"
import "bytes"
import "crypto/rand"

import (
	"github.com/mad-day/cryptoinfra/ciphersuite2"
	
	// The myriad of cryptographic algorithms.
	// ECC curves.
	_ "github.com/mad-day/cryptoinfra/ciphersuite2/fipsecc"
	_ "github.com/mad-day/cryptoinfra/ciphersuite2/brainpool"
	_ "github.com/mad-day/cryptoinfra/ciphersuite2/koblitz"
	
	// Including curve25519
	_ "github.com/mad-day/cryptoinfra/ciphersuite2/pk25519"
	
	// AES encryption algorithm.
	_ "github.com/mad-day/cryptoinfra/ciphersuite2/aesmodes"
)


func main() {
	fmt.Println()
	fmt.Println()
	rpub,rpriv,err := ciphersuite2.GenerateKeyPair(rand.Reader,"curve25519")
	fmt.Printf("%x %x %v\n",rpub,rpriv,err)
	
	pub,err := ciphersuite2.LoadPublicKey("curve25519",rpub)
	fmt.Printf("%v %v\n",pub,err)
	
	priv,err := ciphersuite2.LoadPrivateKey("curve25519",rpriv)
	fmt.Printf("%v %v\n",priv,err)
	
	fmt.Println()
	fmt.Println()
	
	encrypt := &ciphersuite2.EncryptionContext{
		PublicKey:pub,
		PK_Algo:"curve25519",
		Encoding:"aes-256/gcm",
		Random:rand.Reader,
	}
	decrypt := ciphersuite2.Decrypt(ciphersuite2.AsKeyRing(priv))
	buf := new(bytes.Buffer)
	{
		wr,err := format2.NewWriter(buf,encrypt)
		if err!=nil { fmt.Println(err); return }
		fmt.Println(fmt.Fprintln(wr,"Hello World!"))
		wr.Close()
	}
	fmt.Printf("%q\n",buf.Bytes())
	buf2 := new(bytes.Buffer)
	{
		rd,err := format2.NewReader(buf,decrypt)
		if err!=nil { fmt.Println(err); return }
		fmt.Println(buf2.ReadFrom(rd))
	}
	fmt.Printf("%q\n",buf2.Bytes())
}

WARNING: ciphersuite2 is subject to changes, rendering Many things (including Ciphertexts) incompatible. (still).

Bugs.
  • AEAD-modes (GCM, etc) are bugged and don't work.

Directories

Path Synopsis
A (not so extensible) Ciphersuite for Format 2.
A (not so extensible) Ciphersuite for Format 2.
aesmodes
Implements AES (128,192,256) in various modes of operations.
Implements AES (128,192,256) in various modes of operations.
aez
Implements AEZ AEAD cipher.
Implements AEZ AEAD cipher.
bcns
This package implements support for bcns, a key exchange based on the Ring Learning With Errors Problem.
This package implements support for bcns, a key exchange based on the Ring Learning With Errors Problem.
block
Implements Block Modes.
Implements Block Modes.
brainpool
European Brainpool ECC curves.
European Brainpool ECC curves.
camellia
Implements CAMELLIA encryption algorithm (128,192,256 bit) in various modes of operations.
Implements CAMELLIA encryption algorithm (128,192,256 bit) in various modes of operations.
chacha20poly1305
Implements the ChaCha20-Poly1305 AEAD as specified in RFC 7539, and its extended nonce variant XChaCha20-Poly1305.
Implements the ChaCha20-Poly1305 AEAD as specified in RFC 7539, and its extended nonce variant XChaCha20-Poly1305.
ecc
fipsecc
This package implements the cleptographic ECC curves from FIPS 186-3.
This package implements the cleptographic ECC curves from FIPS 186-3.
hs1siv
Implements the HS1-SIV Authenticated Cipher.
Implements the HS1-SIV Authenticated Cipher.
koblitz
Bitelliptic implements several Koblitz PK_Algo = ( "koblitz_s160" "koblitz_s192" "koblitz_s224" "koblitz_s256" )
Bitelliptic implements several Koblitz PK_Algo = ( "koblitz_s160" "koblitz_s192" "koblitz_s224" "koblitz_s256" )
koreancrypt
Implements ciphers from Korea Internet Security Agency.
Implements ciphers from Korea Internet Security Agency.
morus
Implements the MORUS-1280-256 Authenticated Cipher.
Implements the MORUS-1280-256 Authenticated Cipher.
newhope
This package implements support for newhope, a key exchange based on the Ring Learning With Errors Problem.
This package implements support for newhope, a key exchange based on the Ring Learning With Errors Problem.
pk25519
This package implements support for curve25519 PK_Algo = ( "curve25519" )
This package implements support for curve25519 PK_Algo = ( "curve25519" )
stretch
Key Derivation functions for Public-Key-Algorithms.
Key Derivation functions for Public-Key-Algorithms.
twofish
Implements Twofish (128,192,256 keysize) in various modes of operations.
Implements Twofish (128,192,256 keysize) in various modes of operations.
x448
This package implements support for x448 PK_Algo = ( "x448" )
This package implements support for x448 PK_Algo = ( "x448" )
Wire format 2, Encrypted Preamble File.
Wire format 2, Encrypted Preamble File.

Jump to

Keyboard shortcuts

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