zzg_linux.go 3.4 KB

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