cryptoutil

package
v0.0.0-...-26e1c43 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2025 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const SimpleTripleEncryptionHeaderLen int = 4*4 + 96 + 36

Variables

View Source
var CipherTextSizeByKeyType = map[KeyType]KemSizes{
	KeyTypeFrodo640AES:    {19888, 9616, 9720, 16},
	KeyTypeFrodo640SHAKE:  {19888, 9616, 9720, 16},
	KeyTypeFrodo976AES:    {31296, 15632, 15744, 24},
	KeyTypeFrodo976SHAKE:  {31296, 15632, 15744, 24},
	KeyTypeFrodo1344AES:   {43088, 21520, 21632, 32},
	KeyTypeFrodo1344SHAKE: {43088, 21520, 21632, 32},
	KeyTypeKyber768:       {64, 1184, 1088, 32},
	KeyTypeKyber1024:      {64, 1568, 1568, 32},
}
View Source
var CurrentSCryptParameters = SCryptParameters{
	N: 65536 * 2,
	R: 9,
	P: 1,
}
View Source
var KeyTypeAsString = map[KeyType]string{
	KeyTypeFrodo640AES:    "FRODO_640_AES",
	KeyTypeFrodo640SHAKE:  "FRODO_640_SHAKE",
	KeyTypeFrodo976AES:    "FRODO_976_AES",
	KeyTypeFrodo976SHAKE:  "FRODO_976_SHAKE",
	KeyTypeFrodo1344AES:   "FRODO_1344_AES",
	KeyTypeFrodo1344SHAKE: "FRODO_1344_SHAKE",
	KeyTypeKyber768:       "KYBER_768",
	KeyTypeKyber1024:      "KYBER_1024",
}

Functions

func AES256CGMOpen

func AES256CGMOpen(key, nonce, cipherText []byte) (plainText []byte, err error)

func AES256CGMSeal

func AES256CGMSeal(key, nonce, plainText []byte) (cipherText []byte, err error)

func ConcatAll

func ConcatAll(parts ...[]byte) (res []byte)

func Dencapsulate

func Dencapsulate(pub []byte, pvt []byte, ct []byte, keyType KeyType) (ss []byte, err error)

func EncB64

func EncB64(b []byte) string

func Encapsulate

func Encapsulate(pub []byte, keyType KeyType) (ct []byte, ss []byte, err error)

func FrodoGetKem

func FrodoGetKem(keyType KeyType) (kem frodo.FrodoKEM, err error)

func GenKey

func GenKey(keyType KeyType) (pvt []byte, pub []byte, err error)

func KeyId

func KeyId(pub []byte) string

func PrivateKeyAsString

func PrivateKeyAsString(pub []byte) string

func PrivateKeyFromString

func PrivateKeyFromString(key string) (pvt []byte)

func PublicKeyAsString

func PublicKeyAsString(pub []byte) string

func PublicKeyFromString

func PublicKeyFromString(key string) (pub []byte)

func QuickSha256

func QuickSha256(b []byte) []byte

func RandBytes

func RandBytes(size int) []byte

func SimpleSuperTripleDecrypt

func SimpleSuperTripleDecrypt(cipherText []byte, password string) (plainText []byte, err error)

func SimpleSuperTripleEncrypt

func SimpleSuperTripleEncrypt(plainText []byte, password string) (cipherText []byte, err error)

Creates a []byte encrypted with Triple AES256-CGM using Scrypt to derive the password.

Types

type KemSizes

type KemSizes struct {
	Private      int
	Public       int
	CipherText   int
	SharedSecret int
}

type KeyType

type KeyType uint8
const (
	KeyTypeUnknown        KeyType = 255
	KeyTypeInvalid        KeyType = iota
	KeyTypeFrodo640AES    KeyType = iota
	KeyTypeFrodo640SHAKE  KeyType = iota
	KeyTypeFrodo976AES    KeyType = iota
	KeyTypeFrodo976SHAKE  KeyType = iota
	KeyTypeFrodo1344AES   KeyType = iota
	KeyTypeFrodo1344SHAKE KeyType = iota
	KeyTypeKyber768       KeyType = iota
	KeyTypeKyber1024      KeyType = iota
)

type SCryptParameters

type SCryptParameters struct {
	N uint32
	R uint32
	P uint32
}

type SimpleTripleEncryptionHeader

type SimpleTripleEncryptionHeader struct {
	Magic        uint32
	Salt         [32 * 3]byte
	Nonces       [12 * 3]byte
	SCryptParams SCryptParameters
}