-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
本模块最低支持 go1.18 且暂无升级打算,而 unix 构建标记在 go1.19 才被支持。 所以暂时先复制 zzg_linux.go 到 zzg_unix.go 并添加 !windows && !linux 构建标记。 Fixed #1 Signed-off-by: liutianqi <zixizixi@vip.qq.com>
- Loading branch information
Showing
1 changed file
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
//go:build !windows && !linux | ||
|
||
/* | ||
* Copyright (c) 2000-2018, 达梦数据库有限公司. | ||
* All rights reserved. | ||
*/ | ||
|
||
package security | ||
|
||
import "plugin" | ||
|
||
var ( | ||
dmCipherEncryptSo *plugin.Plugin | ||
cipherGetCountProc plugin.Symbol | ||
cipherGetInfoProc plugin.Symbol | ||
cipherEncryptInitProc plugin.Symbol | ||
cipherGetCipherTextSizeProc plugin.Symbol | ||
cipherEncryptProc plugin.Symbol | ||
cipherCleanupProc plugin.Symbol | ||
cipherDecryptInitProc plugin.Symbol | ||
cipherDecryptProc plugin.Symbol | ||
) | ||
|
||
func initThirdPartCipher(cipherPath string) (err error) { | ||
if dmCipherEncryptSo, err = plugin.Open(cipherPath); err != nil { | ||
return err | ||
} | ||
if cipherGetCountProc, err = dmCipherEncryptSo.Lookup("cipher_get_count"); err != nil { | ||
return err | ||
} | ||
if cipherGetInfoProc, err = dmCipherEncryptSo.Lookup("cipher_get_info"); err != nil { | ||
return err | ||
} | ||
if cipherEncryptInitProc, err = dmCipherEncryptSo.Lookup("cipher_encrypt_init"); err != nil { | ||
return err | ||
} | ||
if cipherGetCipherTextSizeProc, err = dmCipherEncryptSo.Lookup("cipher_get_cipher_text_size"); err != nil { | ||
return err | ||
} | ||
if cipherEncryptProc, err = dmCipherEncryptSo.Lookup("cipher_encrypt"); err != nil { | ||
return err | ||
} | ||
if cipherCleanupProc, err = dmCipherEncryptSo.Lookup("cipher_cleanup"); err != nil { | ||
return err | ||
} | ||
if cipherDecryptInitProc, err = dmCipherEncryptSo.Lookup("cipher_decrypt_init"); err != nil { | ||
return err | ||
} | ||
if cipherDecryptProc, err = dmCipherEncryptSo.Lookup("cipher_decrypt"); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func cipherGetCount() int { | ||
ret := cipherGetCountProc.(func() interface{})() | ||
return ret.(int) | ||
} | ||
|
||
func cipherGetInfo(seqno, cipherId, cipherName, _type, blkSize, khSIze uintptr) { | ||
ret := cipherGetInfoProc.(func(uintptr, uintptr, uintptr, uintptr, uintptr, uintptr) interface{})(seqno, cipherId, cipherName, _type, blkSize, khSIze) | ||
if ret.(int) == 0 { | ||
panic("ThirdPartyCipher: call cipher_get_info failed") | ||
} | ||
} | ||
|
||
func cipherEncryptInit(cipherId, key, keySize, cipherPara uintptr) { | ||
ret := cipherEncryptInitProc.(func(uintptr, uintptr, uintptr, uintptr) interface{})(cipherId, key, keySize, cipherPara) | ||
if ret.(int) == 0 { | ||
panic("ThirdPartyCipher: call cipher_encrypt_init failed") | ||
} | ||
} | ||
|
||
func cipherGetCipherTextSize(cipherId, cipherPara, plainTextSize uintptr) uintptr { | ||
ciphertextLen := cipherGetCipherTextSizeProc.(func(uintptr, uintptr, uintptr) interface{})(cipherId, cipherPara, plainTextSize) | ||
return ciphertextLen.(uintptr) | ||
} | ||
|
||
func cipherEncrypt(cipherId, cipherPara, plainText, plainTextSize, cipherText, cipherTextBufSize uintptr) uintptr { | ||
ret := cipherEncryptProc.(func(uintptr, uintptr, uintptr, uintptr, uintptr, uintptr) interface{})(cipherId, cipherPara, plainText, plainTextSize, cipherText, cipherTextBufSize) | ||
return ret.(uintptr) | ||
} | ||
|
||
func cipherClean(cipherId, cipherPara uintptr) { | ||
cipherEncryptProc.(func(uintptr, uintptr))(cipherId, cipherPara) | ||
} | ||
|
||
func cipherDecryptInit(cipherId, key, keySize, cipherPara uintptr) { | ||
ret := cipherDecryptInitProc.(func(uintptr, uintptr, uintptr, uintptr) interface{})(cipherId, key, keySize, cipherPara) | ||
if ret.(int) == 0 { | ||
panic("ThirdPartyCipher: call cipher_decrypt_init failed") | ||
} | ||
} | ||
|
||
func cipherDecrypt(cipherId, cipherPara, cipherText, cipherTextSize, plainText, plainTextBufSize uintptr) uintptr { | ||
ret := cipherDecryptProc.(func(uintptr, uintptr, uintptr, uintptr, uintptr, uintptr) interface{})(cipherId, cipherPara, cipherText, cipherTextSize, plainText, plainTextBufSize) | ||
return ret.(uintptr) | ||
} |