crypto

package
v0.1.3-beta Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2016 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package crypto implements all cryptographic functions used by the 3nigm4 suite: i mainly wrap Golang std lib function and implement specific pre-processing and post-processing logics. This is a security related element and should be modified with care: any change to this package can potentially modify the security of the whole system.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AesDecrypt

func AesDecrypt(key []byte, ciphertext []byte, mode AesMode) ([]byte, error)

AesDecrypt decrypt data with AES256 using a key Salt and IV are passed in the encrypted message.

func AesEncrypt

func AesEncrypt(key []byte, salt []byte, plaintext []byte, mode AesMode) ([]byte, error)

AesEncrypt encrypt data with AES256 using a key. Salt and IV will be passed in the encrypted message.

func CheckHMAC

func CheckHMAC(message []byte, messageMAC []byte, key []byte) bool

CheckHMAC verify an hmac message with a given key and reference message.

func DecodePgpArmored

func DecodePgpArmored(data []byte) ([]byte, error)

DecodePgpArmored decode pgp armored messages from ASCII armored format.

func DeriveKeyWithPbkdf2

func DeriveKeyWithPbkdf2(password []byte, salt []byte, iter int) []byte

DeriveKeyWithPbkdf2 derive a key from a password using Pbkdf2 algorithm. A good number of iterations is ~ 10000 cycles. The derivated key has the right lenght for being used in AES256.

func EncodePgpArmored

func EncodePgpArmored(data []byte, blocktype string) ([]byte, error)

EncodePgpArmored encode a pgp message in armored ASCII format.

func GenerateHMAC

func GenerateHMAC(message []byte, key []byte) []byte

GenerateHMAC produce hmac with a message and a key.

func GetKeyByEmail

func GetKeyByEmail(keyring openpgp.EntityList, email string) *openpgp.Entity

GetKeyByEmail returns a specific key from an email address.

func GetSaltFromCipherText

func GetSaltFromCipherText(ciphertext []byte) ([]byte, error)

GetSaltFromCipherText extract the salt component from an encrypted data blob.

func NewPgpKeypair

func NewPgpKeypair(name, comment, email string) ([]byte, []byte, error)

NewPgpKeypair creates a pgp keypair and encodes them as byte slides. No encryption is introduced at that point.

func OpenPgpDecrypt

func OpenPgpDecrypt(data []byte, keyring openpgp.EntityList) ([]byte, error)

OpenPgpDecrypt decrypt a message using the argument keyring as source to get required keys.

func OpenPgpEncrypt

func OpenPgpEncrypt(data []byte, recipients openpgp.EntityList, signer *openpgp.Entity) ([]byte, error)

OpenPgpEncrypt encrypt using pgp and the passed recipients list and signer entity.

func OpenPgpSignMessage

func OpenPgpSignMessage(msg []byte, signer *openpgp.Entity) ([]byte, error)

OpenPgpSignMessage creates a signature for a message.

func OpenPgpVerifySignature

func OpenPgpVerifySignature(signature []byte, message []byte, publicKey *openpgp.Entity) error

OpenPgpVerifySignature verify a signature using a public PGP key, an error is returned if the signature is not verified otherwise returning nil.

func PKCS5Padding

func PKCS5Padding(src []byte, blockSize int) []byte

PKCS5Padding padding function to pad a certain blob of data with necessary data to be used in AES block cipher.

func PKCS5UnPadding

func PKCS5UnPadding(src []byte) ([]byte, error)

PKCS5UnPadding unpad data after AES block decrypting.

func ReadArmoredKeyRing

func ReadArmoredKeyRing(kr []byte, passphrase []byte) (openpgp.EntityList, error)

ReadArmoredKeyRing read keys in an armored keyring and returns openpgp entities. If a passphrase is passed it will be used to decrypt keys.

func XorKeys

func XorKeys(keys [][]byte, maxlen int) ([]byte, error)

XorKeys xor given keys (passed in a slice) returning an unique key.

Types

type AesMode

type AesMode int8

AesMode defines a enum type for available aes encryption modes

const (
	CBC AesMode = 0 + iota // AES CBC mode
)

Available AES modes:

Jump to

Keyboard shortcuts

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