core

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2021 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const AES_CBC int = 1
View Source
const AES_CFB1 int = 2
View Source
const AES_CFB2 int = 3
View Source
const AES_CFB4 int = 5
View Source
const AES_CTR1 int = 30
View Source
const AES_CTR16 int = 45
View Source
const AES_CTR2 int = 31
View Source
const AES_CTR4 int = 33
View Source
const AES_CTR8 int = 37
View Source
const AES_ECB int = 0
View Source
const AES_OFB1 int = 14
View Source
const AES_OFB16 int = 29
View Source
const AES_OFB2 int = 15
View Source
const AES_OFB4 int = 17
View Source
const AES_OFB8 int = 21
View Source
const GCM_ACCEPTING_CIPHER int = 1
View Source
const GCM_ACCEPTING_HEADER int = 0
View Source
const GCM_DECRYPTING int = 1
View Source
const GCM_ENCRYPTING int = 0
View Source
const GCM_FINISHED int = 3
View Source
const GCM_NOT_ACCEPTING_MORE int = 2
View Source
const MC_SHA2 int = 2
View Source
const MC_SHA3 int = 3
View Source
const NHS_DEGREE int = (1 << NHS_LGN)
View Source
const NHS_LGN uint = 10 // Degree n=2^LGN
View Source
const NHS_ND uint32 = 0xF7002FFF // 1/(R-q) mod R
View Source
const NHS_ONE int32 = 0x2AC8 // R mod q
View Source
const NHS_PRIME int32 = 0x3001 // q in Hex
View Source
const NHS_R2MODP uint64 = 0x1620 // R^2 mod q
View Source
const NHS_WL uint = 32
View Source
const NHS_inv int32 = 0xeab
View Source
const NHS_invpr int32 = 0x2c2a
View Source
const SHA256 int = 32

import "fmt"

View Source
const SHA384 int = 48
View Source
const SHA3_HASH224 int = 28
View Source
const SHA3_HASH256 int = 32
View Source
const SHA3_HASH384 int = 48
View Source
const SHA3_HASH512 int = 64
View Source
const SHA3_SHAKE128 int = 16
View Source
const SHA3_SHAKE256 int = 32
View Source
const SHA512 int = 64

Variables

View Source
var NHS_iroots = [1024]int32{} /* 1024 elements not displayed */
View Source
var NHS_roots = [1024]int32{} /* 1024 elements not displayed */
View Source
var SHA256ID = [...]byte{0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20}

SHAXXX identifier strings

View Source
var SHA256IDb = [...]byte{0x30, 0x2f, 0x30, 0x0b, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x04, 0x20}

SHAXXX identifier strings

View Source
var SHA384ID = [...]byte{0x30, 0x41, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02, 0x05, 0x00, 0x04, 0x30}
View Source
var SHA384IDb = [...]byte{0x30, 0x3f, 0x30, 0x0b, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02, 0x04, 0x30}
View Source
var SHA512ID = [...]byte{0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x05, 0x00, 0x04, 0x40}
View Source
var SHA512IDb = [...]byte{0x30, 0x4f, 0x30, 0x0b, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x04, 0x40}

Functions

func AES_CBC_IV0_DECRYPT

func AES_CBC_IV0_DECRYPT(K []byte, C []byte) []byte

returns plaintext if all consistent, else returns null string

func AES_CBC_IV0_ENCRYPT

func AES_CBC_IV0_ENCRYPT(K []byte, M []byte) []byte

AES encryption/decryption. Encrypt byte array M using key K and returns ciphertext

func GCM_DECRYPT

func GCM_DECRYPT(K []byte, IV []byte, H []byte, C []byte) ([]byte, []byte)

func GCM_ENCRYPT

func GCM_ENCRYPT(K []byte, IV []byte, H []byte, P []byte) ([]byte, []byte)

func GPhashit

func GPhashit(hash int, hlen int, olen int, zpad int, A []byte, n int32, B []byte) []byte

func HKDF_Expand

func HKDF_Expand(hash int, hlen int, olen int, PRK []byte, INFO []byte) []byte

func HKDF_Extract

func HKDF_Extract(hash int, hlen int, SALT []byte, IKM []byte) []byte

func HMAC

func HMAC(hash int, sha int, tag []byte, olen int, K []byte, M []byte) int

Calculate HMAC of m using key k. HMAC is tag of length olen (which is length of tag)

func InttoBytes

func InttoBytes(n int, len int) []byte

Convert Integer to n-byte array

func KDF2

func KDF2(hash int, sha int, Z []byte, P []byte, olen int) []byte

func MGF1

func MGF1(sha int, Z []byte, olen int, K []byte)

func MGF1XOR

func MGF1XOR(sha int, Z []byte, olen int, K []byte)

func NHS_CLIENT

func NHS_CLIENT(rng *RAND, SB []byte, UC []byte, KEY []byte)

optimized to reduce memory UC is U|cbar to be returned to server KEY is shared key

func NHS_SERVER_1

func NHS_SERVER_1(rng *RAND, SB []byte, S []byte)
API functions. See https://eprint.iacr.org/2016/1157.pdf Protocol 1

S is secret key key, SB is seed|public key to be sent to client

func NHS_SERVER_2

func NHS_SERVER_2(S []byte, UC []byte, KEY []byte)

calculate shared key from UC and secret key S

func PBKDF2

func PBKDF2(hash int, sha int, Pass []byte, Salt []byte, rep int, olen int) []byte

Password based Key Derivation Function Input password p, salt s, and repeat count Output key of length olen

func RSA_OAEP_DECODE

func RSA_OAEP_DECODE(sha int, p []byte, f []byte, RFS int) []byte

OAEP Message Decoding for Decryption

func RSA_OAEP_ENCODE

func RSA_OAEP_ENCODE(sha int, m []byte, rng *RAND, p []byte, RFS int) []byte

OAEP Message Encoding for Encryption

func RSA_PKCS15

func RSA_PKCS15(sha int, m []byte, w []byte, RFS int) bool

func RSA_PKCS15b

func RSA_PKCS15b(sha int, m []byte, w []byte, RFS int) bool

func RSA_PSS_ENCODE

func RSA_PSS_ENCODE(sha int, m []byte, rng *RAND, RFS int) []byte

func RSA_PSS_VERIFY

func RSA_PSS_VERIFY(sha int, m []byte, f []byte) bool

func Recover

func Recover(S []*SHARE) []byte

recover M from shares

func SPhashit

func SPhashit(hash int, hlen int, A []byte) []byte

Simple hashing of byte array

func XMD_Expand

func XMD_Expand(hash int, hlen int, olen int, DST []byte, MSG []byte) []byte

func XOF_Expand

func XOF_Expand(hlen int, olen int, DST []byte, MSG []byte) []byte

Types

type AES

type AES struct {
	Nk int
	Nr int
	// contains filtered or unexported fields
}

func NewAES

func NewAES() *AES

func (*AES) Decrypt

func (A *AES) Decrypt(buff []byte) uint32

Decrypt using selected mode of operation

func (*AES) Encrypt

func (A *AES) Encrypt(buff []byte) uint32

Encrypt using selected mode of operation

func (*AES) End

func (A *AES) End()

Clean up and delete left-overs

func (*AES) Getreg

func (A *AES) Getreg() [16]byte

func (*AES) Init

func (A *AES) Init(m int, nk int, key []byte, iv []byte) bool

func (*AES) Reset

func (A *AES) Reset(m int, iv []byte)

reset cipher

type GCM

type GCM struct {
	Y_0 [16]byte
	// contains filtered or unexported fields
}

func (*GCM) Add_cipher

func (G *GCM) Add_cipher(cipher []byte, len int) []byte

Add Ciphertext - decrypts to plaintext

func (*GCM) Add_header

func (G *GCM) Add_header(header []byte, len int) bool

Add Header data - included but not encrypted

func (*GCM) Add_plain

func (G *GCM) Add_plain(plain []byte, len int) []byte

Add Plaintext - included and encrypted

func (*GCM) Finish

func (G *GCM) Finish(extract bool) []byte

Finish and extract Tag

func (*GCM) Init

func (G *GCM) Init(nk int, key []byte, niv int, iv []byte)

Initialize GCM mode

type HASH256

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

func NewHASH256

func NewHASH256() *HASH256

func NewHASH256copy

func NewHASH256copy(HC *HASH256) *HASH256

func (*HASH256) Continuing_Hash

func (H *HASH256) Continuing_Hash() []byte

func (*HASH256) Hash

func (H *HASH256) Hash() []byte

Generate 32-byte Hash

func (*HASH256) Init

func (H *HASH256) Init()

Initialise Hash function

func (*HASH256) Process

func (H *HASH256) Process(byt byte)

process a single byte

func (*HASH256) Process_array

func (H *HASH256) Process_array(b []byte)

process an array of bytes

func (*HASH256) Process_num

func (H *HASH256) Process_num(n int32)

process a 32-bit integer

type HASH384

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

func NewHASH384

func NewHASH384() *HASH384

func NewHASH384copy

func NewHASH384copy(HC *HASH384) *HASH384

func (*HASH384) Continuing_Hash

func (H *HASH384) Continuing_Hash() []byte

func (*HASH384) Hash

func (H *HASH384) Hash() []byte

Generate 32-byte Hash

func (*HASH384) Init

func (H *HASH384) Init()

Initialise Hash function

func (*HASH384) Process

func (H *HASH384) Process(byt byte)

process a single byte

func (*HASH384) Process_array

func (H *HASH384) Process_array(b []byte)

process an array of bytes

func (*HASH384) Process_num

func (H *HASH384) Process_num(n int32)

process a 32-bit integer

type HASH512

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

func NewHASH512

func NewHASH512() *HASH512

func NewHASH512copy

func NewHASH512copy(HC *HASH512) *HASH512

func (*HASH512) Continuing_Hash

func (H *HASH512) Continuing_Hash() []byte

func (*HASH512) Hash

func (H *HASH512) Hash() []byte

Generate 64-byte Hash

func (*HASH512) Init

func (H *HASH512) Init()

Initialise Hash function

func (*HASH512) Process

func (H *HASH512) Process(byt byte)

process a single byte

func (*HASH512) Process_array

func (H *HASH512) Process_array(b []byte)

process an array of bytes

func (*HASH512) Process_num

func (H *HASH512) Process_num(n int32)

process a 32-bit integer

type RAND

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

func NewRAND

func NewRAND() *RAND

func (*RAND) Clean

func (R *RAND) Clean()

Terminate and clean up

func (*RAND) GetByte

func (R *RAND) GetByte() byte

get random byte

func (*RAND) Seed

func (R *RAND) Seed(rawlen int, raw []byte)

Initialize RNG with some real entropy from some external source

type SHA3

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

func NewSHA3

func NewSHA3(olen int) *SHA3

func NewSHA3copy

func NewSHA3copy(HC *SHA3) *SHA3

func (*SHA3) Continuing_Hash

func (H *SHA3) Continuing_Hash() []byte

func (*SHA3) Continuing_Shake

func (H *SHA3) Continuing_Shake(hash []byte, olen int)

func (*SHA3) Hash

func (H *SHA3) Hash() []byte

Generate Hash

func (*SHA3) Init

func (H *SHA3) Init(olen int)

Initialise Hash function

func (*SHA3) Process

func (H *SHA3) Process(byt byte)

process a single byte

func (*SHA3) Process_array

func (H *SHA3) Process_array(b []byte)

process an array of bytes

func (*SHA3) Process_num

func (H *SHA3) Process_num(n int32)

process a 32-bit integer

func (*SHA3) Shake

func (H *SHA3) Shake(hash []byte, olen int)

func (*SHA3) Squeeze

func (H *SHA3) Squeeze(buff []byte, olen int)

squeeze the sponge

type SHARE

type SHARE struct {
	ID  byte   // Unique Share ID
	NSR byte   // Number of Shares required for recovery
	B   []byte // Share
}

func NewSHARE

func NewSHARE(id int, nsr int, M []byte, R []byte) *SHARE

Return a share of M input id - Unique share ID input nsr - Number of shares required for recovery input Message M to be shared input Random seed R return share structure

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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