gitee.com/curryzheng/dm@v0.0.1/security/zzh_linux.go (about)

     1  /*
     2   * Copyright (c) 2000-2018, 达梦数据库有限公司.
     3   * All rights reserved.
     4   */
     5  
     6  package security
     7  
     8  import "plugin"
     9  
    10  var (
    11  	dmCipherEncryptSo           *plugin.Plugin
    12  	cipherGetCountProc          plugin.Symbol
    13  	cipherGetInfoProc           plugin.Symbol
    14  	cipherEncryptInitProc       plugin.Symbol
    15  	cipherGetCipherTextSizeProc plugin.Symbol
    16  	cipherEncryptProc           plugin.Symbol
    17  	cipherCleanupProc           plugin.Symbol
    18  	cipherDecryptInitProc       plugin.Symbol
    19  	cipherDecryptProc           plugin.Symbol
    20  )
    21  
    22  func initThirdPartCipher(cipherPath string) (err error) {
    23  	if dmCipherEncryptSo, err = plugin.Open(cipherPath); err != nil {
    24  		return err
    25  	}
    26  	if cipherGetCountProc, err = dmCipherEncryptSo.Lookup("cipher_get_count"); err != nil {
    27  		return err
    28  	}
    29  	if cipherGetInfoProc, err = dmCipherEncryptSo.Lookup("cipher_get_info"); err != nil {
    30  		return err
    31  	}
    32  	if cipherEncryptInitProc, err = dmCipherEncryptSo.Lookup("cipher_encrypt_init"); err != nil {
    33  		return err
    34  	}
    35  	if cipherGetCipherTextSizeProc, err = dmCipherEncryptSo.Lookup("cipher_get_cipher_text_size"); err != nil {
    36  		return err
    37  	}
    38  	if cipherEncryptProc, err = dmCipherEncryptSo.Lookup("cipher_encrypt"); err != nil {
    39  		return err
    40  	}
    41  	if cipherCleanupProc, err = dmCipherEncryptSo.Lookup("cipher_cleanup"); err != nil {
    42  		return err
    43  	}
    44  	if cipherDecryptInitProc, err = dmCipherEncryptSo.Lookup("cipher_decrypt_init"); err != nil {
    45  		return err
    46  	}
    47  	if cipherDecryptProc, err = dmCipherEncryptSo.Lookup("cipher_decrypt"); err != nil {
    48  		return err
    49  	}
    50  	return nil
    51  }
    52  
    53  func cipherGetCount() int {
    54  	ret := cipherGetCountProc.(func() interface{})()
    55  	return ret.(int)
    56  }
    57  
    58  func cipherGetInfo(seqno, cipherId, cipherName, _type, blkSize, khSIze uintptr) {
    59  	ret := cipherGetInfoProc.(func(uintptr, uintptr, uintptr, uintptr, uintptr, uintptr) interface{})(seqno, cipherId, cipherName, _type, blkSize, khSIze)
    60  	if ret.(int) == 0 {
    61  		panic("ThirdPartyCipher: call cipher_get_info failed")
    62  	}
    63  }
    64  
    65  func cipherEncryptInit(cipherId, key, keySize, cipherPara uintptr) {
    66  	ret := cipherEncryptInitProc.(func(uintptr, uintptr, uintptr, uintptr) interface{})(cipherId, key, keySize, cipherPara)
    67  	if ret.(int) == 0 {
    68  		panic("ThirdPartyCipher: call cipher_encrypt_init failed")
    69  	}
    70  }
    71  
    72  func cipherGetCipherTextSize(cipherId, cipherPara, plainTextSize uintptr) uintptr {
    73  	ciphertextLen := cipherGetCipherTextSizeProc.(func(uintptr, uintptr, uintptr) interface{})(cipherId, cipherPara, plainTextSize)
    74  	return ciphertextLen.(uintptr)
    75  }
    76  
    77  func cipherEncrypt(cipherId, cipherPara, plainText, plainTextSize, cipherText, cipherTextBufSize uintptr) uintptr {
    78  	ret := cipherEncryptProc.(func(uintptr, uintptr, uintptr, uintptr, uintptr, uintptr) interface{})(cipherId, cipherPara, plainText, plainTextSize, cipherText, cipherTextBufSize)
    79  	return ret.(uintptr)
    80  }
    81  
    82  func cipherClean(cipherId, cipherPara uintptr) {
    83  	cipherEncryptProc.(func(uintptr, uintptr))(cipherId, cipherPara)
    84  }
    85  
    86  func cipherDecryptInit(cipherId, key, keySize, cipherPara uintptr) {
    87  	ret := cipherDecryptInitProc.(func(uintptr, uintptr, uintptr, uintptr) interface{})(cipherId, key, keySize, cipherPara)
    88  	if ret.(int) == 0 {
    89  		panic("ThirdPartyCipher: call cipher_decrypt_init failed")
    90  	}
    91  }
    92  
    93  func cipherDecrypt(cipherId, cipherPara, cipherText, cipherTextSize, plainText, plainTextBufSize uintptr) uintptr {
    94  	ret := cipherDecryptProc.(func(uintptr, uintptr, uintptr, uintptr, uintptr, uintptr) interface{})(cipherId, cipherPara, cipherText, cipherTextSize, plainText, plainTextBufSize)
    95  	return ret.(uintptr)
    96  }