zzh_windows.go 2.9 KB

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