From 39363c900be0908dd95f156d9aab5a2c171a383f Mon Sep 17 00:00:00 2001 From: xushiwei Date: Wed, 28 Oct 2026 17:38:01 +0800 Subject: [PATCH 1/2] mv c/openssl => github.com/llarhub/openssl --- c/openssl/_demo/cbigintdemo/fib.go | 44 ---- c/openssl/_demo/chmacdemo/hmac.go | 40 --- c/openssl/_demo/cmd5demo/md5.go | 18 -- c/openssl/_demo/cranddemo/rand.go | 17 -- c/openssl/_demo/cshademo/sha.go | 68 ----- c/openssl/_wrap/openssl.c | 5 - c/openssl/bio.go | 61 ----- c/openssl/bn.go | 409 ----------------------------- c/openssl/err.go | 156 ----------- c/openssl/hmac.go | 133 ---------- c/openssl/md5.go | 85 ------ c/openssl/openssl.go | 38 --- c/openssl/pem.go | 37 --- c/openssl/rand.go | 80 ------ c/openssl/rsa.go | 305 --------------------- c/openssl/sha1.go | 94 ------- c/openssl/sha256.go | 117 --------- c/openssl/sha512.go | 115 -------- 18 files changed, 1822 deletions(-) delete mode 100644 c/openssl/_demo/cbigintdemo/fib.go delete mode 100644 c/openssl/_demo/chmacdemo/hmac.go delete mode 100644 c/openssl/_demo/cmd5demo/md5.go delete mode 100644 c/openssl/_demo/cranddemo/rand.go delete mode 100644 c/openssl/_demo/cshademo/sha.go delete mode 100644 c/openssl/_wrap/openssl.c delete mode 100644 c/openssl/bio.go delete mode 100644 c/openssl/bn.go delete mode 100644 c/openssl/err.go delete mode 100644 c/openssl/hmac.go delete mode 100644 c/openssl/md5.go delete mode 100644 c/openssl/openssl.go delete mode 100644 c/openssl/pem.go delete mode 100644 c/openssl/rand.go delete mode 100644 c/openssl/rsa.go delete mode 100644 c/openssl/sha1.go delete mode 100644 c/openssl/sha256.go delete mode 100644 c/openssl/sha512.go diff --git a/c/openssl/_demo/cbigintdemo/fib.go b/c/openssl/_demo/cbigintdemo/fib.go deleted file mode 100644 index 7179a9af..00000000 --- a/c/openssl/_demo/cbigintdemo/fib.go +++ /dev/null @@ -1,44 +0,0 @@ -package main - -import ( - "github.com/goplus/lib/c" - "github.com/goplus/lib/c/openssl" -) - -func newInt(n openssl.BN_ULONG) *openssl.BIGNUM { - ret := openssl.BNNew() - ret.SetWord(n) - return ret -} - -func main() { - ctx := openssl.BN_CTXNew() - defer ctx.Free() - - // Initialize two big ints with the first two numbers in the sequence. - a := newInt(0) - b := newInt(1) - defer a.Free() - defer b.Free() - - // Initialize limit as 10^99, the smallest integer with 100 digits. - v10, v99 := newInt(10), newInt(99) - defer v10.Free() - defer v99.Free() - - limit := openssl.BNNew() - defer limit.Free() - - limit.Exp(v10, v99, ctx) - - // Loop while a is smaller than 1e100. - for a.Cmp(limit) < 0 { - // Compute the next Fibonacci number, storing it in a. - a.Add(a, b) - // Swap a and b so that b is the next number in the sequence. - a, b = b, a - } - cstr := a.CStr() - c.Printf(c.Str("%s\n"), cstr) // 100-digit Fibonacci number - openssl.FreeCStr(cstr) -} diff --git a/c/openssl/_demo/chmacdemo/hmac.go b/c/openssl/_demo/chmacdemo/hmac.go deleted file mode 100644 index e09ac565..00000000 --- a/c/openssl/_demo/chmacdemo/hmac.go +++ /dev/null @@ -1,40 +0,0 @@ -package main - -import ( - "fmt" - "unsafe" - - "github.com/goplus/lib/c" - "github.com/goplus/lib/c/openssl" -) - -func main() { - str := "Hello, World!" - key := "123456" - var lenKey = len(key) - - var digest = make([]byte, openssl.EVP_MAX_MD_SIZE) - var digestLen c.Uint - ctx := openssl.NewHMAC_CTX() - if ctx == nil { - c.Fprintf(c.Stderr, c.Str("%s\n"), c.Str("Error creating HMAC_CTX")) - return - } - defer ctx.Free() - var ret c.Int = ctx.InitEx(unsafe.Pointer(unsafe.StringData(key)), c.Int(lenKey), openssl.EVP_sha256(), nil) - if ret == 0 { - c.Fprintf(c.Stderr, c.Str("%s\n"), c.Str("Error initializing HMAC_CTX")) - return - } - ret = ctx.UpdateString(str) - if ret == 0 { - c.Fprintf(c.Stderr, c.Str("%s\n"), c.Str("Error updating HMAC_CTX")) - return - } - ret = ctx.Final(unsafe.SliceData(digest), &digestLen) - if ret == 0 { - c.Fprintf(c.Stderr, c.Str("%s\n"), c.Str("Error finalizing HMAC_CTX")) - return - } - fmt.Printf("HMAC:%x\n", digest[:digestLen]) -} diff --git a/c/openssl/_demo/cmd5demo/md5.go b/c/openssl/_demo/cmd5demo/md5.go deleted file mode 100644 index 53aa45d9..00000000 --- a/c/openssl/_demo/cmd5demo/md5.go +++ /dev/null @@ -1,18 +0,0 @@ -package main - -import ( - "fmt" - "unsafe" - - "github.com/goplus/lib/c/openssl" -) - -func main() { - var md5 openssl.MD5_CTX - var h = make([]byte, openssl.MD5_LBLOCK) - md5.Init() - md5.UpdateString("The fog is getting thicker!") - md5.UpdateString("And Leon's getting laaarger!") - md5.Final(unsafe.SliceData(h)) - fmt.Printf("%x", h) -} diff --git a/c/openssl/_demo/cranddemo/rand.go b/c/openssl/_demo/cranddemo/rand.go deleted file mode 100644 index b1444e9c..00000000 --- a/c/openssl/_demo/cranddemo/rand.go +++ /dev/null @@ -1,17 +0,0 @@ -package main - -import ( - "fmt" - - "github.com/goplus/lib/c/openssl" -) - -func main() { - b := make([]byte, 10) - - openssl.RANDBytes(b) - fmt.Printf("%x\n", b) - - openssl.RANDPrivBytes(b) - fmt.Printf("%x\n", b) -} diff --git a/c/openssl/_demo/cshademo/sha.go b/c/openssl/_demo/cshademo/sha.go deleted file mode 100644 index e8dbba70..00000000 --- a/c/openssl/_demo/cshademo/sha.go +++ /dev/null @@ -1,68 +0,0 @@ -package main - -import ( - "fmt" - "unsafe" - - "github.com/goplus/lib/c/openssl" -) - -func main() { - str := "His money is twice tainted:" - - var sha1 openssl.SHA_CTX - sha1.Init() - sha1.UpdateString(str) - - h1 := make([]byte, openssl.SHA_DIGEST_LENGTH) - sha1.Final(unsafe.SliceData(h1)) - fmt.Printf("%x\n", h1) - - h2 := make([]byte, openssl.SHA_DIGEST_LENGTH) - openssl.SHA1String(str, unsafe.SliceData(h2)) - fmt.Printf("%x\n", h2) - - var sha256 openssl.SHA256_CTX - sha256.Init() - sha256.UpdateString(str) - h3 := make([]byte, openssl.SHA256_DIGEST_LENGTH) - sha256.Final(unsafe.SliceData(h3)) - fmt.Printf("%x\n", h3) - - h4 := make([]byte, openssl.SHA256_DIGEST_LENGTH) - openssl.SHA256String(str, unsafe.SliceData(h4)) - fmt.Printf("%x\n", h4) - - var sha512 openssl.SHA512_CTX - sha512.Init() - sha512.UpdateString("His money is twice tainted:") - - h5 := make([]byte, openssl.SHA512_DIGEST_LENGTH) - sha512.Final(unsafe.SliceData(h5)) - fmt.Printf("%x\n", h5) - - h6 := make([]byte, openssl.SHA512_DIGEST_LENGTH) - openssl.SHA512String(str, unsafe.SliceData(h6)) - fmt.Printf("%x\n", h6) - - var sha224 openssl.SHA224_CTX - sha224.Init() - sha224.UpdateString(str) - - h7 := make([]byte, openssl.SHA224_DIGEST_LENGTH) - sha224.Final(unsafe.SliceData(h7)) - fmt.Printf("%x\n", h7) - h8 := make([]byte, openssl.SHA224_DIGEST_LENGTH) - openssl.SHA224String(str, unsafe.SliceData(h8)) - fmt.Printf("%x\n", h8) - - var sha384 openssl.SHA384_CTX - sha384.Init() - sha384.UpdateString(str) - h9 := make([]byte, openssl.SHA384_DIGEST_LENGTH) - sha384.Final(unsafe.SliceData(h9)) - fmt.Printf("%x\n", h9) - h10 := make([]byte, openssl.SHA384_DIGEST_LENGTH) - openssl.SHA384String(str, unsafe.SliceData(h10)) - fmt.Printf("%x\n", h10) -} diff --git a/c/openssl/_wrap/openssl.c b/c/openssl/_wrap/openssl.c deleted file mode 100644 index 7cc5bbdb..00000000 --- a/c/openssl/_wrap/openssl.c +++ /dev/null @@ -1,5 +0,0 @@ -#include - -void opensslFree(void *ptr) { - OPENSSL_free(ptr); -} diff --git a/c/openssl/bio.go b/c/openssl/bio.go deleted file mode 100644 index ec0ea724..00000000 --- a/c/openssl/bio.go +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2024 The XGo Authors (xgo.dev). All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package openssl - -import ( - "unsafe" - - "github.com/goplus/lib/c" -) - -// ----------------------------------------------------------------------------- - -type BIO struct { - Unused [0]byte -} - -// BIO *BIO_new_mem_buf(const void *buf, int len); -// -//go:linkname BIONewMemBuf C.BIO_new_mem_buf -func BIONewMemBuf(buf unsafe.Pointer, len c.Int) *BIO - -// int BIO_free(BIO *a); -// -// llgo:link (*BIO).Free C.BIO_free -func (*BIO) Free() c.Int { return 0 } - -// int BIO_up_ref(BIO *a); -// -// llgo:link (*BIO).UpRef C.BIO_up_ref -func (*BIO) UpRef() c.Int { return 0 } - -// int BIO_read_ex(BIO *b, void *data, size_t dlen, size_t *readbytes); -// -// llgo:link (*BIO).ReadEx C.BIO_read_ex -func (*BIO) ReadEx(data unsafe.Pointer, dlen uintptr, readbytes *uintptr) c.Int { return 0 } - -// int BIO_write(BIO *b, const void *data, int dlen); -// -// llgo:link (*BIO).Write C.BIO_write -func (*BIO) Write(data unsafe.Pointer, dlen c.Int) c.Int { return 0 } - -// int BIO_write_ex(BIO *b, const void *data, size_t dlen, size_t *written); -// -// llgo:link (*BIO).WriteEx C.BIO_write_ex -func (*BIO) WriteEx(data unsafe.Pointer, dlen uintptr, written *uintptr) c.Int { return 0 } - -// ----------------------------------------------------------------------------- diff --git a/c/openssl/bn.go b/c/openssl/bn.go deleted file mode 100644 index 07edb771..00000000 --- a/c/openssl/bn.go +++ /dev/null @@ -1,409 +0,0 @@ -/* - * Copyright (c) 2024 The XGo Authors (xgo.dev). All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package openssl - -import ( - _ "unsafe" - - "github.com/goplus/lib/c" -) - -type BN_ULONG = uint64 - -// ----------------------------------------------------------------------------- - -type BN_CTX struct { - Unused [0]byte -} - -// BN_CTX *BN_CTX_new(void); -// -//go:linkname BN_CTXNew C.BN_CTX_new -func BN_CTXNew() *BN_CTX - -// BN_CTX *BN_CTX_secure_new(void); -// -//go:linkname BN_CTXSecureNew C.BN_CTX_secure_new -func BN_CTXSecureNew() *BN_CTX - -// BN_CTX *BN_CTX_new_ex(OSSL_LIB_CTX *ctx); -// BN_CTX *BN_CTX_secure_new_ex(OSSL_LIB_CTX *ctx); - -// void BN_CTX_free(BN_CTX *c); -// -// llgo:link (*BN_CTX).Free C.BN_CTX_free -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() {} - -// ----------------------------------------------------------------------------- - -type BIGNUM struct { - Unused [0]byte -} - -// BIGNUM *BN_new(void); -// -//go:linkname BNNew C.BN_new -func BNNew() *BIGNUM - -// BIGNUM *BN_secure_new(void); -// -//go:linkname BNSecureNew C.BN_secure_new -func BNSecureNew() *BIGNUM - -// void BN_free(BIGNUM *a); -// -// llgo:link (*BIGNUM).Free C.BN_free -func (*BIGNUM) Free() {} - -// void BN_clear_free(BIGNUM *a); -// -// llgo:link (*BIGNUM).ClearFree C.BN_clear_free -func (*BIGNUM) ClearFree() {} - -// void BN_clear(BIGNUM *a); -// -// llgo:link (*BIGNUM).Clear C.BN_clear -func (*BIGNUM) Clear() {} - -// BIGNUM *BN_dup(const BIGNUM *a); -// -// llgo:link (*BIGNUM).Dup C.BN_dup -func (*BIGNUM) Dup() *BIGNUM { return nil } - -// BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b); -// -// llgo:link (*BIGNUM).Copy C.BN_copy -func (*BIGNUM) Copy(b *BIGNUM) *BIGNUM { return nil } - -// void BN_swap(BIGNUM *a, BIGNUM *b); -// -// llgo:link (*BIGNUM).Swap C.BN_swap -func (*BIGNUM) Swap(b *BIGNUM) {} - -// int BN_is_zero(const BIGNUM *a); -// -// llgo:link (*BIGNUM).IsZero C.BN_is_zero -func (*BIGNUM) IsZero() c.Int { return 0 } - -// void BN_zero_ex(BIGNUM *a); -// -// llgo:link (*BIGNUM).SetZero C.BN_zero_ex -func (*BIGNUM) SetZero() {} - -// int BN_is_one(const BIGNUM *a); -// -// llgo:link (*BIGNUM).IsOne C.BN_is_one -func (*BIGNUM) IsOne() c.Int { return 0 } - -// int BN_is_odd(const BIGNUM *a); -// -// llgo:link (*BIGNUM).IsOdd C.BN_is_odd -func (*BIGNUM) IsOdd() c.Int { return 0 } - -// int BN_abs_is_word(const BIGNUM *a, const BN_ULONG w); -// -// llgo:link (*BIGNUM).AbsIsWord C.BN_abs_is_word -func (*BIGNUM) AbsIsWord(w BN_ULONG) c.Int { return 0 } - -// int BN_is_word(const BIGNUM *a, const BN_ULONG w); -// -// llgo:link (*BIGNUM).IsWord C.BN_is_word -func (*BIGNUM) IsWord(w BN_ULONG) c.Int { return 0 } - -// int BN_set_word(BIGNUM *a, BN_ULONG w); -// -// llgo:link (*BIGNUM).SetWord C.BN_set_word -func (*BIGNUM) SetWord(w BN_ULONG) c.Int { return 0 } - -// BN_ULONG BN_get_word(const BIGNUM *a); -// -// llgo:link (*BIGNUM).GetWord C.BN_get_word -func (*BIGNUM) GetWord() BN_ULONG { return 0 } - -// BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w); -// -// llgo:link (*BIGNUM).ModWord C.BN_mod_word -func (*BIGNUM) ModWord(w BN_ULONG) BN_ULONG { return 0 } - -// BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w); -// -// llgo:link (*BIGNUM).DivWord C.BN_div_word -func (*BIGNUM) DivWord(w BN_ULONG) BN_ULONG { return 0 } - -// int BN_mul_word(BIGNUM *a, BN_ULONG w); -// -// llgo:link (*BIGNUM).MulWord C.BN_mul_word -func (*BIGNUM) MulWord(w BN_ULONG) c.Int { return 0 } - -// int BN_add_word(BIGNUM *a, BN_ULONG w); -// -// llgo:link (*BIGNUM).AddWord C.BN_add_word -func (*BIGNUM) AddWord(w BN_ULONG) c.Int { return 0 } - -// int BN_sub_word(BIGNUM *a, BN_ULONG w); -// -// llgo:link (*BIGNUM).SubWord C.BN_sub_word -func (*BIGNUM) SubWord(w BN_ULONG) c.Int { return 0 } - -// char *BN_bn2hex(const BIGNUM *a); -// -// llgo:link (*BIGNUM).Bn2hex C.BN_bn2hex -func (*BIGNUM) Bn2hex() *c.Char { return nil } - -// char *BN_bn2dec(const BIGNUM *a); -// -// llgo:link (*BIGNUM).Bn2dec C.BN_bn2dec -func (*BIGNUM) Bn2dec() *c.Char { return nil } - -// llgo:link (*BIGNUM).CStr C.BN_bn2dec -func (*BIGNUM) CStr() *c.Char { return nil } - -// int BN_hex2bn(BIGNUM **a, const char *str); -// -//go:linkname BNHex2bn C.BN_hex2bn -func BNHex2bn(a **BIGNUM, str *c.Char) c.Int - -// int BN_dec2bn(BIGNUM **a, const char *str); -// -//go:linkname BNDec2bn C.BN_dec2bn -func BNDec2bn(a **BIGNUM, str *c.Char) c.Int - -// int BN_asc2bn(BIGNUM **a, const char *str); -// -//go:linkname BNAsc2bn C.BN_asc2bn -func BNAsc2bn(a **BIGNUM, str *c.Char) c.Int - -// BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret); -// -//go:linkname BNBin2bn C.BN_bin2bn -func BNBin2bn(s *byte, len c.Int, ret *BIGNUM) *BIGNUM - -// BIGNUM *BN_signed_bin2bn(const unsigned char *s, int len, BIGNUM *ret); -// -//go:linkname BNSignedBin2bn C.BN_signed_bin2bn -func BNSignedBin2bn(s *byte, len c.Int, ret *BIGNUM) *BIGNUM - -// int BN_bn2bin(const BIGNUM *a, unsigned char *to); -// -// llgo:link (*BIGNUM).Bn2bin C.BN_bn2bin -func (bn *BIGNUM) Bn2bin(to *byte) c.Int { return 0 } - -// int BN_bn2binpad(const BIGNUM *a, unsigned char *to, int tolen); -// -// llgo:link (*BIGNUM).Bn2binpad C.BN_bn2binpad -func (bn *BIGNUM) Bn2binpad(to *byte, tolen c.Int) c.Int { return 0 } - -// int BN_signed_bn2bin(const BIGNUM *a, unsigned char *to, int tolen); -// -// llgo:link (*BIGNUM).SignedBn2bin C.BN_signed_bn2bin -func (bn *BIGNUM) SignedBn2bin(to *byte, tolen c.Int) c.Int { return 0 } - -// BIGNUM *BN_lebin2bn(const unsigned char *s, int len, BIGNUM *ret); -// -//go:linkname BNLebin2bn C.BN_lebin2bn -func BNLebin2bn(s *byte, len c.Int, ret *BIGNUM) *BIGNUM - -// BIGNUM *BN_signed_lebin2bn(const unsigned char *s, int len, BIGNUM *ret); -// -//go:linkname BNSignedLebin2bn C.BN_signed_lebin2bn -func BNSignedLebin2bn(s *byte, len c.Int, ret *BIGNUM) *BIGNUM - -// int BN_bn2lebinpad(const BIGNUM *a, unsigned char *to, int tolen); -// -// llgo:link (*BIGNUM).Bn2lebinpad C.BN_bn2lebinpad -func (bn *BIGNUM) Bn2lebinpad(to *byte, tolen c.Int) c.Int { return 0 } - -// int BN_signed_bn2lebin(const BIGNUM *a, unsigned char *to, int tolen); -// -// llgo:link (*BIGNUM).SignedBn2lebin C.BN_signed_bn2lebin -func (bn *BIGNUM) SignedBn2lebin(to *byte, tolen c.Int) c.Int { return 0 } - -// BIGNUM *BN_native2bn(const unsigned char *s, int len, BIGNUM *ret); -// -//go:linkname BNNative2bn C.BN_native2bn -func BNNative2bn(s *byte, len c.Int, ret *BIGNUM) *BIGNUM - -// BIGNUM *BN_signed_native2bn(const unsigned char *s, int len, BIGNUM *ret); -// -//go:linkname BNSignedNative2bn C.BN_signed_native2bn -func BNSignedNative2bn(s *byte, len c.Int, ret *BIGNUM) *BIGNUM - -// int BN_bn2nativepad(const BIGNUM *a, unsigned char *to, int tolen); -// -// llgo:link (*BIGNUM).Bn2nativepad C.BN_bn2nativepad -func (bn *BIGNUM) Bn2nativepad(to *byte, tolen c.Int) c.Int { return 0 } - -// int BN_signed_bn2native(const BIGNUM *a, unsigned char *to, int tolen); -// -// llgo:link (*BIGNUM).SignedBn2native C.BN_signed_bn2native -func (bn *BIGNUM) SignedBn2native(to *byte, tolen c.Int) c.Int { return 0 } - -// BIGNUM *BN_mpi2bn(const unsigned char *s, int len, BIGNUM *ret); -// -//go:linkname BNMpi2bn C.BN_mpi2bn -func BNMpi2bn(s *byte, len c.Int, ret *BIGNUM) *BIGNUM - -// int BN_bn2mpi(const BIGNUM *a, unsigned char *to); -// -// llgo:link (*BIGNUM).Bn2mpi C.BN_bn2mpi -func (bn *BIGNUM) Bn2mpi(to *byte) c.Int { return 0 } - -// int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); -// -// llgo:link (*BIGNUM).Sub C.BN_sub -func (*BIGNUM) Sub(a, b *BIGNUM) c.Int { return 0 } - -// int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); -// -// llgo:link (*BIGNUM).Add C.BN_add -func (*BIGNUM) Add(a, b *BIGNUM) c.Int { return 0 } - -// int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); -// -// llgo:link (*BIGNUM).Usub C.BN_usub -func (*BIGNUM) Usub(a, b *BIGNUM) c.Int { return 0 } - -// int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); -// -// llgo:link (*BIGNUM).Uadd C.BN_uadd -func (*BIGNUM) Uadd(a, b *BIGNUM) c.Int { return 0 } - -// int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx); -// -// llgo:link (*BIGNUM).Mul C.BN_mul -func (*BIGNUM) Mul(r, a, b *BIGNUM, ctx *BN_CTX) c.Int { return 0 } - -// int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx); -// -// llgo:link (*BIGNUM).Sqr C.BN_sqr -func (*BIGNUM) Sqr(r, a *BIGNUM, ctx *BN_CTX) c.Int { return 0 } - -/** BN_set_negative sets sign of a BIGNUM - * \param b pointer to the BIGNUM object - * \param n 0 if the BIGNUM b should be positive and a value != 0 otherwise - */ -// void BN_set_negative(BIGNUM *b, int n); -// -// llgo:link (*BIGNUM).SetNegative C.BN_set_negative -func (*BIGNUM) SetNegative(n c.Int) {} - -/** BN_is_negative returns 1 if the BIGNUM is negative - * \param b pointer to the BIGNUM object - * \return 1 if a < 0 and 0 otherwise - */ -// int BN_is_negative(const BIGNUM *b); -// -// llgo:link (*BIGNUM).IsNegative C.BN_is_negative -func (*BIGNUM) IsNegative() c.Int { return 0 } - -// int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx); -// -// llgo:link (*BIGNUM).Div C.BN_div -func (*BIGNUM) Div(rem, m, d *BIGNUM, ctx *BN_CTX) c.Int { return 0 } - -// int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx); -// -// llgo:link (*BIGNUM).Nnmod C.BN_nnmod -func (*BIGNUM) Nnmod(r, m, d *BIGNUM, ctx *BN_CTX) c.Int { return 0 } - -// int BN_cmp(const BIGNUM *a, const BIGNUM *b); -// -// llgo:link (*BIGNUM).Cmp C.BN_cmp -func (*BIGNUM) Cmp(b *BIGNUM) c.Int { return 0 } - -// int BN_ucmp(const BIGNUM *a, const BIGNUM *b); -// -// llgo:link (*BIGNUM).Ucmp C.BN_ucmp -func (*BIGNUM) Ucmp(b *BIGNUM) c.Int { return 0 } - -// int BN_is_bit_set(const BIGNUM *a, int n); -// -// llgo:link (*BIGNUM).IsBitSet C.BN_is_bit_set -func (*BIGNUM) IsBitSet(n c.Int) c.Int { return 0 } - -// int BN_set_bit(BIGNUM *a, int n); -// -// llgo:link (*BIGNUM).SetBit C.BN_set_bit -func (*BIGNUM) SetBit(n c.Int) c.Int { return 0 } - -// int BN_clear_bit(BIGNUM *a, int n); -// -// llgo:link (*BIGNUM).ClearBit C.BN_clear_bit -func (*BIGNUM) ClearBit(n c.Int) c.Int { return 0 } - -// int BN_lshift(BIGNUM *r, const BIGNUM *a, int n); -// -// llgo:link (*BIGNUM).Lshift C.BN_lshift -func (*BIGNUM) Lshift(a *BIGNUM, n c.Int) c.Int { return 0 } - -// int BN_lshift1(BIGNUM *r, const BIGNUM *a); -// -// llgo:link (*BIGNUM).Lshift1 C.BN_lshift1 -func (*BIGNUM) Lshift1(a *BIGNUM) c.Int { return 0 } - -// int BN_rshift(BIGNUM *r, const BIGNUM *a, int n); -// -// llgo:link (*BIGNUM).Rshift C.BN_rshift -func (*BIGNUM) Rshift(a *BIGNUM, n c.Int) c.Int { return 0 } - -// int BN_rshift1(BIGNUM *r, const BIGNUM *a); -// -// llgo:link (*BIGNUM).Rshift1 C.BN_rshift1 -func (*BIGNUM) Rshift1(a *BIGNUM) c.Int { return 0 } - -// int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx); -// -// llgo:link (*BIGNUM).Exp C.BN_exp -func (*BIGNUM) Exp(a, p *BIGNUM, ctx *BN_CTX) c.Int { return 0 } - -// int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx); -// -// llgo:link (*BIGNUM).ModExp C.BN_mod_exp -func (*BIGNUM) ModExp(a, p, m *BIGNUM, ctx *BN_CTX) c.Int { return 0 } - -// int BN_gcd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx); -// -// llgo:link (*BIGNUM).Gcd C.BN_gcd -func (*BIGNUM) Gcd(a, b *BIGNUM, ctx *BN_CTX) c.Int { return 0 } - -// int BN_are_coprime(const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx); -// -// llgo:link (*BIGNUM).AreCoprime C.BN_are_coprime -func (*BIGNUM) AreCoprime(b *BIGNUM, ctx *BN_CTX) c.Int { return 0 } - -// ----------------------------------------------------------------------------- - -type BN_GENCB struct { - Unused [0]byte -} - -// ----------------------------------------------------------------------------- diff --git a/c/openssl/err.go b/c/openssl/err.go deleted file mode 100644 index be0816f9..00000000 --- a/c/openssl/err.go +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright (c) 2024 The XGo Authors (xgo.dev). All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package openssl - -import ( - "unsafe" - - "github.com/goplus/lib/c" -) - -// ----------------------------------------------------------------------------- - -/*- - * The error code packs differently depending on if it records a system - * error or an OpenSSL error. - * - * A system error packs like this (we follow POSIX and only allow positive - * numbers that fit in an |int|): - * - * +-+-------------------------------------------------------------+ - * |1| system error number | - * +-+-------------------------------------------------------------+ - * - * An OpenSSL error packs like this: - * - * <---------------------------- 32 bits --------------------------> - * <--- 8 bits ---><------------------ 23 bits -----------------> - * +-+---------------+---------------------------------------------+ - * |0| library | reason | - * +-+---------------+---------------------------------------------+ - * - * A few of the reason bits are reserved as flags with special meaning: - * - * <5 bits-<>--------- 19 bits -----------------> - * +-------+-+-----------------------------------+ - * | rflags| | reason | - * +-------+-+-----------------------------------+ - * ^ - * | - * ERR_RFLAG_FATAL = ERR_R_FATAL - * - * The reason flags are part of the overall reason code for practical - * reasons, as they provide an easy way to place different types of - * reason codes in different numeric ranges. - * - * The currently known reason flags are: - * - * ERR_RFLAG_FATAL Flags that the reason code is considered fatal. - * For backward compatibility reasons, this flag - * is also the code for ERR_R_FATAL (that reason - * code served the dual purpose of flag and reason - * code in one in pre-3.0 OpenSSL). - * ERR_RFLAG_COMMON Flags that the reason code is common to all - * libraries. All ERR_R_ macros must use this flag, - * and no other _R_ macro is allowed to use it. - */ -type Errno c.Ulong - -// ERR_get_error returns the earliest error code from the thread's error queue and -// removes the entry. This function can be called repeatedly until there are no more -// error codes to return. -// -// unsigned long ERR_get_error(void); -// -//go:linkname ERRGetError C.ERR_get_error -func ERRGetError() Errno - -// ERR_get_error_all() is the same as ERR_get_error(), but on success it additionally -// stores the filename, line number and function where the error occurred in *file, -// *line and *func, and also extra text and flags in *data, *flags. If any of those -// parameters are NULL, it will not be changed. -// -// unsigned long ERR_get_error_all( -// const char **file, int *line, const char **func, const char **data, int *flags); -// -//go:linkname ERRGetErrorAll C.ERR_get_error_all -func ERRGetErrorAll( - file **c.Char, line *c.Int, function **c.Char, data **c.Char, flags *c.Int) Errno - -// unsigned long ERR_peek_error(void); -// -//go:linkname ERRPeekError C.ERR_peek_error -func ERRPeekError() Errno - -// unsigned long ERR_peek_error_all( -// const char **file, int *line, const char **func, const char **data, int *flags); -// -//go:linkname ERRPeekErrorAll C.ERR_peek_error_all -func ERRPeekErrorAll( - file **c.Char, line *c.Int, function **c.Char, data **c.Char, flags *c.Int) Errno - -// unsigned long ERR_peek_last_error(void); -// -//go:linkname ERRPeekLastError C.ERR_peek_last_error -func ERRPeekLastError() Errno - -// unsigned long ERR_peek_last_error_all( -// const char **file, int *line, const char **func, const char **data, int *flags); -// -//go:linkname ERRPeekLastErrorAll C.ERR_peek_last_error_all -func ERRPeekLastErrorAll( - file **c.Char, line *c.Int, function **c.Char, data **c.Char, flags *c.Int) Errno - -// void ERR_clear_error(void); -// -//go:linkname ERRClearError C.ERR_clear_error -func ERRClearError() - -// ERR_error_string() generates a human-readable string representing the error code e, -// and places it at buf. buf must be at least 256 bytes long. -// -// char *ERR_error_string(unsigned long e, char *buf); -// -//go:linkname ERRErrorString C.ERR_error_string -func ERRErrorString(e Errno, buf *c.Char) *c.Char - -// ERR_lib_error_string() and ERR_reason_error_string() return the library name and -// reason string respectively. -// -// const char *ERR_lib_error_string(unsigned long e); -// -//go:linkname ERRLibErrorString C.ERR_lib_error_string -func ERRLibErrorString(e Errno) *c.Char - -// const char *ERR_reason_error_string(unsigned long e); -// -//go:linkname ERRReasonErrorString C.ERR_reason_error_string -func ERRReasonErrorString(e Errno) *c.Char - -// void ERR_print_errors_cb(int (*cb) (const char *str, size_t len, void *u), void *u); -// -// [pid]:error:[error code]:[library name]:[function name]:[reason string]:[filename]:[line]:[optional text message] -// -//go:linkname ERRPrintErrorsCb C.ERR_print_errors_cb -func ERRPrintErrorsCb(cb func(str *c.Char, len uintptr, u unsafe.Pointer) c.Int, u unsafe.Pointer) - -// void ERR_print_errors_fp(FILE *fp); -// -//go:linkname ERRPrintErrorsFp C.ERR_print_errors_fp -func ERRPrintErrorsFp(fp c.FilePtr) - -// ----------------------------------------------------------------------------- diff --git a/c/openssl/hmac.go b/c/openssl/hmac.go deleted file mode 100644 index 28d1d52c..00000000 --- a/c/openssl/hmac.go +++ /dev/null @@ -1,133 +0,0 @@ -package openssl - -import ( - "unsafe" - - "github.com/goplus/lib/c" -) - -const ( - EVP_MAX_MD_SIZE = 64 /* longest known is SHA512 */ -) - -// ----------------------------------------------------------------------------- - -type EVP_MD struct { - Unused [0]byte -} - -// const EVP_MD *EVP_sha1(void) -// -//go:linkname EVP_sha1 C.EVP_sha1 -func EVP_sha1() *EVP_MD - -// const EVP_MD *EVP_sha224(void) -// -//go:linkname EVP_sha224 C.EVP_sha224 -func EVP_sha224() *EVP_MD - -// func EVP_sha256() *EVP_MD -// -//go:linkname EVP_sha256 C.EVP_sha256 -func EVP_sha256() *EVP_MD - -// const EVP_MD *EVP_sha512_224(void) -// -//go:linkname EVP_sha512_224 C.EVP_sha512_224 -func EVP_sha512_224() *EVP_MD - -// const EVP_MD *EVP_sha512_256(void) -// -//go:linkname EVP_sha512_256 C.EVP_sha512_256 -func EVP_sha512_256() *EVP_MD - -// const EVP_MD *EVP_sha384(void) -// -//go:linkname EVP_sha384 C.EVP_sha384 -func EVP_sha384() *EVP_MD - -// const EVP_MD *EVP_sha512(void) -// -//go:linkname EVP_sha512 C.EVP_sha512 -func EVP_sha512() *EVP_MD - -// ----------------------------------------------------------------------------- - -type HMAC_CTX struct { - Unused [0]byte -} - -// OSSL_DEPRECATEDIN_3_0 HMAC_CTX *HMAC_CTX_new(void); -// -//go:linkname NewHMAC_CTX C.HMAC_CTX_new -func NewHMAC_CTX() *HMAC_CTX - -// OSSL_DEPRECATEDIN_3_0 void HMAC_CTX_free(HMAC_CTX *ctx); -// -// llgo:link (*HMAC_CTX).Free C.HMAC_CTX_free -func (ctx *HMAC_CTX) Free() {} - -// OSSL_DEPRECATEDIN_3_0 size_t HMAC_size(const HMAC_CTX *e); -// -// llgo:link (*HMAC_CTX).Size C.HMAC_size -func (ctx *HMAC_CTX) Size() uintptr { return 0 } - -// OSSL_DEPRECATEDIN_3_0 int HMAC_CTX_reset(HMAC_CTX *ctx); -// -// llgo:link (*HMAC_CTX).Reset C.HMAC_CTX_reset -func (ctx *HMAC_CTX) Reset() c.Int { return 0 } - -// OSSL_DEPRECATEDIN_1_1_0 __owur int HMAC_Init(HMAC_CTX *ctx, -// const void *key, int len, -// const EVP_MD *md); -// -// llgo:link (*HMAC_CTX).Init C.HMAC_Init -func (ctx *HMAC_CTX) Init(key unsafe.Pointer, len c.Int, md *EVP_MD) c.Int { return 0 } - -func (ctx *HMAC_CTX) InitBytes(key []byte, md *EVP_MD) c.Int { - return ctx.Init(unsafe.Pointer(unsafe.SliceData(key)), c.Int(len(key)), md) -} - -func (ctx *HMAC_CTX) InitString(key string, md *EVP_MD) c.Int { - return ctx.Init(unsafe.Pointer(unsafe.StringData(key)), c.Int(len(key)), md) -} - -// OSSL_DEPRECATEDIN_3_0 int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len, -// const EVP_MD *md, ENGINE *impl); -// -// llgo:link (*HMAC_CTX).InitEx C.HMAC_Init_ex -func (ctx *HMAC_CTX) InitEx(key unsafe.Pointer, len c.Int, md *EVP_MD, impl unsafe.Pointer) c.Int { - return 0 -} - -// OSSL_DEPRECATEDIN_3_0 int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, -// size_t len); -// -// llgo:link (*HMAC_CTX).Update C.HMAC_Update -func (ctx *HMAC_CTX) Update(data unsafe.Pointer, len uintptr) c.Int { return 0 } - -func (ctx *HMAC_CTX) UpdateBytes(data []byte) c.Int { - return ctx.Update(unsafe.Pointer(unsafe.SliceData(data)), uintptr(len(data))) -} - -func (ctx *HMAC_CTX) UpdateString(data string) c.Int { - return ctx.Update(unsafe.Pointer(unsafe.StringData(data)), uintptr(len(data))) -} - -// OSSL_DEPRECATEDIN_3_0 int HMAC_Final(HMAC_CTX *ctx, unsigned char *md, -// unsigned int *len); -// -// llgo:link (*HMAC_CTX).Final C.HMAC_Final -func (ctx *HMAC_CTX) Final(md *byte, len *c.Uint) c.Int { return 0 } - -// OSSL_DEPRECATEDIN_3_0 __owur int HMAC_CTX_copy(HMAC_CTX *dctx, HMAC_CTX *sctx); -// -// llgo:link (*HMAC_CTX).Copy C.HMAC_CTX_copy -func (ctx *HMAC_CTX) Copy(sctx *HMAC_CTX) c.Int { return 0 } - -// OSSL_DEPRECATEDIN_3_0 void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags); -// -// llgo:link (*HMAC_CTX).SetFlags C.HMAC_CTX_set_flags -func (ctx *HMAC_CTX) SetFlags(flags c.Ulong) {} - -// ----------------------------------------------------------------------------- diff --git a/c/openssl/md5.go b/c/openssl/md5.go deleted file mode 100644 index c0c70a54..00000000 --- a/c/openssl/md5.go +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2024 The XGo Authors (xgo.dev). All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package openssl - -import ( - "unsafe" - - "github.com/goplus/lib/c" -) - -// ----------------------------------------------------------------------------- - -const ( - MD5_CBLOCK = 64 - MD5_LBLOCK = MD5_CBLOCK / 4 -) - -// ----------------------------------------------------------------------------- - -type MD5_LONG = c.Uint - -type MD5_CTX struct { - A, B, C, D MD5_LONG - Nl, Nh MD5_LONG - Data [MD5_LBLOCK]MD5_LONG - Num c.Uint -} - -// OSSL_DEPRECATEDIN_3_0 int MD5_Init(MD5_CTX *c); -// -// llgo:link (*MD5_CTX).Init C.MD5_Init -func (c *MD5_CTX) Init() c.Int { return 0 } - -// OSSL_DEPRECATEDIN_3_0 int MD5_Update(MD5_CTX *c, const void *data, size_t len); -// -// llgo:link (*MD5_CTX).Update C.MD5_Update -func (c *MD5_CTX) Update(data unsafe.Pointer, n uintptr) c.Int { return 0 } - -func (c *MD5_CTX) UpdateBytes(data []byte) c.Int { - return c.Update(unsafe.Pointer(unsafe.SliceData(data)), uintptr(len(data))) -} - -func (c *MD5_CTX) UpdateString(data string) c.Int { - return c.Update(unsafe.Pointer(unsafe.StringData(data)), uintptr(len(data))) -} - -// OSSL_DEPRECATEDIN_3_0 int MD5_Final(unsigned char *md, MD5_CTX *c); -// -//go:linkname md5Final C.MD5_Final -func md5Final(md *byte, c *MD5_CTX) c.Int - -func (c *MD5_CTX) Final(md *byte) c.Int { - return md5Final(md, c) -} - -// OSSL_DEPRECATEDIN_3_0 unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md); -// -//go:linkname MD5 C.MD5 -func MD5(data unsafe.Pointer, n uintptr, md *byte) *byte - -func MD5Bytes(data []byte, md *byte) *byte { - return MD5(unsafe.Pointer(unsafe.SliceData(data)), uintptr(len(data)), md) -} - -func MD5String(data string, md *byte) *byte { - return MD5(unsafe.Pointer(unsafe.StringData(data)), uintptr(len(data)), md) -} - -// OSSL_DEPRECATEDIN_3_0 void MD5_Transform(MD5_CTX *c, const unsigned char *b); - -// ----------------------------------------------------------------------------- diff --git a/c/openssl/openssl.go b/c/openssl/openssl.go deleted file mode 100644 index 0aa0635b..00000000 --- a/c/openssl/openssl.go +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2024 The XGo Authors (xgo.dev). All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package openssl - -import ( - "unsafe" - - "github.com/goplus/lib/c" -) - -// ----------------------------------------------------------------------------- - -const ( - LLGoFiles = "$(pkg-config --cflags openssl): _wrap/openssl.c" - LLGoPackage = "link: $(pkg-config --libs openssl); -lssl -lcrypto" -) - -//go:linkname Free C.opensslFree -func Free(ptr unsafe.Pointer) - -//go:linkname FreeCStr C.opensslFree -func FreeCStr(ptr *c.Char) - -// ----------------------------------------------------------------------------- diff --git a/c/openssl/pem.go b/c/openssl/pem.go deleted file mode 100644 index 795a7c06..00000000 --- a/c/openssl/pem.go +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2024 The XGo Authors (xgo.dev). All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package openssl - -import ( - "unsafe" - - "github.com/goplus/lib/c" -) - -// ----------------------------------------------------------------------------- - -// typedef int (*pem_password_cb)(char *buf, int size, int rwflag, void *userdata); -// -//llgo:cdecl -type PemPasswordCb func(buf *c.Char, size, rwflag c.Int, userdata unsafe.Pointer) c.Int - -// RSA *PEM_read_bio_RSAPrivateKey(BIO *bp, RSA **x, pem_password_cb *cb, void *u); -// -//go:linkname PEMReadBioRSAPrivateKey C.PEM_read_bio_RSAPrivateKey -func PEMReadBioRSAPrivateKey(bp *BIO, x **RSA, cb PemPasswordCb, u unsafe.Pointer) *RSA - -// ----------------------------------------------------------------------------- diff --git a/c/openssl/rand.go b/c/openssl/rand.go deleted file mode 100644 index 60ea89fc..00000000 --- a/c/openssl/rand.go +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2024 The XGo Authors (xgo.dev). All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package openssl - -import ( - "unsafe" - - "github.com/goplus/lib/c" -) - -// ----------------------------------------------------------------------------- - -// int RAND_bytes(unsigned char *buf, int num); -// -//go:linkname RANDBufferWithLen C.RAND_bytes -func RANDBufferWithLen(buf *byte, num c.Int) c.Int - -func RANDBytes(buf []byte) c.Int { - return RANDBufferWithLen(unsafe.SliceData(buf), c.Int(len(buf))) -} - -// int RAND_priv_bytes(unsigned char *buf, int num); -// -//go:linkname RANDPrivBufferWithLen C.RAND_priv_bytes -func RANDPrivBufferWithLen(buf *byte, num c.Int) c.Int - -func RANDPrivBytes(buf []byte) c.Int { - return RANDPrivBufferWithLen(unsafe.SliceData(buf), c.Int(len(buf))) -} - -// void RAND_seed(const void *buf, int num); -// -//go:linkname RANDSeed C.RAND_seed -func RANDSeed(buf unsafe.Pointer, num c.Int) - -// void RAND_keep_random_devices_open(int keep); -// -//go:linkname RANDKeepRandomDevicesOpen C.RAND_keep_random_devices_open -func RANDKeepRandomDevicesOpen(keep c.Int) - -// int RAND_load_file(const char *file, long max_bytes); -// -//go:linkname RANDLoadFile C.RAND_load_file -func RANDLoadFile(file *c.Char, maxBytes c.Long) c.Int - -// int RAND_write_file(const char *file); -// -//go:linkname RANDWriteFile C.RAND_write_file -func RANDWriteFile(file *c.Char) c.Int - -// const char *RAND_file_name(char *file, size_t num); -// -//go:linkname RANDFileName C.RAND_file_name -func RANDFileName(file *c.Char, num uintptr) *c.Char - -// int RAND_status(void); -// -//go:linkname RANDStatus C.RAND_status -func RANDStatus() c.Int - -// int RAND_poll(void); -// -//go:linkname RANDPoll C.RAND_poll -func RANDPoll() c.Int - -// ----------------------------------------------------------------------------- diff --git a/c/openssl/rsa.go b/c/openssl/rsa.go deleted file mode 100644 index 2254c824..00000000 --- a/c/openssl/rsa.go +++ /dev/null @@ -1,305 +0,0 @@ -/* - * Copyright (c) 2024 The XGo Authors (xgo.dev). All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package openssl - -import ( - "unsafe" - - "github.com/goplus/lib/c" -) - -// ----------------------------------------------------------------------------- - -type RSA_METHOD struct { - Unused [0]byte -} - -// OSSL_DEPRECATEDIN_3_0 RSA_METHOD *RSA_meth_new(const char *name, int flags); -// -//go:linkname RSAMethNew C.RSA_meth_new -func RSAMethNew(name *byte, flags c.Int) *RSA_METHOD - -// OSSL_DEPRECATEDIN_3_0 void RSA_meth_free(RSA_METHOD *meth); -// -// llgo:link (*RSA_METHOD).Free C.RSA_meth_free -func (*RSA_METHOD) Free() {} - -// OSSL_DEPRECATEDIN_3_0 -// int RSA_meth_set_init(RSA_METHOD *rsa, int (*init) (RSA *rsa)); -// -// llgo:link (*RSA_METHOD).SetInit C.RSA_meth_set_init -func (*RSA_METHOD) SetInit(init func(rsa *RSA) c.Int) c.Int { return 0 } - -// OSSL_DEPRECATEDIN_3_0 -// int RSA_meth_set_finish(RSA_METHOD *rsa, int (*finish) (RSA *rsa)); -// -// llgo:link (*RSA_METHOD).SetFinish C.RSA_meth_set_finish -func (*RSA_METHOD) SetFinish(finish func(rsa *RSA) c.Int) c.Int { return 0 } - -/* -OSSL_DEPRECATEDIN_3_0 -int RSA_meth_set_mod_exp(RSA_METHOD *rsa, - int (*mod_exp) (BIGNUM *r0, const BIGNUM *i, RSA *rsa, - BN_CTX *ctx)); -*/ -// llgo:link (*RSA_METHOD).SetModExp C.RSA_meth_set_mod_exp -func (*RSA_METHOD) SetModExp(modExp func( - r0 *BIGNUM, i *BIGNUM, rsa *RSA, ctx *BN_CTX) c.Int) c.Int { - return 0 -} - -/* -OSSL_DEPRECATEDIN_3_0 -int RSA_meth_set_bn_mod_exp(RSA_METHOD *rsa, - int (*bn_mod_exp) (BIGNUM *r, - const BIGNUM *a, - const BIGNUM *p, - const BIGNUM *m, - BN_CTX *ctx, - BN_MONT_CTX *m_ctx)); -//-llgo:link (*RSA_METHOD).SetBnModExp C.RSA_meth_set_bn_mod_exp -func (*RSA_METHOD) SetBnModExp(bnModExp func( - r *BIGNUM, a *BIGNUM, p *BIGNUM, m *BIGNUM, ctx *BN_CTX, mCtx *BN_MONT_CTX) c.Int) c.Int { - return 0 -} -*/ - -/* -OSSL_DEPRECATEDIN_3_0 -int RSA_meth_set_pub_enc(RSA_METHOD *rsa, - int (*pub_enc) (int flen, const unsigned char *from, - unsigned char *to, RSA *rsa, - int padding)); -*/ -// llgo:link (*RSA_METHOD).SetPubEnc C.RSA_meth_set_pub_enc -func (*RSA_METHOD) SetPubEnc(pubEnc func( - flen c.Int, from *byte, to *byte, rsa *RSA, padding c.Int) c.Int) c.Int { - return 0 -} - -/* -OSSL_DEPRECATEDIN_3_0 -int RSA_meth_set_pub_dec(RSA_METHOD *rsa, - int (*pub_dec) (int flen, const unsigned char *from, - unsigned char *to, RSA *rsa, - int padding)); -*/ -// llgo:link (*RSA_METHOD).SetPubDec C.RSA_meth_set_pub_dec -func (*RSA_METHOD) SetPubDec(pubDec func( - flen c.Int, from *byte, to *byte, rsa *RSA, padding c.Int) c.Int) c.Int { - return 0 -} - -/* -OSSL_DEPRECATEDIN_3_0 -int RSA_meth_set_priv_enc(RSA_METHOD *rsa, - int (*priv_enc) (int flen, const unsigned char *from, - unsigned char *to, RSA *rsa, - int padding)); -*/ -// llgo:link (*RSA_METHOD).SetPrivEnc C.RSA_meth_set_priv_enc -func (*RSA_METHOD) SetPrivEnc(privEnc func( - flen c.Int, from *byte, to *byte, rsa *RSA, padding c.Int) c.Int) c.Int { - return 0 -} - -/* -OSSL_DEPRECATEDIN_3_0 -int RSA_meth_set_priv_dec(RSA_METHOD *rsa, - int (*priv_dec) (int flen, const unsigned char *from, - unsigned char *to, RSA *rsa, - int padding)); -*/ -// llgo:link (*RSA_METHOD).SetPrivDec C.RSA_meth_set_priv_dec -func (*RSA_METHOD) SetPrivDec(privDec func( - flen c.Int, from *byte, to *byte, rsa *RSA, padding c.Int) c.Int) c.Int { - return 0 -} - -/* -OSSL_DEPRECATEDIN_3_0 -int RSA_meth_set_sign(RSA_METHOD *rsa, - int (*sign) (int type, const unsigned char *m, - unsigned int m_length, - unsigned char *sigret, unsigned int *siglen, - const RSA *rsa)); -*/ -// llgo:link (*RSA_METHOD).SetSign C.RSA_meth_set_sign -func (*RSA_METHOD) SetSign(sign func( - typ c.Int, msg *byte, mlen c.Uint, - sigret *byte, siglen *c.Uint, rsa *RSA) c.Int) c.Int { - return 0 -} - -/* -OSSL_DEPRECATEDIN_3_0 -int RSA_meth_set_verify(RSA_METHOD *rsa, - int (*verify) (int dtype, const unsigned char *m, - unsigned int m_length, - const unsigned char *sigbuf, - unsigned int siglen, const RSA *rsa)); -*/ -// llgo:link (*RSA_METHOD).SetVerify C.RSA_meth_set_verify -func (*RSA_METHOD) SetVerify(verify func( - dtype c.Int, msg *byte, mlen c.Uint, - sigbuf *byte, siglen c.Uint, rsa *RSA) c.Int) c.Int { - return 0 -} - -/* -OSSL_DEPRECATEDIN_3_0 -int RSA_meth_set_keygen(RSA_METHOD *rsa, - int (*keygen) (RSA *rsa, int bits, BIGNUM *e, - BN_GENCB *cb)); - -OSSL_DEPRECATEDIN_3_0 -int RSA_meth_set_multi_prime_keygen(RSA_METHOD *meth, - int (*keygen) (RSA *rsa, int bits, - int primes, BIGNUM *e, - BN_GENCB *cb)); -*/ - -// ----------------------------------------------------------------------------- - -type RSA struct { - Unused [0]byte -} - -// OSSL_DEPRECATEDIN_3_0 RSA *RSA_new(void); -// -//go:linkname RSANew C.RSA_new -func RSANew() *RSA - -// OSSL_DEPRECATEDIN_3_0 RSA *RSA_new_method(ENGINE *engine); - -// OSSL_DEPRECATEDIN_3_0 void RSA_free(RSA *r); -// -// llgo:link (*RSA).Free C.RSA_free -func (*RSA) Free() {} - -// "up" the RSA object's reference count -// OSSL_DEPRECATEDIN_3_0 int RSA_up_ref(RSA *r); -// -// llgo:link (*RSA).UpRef C.RSA_up_ref -func (*RSA) UpRef() c.Int { return 0 } - -// OSSL_DEPRECATEDIN_3_0 int RSA_bits(const RSA *rsa); -// -// llgo:link (*RSA).Bits C.RSA_bits -func (*RSA) Bits() c.Int { return 0 } - -// OSSL_DEPRECATEDIN_3_0 int RSA_size(const RSA *rsa); -// -// llgo:link (*RSA).Size C.RSA_size -func (*RSA) Size() c.Int { return 0 } - -// OSSL_DEPRECATEDIN_3_0 int RSA_security_bits(const RSA *rsa); -// -// llgo:link (*RSA).SecurityBits C.RSA_security_bits -func (*RSA) SecurityBits() c.Int { return 0 } - -// OSSL_DEPRECATEDIN_3_0 int RSA_flags(const RSA *r); -// -// llgo:link (*RSA).Flags C.RSA_flags -func (*RSA) Flags() c.Int { return 0 } - -// OSSL_DEPRECATEDIN_3_0 void RSA_set_flags(RSA *r, int flags); -// -// llgo:link (*RSA).SetFlags C.RSA_set_flags -func (*RSA) SetFlags(flags c.Int) {} - -// OSSL_DEPRECATEDIN_3_0 void RSA_clear_flags(RSA *r, int flags); -// -// llgo:link (*RSA).ClearFlags C.RSA_clear_flags -func (*RSA) ClearFlags(flags c.Int) {} - -// OSSL_DEPRECATEDIN_3_0 int RSA_test_flags(const RSA *r, int flags); -// -// llgo:link (*RSA).TestFlags C.RSA_test_flags -func (*RSA) TestFlags(flags c.Int) c.Int { return 0 } - -// OSSL_DEPRECATEDIN_3_0 int RSA_get_version(RSA *r); -// -// llgo:link (*RSA).GetVersion C.RSA_get_version -func (*RSA) GetVersion() c.Int { return 0 } - -// OSSL_DEPRECATEDIN_3_0 int RSA_set_ex_data(RSA *r, int idx, void *arg); -// -// llgo:link (*RSA).SetExData C.RSA_set_ex_data -func (*RSA) SetExData(idx c.Int, arg unsafe.Pointer) c.Int { return 0 } - -// OSSL_DEPRECATEDIN_3_0 void *RSA_get_ex_data(const RSA *r, int idx); -// -// llgo:link (*RSA).GetExData C.RSA_get_ex_data -func (*RSA) GetExData(idx c.Int) unsafe.Pointer { return nil } - -// OSSL_DEPRECATEDIN_3_0 int RSA_set_method(RSA *rsa, const RSA_METHOD *meth); -// -// llgo:link (*RSA).SetMethod C.RSA_set_method -func (*RSA) SetMethod(meth *RSA_METHOD) c.Int { return 0 } - -// OSSL_DEPRECATEDIN_3_0 int RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb); -// -// llgo:link (*RSA).GenerateKeyEx C.RSA_generate_key_ex -func (*RSA) GenerateKeyEx(bits c.Int, e *BIGNUM, cb *BN_GENCB) c.Int { return 0 } - -// OSSL_DEPRECATEDIN_3_0 int RSA_generate_multi_prime_key(RSA *rsa, int bits, int primes, BIGNUM *e, BN_GENCB *cb); -// -// llgo:link (*RSA).GenerateMultiPrimeKey C.RSA_generate_multi_prime_key -func (*RSA) GenerateMultiPrimeKey(bits, primes c.Int, e *BIGNUM, cb *BN_GENCB) c.Int { return 0 } - -/* -// next 4 return -1 on error - -OSSL_DEPRECATEDIN_3_0 -int RSA_public_encrypt(int flen, const unsigned char *from, unsigned char *to, - RSA *rsa, int padding); -OSSL_DEPRECATEDIN_3_0 -int RSA_private_encrypt(int flen, const unsigned char *from, unsigned char *to, - RSA *rsa, int padding); -OSSL_DEPRECATEDIN_3_0 -int RSA_public_decrypt(int flen, const unsigned char *from, unsigned char *to, - RSA *rsa, int padding); -OSSL_DEPRECATEDIN_3_0 -int RSA_private_decrypt(int flen, const unsigned char *from, unsigned char *to, - RSA *rsa, int padding); -*/ -//go:linkname RSAPublicEncrypt C.RSA_public_encrypt -func RSAPublicEncrypt(flen c.Int, from *byte, to *byte, rsa *RSA, padding c.Int) c.Int - -//go:linkname RSAPrivateEncrypt C.RSA_private_encrypt -func RSAPrivateEncrypt(flen c.Int, from *byte, to *byte, rsa *RSA, padding c.Int) c.Int - -//go:linkname RSAPublicDecrypt C.RSA_public_decrypt -func RSAPublicDecrypt(flen c.Int, from *byte, to *byte, rsa *RSA, padding c.Int) c.Int - -//go:linkname RSAPrivateDecrypt C.RSA_private_decrypt -func RSAPrivateDecrypt(flen c.Int, from *byte, to *byte, rsa *RSA, padding c.Int) c.Int - -// OSSL_DEPRECATEDIN_3_0 int RSA_sign( -// int type, const unsigned char *m, unsigned int m_length, -// unsigned char *sigret, unsigned int *siglen, RSA *rsa); -// -//go:linkname RSASign C.RSA_sign -func RSASign(typ c.Int, msg *byte, mlen c.Uint, sigret *byte, siglen *c.Uint, rsa *RSA) c.Int - -// OSSL_DEPRECATEDIN_3_0 int RSA_verify(int type, const unsigned char *m, -// unsigned int m_length, -// const unsigned char *sigbuf, -// unsigned int siglen, RSA *rsa); - -// ----------------------------------------------------------------------------- diff --git a/c/openssl/sha1.go b/c/openssl/sha1.go deleted file mode 100644 index 874c42ef..00000000 --- a/c/openssl/sha1.go +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2024 The XGo Authors (xgo.dev). All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package openssl - -import ( - "unsafe" - - "github.com/goplus/lib/c" -) - -const ( - SHA_DIGEST_LENGTH = 20 - SHA_LBLOCK = 16 - SHA_CBLOCK = (SHA_LBLOCK * 4) - SHA_LAST_BLOCK = (SHA_CBLOCK - 8) - - SHA256_CBLOCK = (SHA_LBLOCK * 4) - SHA256_192_DIGEST_LENGTH = 24 - SHA224_DIGEST_LENGTH = 28 - SHA256_DIGEST_LENGTH = 32 - SHA384_DIGEST_LENGTH = 48 - SHA512_DIGEST_LENGTH = 64 - SHA512_CBLOCK = (SHA_LBLOCK * 8) -) - -type SHA_LONG64 = c.UlongLong - -type SHA_LONG = c.Uint - -type SHA_CTX struct { - H0, H1, H2, H3, H4 SHA_LONG - Nl, Nh SHA_LONG - Data [SHA_LBLOCK]SHA_LONG - Num c.Uint -} - -// OSSL_DEPRECATEDIN_3_0 int SHA1_Init(SHA_CTX *c); -// -// llgo:link (*SHA_CTX).Init C.SHA1_Init -func (c *SHA_CTX) Init() c.Int { return 0 } - -// OSSL_DEPRECATEDIN_3_0 int SHA1_Update(SHA_CTX *c, const void *data, size_t len); -// -// llgo:link (*SHA_CTX).Update C.SHA1_Update -func (c *SHA_CTX) Update(data unsafe.Pointer, n uintptr) c.Int { return 0 } - -func (c *SHA_CTX) UpdateBytes(data []byte) c.Int { - return c.Update(unsafe.Pointer(unsafe.SliceData(data)), uintptr(len(data))) -} - -func (c *SHA_CTX) UpdateString(data string) c.Int { - return c.Update(unsafe.Pointer(unsafe.StringData(data)), uintptr(len(data))) -} - -// OSSL_DEPRECATEDIN_3_0 int SHA1_Final(unsigned char *md, SHA_CTX *c); -// -//go:linkname sha1Final C.SHA1_Final -func sha1Final(md *byte, c *SHA_CTX) c.Int - -func (c *SHA_CTX) Final(md *byte) c.Int { - return sha1Final(md, c) -} - -// OSSL_DEPRECATEDIN_3_0 void SHA1_Transform(SHA_CTX *c, const unsigned char *data); -// -// llgo:link (*SHA_CTX).Transform C.SHA1_Transform -func (c *SHA_CTX) Transform(data *byte) {} - -// unsigned char *SHA1(const unsigned char *d, size_t n, unsigned char *md); -// -//go:linkname SHA1 C.SHA1 -func SHA1(data unsafe.Pointer, n uintptr, md *byte) *byte - -func SHA1Bytes(data []byte, md *byte) *byte { - return SHA1(unsafe.Pointer(unsafe.SliceData(data)), uintptr(len(data)), md) -} - -func SHA1String(data string, md *byte) *byte { - return SHA1(unsafe.Pointer(unsafe.StringData(data)), uintptr(len(data)), md) -} diff --git a/c/openssl/sha256.go b/c/openssl/sha256.go deleted file mode 100644 index 783b935a..00000000 --- a/c/openssl/sha256.go +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2024 The XGo Authors (xgo.dev). All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package openssl - -import ( - "unsafe" - - "github.com/goplus/lib/c" -) - -type SHA256_CTX struct { - H [8]SHA_LONG - Nl, Nh SHA_LONG - Data [SHA_LBLOCK]SHA_LONG - Num, MdLen c.Uint -} - -type SHA224_CTX SHA256_CTX - -// OSSL_DEPRECATEDIN_3_0 int SHA224_Init(SHA256_CTX *c); -// -// llgo:link (*SHA224_CTX).Init C.SHA224_Init -func (c *SHA224_CTX) Init() c.Int { return 0 } - -// OSSL_DEPRECATEDIN_3_0 int SHA224_Update(SHA256_CTX *c, const void *data, size_t len); -// -// llgo:link (*SHA224_CTX).Update C.SHA224_Update -func (c *SHA224_CTX) Update(data unsafe.Pointer, n uintptr) c.Int { return 0 } - -func (c *SHA224_CTX) UpdateBytes(data []byte) c.Int { - return c.Update(unsafe.Pointer(unsafe.SliceData(data)), uintptr(len(data))) -} - -func (c *SHA224_CTX) UpdateString(data string) c.Int { - return c.Update(unsafe.Pointer(unsafe.StringData(data)), uintptr(len(data))) -} - -// OSSL_DEPRECATEDIN_3_0 int SHA224_Final(unsigned char *md, SHA256_CTX *c); -// -//go:linkname sha224Final C.SHA224_Final -func sha224Final(md *byte, c *SHA224_CTX) c.Int - -func (c *SHA224_CTX) Final(md *byte) c.Int { - return sha224Final(md, c) -} - -// OSSL_DEPRECATEDIN_3_0 int SHA256_Init(SHA256_CTX *c); -// -// llgo:link (*SHA256_CTX).Init C.SHA256_Init -func (c *SHA256_CTX) Init() c.Int { return 0 } - -// OSSL_DEPRECATEDIN_3_0 int SHA256_Update(SHA256_CTX *c, const void *data, size_t len); -// -// llgo:link (*SHA256_CTX).Update C.SHA256_Update -func (c *SHA256_CTX) Update(data unsafe.Pointer, n uintptr) c.Int { return 0 } - -func (c *SHA256_CTX) UpdateBytes(data []byte) c.Int { - return c.Update(unsafe.Pointer(unsafe.SliceData(data)), uintptr(len(data))) -} - -func (c *SHA256_CTX) UpdateString(data string) c.Int { - return c.Update(unsafe.Pointer(unsafe.StringData(data)), uintptr(len(data))) -} - -// OSSL_DEPRECATEDIN_3_0 int SHA256_Final(unsigned char *md, SHA256_CTX *c); -// -//go:linkname sha256Final C.SHA256_Final -func sha256Final(md *byte, c *SHA256_CTX) c.Int - -func (c *SHA256_CTX) Final(md *byte) c.Int { - return sha256Final(md, c) -} - -// OSSL_DEPRECATEDIN_3_0 void SHA256_Transform(SHA256_CTX *c, const unsigned char *data); -// -// llgo:link (*SHA256_CTX).Transform C.SHA256_Transform -func (c *SHA256_CTX) Transform(data *byte) {} - -// unsigned char *SHA224(const unsigned char *d, size_t n, unsigned char *md); -// -//go:linkname SHA224 C.SHA224 -func SHA224(data unsafe.Pointer, n uintptr, md *byte) *byte - -func SHA224Bytes(data []byte, md *byte) *byte { - return SHA224(unsafe.Pointer(unsafe.SliceData(data)), uintptr(len(data)), md) -} - -func SHA224String(data string, md *byte) *byte { - return SHA224(unsafe.Pointer(unsafe.StringData(data)), uintptr(len(data)), md) -} - -// unsigned char *SHA256(const unsigned char *d, size_t n, unsigned char *md); -// -//go:linkname SHA256 C.SHA256 -func SHA256(data unsafe.Pointer, n uintptr, md *byte) *byte - -func SHA256Bytes(data []byte, md *byte) *byte { - return SHA256(unsafe.Pointer(unsafe.SliceData(data)), uintptr(len(data)), md) -} - -func SHA256String(data string, md *byte) *byte { - return SHA256(unsafe.Pointer(unsafe.StringData(data)), uintptr(len(data)), md) -} diff --git a/c/openssl/sha512.go b/c/openssl/sha512.go deleted file mode 100644 index a32c4203..00000000 --- a/c/openssl/sha512.go +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (c) 2024 The XGo Authors (xgo.dev). All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package openssl - -import ( - "unsafe" - - "github.com/goplus/lib/c" -) - -type SHA512_CTX struct { - H [8]SHA_LONG64 - N1, Nh SHA_LONG64 - D [SHA_LBLOCK]SHA_LONG64 - Num, MdLen c.Uint -} - -type SHA384_CTX SHA512_CTX - -// OSSL_DEPRECATEDIN_3_0 int SHA384_Init(SHA512_CTX *c); -// -// llgo:link (*SHA384_CTX).Init C.SHA384_Init -func (c *SHA384_CTX) Init() c.Int { return 0 } - -// OSSL_DEPRECATEDIN_3_0 int SHA384_Update(SHA512_CTX *c, const void *data, size_t len); -// -// llgo:link (*SHA384_CTX).Update C.SHA384_Update -func (c *SHA384_CTX) Update(data unsafe.Pointer, n uintptr) c.Int { return 0 } - -func (c *SHA384_CTX) UpdateBytes(data []byte) c.Int { - return c.Update(unsafe.Pointer(unsafe.SliceData(data)), uintptr(len(data))) -} - -func (c *SHA384_CTX) UpdateString(data string) c.Int { - return c.Update(unsafe.Pointer(unsafe.StringData(data)), uintptr(len(data))) -} - -// OSSL_DEPRECATEDIN_3_0 int SHA384_Final(unsigned char *md, SHA512_CTX *c); -// -//go:linkname sha384Final C.SHA384_Final -func sha384Final(md *byte, c *SHA384_CTX) c.Int - -func (c *SHA384_CTX) Final(md *byte) c.Int { - return sha384Final(md, c) -} - -// OSSL_DEPRECATEDIN_3_0 int SHA512_Init(SHA512_CTX *c); -// -// llgo:link (*SHA512_CTX).Init C.SHA512_Init -func (c *SHA512_CTX) Init() c.Int { return 0 } - -// OSSL_DEPRECATEDIN_3_0 int SHA512_Update(SHA512_CTX *c, const void *data, size_t len); -// -// llgo:link (*SHA512_CTX).Update C.SHA512_Update -func (c *SHA512_CTX) Update(data unsafe.Pointer, n uintptr) c.Int { return 0 } -func (c *SHA512_CTX) UpdateBytes(data []byte) c.Int { - return c.Update(unsafe.Pointer(unsafe.SliceData(data)), uintptr(len(data))) -} -func (c *SHA512_CTX) UpdateString(data string) c.Int { - return c.Update(unsafe.Pointer(unsafe.StringData(data)), uintptr(len(data))) -} - -// OSSL_DEPRECATEDIN_3_0 int SHA512_Final(unsigned char *md, SHA512_CTX *c); -// -//go:linkname sha512Final C.SHA512_Final -func sha512Final(md *byte, c *SHA512_CTX) c.Int - -func (c *SHA512_CTX) Final(md *byte) c.Int { - return sha512Final(md, c) -} - -// OSSL_DEPRECATEDIN_3_0 void SHA512_Transform(SHA512_CTX *c, const unsigned char *data); -// -// llgo:link (*SHA512_CTX).Transform C.SHA512_Transform -func (c *SHA512_CTX) Transform(data *byte) {} - -// unsigned char *SHA384(const unsigned char *d, size_t n, unsigned char *md); -// -//go:linkname SHA384 C.SHA384 -func SHA384(data unsafe.Pointer, n uintptr, md *byte) *byte - -func SHA384Bytes(data []byte, md *byte) *byte { - return SHA384(unsafe.Pointer(unsafe.SliceData(data)), uintptr(len(data)), md) -} - -func SHA384String(data string, md *byte) *byte { - return SHA384(unsafe.Pointer(unsafe.StringData(data)), uintptr(len(data)), md) -} - -// unsigned char *SHA512(const unsigned char *d, size_t n, unsigned char *md); -// -//go:linkname SHA512 C.SHA512 -func SHA512(data unsafe.Pointer, n uintptr, md *byte) *byte - -func SHA512Bytes(data []byte, md *byte) *byte { - return SHA512(unsafe.Pointer(unsafe.SliceData(data)), uintptr(len(data)), md) -} - -func SHA512String(data string, md *byte) *byte { - return SHA512(unsafe.Pointer(unsafe.StringData(data)), uintptr(len(data)), md) -} From 3b52d9462c6f86ddc03c1481cd8274e37c304280 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Wed, 28 Oct 2026 18:11:35 +0800 Subject: [PATCH 2/2] c: intptr types => int --- c/c.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/c/c.go b/c/c.go index 959be22f..46eabe50 100644 --- a/c/c.go +++ b/c/c.go @@ -57,11 +57,11 @@ type integer interface { } type SizeT = uintptr -type SsizeT = Long -type PtrdiffT = Long - -type IntptrT = uintptr +type SsizeT = int +type PtrdiffT = int +type IntptrT = int type UintptrT = uintptr + type Int8T = int8 type Int16T = int16 type Int32T = int32