From 3bbb8c0b304ee186f2c0d4d00c7aa50b60b59694 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Fri, 24 Nov 2017 14:52:06 +0100 Subject: sys/linux: prefix non-autogenerated files with init_ --- sys/linux/alg.go | 506 --------------------------------------------- sys/linux/alg_test.go | 215 ------------------- sys/linux/init_alg.go | 506 +++++++++++++++++++++++++++++++++++++++++++++ sys/linux/init_alg_test.go | 215 +++++++++++++++++++ 4 files changed, 721 insertions(+), 721 deletions(-) delete mode 100644 sys/linux/alg.go delete mode 100644 sys/linux/alg_test.go create mode 100644 sys/linux/init_alg.go create mode 100644 sys/linux/init_alg_test.go diff --git a/sys/linux/alg.go b/sys/linux/alg.go deleted file mode 100644 index 581b3b364..000000000 --- a/sys/linux/alg.go +++ /dev/null @@ -1,506 +0,0 @@ -// Copyright 2017 syzkaller project authors. All rights reserved. -// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. - -package linux - -import ( - "math/rand" - - "github.com/google/syzkaller/prog" -) - -func (arch *arch) generateSockaddrAlg(g *prog.Gen, typ *prog.StructType, old *prog.GroupArg) ( - arg prog.Arg, calls []*prog.Call) { - family := g.GenerateArg(typ.Fields[0], &calls) - // There is very little point in generating feat/mask, - // because that can only fail otherwise correct bind. - feat := prog.MakeConstArg(typ.Fields[2], 0) - mask := prog.MakeConstArg(typ.Fields[3], 0) - if g.NOutOf(1, 1000) { - feat = g.GenerateArg(typ.Fields[2], &calls) - mask = g.GenerateArg(typ.Fields[3], &calls) - } - algType, algName := generateAlgName(g.Rand()) - // Extend/truncate type/name to their fixed sizes. - typeSize := typ.Fields[1].Size() - algTypeData := append([]byte(algType), make([]byte, typeSize)...)[:typeSize] - nameSize := typ.Fields[4].Size() - algNameData := append([]byte(algName), make([]byte, nameSize)...)[:nameSize] - arg = prog.MakeGroupArg(typ, []prog.Arg{ - family, - prog.MakeDataArg(typ.Fields[1], algTypeData), - feat, - mask, - prog.MakeDataArg(typ.Fields[4], algNameData), - }) - return -} - -func generateAlgName(rnd *rand.Rand) (string, string) { - typ := allTypes[rnd.Intn(len(allTypes))] - name := generateAlg(rnd, typ.typ) - return typ.name, name -} - -func generateAlg(rnd *rand.Rand, typ int) string { - algs := allAlgs[typ] - alg := algs[rnd.Intn(len(algs))] - return generateAlgImpl(rnd, alg) -} - -func generateAlgImpl(rnd *rand.Rand, alg algDesc) string { - args := "" - if len(alg.args) != 0 { - args += "(" - for i, a := range alg.args { - if i != 0 { - args += "," - } - args += generateAlg(rnd, a) - } - args += ")" - } - return alg.name + args -} - -type algType struct { - name string - typ int -} - -type algDesc struct { - name string - args []int -} - -const ( - ALG_CIPHER = iota - ALG_BLKCIPHER - ALG_AEAD - ALG_HASH - ALG_RNG -) - -var allTypes = []algType{ - {"aead", ALG_AEAD}, - {"skcipher", ALG_BLKCIPHER}, - {"hash", ALG_HASH}, - {"rng", ALG_RNG}, -} - -var allAlgs = map[int][]algDesc{ - ALG_AEAD: []algDesc{ - // templates: - {"authencesn", []int{ALG_HASH, ALG_BLKCIPHER}}, - {"authenc", []int{ALG_HASH, ALG_BLKCIPHER}}, - {"rfc7539esp", []int{ALG_BLKCIPHER, ALG_HASH}}, - {"rfc7539", []int{ALG_BLKCIPHER, ALG_HASH}}, - {"rfc4543", []int{ALG_AEAD}}, - {"rfc4106", []int{ALG_AEAD}}, - {"pcrypt", []int{ALG_AEAD}}, - {"rfc4309", []int{ALG_AEAD}}, - {"gcm", []int{ALG_CIPHER}}, - {"gcm_base", []int{ALG_BLKCIPHER, ALG_HASH}}, - {"ccm", []int{ALG_CIPHER}}, - {"ccm_base", []int{ALG_BLKCIPHER, ALG_HASH}}, - {"echainiv", []int{ALG_AEAD}}, - {"seqiv", []int{ALG_AEAD}}, - - // algorithms: - {"gcm(aes)", nil}, - {"gcm_base(ctr(aes-aesni),ghash-generic)", nil}, - {"generic-gcm-aesni", nil}, - {"rfc4106(gcm(aes))", nil}, - {"rfc4106-gcm-aesni", nil}, - {"__gcm-aes-aesni", nil}, - {"__driver-gcm-aes-aesni", nil}, - }, - ALG_BLKCIPHER: []algDesc{ - // templates: - {"pcbc", []int{ALG_CIPHER}}, - {"cbc", []int{ALG_CIPHER}}, - {"xts", []int{ALG_CIPHER}}, - {"ctr", []int{ALG_CIPHER}}, - {"lrw", []int{ALG_CIPHER}}, - {"ecb", []int{ALG_CIPHER}}, - {"kw", []int{ALG_CIPHER}}, - {"cts", []int{ALG_BLKCIPHER}}, - {"fpu", []int{ALG_BLKCIPHER}}, - {"xts", []int{ALG_BLKCIPHER}}, - {"lrw", []int{ALG_BLKCIPHER}}, - {"rfc3686", []int{ALG_BLKCIPHER}}, - {"cryptd", []int{ALG_BLKCIPHER}}, - - // algorithms: - {"cbc(aes)", nil}, - {"cbc(aes-aesni)", nil}, - {"chacha20", nil}, - {"chacha20-simd", nil}, - {"pcbc(aes)", nil}, - {"pcbc-aes-aesni", nil}, - {"fpu(pcbc(__aes))", nil}, - {"fpu(pcbc(__aes-aesni))", nil}, - {"pcbc(__aes)", nil}, - {"pcbc(__aes-aesni)", nil}, - {"xts(aes)", nil}, - {"xts-aes-aesni", nil}, - {"ctr(aes)", nil}, - {"ctr-aes-aesni", nil}, - {"cbc-aes-aesni", nil}, - {"ecb(aes)", nil}, - {"ecb-aes-aesni", nil}, - {"__xts(aes)", nil}, - {"__xts-aes-aesni", nil}, - {"__ctr(aes)", nil}, - {"__ctr-aes-aesni", nil}, - {"__cbc(aes)", nil}, - {"__cbc-aes-aesni", nil}, - {"__ecb(aes)", nil}, - {"__ecb-aes-aesni", nil}, - {"chacha20-generic", nil}, - {"xts(serpent)", nil}, - {"xts-serpent-avx2", nil}, - {"lrw(serpent)", nil}, - {"lrw-serpent-avx2", nil}, - {"ctr(serpent)", nil}, - {"ctr-serpent-avx2", nil}, - {"cbc(serpent)", nil}, - {"cbc-serpent-avx2", nil}, - {"ecb(serpent)", nil}, - {"ecb-serpent-avx2", nil}, - {"xts(camellia)", nil}, - {"xts-camellia-aesni-avx2", nil}, - {"lrw(camellia)", nil}, - {"lrw-camellia-aesni-avx2", nil}, - {"ctr(camellia)", nil}, - {"ctr-camellia-aesni-avx2", nil}, - {"cbc(camellia)", nil}, - {"cbc-camellia-aesni-avx2", nil}, - {"ecb(camellia)", nil}, - {"ecb-camellia-aesni-avx2", nil}, - {"xts-serpent-avx", nil}, - {"lrw-serpent-avx", nil}, - {"ctr-serpent-avx", nil}, - {"cbc-serpent-avx", nil}, - {"ecb-serpent-avx", nil}, - {"xts(twofish)", nil}, - {"xts-twofish-avx", nil}, - {"lrw(twofish)", nil}, - {"lrw-twofish-avx", nil}, - {"ctr(twofish)", nil}, - {"ctr-twofish-avx", nil}, - {"cbc(twofish)", nil}, - {"cbc-twofish-avx", nil}, - {"ecb(twofish)", nil}, - {"ecb-twofish-avx", nil}, - {"xts(cast6)", nil}, - {"xts-cast6-avx", nil}, - {"lrw(cast6)", nil}, - {"lrw-cast6-avx", nil}, - {"ctr(cast6)", nil}, - {"ctr-cast6-avx", nil}, - {"cbc(cast6)", nil}, - {"cbc-cast6-avx", nil}, - {"ecb(cast6)", nil}, - {"ecb-cast6-avx", nil}, - {"ctr(cast5)", nil}, - {"ctr-cast5-avx", nil}, - {"cbc(cast5)", nil}, - {"cbc-cast5-avx", nil}, - {"ecb(cast5)", nil}, - {"ecb-cast5-avx", nil}, - {"xts-camellia-aesni", nil}, - {"lrw-camellia-aesni", nil}, - {"ctr-camellia-aesni", nil}, - {"cbc-camellia-aesni", nil}, - {"ecb-camellia-aesni", nil}, - {"xts-serpent-sse2", nil}, - {"lrw-serpent-sse2", nil}, - {"ctr-serpent-sse2", nil}, - {"cbc-serpent-sse2", nil}, - {"ecb-serpent-sse2", nil}, - {"ctr(aes-aesni)", nil}, - {"salsa20", nil}, - {"salsa20-generic", nil}, - {"ecb(arc4)", nil}, - {"ecb(arc4)-generic", nil}, - {"ecb(cipher_null)", nil}, - {"ecb-cipher_null", nil}, - {"__xts-serpent-avx2", nil}, - {"__driver-xts-serpent-avx2", nil}, - {"__lrw-serpent-avx2", nil}, - {"__driver-lrw-serpent-avx2", nil}, - {"__ctr-serpent-avx2", nil}, - {"__driver-ctr-serpent-avx2", nil}, - {"__cbc-serpent-avx2", nil}, - {"__driver-cbc-serpent-avx2", nil}, - {"__ecb-serpent-avx2", nil}, - {"__driver-ecb-serpent-avx2", nil}, - {"__xts-camellia-aesni-avx2", nil}, - {"__driver-xts-camellia-aesni-avx2", nil}, - {"__lrw-camellia-aesni-avx2", nil}, - {"__driver-lrw-camellia-aesni-avx2", nil}, - {"__ctr-camellia-aesni-avx2", nil}, - {"__driver-ctr-camellia-aesni-avx2", nil}, - {"__cbc-camellia-aesni-avx2", nil}, - {"__driver-cbc-camellia-aesni-avx2", nil}, - {"__ecb-camellia-aesni-avx2", nil}, - {"__driver-ecb-camellia-aesni-avx2", nil}, - {"__xts-serpent-avx", nil}, - {"__driver-xts-serpent-avx", nil}, - {"__lrw-serpent-avx", nil}, - {"__driver-lrw-serpent-avx", nil}, - {"__ctr-serpent-avx", nil}, - {"__driver-ctr-serpent-avx", nil}, - {"__cbc-serpent-avx", nil}, - {"__driver-cbc-serpent-avx", nil}, - {"__ecb-serpent-avx", nil}, - {"__driver-ecb-serpent-avx", nil}, - {"__xts-twofish-avx", nil}, - {"__driver-xts-twofish-avx", nil}, - {"__lrw-twofish-avx", nil}, - {"__driver-lrw-twofish-avx", nil}, - {"__ctr-twofish-avx", nil}, - {"__driver-ctr-twofish-avx", nil}, - {"__cbc-twofish-avx", nil}, - {"__driver-cbc-twofish-avx", nil}, - {"__ecb-twofish-avx", nil}, - {"__driver-ecb-twofish-avx", nil}, - {"__xts-cast6-avx", nil}, - {"__driver-xts-cast6-avx", nil}, - {"__lrw-cast6-avx", nil}, - {"__driver-lrw-cast6-avx", nil}, - {"__ctr-cast6-avx", nil}, - {"__driver-ctr-cast6-avx", nil}, - {"__cbc-cast6-avx", nil}, - {"__driver-cbc-cast6-avx", nil}, - {"__ecb-cast6-avx", nil}, - {"__driver-ecb-cast6-avx", nil}, - {"__ctr-cast5-avx", nil}, - {"__driver-ctr-cast5-avx", nil}, - {"__cbc-cast5-avx", nil}, - {"__driver-cbc-cast5-avx", nil}, - {"__ecb-cast5-avx", nil}, - {"__driver-ecb-cast5-avx", nil}, - {"__xts-camellia-aesni", nil}, - {"__driver-xts-camellia-aesni", nil}, - {"__lrw-camellia-aesni", nil}, - {"__driver-lrw-camellia-aesni", nil}, - {"__ctr-camellia-aesni", nil}, - {"__driver-ctr-camellia-aesni", nil}, - {"__cbc-camellia-aesni", nil}, - {"__driver-cbc-camellia-aesni", nil}, - {"__ecb-camellia-aesni", nil}, - {"__driver-ecb-camellia-aesni", nil}, - {"__xts-serpent-sse2", nil}, - {"__driver-xts-serpent-sse2", nil}, - {"__lrw-serpent-sse2", nil}, - {"__driver-lrw-serpent-sse2", nil}, - {"__ctr-serpent-sse2", nil}, - {"__driver-ctr-serpent-sse2", nil}, - {"__cbc-serpent-sse2", nil}, - {"__driver-cbc-serpent-sse2", nil}, - {"__ecb-serpent-sse2", nil}, - {"__driver-ecb-serpent-sse2", nil}, - {"salsa20-asm", nil}, - {"xts-twofish-3way", nil}, - {"lrw-twofish-3way", nil}, - {"ctr-twofish-3way", nil}, - {"cbc-twofish-3way", nil}, - {"ecb-twofish-3way", nil}, - {"ctr(blowfish)", nil}, - {"ctr-blowfish-asm", nil}, - {"cbc(blowfish)", nil}, - {"cbc-blowfish-asm", nil}, - {"ecb(blowfish)", nil}, - {"ecb-blowfish-asm", nil}, - {"xts-camellia-asm", nil}, - {"lrw-camellia-asm", nil}, - {"ctr-camellia-asm", nil}, - {"cbc-camellia-asm", nil}, - {"ecb-camellia-asm", nil}, - {"ctr(des3_ede)", nil}, - {"ctr-des3_ede-asm", nil}, - {"cbc(des3_ede)", nil}, - {"cbc-des3_ede-asm", nil}, - {"ecb(des3_ede)", nil}, - {"ecb-des3_ede-asm", nil}, - }, - ALG_CIPHER: []algDesc{ - {"aes", nil}, - {"__aes", nil}, - {"__aes-aesni", nil}, - {"aes-aesni", nil}, - {"seed", nil}, - {"seed-generic", nil}, - {"anubis", nil}, - {"anubis-generic", nil}, - {"khazad", nil}, - {"khazad-generic", nil}, - {"xeta", nil}, - {"xeta-generic", nil}, - {"xtea", nil}, - {"xtea-generic", nil}, - {"tea", nil}, - {"tea-generic", nil}, - {"arc4", nil}, - {"arc4-generic", nil}, - {"cast6", nil}, - {"cast6-generic", nil}, - {"cast5", nil}, - {"cast5-generic", nil}, - {"camellia", nil}, - {"camellia-generic", nil}, - {"camellia-asm", nil}, - {"tnepres", nil}, - {"aes-fixed-time", nil}, - {"aes-generic", nil}, - {"tnepres-generic", nil}, - {"serpent", nil}, - {"serpent-generic", nil}, - {"twofish", nil}, - {"twofish-generic", nil}, - {"twofish-asm", nil}, - {"blowfish", nil}, - {"blowfish-generic", nil}, - {"blowfish-asm", nil}, - {"fcrypt", nil}, - {"fcrypt-generic", nil}, - {"des3_ede", nil}, - {"des3_ede-generic", nil}, - {"des3_ede-asm", nil}, - {"des", nil}, - {"des-generic", nil}, - {"cipher_null", nil}, - {"cipher_null-generic", nil}, - {"aes-asm", nil}, - }, - ALG_HASH: []algDesc{ - // templates: - {"cmac", []int{ALG_CIPHER}}, - {"cbcmac", []int{ALG_CIPHER}}, - {"xcbc", []int{ALG_CIPHER}}, - {"vmac", []int{ALG_CIPHER}}, - {"hmac", []int{ALG_HASH}}, - {"mcryptd", []int{ALG_HASH}}, - {"cryptd", []int{ALG_HASH}}, - - // algorithms: - {"sha512", nil}, - {"sha512_mb", nil}, - {"__sha512-mb", nil}, - {"__intel_sha512-mb", nil}, - {"sha256", nil}, - {"sha256_mb", nil}, - {"__sha256-mb", nil}, - {"__intel_sha256-mb", nil}, - {"sha1", nil}, - {"sha1_mb", nil}, - {"__sha1-mb", nil}, - {"__intel_sha1-mb", nil}, - {"ghash", nil}, - {"ghash-clmulni", nil}, - {"md4", nil}, - {"md4-generic", nil}, - {"md5", nil}, - {"md5-generic", nil}, - {"ghash-generic", nil}, - {"crct10dif", nil}, - {"crct10dif-generic", nil}, - {"crct10dif-pclmul", nil}, - {"crc32", nil}, - {"crc32-generic", nil}, - {"crc32c", nil}, - {"crc32c-generic", nil}, - {"michael_mic", nil}, - {"michael_mic-generic", nil}, - {"poly1305", nil}, - {"poly1305-generic", nil}, - {"tgr128", nil}, - {"tgr128-generic", nil}, - {"tgr160", nil}, - {"tgr160-generic", nil}, - {"tgr192", nil}, - {"tgr192-generic", nil}, - {"wp256", nil}, - {"wp256-generic", nil}, - {"wp384", nil}, - {"wp384-generic", nil}, - {"wp512", nil}, - {"wp512-generic", nil}, - {"sm3", nil}, - {"sm3-generic", nil}, - {"sha3-512", nil}, - {"sha3-512-generic", nil}, - {"sha3-384", nil}, - {"sha3-384-generic", nil}, - {"sha3-256", nil}, - {"sha3-256-generic", nil}, - {"sha3-224", nil}, - {"sha3-224-generic", nil}, - {"sha384", nil}, - {"sha384-generic", nil}, - {"sha512-generic", nil}, - {"sha224", nil}, - {"sha224-generic", nil}, - {"sha256-generic", nil}, - {"sha1-generic", nil}, - {"rmd320", nil}, - {"rmd320-generic", nil}, - {"rmd256", nil}, - {"rmd256-generic", nil}, - {"rmd160", nil}, - {"rmd160-generic", nil}, - {"rmd128", nil}, - {"rmd128-generic", nil}, - {"digest_null", nil}, - {"digest_null-generic", nil}, - {"poly1305-simd", nil}, - {"sha384-avx2", nil}, - {"sha512-avx2", nil}, - {"sha384-avx", nil}, - {"sha512-avx", nil}, - {"sha384-ssse3", nil}, - {"sha512-ssse3", nil}, - {"sha224-avx2", nil}, - {"sha256-avx2", nil}, - {"sha224-avx", nil}, - {"sha256-avx", nil}, - {"sha224-ssse3", nil}, - {"sha256-ssse3", nil}, - {"crc32-pclmul", nil}, - {"sha1-avx2", nil}, - {"sha1-avx", nil}, - {"sha1-ssse3", nil}, - {"crc32c-intel", nil}, - {"__ghash", nil}, - {"__ghash-pclmulqdqni", nil}, - }, - ALG_RNG: []algDesc{ - {"stdrng", nil}, - {"ansi_cprng", nil}, - {"jitterentropy_rng", nil}, - {"drbg_nopr_hmac_sha256", nil}, - {"drbg_nopr_hmac_sha512", nil}, - {"drbg_nopr_hmac_sha384", nil}, - {"drbg_nopr_hmac_sha1", nil}, - {"drbg_nopr_sha256", nil}, - {"drbg_nopr_sha512", nil}, - {"drbg_nopr_sha384", nil}, - {"drbg_nopr_sha1", nil}, - {"drbg_nopr_ctr_aes256", nil}, - {"drbg_nopr_ctr_aes192", nil}, - {"drbg_nopr_ctr_aes128", nil}, - {"drbg_pr_hmac_sha256", nil}, - {"drbg_pr_hmac_sha512", nil}, - {"drbg_pr_hmac_sha384", nil}, - {"drbg_pr_hmac_sha1", nil}, - {"drbg_pr_sha256", nil}, - {"drbg_pr_sha512", nil}, - {"drbg_pr_sha384", nil}, - {"drbg_pr_sha1", nil}, - {"drbg_pr_ctr_aes256", nil}, - {"drbg_pr_ctr_aes192", nil}, - {"drbg_pr_ctr_aes128", nil}, - }, -} diff --git a/sys/linux/alg_test.go b/sys/linux/alg_test.go deleted file mode 100644 index b3622a6c9..000000000 --- a/sys/linux/alg_test.go +++ /dev/null @@ -1,215 +0,0 @@ -// Copyright 2017 syzkaller project authors. All rights reserved. -// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. - -// +build linux - -package linux - -import ( - "flag" - "fmt" - "math/rand" - "strings" - "syscall" - "testing" - "unsafe" -) - -// AF_ALG tests won't generally pass and intended for manual testing. -// First, they require fresh kernel with _all_ crypto algorithms enabled. -// Second, they require the newest hardware with all of SSE/AVX. -// Finally, they still won't pass because some algorithms are arch-dependent. -var flagRunAlgTests = flag.Bool("algtests", false, "run AF_ALG tests") - -func algTest(t *testing.T) { - if !*flagRunAlgTests { - t.Skip() - } - t.Parallel() -} - -// TestAlgDescriptions checks that there are no duplicate names and that -// templates mentioned in complete algorithms are also present as standalone templates. -func TestAlgDescriptions(t *testing.T) { - algTest(t) - allall := make(map[string]bool) - for typ, algList := range allAlgs { - algs := make(map[string]bool) - templates := make(map[string]bool) - for _, alg := range algList { - allall[alg.name] = true - if algs[alg.name] { - t.Errorf("duplicate: %v", alg.name) - } - algs[alg.name] = true - if len(alg.args) > 0 { - templates[alg.name] = true - } - } - for _, alg := range algList { - if len(alg.args) > 0 || strings.HasPrefix(alg.name, "__") { - continue - } - brace := strings.IndexByte(alg.name, '(') - if brace == -1 { - continue - } - templ := alg.name[:brace] - if !templates[templ] { - t.Errorf("template %v is missing for type %v", templ, typ) - } - templates[templ] = true - } - } -} - -// TestSingleAlg tests creation of all algorithms (not templates). -func TestSingleAlg(t *testing.T) { - algTest(t) - for _, typ := range allTypes { - for _, alg := range allAlgs[typ.typ] { - if len(alg.args) != 0 { - continue - } - ok, skip := testAlg(t, typ.name, alg.name) - if skip { - t.Errorf("SKIP\t%10v\t%v", typ.name, alg.name) - continue - } - if !ok { - t.Errorf("FAIL\t%10v\t%v", typ.name, alg.name) - continue - } - } - } -} - -// TestTemplateAlg1 tests creation of all templates with 1 argument. -func TestTemplateAlg1(t *testing.T) { - algTest(t) - for _, typ := range allTypes { - for _, alg := range allAlgs[typ.typ] { - if len(alg.args) != 1 { - continue - } - var works []int - nextType: - for typ1, algs1 := range allAlgs { - var selection []algDesc - for _, x := range rand.Perm(len(algs1)) { - if len(algs1[x].args) != 0 { - continue - } - selection = append(selection, algs1[x]) - if len(selection) == 10 { - break - } - } - for _, alg1 := range selection { - name := fmt.Sprintf("%v(%v)", alg.name, alg1.name) - ok, _ := testAlg(t, typ.name, name) - if ok { - works = append(works, typ1) - continue nextType - } - } - } - if len(works) == 1 && works[0] == alg.args[0] { - continue - } - t.Errorf("FAIL\t%10v\t%v\tclaimed %v works with %v", - typ.name, alg.name, alg.args[0], works) - } - } -} - -// TestTemplateAlg2 tests creation of all templates with 2 argument. -func TestTemplateAlg2(t *testing.T) { - algTest(t) - // Can't affort to test all permutations of 2 algorithms, - // 20 algorithm pairs for each type pair and use them. - selections := make(map[int][]int) - for typ1, algs1 := range allAlgs { - for typ2, algs2 := range allAlgs { - var pairs []int - for i1, alg1 := range algs1 { - if len(alg1.args) != 0 { - continue - } - for i2, alg2 := range algs2 { - if len(alg2.args) != 0 { - continue - } - pairs = append(pairs, i1*1000+i2) - } - } - var selection []int - for _, x := range rand.Perm(len(pairs)) { - selection = append(selection, pairs[x]) - if len(selection) > 20 { - break - } - } - selections[typ1*1000+typ2] = selection - } - } - for _, typ := range allTypes { - for _, alg := range allAlgs[typ.typ] { - if len(alg.args) != 2 { - continue - } - for typ1, algs1 := range allAlgs { - for typ2, algs2 := range allAlgs { - selection := selections[typ1*1000+typ2] - for _, x := range selection { - alg1 := algs1[x/1000] - alg2 := algs2[x%1000] - name := fmt.Sprintf("%v(%v,%v)", - alg.name, alg1.name, alg2.name) - if ok, _ := testAlg(t, typ.name, name); ok { - t.Logf("%10v\t%v\tclaimed %v works with %v/%v (%v)", - typ.name, alg.name, alg.args, typ1, typ2, name) - break - } - } - } - } - } - } -} - -type sockaddrAlg struct { - family uint16 - typ [14]byte - feat uint32 - mask uint32 - name [64]byte -} - -func testAlg(t *testing.T, typ, name string) (ok, skip bool) { - const AF_ALG = 0x26 - addr := &sockaddrAlg{ - family: AF_ALG, - } - if len(typ) >= int(unsafe.Sizeof(addr.typ)) || - len(name) >= int(unsafe.Sizeof(addr.name)) { - return false, true - } - for i := 0; i < len(typ); i++ { - addr.typ[i] = typ[i] - } - for i := 0; i < len(name); i++ { - addr.name[i] = name[i] - } - sock, err := syscall.Socket(AF_ALG, syscall.SOCK_SEQPACKET, 0) - if err != nil { - t.Fatalf("failed to create AF_ALG socket: %v", err) - } - defer syscall.Close(sock) - _, _, errno := syscall.Syscall(syscall.SYS_BIND, uintptr(sock), - uintptr(unsafe.Pointer(addr)), unsafe.Sizeof(*addr)) - if errno != 0 { - return false, false - } - return true, false -} diff --git a/sys/linux/init_alg.go b/sys/linux/init_alg.go new file mode 100644 index 000000000..581b3b364 --- /dev/null +++ b/sys/linux/init_alg.go @@ -0,0 +1,506 @@ +// Copyright 2017 syzkaller project authors. All rights reserved. +// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. + +package linux + +import ( + "math/rand" + + "github.com/google/syzkaller/prog" +) + +func (arch *arch) generateSockaddrAlg(g *prog.Gen, typ *prog.StructType, old *prog.GroupArg) ( + arg prog.Arg, calls []*prog.Call) { + family := g.GenerateArg(typ.Fields[0], &calls) + // There is very little point in generating feat/mask, + // because that can only fail otherwise correct bind. + feat := prog.MakeConstArg(typ.Fields[2], 0) + mask := prog.MakeConstArg(typ.Fields[3], 0) + if g.NOutOf(1, 1000) { + feat = g.GenerateArg(typ.Fields[2], &calls) + mask = g.GenerateArg(typ.Fields[3], &calls) + } + algType, algName := generateAlgName(g.Rand()) + // Extend/truncate type/name to their fixed sizes. + typeSize := typ.Fields[1].Size() + algTypeData := append([]byte(algType), make([]byte, typeSize)...)[:typeSize] + nameSize := typ.Fields[4].Size() + algNameData := append([]byte(algName), make([]byte, nameSize)...)[:nameSize] + arg = prog.MakeGroupArg(typ, []prog.Arg{ + family, + prog.MakeDataArg(typ.Fields[1], algTypeData), + feat, + mask, + prog.MakeDataArg(typ.Fields[4], algNameData), + }) + return +} + +func generateAlgName(rnd *rand.Rand) (string, string) { + typ := allTypes[rnd.Intn(len(allTypes))] + name := generateAlg(rnd, typ.typ) + return typ.name, name +} + +func generateAlg(rnd *rand.Rand, typ int) string { + algs := allAlgs[typ] + alg := algs[rnd.Intn(len(algs))] + return generateAlgImpl(rnd, alg) +} + +func generateAlgImpl(rnd *rand.Rand, alg algDesc) string { + args := "" + if len(alg.args) != 0 { + args += "(" + for i, a := range alg.args { + if i != 0 { + args += "," + } + args += generateAlg(rnd, a) + } + args += ")" + } + return alg.name + args +} + +type algType struct { + name string + typ int +} + +type algDesc struct { + name string + args []int +} + +const ( + ALG_CIPHER = iota + ALG_BLKCIPHER + ALG_AEAD + ALG_HASH + ALG_RNG +) + +var allTypes = []algType{ + {"aead", ALG_AEAD}, + {"skcipher", ALG_BLKCIPHER}, + {"hash", ALG_HASH}, + {"rng", ALG_RNG}, +} + +var allAlgs = map[int][]algDesc{ + ALG_AEAD: []algDesc{ + // templates: + {"authencesn", []int{ALG_HASH, ALG_BLKCIPHER}}, + {"authenc", []int{ALG_HASH, ALG_BLKCIPHER}}, + {"rfc7539esp", []int{ALG_BLKCIPHER, ALG_HASH}}, + {"rfc7539", []int{ALG_BLKCIPHER, ALG_HASH}}, + {"rfc4543", []int{ALG_AEAD}}, + {"rfc4106", []int{ALG_AEAD}}, + {"pcrypt", []int{ALG_AEAD}}, + {"rfc4309", []int{ALG_AEAD}}, + {"gcm", []int{ALG_CIPHER}}, + {"gcm_base", []int{ALG_BLKCIPHER, ALG_HASH}}, + {"ccm", []int{ALG_CIPHER}}, + {"ccm_base", []int{ALG_BLKCIPHER, ALG_HASH}}, + {"echainiv", []int{ALG_AEAD}}, + {"seqiv", []int{ALG_AEAD}}, + + // algorithms: + {"gcm(aes)", nil}, + {"gcm_base(ctr(aes-aesni),ghash-generic)", nil}, + {"generic-gcm-aesni", nil}, + {"rfc4106(gcm(aes))", nil}, + {"rfc4106-gcm-aesni", nil}, + {"__gcm-aes-aesni", nil}, + {"__driver-gcm-aes-aesni", nil}, + }, + ALG_BLKCIPHER: []algDesc{ + // templates: + {"pcbc", []int{ALG_CIPHER}}, + {"cbc", []int{ALG_CIPHER}}, + {"xts", []int{ALG_CIPHER}}, + {"ctr", []int{ALG_CIPHER}}, + {"lrw", []int{ALG_CIPHER}}, + {"ecb", []int{ALG_CIPHER}}, + {"kw", []int{ALG_CIPHER}}, + {"cts", []int{ALG_BLKCIPHER}}, + {"fpu", []int{ALG_BLKCIPHER}}, + {"xts", []int{ALG_BLKCIPHER}}, + {"lrw", []int{ALG_BLKCIPHER}}, + {"rfc3686", []int{ALG_BLKCIPHER}}, + {"cryptd", []int{ALG_BLKCIPHER}}, + + // algorithms: + {"cbc(aes)", nil}, + {"cbc(aes-aesni)", nil}, + {"chacha20", nil}, + {"chacha20-simd", nil}, + {"pcbc(aes)", nil}, + {"pcbc-aes-aesni", nil}, + {"fpu(pcbc(__aes))", nil}, + {"fpu(pcbc(__aes-aesni))", nil}, + {"pcbc(__aes)", nil}, + {"pcbc(__aes-aesni)", nil}, + {"xts(aes)", nil}, + {"xts-aes-aesni", nil}, + {"ctr(aes)", nil}, + {"ctr-aes-aesni", nil}, + {"cbc-aes-aesni", nil}, + {"ecb(aes)", nil}, + {"ecb-aes-aesni", nil}, + {"__xts(aes)", nil}, + {"__xts-aes-aesni", nil}, + {"__ctr(aes)", nil}, + {"__ctr-aes-aesni", nil}, + {"__cbc(aes)", nil}, + {"__cbc-aes-aesni", nil}, + {"__ecb(aes)", nil}, + {"__ecb-aes-aesni", nil}, + {"chacha20-generic", nil}, + {"xts(serpent)", nil}, + {"xts-serpent-avx2", nil}, + {"lrw(serpent)", nil}, + {"lrw-serpent-avx2", nil}, + {"ctr(serpent)", nil}, + {"ctr-serpent-avx2", nil}, + {"cbc(serpent)", nil}, + {"cbc-serpent-avx2", nil}, + {"ecb(serpent)", nil}, + {"ecb-serpent-avx2", nil}, + {"xts(camellia)", nil}, + {"xts-camellia-aesni-avx2", nil}, + {"lrw(camellia)", nil}, + {"lrw-camellia-aesni-avx2", nil}, + {"ctr(camellia)", nil}, + {"ctr-camellia-aesni-avx2", nil}, + {"cbc(camellia)", nil}, + {"cbc-camellia-aesni-avx2", nil}, + {"ecb(camellia)", nil}, + {"ecb-camellia-aesni-avx2", nil}, + {"xts-serpent-avx", nil}, + {"lrw-serpent-avx", nil}, + {"ctr-serpent-avx", nil}, + {"cbc-serpent-avx", nil}, + {"ecb-serpent-avx", nil}, + {"xts(twofish)", nil}, + {"xts-twofish-avx", nil}, + {"lrw(twofish)", nil}, + {"lrw-twofish-avx", nil}, + {"ctr(twofish)", nil}, + {"ctr-twofish-avx", nil}, + {"cbc(twofish)", nil}, + {"cbc-twofish-avx", nil}, + {"ecb(twofish)", nil}, + {"ecb-twofish-avx", nil}, + {"xts(cast6)", nil}, + {"xts-cast6-avx", nil}, + {"lrw(cast6)", nil}, + {"lrw-cast6-avx", nil}, + {"ctr(cast6)", nil}, + {"ctr-cast6-avx", nil}, + {"cbc(cast6)", nil}, + {"cbc-cast6-avx", nil}, + {"ecb(cast6)", nil}, + {"ecb-cast6-avx", nil}, + {"ctr(cast5)", nil}, + {"ctr-cast5-avx", nil}, + {"cbc(cast5)", nil}, + {"cbc-cast5-avx", nil}, + {"ecb(cast5)", nil}, + {"ecb-cast5-avx", nil}, + {"xts-camellia-aesni", nil}, + {"lrw-camellia-aesni", nil}, + {"ctr-camellia-aesni", nil}, + {"cbc-camellia-aesni", nil}, + {"ecb-camellia-aesni", nil}, + {"xts-serpent-sse2", nil}, + {"lrw-serpent-sse2", nil}, + {"ctr-serpent-sse2", nil}, + {"cbc-serpent-sse2", nil}, + {"ecb-serpent-sse2", nil}, + {"ctr(aes-aesni)", nil}, + {"salsa20", nil}, + {"salsa20-generic", nil}, + {"ecb(arc4)", nil}, + {"ecb(arc4)-generic", nil}, + {"ecb(cipher_null)", nil}, + {"ecb-cipher_null", nil}, + {"__xts-serpent-avx2", nil}, + {"__driver-xts-serpent-avx2", nil}, + {"__lrw-serpent-avx2", nil}, + {"__driver-lrw-serpent-avx2", nil}, + {"__ctr-serpent-avx2", nil}, + {"__driver-ctr-serpent-avx2", nil}, + {"__cbc-serpent-avx2", nil}, + {"__driver-cbc-serpent-avx2", nil}, + {"__ecb-serpent-avx2", nil}, + {"__driver-ecb-serpent-avx2", nil}, + {"__xts-camellia-aesni-avx2", nil}, + {"__driver-xts-camellia-aesni-avx2", nil}, + {"__lrw-camellia-aesni-avx2", nil}, + {"__driver-lrw-camellia-aesni-avx2", nil}, + {"__ctr-camellia-aesni-avx2", nil}, + {"__driver-ctr-camellia-aesni-avx2", nil}, + {"__cbc-camellia-aesni-avx2", nil}, + {"__driver-cbc-camellia-aesni-avx2", nil}, + {"__ecb-camellia-aesni-avx2", nil}, + {"__driver-ecb-camellia-aesni-avx2", nil}, + {"__xts-serpent-avx", nil}, + {"__driver-xts-serpent-avx", nil}, + {"__lrw-serpent-avx", nil}, + {"__driver-lrw-serpent-avx", nil}, + {"__ctr-serpent-avx", nil}, + {"__driver-ctr-serpent-avx", nil}, + {"__cbc-serpent-avx", nil}, + {"__driver-cbc-serpent-avx", nil}, + {"__ecb-serpent-avx", nil}, + {"__driver-ecb-serpent-avx", nil}, + {"__xts-twofish-avx", nil}, + {"__driver-xts-twofish-avx", nil}, + {"__lrw-twofish-avx", nil}, + {"__driver-lrw-twofish-avx", nil}, + {"__ctr-twofish-avx", nil}, + {"__driver-ctr-twofish-avx", nil}, + {"__cbc-twofish-avx", nil}, + {"__driver-cbc-twofish-avx", nil}, + {"__ecb-twofish-avx", nil}, + {"__driver-ecb-twofish-avx", nil}, + {"__xts-cast6-avx", nil}, + {"__driver-xts-cast6-avx", nil}, + {"__lrw-cast6-avx", nil}, + {"__driver-lrw-cast6-avx", nil}, + {"__ctr-cast6-avx", nil}, + {"__driver-ctr-cast6-avx", nil}, + {"__cbc-cast6-avx", nil}, + {"__driver-cbc-cast6-avx", nil}, + {"__ecb-cast6-avx", nil}, + {"__driver-ecb-cast6-avx", nil}, + {"__ctr-cast5-avx", nil}, + {"__driver-ctr-cast5-avx", nil}, + {"__cbc-cast5-avx", nil}, + {"__driver-cbc-cast5-avx", nil}, + {"__ecb-cast5-avx", nil}, + {"__driver-ecb-cast5-avx", nil}, + {"__xts-camellia-aesni", nil}, + {"__driver-xts-camellia-aesni", nil}, + {"__lrw-camellia-aesni", nil}, + {"__driver-lrw-camellia-aesni", nil}, + {"__ctr-camellia-aesni", nil}, + {"__driver-ctr-camellia-aesni", nil}, + {"__cbc-camellia-aesni", nil}, + {"__driver-cbc-camellia-aesni", nil}, + {"__ecb-camellia-aesni", nil}, + {"__driver-ecb-camellia-aesni", nil}, + {"__xts-serpent-sse2", nil}, + {"__driver-xts-serpent-sse2", nil}, + {"__lrw-serpent-sse2", nil}, + {"__driver-lrw-serpent-sse2", nil}, + {"__ctr-serpent-sse2", nil}, + {"__driver-ctr-serpent-sse2", nil}, + {"__cbc-serpent-sse2", nil}, + {"__driver-cbc-serpent-sse2", nil}, + {"__ecb-serpent-sse2", nil}, + {"__driver-ecb-serpent-sse2", nil}, + {"salsa20-asm", nil}, + {"xts-twofish-3way", nil}, + {"lrw-twofish-3way", nil}, + {"ctr-twofish-3way", nil}, + {"cbc-twofish-3way", nil}, + {"ecb-twofish-3way", nil}, + {"ctr(blowfish)", nil}, + {"ctr-blowfish-asm", nil}, + {"cbc(blowfish)", nil}, + {"cbc-blowfish-asm", nil}, + {"ecb(blowfish)", nil}, + {"ecb-blowfish-asm", nil}, + {"xts-camellia-asm", nil}, + {"lrw-camellia-asm", nil}, + {"ctr-camellia-asm", nil}, + {"cbc-camellia-asm", nil}, + {"ecb-camellia-asm", nil}, + {"ctr(des3_ede)", nil}, + {"ctr-des3_ede-asm", nil}, + {"cbc(des3_ede)", nil}, + {"cbc-des3_ede-asm", nil}, + {"ecb(des3_ede)", nil}, + {"ecb-des3_ede-asm", nil}, + }, + ALG_CIPHER: []algDesc{ + {"aes", nil}, + {"__aes", nil}, + {"__aes-aesni", nil}, + {"aes-aesni", nil}, + {"seed", nil}, + {"seed-generic", nil}, + {"anubis", nil}, + {"anubis-generic", nil}, + {"khazad", nil}, + {"khazad-generic", nil}, + {"xeta", nil}, + {"xeta-generic", nil}, + {"xtea", nil}, + {"xtea-generic", nil}, + {"tea", nil}, + {"tea-generic", nil}, + {"arc4", nil}, + {"arc4-generic", nil}, + {"cast6", nil}, + {"cast6-generic", nil}, + {"cast5", nil}, + {"cast5-generic", nil}, + {"camellia", nil}, + {"camellia-generic", nil}, + {"camellia-asm", nil}, + {"tnepres", nil}, + {"aes-fixed-time", nil}, + {"aes-generic", nil}, + {"tnepres-generic", nil}, + {"serpent", nil}, + {"serpent-generic", nil}, + {"twofish", nil}, + {"twofish-generic", nil}, + {"twofish-asm", nil}, + {"blowfish", nil}, + {"blowfish-generic", nil}, + {"blowfish-asm", nil}, + {"fcrypt", nil}, + {"fcrypt-generic", nil}, + {"des3_ede", nil}, + {"des3_ede-generic", nil}, + {"des3_ede-asm", nil}, + {"des", nil}, + {"des-generic", nil}, + {"cipher_null", nil}, + {"cipher_null-generic", nil}, + {"aes-asm", nil}, + }, + ALG_HASH: []algDesc{ + // templates: + {"cmac", []int{ALG_CIPHER}}, + {"cbcmac", []int{ALG_CIPHER}}, + {"xcbc", []int{ALG_CIPHER}}, + {"vmac", []int{ALG_CIPHER}}, + {"hmac", []int{ALG_HASH}}, + {"mcryptd", []int{ALG_HASH}}, + {"cryptd", []int{ALG_HASH}}, + + // algorithms: + {"sha512", nil}, + {"sha512_mb", nil}, + {"__sha512-mb", nil}, + {"__intel_sha512-mb", nil}, + {"sha256", nil}, + {"sha256_mb", nil}, + {"__sha256-mb", nil}, + {"__intel_sha256-mb", nil}, + {"sha1", nil}, + {"sha1_mb", nil}, + {"__sha1-mb", nil}, + {"__intel_sha1-mb", nil}, + {"ghash", nil}, + {"ghash-clmulni", nil}, + {"md4", nil}, + {"md4-generic", nil}, + {"md5", nil}, + {"md5-generic", nil}, + {"ghash-generic", nil}, + {"crct10dif", nil}, + {"crct10dif-generic", nil}, + {"crct10dif-pclmul", nil}, + {"crc32", nil}, + {"crc32-generic", nil}, + {"crc32c", nil}, + {"crc32c-generic", nil}, + {"michael_mic", nil}, + {"michael_mic-generic", nil}, + {"poly1305", nil}, + {"poly1305-generic", nil}, + {"tgr128", nil}, + {"tgr128-generic", nil}, + {"tgr160", nil}, + {"tgr160-generic", nil}, + {"tgr192", nil}, + {"tgr192-generic", nil}, + {"wp256", nil}, + {"wp256-generic", nil}, + {"wp384", nil}, + {"wp384-generic", nil}, + {"wp512", nil}, + {"wp512-generic", nil}, + {"sm3", nil}, + {"sm3-generic", nil}, + {"sha3-512", nil}, + {"sha3-512-generic", nil}, + {"sha3-384", nil}, + {"sha3-384-generic", nil}, + {"sha3-256", nil}, + {"sha3-256-generic", nil}, + {"sha3-224", nil}, + {"sha3-224-generic", nil}, + {"sha384", nil}, + {"sha384-generic", nil}, + {"sha512-generic", nil}, + {"sha224", nil}, + {"sha224-generic", nil}, + {"sha256-generic", nil}, + {"sha1-generic", nil}, + {"rmd320", nil}, + {"rmd320-generic", nil}, + {"rmd256", nil}, + {"rmd256-generic", nil}, + {"rmd160", nil}, + {"rmd160-generic", nil}, + {"rmd128", nil}, + {"rmd128-generic", nil}, + {"digest_null", nil}, + {"digest_null-generic", nil}, + {"poly1305-simd", nil}, + {"sha384-avx2", nil}, + {"sha512-avx2", nil}, + {"sha384-avx", nil}, + {"sha512-avx", nil}, + {"sha384-ssse3", nil}, + {"sha512-ssse3", nil}, + {"sha224-avx2", nil}, + {"sha256-avx2", nil}, + {"sha224-avx", nil}, + {"sha256-avx", nil}, + {"sha224-ssse3", nil}, + {"sha256-ssse3", nil}, + {"crc32-pclmul", nil}, + {"sha1-avx2", nil}, + {"sha1-avx", nil}, + {"sha1-ssse3", nil}, + {"crc32c-intel", nil}, + {"__ghash", nil}, + {"__ghash-pclmulqdqni", nil}, + }, + ALG_RNG: []algDesc{ + {"stdrng", nil}, + {"ansi_cprng", nil}, + {"jitterentropy_rng", nil}, + {"drbg_nopr_hmac_sha256", nil}, + {"drbg_nopr_hmac_sha512", nil}, + {"drbg_nopr_hmac_sha384", nil}, + {"drbg_nopr_hmac_sha1", nil}, + {"drbg_nopr_sha256", nil}, + {"drbg_nopr_sha512", nil}, + {"drbg_nopr_sha384", nil}, + {"drbg_nopr_sha1", nil}, + {"drbg_nopr_ctr_aes256", nil}, + {"drbg_nopr_ctr_aes192", nil}, + {"drbg_nopr_ctr_aes128", nil}, + {"drbg_pr_hmac_sha256", nil}, + {"drbg_pr_hmac_sha512", nil}, + {"drbg_pr_hmac_sha384", nil}, + {"drbg_pr_hmac_sha1", nil}, + {"drbg_pr_sha256", nil}, + {"drbg_pr_sha512", nil}, + {"drbg_pr_sha384", nil}, + {"drbg_pr_sha1", nil}, + {"drbg_pr_ctr_aes256", nil}, + {"drbg_pr_ctr_aes192", nil}, + {"drbg_pr_ctr_aes128", nil}, + }, +} diff --git a/sys/linux/init_alg_test.go b/sys/linux/init_alg_test.go new file mode 100644 index 000000000..b3622a6c9 --- /dev/null +++ b/sys/linux/init_alg_test.go @@ -0,0 +1,215 @@ +// Copyright 2017 syzkaller project authors. All rights reserved. +// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. + +// +build linux + +package linux + +import ( + "flag" + "fmt" + "math/rand" + "strings" + "syscall" + "testing" + "unsafe" +) + +// AF_ALG tests won't generally pass and intended for manual testing. +// First, they require fresh kernel with _all_ crypto algorithms enabled. +// Second, they require the newest hardware with all of SSE/AVX. +// Finally, they still won't pass because some algorithms are arch-dependent. +var flagRunAlgTests = flag.Bool("algtests", false, "run AF_ALG tests") + +func algTest(t *testing.T) { + if !*flagRunAlgTests { + t.Skip() + } + t.Parallel() +} + +// TestAlgDescriptions checks that there are no duplicate names and that +// templates mentioned in complete algorithms are also present as standalone templates. +func TestAlgDescriptions(t *testing.T) { + algTest(t) + allall := make(map[string]bool) + for typ, algList := range allAlgs { + algs := make(map[string]bool) + templates := make(map[string]bool) + for _, alg := range algList { + allall[alg.name] = true + if algs[alg.name] { + t.Errorf("duplicate: %v", alg.name) + } + algs[alg.name] = true + if len(alg.args) > 0 { + templates[alg.name] = true + } + } + for _, alg := range algList { + if len(alg.args) > 0 || strings.HasPrefix(alg.name, "__") { + continue + } + brace := strings.IndexByte(alg.name, '(') + if brace == -1 { + continue + } + templ := alg.name[:brace] + if !templates[templ] { + t.Errorf("template %v is missing for type %v", templ, typ) + } + templates[templ] = true + } + } +} + +// TestSingleAlg tests creation of all algorithms (not templates). +func TestSingleAlg(t *testing.T) { + algTest(t) + for _, typ := range allTypes { + for _, alg := range allAlgs[typ.typ] { + if len(alg.args) != 0 { + continue + } + ok, skip := testAlg(t, typ.name, alg.name) + if skip { + t.Errorf("SKIP\t%10v\t%v", typ.name, alg.name) + continue + } + if !ok { + t.Errorf("FAIL\t%10v\t%v", typ.name, alg.name) + continue + } + } + } +} + +// TestTemplateAlg1 tests creation of all templates with 1 argument. +func TestTemplateAlg1(t *testing.T) { + algTest(t) + for _, typ := range allTypes { + for _, alg := range allAlgs[typ.typ] { + if len(alg.args) != 1 { + continue + } + var works []int + nextType: + for typ1, algs1 := range allAlgs { + var selection []algDesc + for _, x := range rand.Perm(len(algs1)) { + if len(algs1[x].args) != 0 { + continue + } + selection = append(selection, algs1[x]) + if len(selection) == 10 { + break + } + } + for _, alg1 := range selection { + name := fmt.Sprintf("%v(%v)", alg.name, alg1.name) + ok, _ := testAlg(t, typ.name, name) + if ok { + works = append(works, typ1) + continue nextType + } + } + } + if len(works) == 1 && works[0] == alg.args[0] { + continue + } + t.Errorf("FAIL\t%10v\t%v\tclaimed %v works with %v", + typ.name, alg.name, alg.args[0], works) + } + } +} + +// TestTemplateAlg2 tests creation of all templates with 2 argument. +func TestTemplateAlg2(t *testing.T) { + algTest(t) + // Can't affort to test all permutations of 2 algorithms, + // 20 algorithm pairs for each type pair and use them. + selections := make(map[int][]int) + for typ1, algs1 := range allAlgs { + for typ2, algs2 := range allAlgs { + var pairs []int + for i1, alg1 := range algs1 { + if len(alg1.args) != 0 { + continue + } + for i2, alg2 := range algs2 { + if len(alg2.args) != 0 { + continue + } + pairs = append(pairs, i1*1000+i2) + } + } + var selection []int + for _, x := range rand.Perm(len(pairs)) { + selection = append(selection, pairs[x]) + if len(selection) > 20 { + break + } + } + selections[typ1*1000+typ2] = selection + } + } + for _, typ := range allTypes { + for _, alg := range allAlgs[typ.typ] { + if len(alg.args) != 2 { + continue + } + for typ1, algs1 := range allAlgs { + for typ2, algs2 := range allAlgs { + selection := selections[typ1*1000+typ2] + for _, x := range selection { + alg1 := algs1[x/1000] + alg2 := algs2[x%1000] + name := fmt.Sprintf("%v(%v,%v)", + alg.name, alg1.name, alg2.name) + if ok, _ := testAlg(t, typ.name, name); ok { + t.Logf("%10v\t%v\tclaimed %v works with %v/%v (%v)", + typ.name, alg.name, alg.args, typ1, typ2, name) + break + } + } + } + } + } + } +} + +type sockaddrAlg struct { + family uint16 + typ [14]byte + feat uint32 + mask uint32 + name [64]byte +} + +func testAlg(t *testing.T, typ, name string) (ok, skip bool) { + const AF_ALG = 0x26 + addr := &sockaddrAlg{ + family: AF_ALG, + } + if len(typ) >= int(unsafe.Sizeof(addr.typ)) || + len(name) >= int(unsafe.Sizeof(addr.name)) { + return false, true + } + for i := 0; i < len(typ); i++ { + addr.typ[i] = typ[i] + } + for i := 0; i < len(name); i++ { + addr.name[i] = name[i] + } + sock, err := syscall.Socket(AF_ALG, syscall.SOCK_SEQPACKET, 0) + if err != nil { + t.Fatalf("failed to create AF_ALG socket: %v", err) + } + defer syscall.Close(sock) + _, _, errno := syscall.Syscall(syscall.SYS_BIND, uintptr(sock), + uintptr(unsafe.Pointer(addr)), unsafe.Sizeof(*addr)) + if errno != 0 { + return false, false + } + return true, false +} -- cgit mrf-deployment