1// Copyright 2019 The Prometheus Authors 2// Licensed under the Apache License, Version 2.0 (the "License"); 3// you may not use this file except in compliance with the License. 4// You may obtain a copy of the License at 5// 6// http://www.apache.org/licenses/LICENSE-2.0 7// 8// Unless required by applicable law or agreed to in writing, software 9// distributed under the License is distributed on an "AS IS" BASIS, 10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11// See the License for the specific language governing permissions and 12// limitations under the License. 13 14package procfs 15 16import ( 17 "testing" 18 19 "github.com/google/go-cmp/cmp" 20) 21 22func TestFS_Crypto(t *testing.T) { 23 fs := getProcFixtures(t) 24 crypto, err := fs.Crypto() 25 26 if err != nil { 27 t.Fatalf("parsing of reference-file failed entirely: %s", err) 28 } 29 30 refs := []Crypto{ 31 { 32 Name: "ccm(aes)", 33 Driver: "ccm_base(ctr(aes-aesni),cbcmac(aes-aesni))", 34 Module: "ccm", 35 Priority: newint64(300), 36 Refcnt: newint64(4), 37 Selftest: "passed", 38 Internal: "no", 39 Type: "aead", 40 Async: false, 41 Blocksize: newuint64(1), 42 Ivsize: newuint64(16), 43 Maxauthsize: newuint64(16), 44 Geniv: "<none>", 45 }, 46 { 47 Name: "cbcmac(aes)", 48 Driver: "cbcmac(aes-aesni)", 49 Module: "ccm", 50 Priority: newint64(300), 51 Refcnt: newint64(7), 52 Selftest: "passed", 53 Internal: "no", 54 Type: "shash", 55 Blocksize: newuint64(1), 56 Digestsize: newuint64(16), 57 }, 58 { 59 Name: "ecdh", 60 Driver: "ecdh-generic", 61 Module: "ecdh_generic", 62 Priority: newint64(100), 63 Refcnt: newint64(1), 64 Selftest: "passed", 65 Internal: "no", 66 Type: "kpp", 67 Async: true, 68 }, 69 { 70 Name: "ecb(arc4)", 71 Driver: "ecb(arc4)-generic", 72 Module: "arc4", 73 Priority: newint64(100), 74 Refcnt: newint64(1), 75 Selftest: "passed", 76 Internal: "no", 77 Type: "skcipher", 78 Async: false, 79 Blocksize: newuint64(1), 80 MinKeysize: newuint64(1), 81 MaxKeysize: newuint64(256), 82 Ivsize: newuint64(0), 83 Chunksize: newuint64(1), 84 Walksize: newuint64(1), 85 }, 86 { 87 Name: "arc4", 88 Driver: "arc4-generic", 89 Module: "arc4", 90 Priority: newint64(0), 91 Refcnt: newint64(3), 92 Selftest: "passed", 93 Internal: "no", 94 Type: "cipher", 95 Blocksize: newuint64(1), 96 MinKeysize: newuint64(1), 97 MaxKeysize: newuint64(256), 98 }, 99 { 100 Name: "crct10dif", 101 Driver: "crct10dif-pclmul", 102 Module: "crct10dif_pclmul", 103 Priority: newint64(200), 104 Refcnt: newint64(2), 105 Selftest: "passed", 106 Internal: "no", 107 Type: "shash", 108 Blocksize: newuint64(1), 109 Digestsize: newuint64(2), 110 }, 111 } 112 113 if want, have := len(refs), len(crypto); want > have { 114 t.Errorf("want at least %d parsed crypto-entries, have %d", want, have) 115 } 116 for index, ref := range refs { 117 want, got := ref, crypto[index] 118 if diff := cmp.Diff(want, got); diff != "" { 119 t.Fatalf("unexpected crypto entry (-want +got):\n%s", diff) 120 } 121 } 122} 123 124func newint64(i int64) *int64 { 125 return &i 126} 127 128func newuint64(i uint64) *uint64 { 129 return &i 130} 131