add BN_CTX Start, Get, End and Add big.Int Mul and test it
This commit is contained in:
@@ -49,8 +49,19 @@ func BN_CTXSecureNew() *BN_CTX
|
||||
func (*BN_CTX) Free() {}
|
||||
|
||||
// void BN_CTX_start(BN_CTX *ctx);
|
||||
//
|
||||
// llgo:link (*BN_CTX).Start C.BN_CTX_start
|
||||
func (*BN_CTX) Start() {}
|
||||
|
||||
// BIGNUM *BN_CTX_get(BN_CTX *ctx);
|
||||
//
|
||||
// llgo:link (*BN_CTX).Get C.BN_CTX_get
|
||||
func (*BN_CTX) Get() *BIGNUM { return nil }
|
||||
|
||||
// void BN_CTX_end(BN_CTX *ctx);
|
||||
//
|
||||
// llgo:link (*BN_CTX).End C.BN_CTX_end
|
||||
func (*BN_CTX) End() {}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@ package big
|
||||
|
||||
// llgo:skipall
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/goplus/llgo/c/openssl"
|
||||
)
|
||||
|
||||
@@ -35,6 +37,18 @@ func ctxPut(ctx *openssl.BN_CTX) {
|
||||
ctx.Free()
|
||||
}
|
||||
|
||||
var g_lock = &sync.Mutex{}
|
||||
var g_ctx *openssl.BN_CTX
|
||||
|
||||
func getCtxInstance() *openssl.BN_CTX {
|
||||
if g_ctx == nil {
|
||||
g_lock.Lock()
|
||||
defer g_lock.Unlock()
|
||||
g_ctx = ctxGet()
|
||||
}
|
||||
return g_ctx
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
type Int openssl.BIGNUM
|
||||
@@ -147,7 +161,9 @@ func (z *Int) Mul(x, y *Int) *Int {
|
||||
a := (*openssl.BIGNUM)(z)
|
||||
xx := (*openssl.BIGNUM)(x)
|
||||
yy := (*openssl.BIGNUM)(y)
|
||||
a.Mul(a, xx, yy, ctxGet())
|
||||
getCtxInstance().Start()
|
||||
defer getCtxInstance().End()
|
||||
a.Mul(a, xx, yy, getCtxInstance())
|
||||
return z
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user