cryptoswitch

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2021 License: MIT Imports: 19 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Библиотека обеспечения безопасности данных на основе эллиптических кривых

Пакет cryptoswitch реализует схему ECIES с выбором алгоритма шифрования (на вход подаются симметричные алгоритмы шифрования, такие как AES, TwoFish и т.д., и режим шифрования )

ECIES

Encryption

Decryption

Возможные алгоритмы (курсивом - не реализовано):

  • AES
  • DES
  • 3DES (TripleDES)
  • RC5
  • Blowfish
  • Twofish
  • Camellia
  • RC4
  • SEAl
privKey, err := cryptoswitch.GenerateKey()
if err != nil {
    log.WithError(err).Error("can't generate private key")
    return err
}

cw := cryptoswitch.NewCryptoSwitch(cryptoswitch.AES, cryptoswitch.GCM)

encrypt, err := cw.Encrypt(privKey.PublicKey, []byte(testingMessage))
if err != nil {
    log.WithError(err).Error("can't encrypt aes")
    return err
}

Возможные режимы шифрования:

  • CBC
  • GCM (работает только с шифрованием ключа 128 бит)

GCM – Galois/Counter Mode – режим счётчика с аутентификацией Галуа: это режим аутентифицированного шифрования, который, к тому же, поддерживает аутентификацию дополнительных данных (передаются в открытом виде). В англоязычной литературе это называется AEAD – Authenticated Encryption with Associated Data. В ГОСТовой криптографии такого режима как раз не хватает. Аутентифицированное шифрование позволяет обнаружить изменения сообщения до его расшифрования, для этого сообщение снабжается специальным кодом аутентификации (в русскоязычной традиции также называется имитовставкой). GCM позволяет защитить кодом аутентификации не только шифрованную часть сообщения, но и произвольные прикреплённые данные – это полезно, потому что в этих данных может быть записан, например, адрес получателя или другая открытая информация, которую, вместе с тем, требуется защитить от искажений/подмены.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cipher

type Cipher int
const (
	AES Cipher = iota
	DES
	TripleDES
	RC5
	Blowfish
	Twofish
	Camellia
	RC4
	SEAL
)

type CryptoSwitch

type CryptoSwitch struct {
	// contains filtered or unexported fields
}

func NewCryptoSwitch

func NewCryptoSwitch(cipher Cipher, mode Mode) *CryptoSwitch

func (*CryptoSwitch) Decapsulate

func (cw *CryptoSwitch) Decapsulate(alicePubKey *PublicKey, bobPrivKy *PrivateKey) ([]byte, []byte, error)

Decapsulate decapsulates key by using Key Encapsulation Mechanism and returns k_enc, k_mac

func (*CryptoSwitch) Decrypt

func (cw *CryptoSwitch) Decrypt(bobPrivKey *PrivateKey, msgPtr *[]byte) (*[]byte, error)

Decrypt decrypts a passed message with a receiver private key, returns plaintext or decryption error

func (*CryptoSwitch) Encapsulate

func (cw *CryptoSwitch) Encapsulate(alicePriveKey *PrivateKey, bobPubKey *PublicKey) ([]byte, []byte, error)

Decapsulate decapsulates key by using Key Encapsulation Mechanism and returns k_enc, k_mac can be safely used as encryption key

func (*CryptoSwitch) Encrypt

func (cw *CryptoSwitch) Encrypt(bobPubKey *PublicKey, msg *[]byte) (*[]byte, error)

Encrypt encrypts a passed message with a receiver public key, returns ciphertext or encryption error

type Mode

type Mode int
const (
	CBC Mode = iota
	GCM
)

type PrivateKey

type PrivateKey struct {
	*PublicKey
	D *big.Int
}

func GenerateKey

func GenerateKey() (*PrivateKey, error)

GenerateKey generates secp256k1 key pair

type PublicKey

type PublicKey struct {
	elliptic.Curve
	X, Y *big.Int
}

PublicKey instance with nested elliptic.Curve interface (secp256k1 instance in our case)

func (*PublicKey) Bytes

func (k *PublicKey) Bytes() []byte

Bytes returns public key raw bytes; Could be optionally compressed by dropping Y part

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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