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