github.com/whtcorpsinc/milevadb-prod@v0.0.0-20211104133533-f57f4be3b597/dbs/memristed/memex/builtin_encryption_vec_test.go (about)

     1  // Copyright 2020 WHTCORPS INC, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package memex
    15  
    16  import (
    17  	"testing"
    18  
    19  	. "github.com/whtcorpsinc/check"
    20  	"github.com/whtcorpsinc/BerolinaSQL/ast"
    21  	"github.com/whtcorpsinc/milevadb/types"
    22  )
    23  
    24  var vecBuiltinEncryptionCases = map[string][]vecExprBenchCase{
    25  	ast.AesEncrypt: {
    26  		{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETString}, aesModes: "aes-128-ecb"},
    27  		{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETString, types.ETString}, geners: []dataGenerator{nil, nil, &constStrGener{"iv"}}, aesModes: "aes-128-ecb"},
    28  		{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETString, types.ETString}, geners: []dataGenerator{nil, nil, newRandLenStrGener(16, 17)}, aesModes: "aes-128-cbc"},
    29  		{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETString, types.ETString}, geners: []dataGenerator{nil, nil, newRandLenStrGener(16, 17)}, aesModes: "aes-128-ofb"},
    30  		{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETString, types.ETString}, geners: []dataGenerator{nil, nil, newRandLenStrGener(16, 17)}, aesModes: "aes-128-cfb"},
    31  	},
    32  	ast.Uncompress: {
    33  		{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString}},
    34  	},
    35  	ast.AesDecrypt: {
    36  		{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETString}, aesModes: "aes-128-ecb"},
    37  		{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETString, types.ETString}, geners: []dataGenerator{nil, nil, &constStrGener{"iv"}}, aesModes: "aes-128-ecb"},
    38  		{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETString, types.ETString}, geners: []dataGenerator{nil, nil, newRandLenStrGener(16, 17)}, aesModes: "aes-128-cbc"},
    39  		{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETString, types.ETString}, geners: []dataGenerator{nil, nil, newRandLenStrGener(16, 17)}, aesModes: "aes-128-ofb"},
    40  		{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETString, types.ETString}, geners: []dataGenerator{nil, nil, newRandLenStrGener(16, 17)}, aesModes: "aes-128-cfb"},
    41  	},
    42  	ast.Compress: {
    43  		{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString}},
    44  	},
    45  	ast.MD5: {
    46  		{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString}},
    47  	},
    48  	ast.SHA: {
    49  		{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString}},
    50  	},
    51  	ast.RandomBytes: {},
    52  	ast.UncompressedLength: {
    53  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETString}},
    54  		{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETString}, geners: []dataGenerator{newRandLenStrGener(1, 5)}},
    55  	},
    56  	ast.SHA1: {
    57  		{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString}},
    58  	},
    59  	ast.PasswordFunc: {
    60  		{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString}, geners: []dataGenerator{newRandLenStrGener(10, 20)}},
    61  	},
    62  	ast.SHA2: {
    63  		{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETInt}, geners: []dataGenerator{newRandLenStrGener(10, 20), newRangeInt64Gener(SHA0, SHA0+1)}},
    64  		{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETInt}, geners: []dataGenerator{newRandLenStrGener(10, 20), newRangeInt64Gener(SHA224, SHA224+1)}},
    65  		{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETInt}, geners: []dataGenerator{newRandLenStrGener(10, 20), newRangeInt64Gener(SHA256, SHA256+1)}},
    66  		{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETInt}, geners: []dataGenerator{newRandLenStrGener(10, 20), newRangeInt64Gener(SHA384, SHA384+1)}},
    67  		{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETInt}, geners: []dataGenerator{newRandLenStrGener(10, 20), newRangeInt64Gener(SHA512, SHA512+1)}},
    68  	},
    69  	ast.Encode: {
    70  		{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETString}},
    71  	},
    72  	ast.Decode: {
    73  		{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETString}, geners: []dataGenerator{newRandLenStrGener(10, 20)}},
    74  	},
    75  }
    76  
    77  func (s *testEvaluatorSuite) TestVectorizedBuiltinEncryptionFunc(c *C) {
    78  	testVectorizedBuiltinFunc(c, vecBuiltinEncryptionCases)
    79  }
    80  
    81  func BenchmarkVectorizedBuiltinEncryptionFunc(b *testing.B) {
    82  	benchmarkVectorizedBuiltinFunc(b, vecBuiltinEncryptionCases)
    83  }