Documentation
¶
Overview ¶
- Copyright (c) 2012-2020 MIRACL UK Ltd. *
- This file is part of MIRACL Core
- (see https://github.com/miracl/core). *
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
You may obtain a copy of the License at *
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
Arwa Alblooshi 15/12/2022
Index ¶
- Constants
- Variables
- func AES_CBC_IV0_DECRYPT(K []byte, C []byte) []byte
- func AES_CBC_IV0_ENCRYPT(K []byte, M []byte) []byte
- func DL_CRH1(params []int, H []byte, rho []byte, t1 [][DL_DEGREE]int16)
- func DL_CRH2(H []byte, tr []byte, ph bool, ctx []byte, mess []byte)
- func DL_CRH3(H []byte, bK []byte, rn []byte, mu []byte)
- func DL_ExpandAij(rho []byte, Aij []int32, i int, j int)
- func DL_H4(params []int, CT []byte, mu []byte, w1 [][DL_DEGREE]int8)
- func DL_MakePartialHint(params []int, h []byte, hptr int, z []int32, r []int32) int
- func DL_Power2Round(t []int32, t0 []int16, t1 []int16)
- func DL_SampleInBall(params []int, ct []byte, c []int32)
- func DL_UsePartialHint(params []int, r []int8, h []byte, hptr int, i int, w []int32) int
- func DL_decompose_hi(params []int, a int32) int8
- func DL_decompose_lo(params []int, a int32) int32
- func DL_hibits(params []int, r1 []int8, r []int32)
- func DL_infinity_norm(w []int32) int32
- func DL_intt(x []int32)
- func DL_keypair(params []int, tau []byte, sk []byte, pk []byte)
- func DL_keypair_2(tau []byte, sk []byte, pk []byte)
- func DL_keypair_3(tau []byte, sk []byte, pk []byte)
- func DL_keypair_5(tau []byte, sk []byte, pk []byte)
- func DL_lobits(params []int, r0 []int32, r []int32)
- func DL_modmul(a uint32, b uint32) int32
- func DL_nabs(x int32) int32
- func DL_nextbyte16(ab int, max int, t []int16, position []int) byte
- func DL_nextbyte32(ab int, max int, t []int32, position []int) byte
- func DL_nextbyte8(ab int, max int, t []int8, position []int) byte
- func DL_nextword(ab int, max int, t []byte, position []int) int32
- func DL_nres(x uint32) int32
- func DL_nres_it(p []int32)
- func DL_ntt(x []int32)
- func DL_pack_pk(params []int, pk []byte, rho []byte, t1 [][DL_DEGREE]int16) int
- func DL_pack_sig(params []int, sig []byte, z [][DL_DEGREE]int32, ct []byte, h []byte) int
- func DL_pack_sk(params []int, sk []byte, rho []byte, bK []byte, tr []byte, ...) int
- func DL_poly_add(p1 []int32, p2 []int32, p3 []int32)
- func DL_poly_copy(p1 []int32, p2 []int32)
- func DL_poly_hard_reduce(poly []int32)
- func DL_poly_mcopy(p1 []int32, p2 []int16)
- func DL_poly_mul(p1 []int32, p2 []int32, p3 []int32)
- func DL_poly_negate(p1 []int32, p2 []int32)
- func DL_poly_pos(p []int32)
- func DL_poly_scopy(p1 []int32, p2 []int8)
- func DL_poly_soft_reduce(poly []int32)
- func DL_poly_sub(p1 []int32, p2 []int32, p3 []int32)
- func DL_poly_zero(p1 []int32)
- func DL_redc(T uint64) int32
- func DL_redc_it(p []int32)
- func DL_round(a int32, b int32) int32
- func DL_sample_Sn(params []int, rhod []byte, s []int8, n int)
- func DL_sample_Y(params []int, k int, rhod []byte, y [][DL_DEGREE]int32)
- func DL_signature(params []int, ph bool, rn []byte, sk []byte, ctx []byte, M []byte, sig []byte) int
- func DL_signature_2(ph bool, rn []byte, sk []byte, ctx []byte, M []byte, sig []byte) int
- func DL_signature_3(ph bool, rn []byte, sk []byte, ctx []byte, M []byte, sig []byte) int
- func DL_signature_5(ph bool, rn []byte, sk []byte, ctx []byte, M []byte, sig []byte) int
- func DL_unpack_pk(params []int, rho []byte, t1 [][DL_DEGREE]int16, pk []byte)
- func DL_unpack_sig(params []int, z [][DL_DEGREE]int32, ct []byte, h []byte, sig []byte)
- func DL_unpack_sk(params []int, rho []byte, bK []byte, tr []byte, s1 [][DL_DEGREE]int8, ...)
- func DL_verify(params []int, ph bool, pk []byte, ctx []byte, M []byte, sig []byte) bool
- func DL_verify_2(ph bool, pk []byte, ctx []byte, M []byte, sig []byte) bool
- func DL_verify_3(ph bool, pk []byte, ctx []byte, M []byte, sig []byte) bool
- func DL_verify_5(ph bool, pk []byte, ctx []byte, M []byte, sig []byte) bool
- func GCM_DECRYPT(K []byte, IV []byte, H []byte, C []byte) ([]byte, []byte)
- func GCM_ENCRYPT(K []byte, IV []byte, H []byte, P []byte) ([]byte, []byte)
- func GPhashit(hash int, hlen int, olen int, zpad int, A []byte, n int32, B []byte) []byte
- func HKDF_Expand(hash int, hlen int, olen int, PRK []byte, INFO []byte) []byte
- func HKDF_Extract(hash int, hlen int, SALT []byte, IKM []byte) []byte
- func HMAC(hash int, sha int, tag []byte, olen int, K []byte, M []byte) int
- func InttoBytes(n int, len int) []byte
- func KDF2(hash int, sha int, Z []byte, P []byte, olen int) []byte
- func KYBER_decrypt1024(SK []byte, CT []byte, SS []byte)
- func KYBER_decrypt512(SK []byte, CT []byte, SS []byte)
- func KYBER_decrypt768(SK []byte, CT []byte, SS []byte)
- func KYBER_encrypt1024(r32 []byte, PK []byte, SS []byte, CT []byte)
- func KYBER_encrypt512(r32 []byte, PK []byte, SS []byte, CT []byte)
- func KYBER_encrypt768(r32 []byte, PK []byte, SS []byte, CT []byte)
- func KYBER_keypair1024(r64 []byte, SK []byte, PK []byte)
- func KYBER_keypair512(r64 []byte, SK []byte, PK []byte)
- func KYBER_keypair768(r64 []byte, SK []byte, PK []byte)
- func MGF1(sha int, Z []byte, olen int, K []byte)
- func MGF1XOR(sha int, Z []byte, olen int, K []byte)
- func PBKDF2(hash int, sha int, Pass []byte, Salt []byte, rep int, olen int) []byte
- func RSA_OAEP_DECODE(sha int, p []byte, f []byte, RFS int) []byte
- func RSA_OAEP_ENCODE(sha int, m []byte, rng *RAND, p []byte, RFS int) []byte
- func RSA_PKCS15(sha int, m []byte, w []byte, RFS int) bool
- func RSA_PKCS15b(sha int, m []byte, w []byte, RFS int) bool
- func RSA_PSS_ENCODE(sha int, m []byte, rng *RAND, RFS int) []byte
- func RSA_PSS_VERIFY(sha int, m []byte, f []byte) bool
- func Recover(S []*SHARE) []byte
- func SPhashit(hash int, hlen int, A []byte) []byte
- func XMD_Expand(hash int, hlen int, olen int, DST []byte, MSG []byte) []byte
- func XOF_Expand(hlen int, olen int, DST []byte, MSG []byte) []byte
- type AES
- type GCM
- type HASH256
- type HASH384
- type HASH512
- type RAND
- type SHA3
- func (H *SHA3) Continuing_Hash() []byte
- func (H *SHA3) Continuing_Shake(hash []byte, olen int)
- func (H *SHA3) Hash() []byte
- func (H *SHA3) Init(olen int)
- func (H *SHA3) Process(byt byte)
- func (H *SHA3) Process_array(b []byte)
- func (H *SHA3) Process_num(n int32)
- func (H *SHA3) Shake(hash []byte, olen int)
- func (H *SHA3) Squeeze(buff []byte, olen int)
- type SHARE
Constants ¶
const AES_CBC int = 1
const AES_CFB1 int = 2
const AES_CFB2 int = 3
const AES_CFB4 int = 5
const AES_CTR1 int = 30
const AES_CTR16 int = 45
const AES_CTR2 int = 31
const AES_CTR4 int = 33
const AES_CTR8 int = 37
const AES_ECB int = 0
const AES_OFB1 int = 14
const AES_OFB16 int = 29
const AES_OFB2 int = 15
const AES_OFB4 int = 17
const AES_OFB8 int = 21
const DL_COMBO = 0xA3FA // ONE*inv mod Q
const DL_D = 13
const DL_DEGREE = (1 << DL_LGN)
const DL_LGN = 8
q = 8380417
const DL_MAXK = 8 // could reduce these if not using highest security
const DL_MAXL = 7
const DL_MAXLG = 19
const DL_ND = 0xFC7FDFFF // 1/(R-Q) mod R
const DL_ONE = 0x3FFE00 // R mod Q
const DL_PK_SIZE_2 = ((4*DL_DEGREE*DL_TD)/8 + 32)
const DL_PK_SIZE_3 = ((6*DL_DEGREE*DL_TD)/8 + 32)
const DL_PK_SIZE_5 = ((8*DL_DEGREE*DL_TD)/8 + 32)
const DL_PRIME = 0x7fe001
const DL_R2MODP = 0x2419FF // R^2 mod Q
const DL_SIG_SIZE_2 = ((DL_DEGREE*4*(17+1))/8 + 80 + 4 + 32)
const DL_SIG_SIZE_3 = ((DL_DEGREE*5*(19+1))/8 + 55 + 6 + 48)
const DL_SIG_SIZE_5 = ((DL_DEGREE*7*(19+1))/8 + 75 + 8 + 64)
const DL_SK_SIZE_2 = (64 + TRSIZE + DL_DEGREE*(4*13+4*3+4*3)/8)
const DL_SK_SIZE_3 = (64 + TRSIZE + DL_DEGREE*(6*13+5*4+6*4)/8)
const DL_SK_SIZE_5 = (64 + TRSIZE + DL_DEGREE*(8*13+7*3+8*3)/8)
const DL_TD = (23 - DL_D)
const DL_YBYTES = (((DL_MAXLG + 1) * DL_DEGREE) / 8)
const GCM_ACCEPTING_CIPHER int = 1
const GCM_ACCEPTING_HEADER int = 0
const GCM_DECRYPTING int = 1
const GCM_ENCRYPTING int = 0
const GCM_FINISHED int = 3
const GCM_NOT_ACCEPTING_MORE int = 2
const KYBER_CIPHERTEXT_SIZE_1024 int = ((11*4 + 5) * KY_DEGREE / 8)
const KYBER_CIPHERTEXT_SIZE_512 int = ((10*2 + 4) * KY_DEGREE / 8)
const KYBER_CIPHERTEXT_SIZE_768 int = ((10*3 + 4) * KY_DEGREE / 8)
const KYBER_PUBLIC_SIZE_1024 int = (32 + 4*(KY_DEGREE*3)/2)
const KYBER_PUBLIC_SIZE_512 int = (32 + 2*(KY_DEGREE*3)/2)
const KYBER_PUBLIC_SIZE_768 int = (32 + 3*(KY_DEGREE*3)/2)
const KYBER_SECRET_CCA_SIZE_1024 int = (KYBER_SECRET_CPA_SIZE_1024 + KYBER_PUBLIC_SIZE_1024 + 64)
const KYBER_SECRET_CCA_SIZE_512 int = (KYBER_SECRET_CPA_SIZE_512 + KYBER_PUBLIC_SIZE_512 + 64)
const KYBER_SECRET_CCA_SIZE_768 int = (KYBER_SECRET_CPA_SIZE_768 + KYBER_PUBLIC_SIZE_768 + 64)
const KYBER_SECRET_CPA_SIZE_1024 int = (4 * (KY_DEGREE * 3) / 2)
const KYBER_SECRET_CPA_SIZE_512 int = (2 * (KY_DEGREE * 3) / 2)
const KYBER_SECRET_CPA_SIZE_768 int = (3 * (KY_DEGREE * 3) / 2)
const KYBER_SHARED_SECRET_1024 int = 32
const KYBER_SHARED_SECRET_512 int = 32
const KYBER_SHARED_SECRET_768 int = 32
const KY_DEGREE int = (1 << KY_LGN)
const KY_LGN uint = 8
const KY_MAXK = 4
const KY_ONE int32 = 0x549 // R mod Q
const KY_PRIME int32 = 0xD01
const KY_QINV int32 = 62209 // q^(-1) mod 2^16
const MC_SHA2 int = 2
const MC_SHA3 int = 3
const NTTL = 1
Gentleman-Sande INTT Excess of 2 allowed on input - coefficients must be < 2*PRIME Output fully reduced
const SHA256 int = 32
import "fmt"
const SHA384 int = 48
const SHA3_HASH224 int = 28
const SHA3_HASH256 int = 32
const SHA3_HASH384 int = 48
const SHA3_HASH512 int = 64
const SHA3_SHAKE128 int = 16
const SHA3_SHAKE256 int = 32
const SHA512 int = 64
const TRSIZE = 64
const Version = "b663f1d673accfaea5c8578619b068fd81bffa0f"
Variables ¶
var DL_PARAMS_2 = []int{39, 17, 88, 4, 4, 2, 3, 80, 32}
var DL_PARAMS_3 = []int{49, 19, 32, 6, 5, 4, 4, 55, 48}
var DL_PARAMS_5 = []int{60, 19, 32, 8, 7, 2, 3, 75, 64}
var DL_iroots = []int32{} /* 256 elements not displayed */
var DL_roots = []int32{} /* 256 elements not displayed */
var PARAMS_1024 = [6]int{4, 2, 2, 11, 5, 32}
var PARAMS_512 = [6]int{2, 3, 2, 10, 4, 32}
parameters for each security level K,eta1,eta2,du,dv,shared secret
var PARAMS_768 = [6]int{3, 2, 2, 10, 4, 32}
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
var SHA256IDb = [...]byte{0x30, 0x2f, 0x30, 0x0b, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x04, 0x20}
SHAXXX identifier strings
var SHA384ID = [...]byte{0x30, 0x41, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02, 0x05, 0x00, 0x04, 0x30}
var SHA384IDb = [...]byte{0x30, 0x3f, 0x30, 0x0b, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02, 0x04, 0x30}
var SHA512ID = [...]byte{0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x05, 0x00, 0x04, 0x40}
var SHA512IDb = [...]byte{0x30, 0x4f, 0x30, 0x0b, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x04, 0x40}
var ZETAS = [256]int16{}/* 128 elements not displayed */
Translated from public domain reference implementation code - taken from https://github.com/pq-crystals/kyber
Functions ¶
func AES_CBC_IV0_DECRYPT ¶
returns plaintext if all consistent, else returns null string
func AES_CBC_IV0_ENCRYPT ¶
AES encryption/decryption. Encrypt byte array M using key K and returns ciphertext
func DL_ExpandAij ¶
Generate A[i][j] from rho
func DL_MakePartialHint ¶
before h initialised to zeros, hptr=0 after new hptr returned and h[OMEGA+i]= hptr
func DL_Power2Round ¶
func DL_SampleInBall ¶
func DL_UsePartialHint ¶
func DL_decompose_lo ¶
ALPHA = (Q-1)/16 - borrowed from dilithium ref implementation
func DL_infinity_norm ¶
func DL_keypair_2 ¶
func DL_keypair_3 ¶
func DL_keypair_5 ¶
func DL_nextbyte16 ¶
array t has ab active bits per word extract dense bytes from array of words if max!=0 then -max<=t[i]<=+max
func DL_nextbyte32 ¶
array t has ab active bits per word extract bytes from array of words if max!=0 then -max<=t[i]<=+max
func DL_nextbyte8 ¶
array t has ab active bits per word extract dense bytes from array of words if max!=0 then -max<=t[i]<=+max
func DL_nextword ¶
extract ab bits into word from dense byte stream
func DL_nres_it ¶
func DL_nres_it(p []int32)
func DL_pack_pk ¶
pack public key
func DL_pack_sig ¶
pack signature - change z
func DL_pack_sk ¶
func DL_pack_sk(params []int, sk []byte, rho []byte, bK []byte, tr []byte, s1 [][DL_DEGREE]int8, s2 [][DL_DEGREE]int8, t0 [][DL_DEGREE]int16) int
secret key of size 32*3+DEGREE*(K*D+L*LG2ETA1+K*LG2ETA1)/8
func DL_poly_add ¶
func DL_poly_mul ¶
func DL_poly_negate ¶
func DL_poly_soft_reduce ¶
func DL_poly_soft_reduce(poly []int32)
reduce inputs that are already < 2q
func DL_poly_sub ¶
func DL_poly_zero ¶
func DL_poly_zero(p1 []int32)
func DL_redc_it ¶
func DL_redc_it(p []int32)
func DL_sample_Sn ¶
rejection sampling in range -ETA to +ETA
func DL_sample_Y ¶
uniform random sampling
func DL_signature ¶
func DL_signature_2 ¶
func DL_signature_3 ¶
func DL_signature_5 ¶
func DL_unpack_pk ¶
unpack public key
func DL_unpack_sig ¶
func DL_unpack_sk ¶
func KYBER_decrypt1024 ¶
func KYBER_decrypt512 ¶
func KYBER_decrypt768 ¶
func KYBER_keypair1024 ¶
func KYBER_keypair512 ¶
func KYBER_keypair768 ¶
func PBKDF2 ¶
Password based Key Derivation Function Input password p, salt s, and repeat count Output key of length olen
func RSA_OAEP_DECODE ¶
OAEP Message Decoding for Decryption
func RSA_OAEP_ENCODE ¶
OAEP Message Encoding for Encryption
Types ¶
type AES ¶
type GCM ¶
type GCM struct { Y_0 [16]byte // contains filtered or unexported fields }
func (*GCM) Add_cipher ¶
Add Ciphertext - decrypts to plaintext
func (*GCM) Add_header ¶
Add Header data - included but not encrypted
type HASH256 ¶
type HASH256 struct {
// contains filtered or unexported fields
}
func NewHASH256 ¶
func NewHASH256() *HASH256
func NewHASH256copy ¶
func (*HASH256) Continuing_Hash ¶
type HASH384 ¶
type HASH384 struct {
// contains filtered or unexported fields
}
func NewHASH384 ¶
func NewHASH384() *HASH384
func NewHASH384copy ¶
func (*HASH384) Continuing_Hash ¶
type HASH512 ¶
type HASH512 struct {
// contains filtered or unexported fields
}
func NewHASH512 ¶
func NewHASH512() *HASH512
func NewHASH512copy ¶
func (*HASH512) Continuing_Hash ¶
type SHA3 ¶
type SHA3 struct {
// contains filtered or unexported fields
}