Skip to content

Commit 816703e

Browse files
authored
Merge pull request #98 from corhere/windows-support
Support Unix and Windows
2 parents 758238f + f15d212 commit 816703e

35 files changed

+358
-88
lines changed

.github/workflows/test.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,39 @@ jobs:
4545
$ok
4646
env:
4747
GO_OPENSSL_VERSION_OVERRIDE: ${{ matrix.openssl-version }}
48+
wintest:
49+
runs-on: windows-2022
50+
strategy:
51+
fail-fast: false
52+
matrix:
53+
go-version: [1.20.x]
54+
openssl-version: [libcrypto-1_1-x64.dll, libcrypto-3-x64.dll]
55+
steps:
56+
- name: Install Go
57+
uses: actions/setup-go@v3
58+
with:
59+
go-version: ${{ matrix.go-version }}
60+
- name: Checkout code
61+
uses: actions/checkout@v3
62+
- name: Run Test
63+
run: go test -gcflags=all=-d=checkptr -count 10 -v ./...
64+
env:
65+
GO_OPENSSL_VERSION_OVERRIDE: ${{ matrix.openssl-version }}
66+
mactest:
67+
strategy:
68+
fail-fast: false
69+
matrix:
70+
go-version: [1.20.x]
71+
openssl-version: [libcrypto.3.dylib]
72+
runs-on: macos-12
73+
steps:
74+
- name: Install Go
75+
uses: actions/setup-go@v3
76+
with:
77+
go-version: ${{ matrix.go-version }}
78+
- name: Checkout code
79+
uses: actions/checkout@v3
80+
- name: Run Test
81+
run: go test -gcflags=all=-d=checkptr -count 10 -v ./...
82+
env:
83+
GO_OPENSSL_VERSION_OVERRIDE: ${{ matrix.openssl-version }}

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ This feature does not require any additional configuration, but it only works wi
5050

5151
## Limitations
5252

53-
OpenSSL is used for a given build only in limited circumstances:
54-
55-
- The platform must be `GOOS=linux`.
53+
- Only Unix, Unix-like and Windows platforms are supported.
5654
- The build must set `CGO_ENABLED=1`.
5755

5856
## Acknowledgements

aes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build linux && !cmd_go_bootstrap
1+
//go:build !cmd_go_bootstrap
22

33
package openssl
44

aes_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//go:build linux
2-
31
package openssl
42

53
import (

ec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build linux && !cmd_go_bootstrap
1+
//go:build !cmd_go_bootstrap
22

33
package openssl
44

ecdh.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build linux && !cmd_go_bootstrap
1+
//go:build !cmd_go_bootstrap
22

33
package openssl
44

@@ -101,7 +101,7 @@ func (k *PrivateKeyECDH) PublicKey() (*PublicKeyECDH, error) {
101101
return nil, newOpenSSLError("EVP_PKEY_get_octet_string_param")
102102
}
103103
bytes = C.GoBytes(unsafe.Pointer(cbytes), C.int(n))
104-
C.free(unsafe.Pointer(cbytes))
104+
cryptoFree(unsafe.Pointer(cbytes))
105105
default:
106106
panic(errUnsupportedVersion())
107107
}
@@ -314,8 +314,8 @@ func GenerateKeyECDH(curve string) (*PrivateKeyECDH, []byte, error) {
314314
// generating a private ECDH key.
315315
bits := C.go_openssl_EVP_PKEY_get_bits(pkey)
316316
bytes := make([]byte, (bits+7)/8)
317-
if C.go_openssl_BN_bn2binpad(priv, base(bytes), C.int(len(bytes))) == 0 {
318-
return nil, nil, newOpenSSLError("BN_bn2binpad")
317+
if err := bnToBinPad(priv, bytes); err != nil {
318+
return nil, nil, err
319319
}
320320
k = &PrivateKeyECDH{pkey, curve, true}
321321
runtime.SetFinalizer(k, (*PrivateKeyECDH).finalize)

ecdh_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//go:build linux
2-
31
package openssl_test
42

53
import (

ecdsa.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build linux && !cmd_go_bootstrap
1+
//go:build !cmd_go_bootstrap
22

33
package openssl
44

ecdsa_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//go:build linux
2-
31
package openssl_test
42

53
import (

evp.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build linux && !cmd_go_bootstrap
1+
//go:build !cmd_go_bootstrap
22

33
package openssl
44

@@ -197,12 +197,11 @@ func setupEVP(withKey withKeyFunc, padding C.int,
197197
}
198198
}
199199
// ctx takes ownership of label, so malloc a copy for OpenSSL to free.
200-
// OpenSSL 1.1.1 and higher does not take ownership of the label if the length is zero,
200+
// OpenSSL does not take ownership of the label if the length is zero,
201201
// so better avoid the allocation.
202202
var clabel *C.uchar
203203
if len(label) > 0 {
204-
// Go guarantees C.malloc never returns nil.
205-
clabel = (*C.uchar)(C.malloc(C.size_t(len(label))))
204+
clabel = (*C.uchar)(cryptoMalloc(len(label)))
206205
copy((*[1 << 30]byte)(unsafe.Pointer(clabel))[:len(label)], label)
207206
}
208207
var ret C.int
@@ -212,7 +211,7 @@ func setupEVP(withKey withKeyFunc, padding C.int,
212211
ret = C.go_openssl_EVP_PKEY_CTX_ctrl(ctx, C.GO_EVP_PKEY_RSA, -1, C.GO_EVP_PKEY_CTRL_RSA_OAEP_LABEL, C.int(len(label)), unsafe.Pointer(clabel))
213212
}
214213
if ret != 1 {
215-
C.free(unsafe.Pointer(clabel))
214+
cryptoFree(unsafe.Pointer(clabel))
216215
return nil, newOpenSSLError("EVP_PKEY_CTX_ctrl failed")
217216
}
218217
case C.GO_RSA_PKCS1_PSS_PADDING:

0 commit comments

Comments
 (0)