ascon-go

module
v0.0.0-...-81a204c Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: MIT

README

Ascon cipher

Ascon cipher in idiomatic Go using interfaces by the standard library. Reference:

Don't expect too much of this. There's no guarentee that this is actually safe, use at your own risk. It might delete your files if the cat in the void meows.

General overview

Examples

Encrypting with Ascon:

// Can be swapped with New128a or New80pq for Ascon-128a and Ascon-80pq respectively.
c, err := ascon_aead.New128(key)
if err != nil {
    // [...]
}

cipherText := c.Seal(nil, nonce, cipherText, nil)

Decrypting with Ascon:

// Can be swapped with New128a or New80pq for Ascon-128a and Ascon-80pq respectively.
c, err := ascon_aead.New128(key)
if err != nil {
    // [...]
}

plainText, err := c.Open(nil, nonce, cipherText, nil)
if err != nil {
    // [...]
}

Hashing with Ascon:

message := []byte("Hello, world")

// Can be swapped with Suma for Ascon-Hasha.
messageDigest := ascon_hash.Sum(message)

Hash of file with Ascon:

f, err := os.Open("README.md")
if err != nil {
    // [...]
}
defer f.Close()

// Can be swapped with Newa for Ascon-Hasha.
h := ascon_hash.New()
h.Write(f)
fileHash := h.Sum(nil)

XOF with Ascon:

message := []byte("Hello, world")
longHash := make([]byte, 1024)

// Can be swapped with NewXofa for Ascon-Xofa.
xof := ascon_hash.NewXof()
xof.Write(message)
xof.Read(longHash) // Produces a hash with a length of 1024 bytes.

Generate MAC tag with Ascon:

key := []byte("Ascon-Mac keyzzz")
message := []byte("Hello, world")

mac, err := ascon_prf.NewMac(key)
if err != nil {
    // [...]
}
mac.Write(message)
tag := mac.Sum(nil)

Verify MAC tag with Ascon:

key := []byte("Ascon-Mac keyzzz")
message := []byte("Hello, world")
tag := []byte{149, 86, 87, 32, 71, 31, 182, 39, 220, 208, 135, 131, 103, 176, 255, 44}

ok, err := ascon_prf.ValidateMac(message, tag, key)
if err != nil {
    // [...]
}
fmt.Println(ok) // Result: true

License

The code is licensed under the MIT License. Files in the testdata directory is licensed differently.

Directories

Path Synopsis
Package ascon_aead implements the Ascon-128, Ascon-128a and Ascon-80pq AEAD, as specified in Section 2.4 of https://ascon.iaik.tugraz.at/files/asconv12-nist.pdf.
Package ascon_aead implements the Ascon-128, Ascon-128a and Ascon-80pq AEAD, as specified in Section 2.4 of https://ascon.iaik.tugraz.at/files/asconv12-nist.pdf.
Package ascon_hash implements the Ascon-Hash, Ascon-Hasha, Ascon-Xof and Asxon-Xofa, as specified in Section 2.5 of https://ascon.iaik.tugraz.at/files/asconv12-nist.pdf.
Package ascon_hash implements the Ascon-Hash, Ascon-Hasha, Ascon-Xof and Asxon-Xofa, as specified in Section 2.5 of https://ascon.iaik.tugraz.at/files/asconv12-nist.pdf.
Package ascon_prf implements the Ascon-Mac, as specified in Section 2.5 of https://eprint.iacr.org/2021/1574.pdf.
Package ascon_prf implements the Ascon-Mac, as specified in Section 2.5 of https://eprint.iacr.org/2021/1574.pdf.
internal
ascon-permutation
Package ascon_permutation implements Ascon's permutation according to section 2.6 in https://ascon.iaik.tugraz.at/files/asconv12-nist.pdf.
Package ascon_permutation implements Ascon's permutation according to section 2.6 in https://ascon.iaik.tugraz.at/files/asconv12-nist.pdf.

Jump to

Keyboard shortcuts

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