Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
51c7f68
openssl: implement cgoless wrappers for C functions
gdams Sep 17, 2025
4f87ad6
fix aes test
gdams Sep 17, 2025
51e901b
remove darwin pins
gdams Sep 17, 2025
ddd7774
unskip md4 hash test
gdams Sep 18, 2025
34c5fd4
enable more tests
gdams Sep 18, 2025
1a5cb17
re enable symcrypt tests
gdams Sep 18, 2025
0b19b6c
add boiletplate linux syscall file
gdams Sep 18, 2025
1c20c23
auto generate variadic functions
gdams Sep 18, 2025
04d709b
add checkheader if statement back
gdams Sep 18, 2025
c80a17c
fix windows
qmuntal Sep 18, 2025
2578b21
implement windows support
gdams Sep 18, 2025
52dd559
fix iSAvailable functions
gdams Sep 18, 2025
dbb9f7c
fix renamed function in nocgo
qmuntal Sep 18, 2025
66675a7
support dynload mode
qmuntal Sep 18, 2025
6be1548
panic if non-optional functions can't be loaded
qmuntal Sep 18, 2025
24155f2
deduplicate code
qmuntal Sep 18, 2025
2786eb2
fix unix
qmuntal Sep 18, 2025
53bc23d
fix windows
qmuntal Sep 18, 2025
b65d29d
fix windows
qmuntal Sep 18, 2025
d0f3699
fix windows
qmuntal Sep 18, 2025
f05bda7
deduplicate variadic handling
qmuntal Sep 19, 2025
6dab456
Merge branch 'dev/gadams/cgoless' of https://github.com/golang-fips/o…
qmuntal Sep 19, 2025
1d209ec
simplify code a bit
qmuntal Sep 19, 2025
395d805
fix nocgo error handling
qmuntal Sep 19, 2025
9f97be8
fix typedefs
qmuntal Sep 19, 2025
14c9c12
fix dlsym
qmuntal Sep 19, 2025
2e8e785
fix pointer tests
qmuntal Sep 19, 2025
3aa6a11
several improvements and fixes
qmuntal Sep 22, 2025
3301db2
fix cTypeSize
qmuntal Sep 22, 2025
73495f7
fix type map
qmuntal Sep 22, 2025
661ae71
fix type map
qmuntal Sep 22, 2025
726ab1f
fix data types
qmuntal Sep 22, 2025
4fb55c6
use dlclose on nocgo
qmuntal Sep 22, 2025
3cf9816
fix newMkcgoErr
qmuntal Sep 22, 2025
bec504e
unhardcode dlopen and friends
qmuntal Sep 26, 2025
5c645a7
fix RTLD_LOCAL
qmuntal Sep 26, 2025
73a54e4
use keepalive
qmuntal Sep 26, 2025
aad5524
support cgoless linux and darwin
qmuntal Sep 26, 2025
28e8640
add cgoless test to CI
qmuntal Sep 26, 2025
81ad5a7
gate syscallN assembly
qmuntal Sep 26, 2025
25bd579
deduplicate some code
qmuntal Sep 26, 2025
c2b8961
revert msgo bump
qmuntal Sep 26, 2025
7da1aeb
mkcgo cleanup
qmuntal Sep 26, 2025
a3daf33
fix static trmapolines
qmuntal Sep 26, 2025
8ca4b40
fix static trmapolines
qmuntal Sep 26, 2025
77c19d3
remove point_conversion_form_t special case
qmuntal Sep 26, 2025
5e8fadb
remove point_conversion_form_t special case
qmuntal Sep 26, 2025
51aadf9
remove stale comment
qmuntal Sep 26, 2025
68b2548
don't hardcode zdl.go
qmuntal Sep 26, 2025
65cd8e1
don't hardcode zdl.go
qmuntal Sep 26, 2025
562a6c1
fix needsAssembly
qmuntal Sep 29, 2025
8011277
cleanup
qmuntal Sep 29, 2025
8080a52
deduplicate fakecgo
qmuntal Sep 29, 2025
9834bbf
support 32-bit arches
qmuntal Sep 29, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
193 changes: 100 additions & 93 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,120 +5,127 @@ jobs:
strategy:
fail-fast: false
matrix:
go-version: [1.23.x, 1.24.x]
openssl-version: [1.1.0, 1.1.1, 3.0.1, 3.0.13, 3.1.5, 3.2.1, 3.3.0, 3.3.1]
go-version: [1.24.x, 1.25.x]
openssl-version:
[1.1.0, 1.1.1, 3.0.1, 3.0.13, 3.1.5, 3.2.1, 3.3.0, 3.3.1]
runs-on: ubuntu-22.04
steps:
- name: Install build tools
run: sudo apt-get install -y build-essential
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v4
- name: Verify go generate leaves no changes
run: |
go generate ./...
git diff --exit-code
- name: Install OpenSSL
run: sudo sh ./scripts/openssl.sh ${{ matrix.openssl-version }}
- name: Check headers
working-directory: ./cmd/checkheader
run: |
go run . --ossl-include /usr/local/src/openssl-${{ matrix.openssl-version }}/include -shim ../../internal/ossl/shims.h
- name: Set OpenSSL config and prove FIPS
run: |
sudo cp ./scripts/openssl-3.cnf /usr/local/ssl/openssl.cnf
go test -v -count 0 . | grep -q "FIPS enabled: true"
if: ${{ matrix.openssl-version == '3.0.1' }}
env:
GO_OPENSSL_VERSION_OVERRIDE: ${{ matrix.openssl-version }}
- name: Run Test
# Run each test 10 times so the garbage collector chimes in
# and exercises the multiple finalizers we use.
# This can detect use-after-free and double-free issues.
run: go test -gcflags=all=-d=checkptr -count 10 -v ./...
env:
GO_OPENSSL_VERSION_OVERRIDE: ${{ matrix.openssl-version }}
- name: Run Test with address sanitizer
run: |
ok=true
for t in $(go test ./... -list=. | grep '^Test'); do
go test ./... -gcflags=all=-d=checkptr -asan -run ^$t$ -v || ok=false
done
$ok
env:
GO_OPENSSL_VERSION_OVERRIDE: ${{ matrix.openssl-version }}
- name: Install build tools
run: sudo apt-get install -y build-essential
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v4
- name: Verify go generate leaves no changes
run: |
go generate ./...
git diff --exit-code
- name: Install OpenSSL
run: sudo sh ./scripts/openssl.sh ${{ matrix.openssl-version }}
- name: Check headers
working-directory: ./cmd/checkheader
run: |
go run . --ossl-include /usr/local/src/openssl-${{ matrix.openssl-version }}/include -shim ../../internal/ossl/shims.h
- name: Set OpenSSL config and prove FIPS
run: |
sudo cp ./scripts/openssl-3.cnf /usr/local/ssl/openssl.cnf
go test -v -count 0 . | grep -q "FIPS enabled: true"
if: ${{ matrix.openssl-version == '3.0.1' }}
env:
GO_OPENSSL_VERSION_OVERRIDE: ${{ matrix.openssl-version }}
- name: Run Test
# Run each test 10 times so the garbage collector chimes in
# and exercises the multiple finalizers we use.
# This can detect use-after-free and double-free issues.
run: go test -gcflags=all=-d=checkptr -count 10 -v ./...
env:
GO_OPENSSL_VERSION_OVERRIDE: ${{ matrix.openssl-version }}
CGO_ENABLED: 0
- name: Run Test CGO disabled
run: go test -count 10 -v ./...
env:
GO_OPENSSL_VERSION_OVERRIDE: ${{ matrix.openssl-version }}
- name: Run Test with address sanitizer
run: |
ok=true
for t in $(go test ./... -list=. | grep '^Test'); do
go test ./... -gcflags=all=-d=checkptr -asan -run ^$t$ -v || ok=false
done
$ok
env:
GO_OPENSSL_VERSION_OVERRIDE: ${{ matrix.openssl-version }}

wintest:
runs-on: windows-2022
strategy:
fail-fast: false
matrix:
go-version: [1.22.x, 1.23.x]
go-version: [1.24.x, 1.25.x]
openssl-version: [libcrypto-1_1-x64.dll, libcrypto-3-x64.dll]
steps:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v4
- name: Run Test
run: go test -gcflags=all=-d=checkptr -count 10 -v ./...
env:
GO_OPENSSL_VERSION_OVERRIDE: ${{ matrix.openssl-version }}
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v4
- name: Run Test
run: go test -gcflags=all=-d=checkptr -count 10 -v ./...
env:
GO_OPENSSL_VERSION_OVERRIDE: ${{ matrix.openssl-version }}
CGO_ENABLED: 1
- name: Run Test CGO disabled
run: go test -count 10 -v ./...
env:
GO_OPENSSL_VERSION_OVERRIDE: ${{ matrix.openssl-version }}
CGO_ENABLED: 0

mactest:
strategy:
fail-fast: false
matrix:
go-version: [1.22.x, 1.23.x]
go-version: [1.24.x, 1.25.x]
openssl-version: [/usr/local/opt/openssl@3/lib/libcrypto.3.dylib]
runs-on: macos-13
steps:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v4
- name: Run Test
run: go test -gcflags=all=-d=checkptr -count 10 -v ./...
env:
GO_OPENSSL_VERSION_OVERRIDE: ${{ matrix.openssl-version }}
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v4
- name: Run Test
run: go test -gcflags=all=-d=checkptr -count 10 -v ./...
env:
GO_OPENSSL_VERSION_OVERRIDE: ${{ matrix.openssl-version }}
- name: Run Test CGO disabled
run: go test -count 10 -v ./...
env:
GO_OPENSSL_VERSION_OVERRIDE: ${{ matrix.openssl-version }}
CGO_ENABLED: 0

azurelinux:
runs-on: ubuntu-latest
container: mcr.microsoft.com/oss/go/microsoft/golang:1.23-azurelinux3.0
steps:
- name: Checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Run Test
run: go test -v ./...
- name: Checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Run Test
run: go test -v ./...
- name: Run Test CGO disabled
run: go test -v ./...
env:
CGO_ENABLED: 0

mariner2:
runs-on: ubuntu-latest
container: mcr.microsoft.com/oss/go/microsoft/golang:1.23.1-3-cbl-mariner2.0
steps:
- name: Checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Run Test
run: go test -v ./...

# Verify that golang-fips/openssl builds successfully without cgo enabled.
#
# A project can avoid attempting to build the openssl package by only
# importing it from Go files with a cgo build tag. However, this isn't always
# reasonable. In that case, we can help by making sure the openssl package
# builds successfully even without cgo.
#
# For example, the Microsoft build of Go compiles this module without cgo when
# running a cross-platform build.
#
# The golang-fips/openssl module can't do any crypto when built without cgo,
# but it exports a few simple functions and types.
cgolessbuild:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Run Build
run: CGO_ENABLED=0 go build ./...
- name: Checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Run Test CGO disabled
run: go test -v ./...
env:
CGO_ENABLED: 0
1 change: 0 additions & 1 deletion aes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

package openssl

import "C"
import (
"crypto/cipher"
"errors"
Expand Down
2 changes: 0 additions & 2 deletions cipher.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

package openssl

import "C"

import (
"crypto/cipher"
"errors"
Expand Down
20 changes: 11 additions & 9 deletions cmd/checkheader/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

const description = `
Example: A check operation:
go run ./cmd/checkheader --ossl-include /usr/local/src/openssl-1.1.1/include -shim ./internal/ossl/shims.h
go run ./cmd/checkheader --ossl-include /usr/local/src/openssl-1.1.1/include -shim ./internal/ossl/shims.h
Checkheader generates a C program and compiles it with gcc. The compilation verifies types and functions defined in the target
header file match the definitions in --ossl-include.
`
Expand Down Expand Up @@ -119,15 +119,17 @@ func generate(header string) (string, error) {
}

for _, enum := range src.Enums {
if enum.Name == "_EVP_PKEY_OP_DERIVE" {
// This is defined differently in OpenSSL 3,
// but in our code it is only used in OpenSSL 1.
continue
for _, enumValue := range enum.Values {
if enumValue.Name == "_EVP_PKEY_OP_DERIVE" {
// This is defined differently in OpenSSL 3,
// but in our code it is only used in OpenSSL 1.
continue
}
name := strings.TrimPrefix(enumValue.Name, "_")
fmt.Fprintf(w, "#ifdef %s\n", name)
fmt.Fprintf(w, "_Static_assert(%s == %s, \"%s\");\n", enumValue.Value, name, enumValue.Name)
fmt.Fprintln(w, "#endif")
}
name := strings.TrimPrefix(enum.Name, "_")
fmt.Fprintf(w, "#ifdef %s\n", name)
fmt.Fprintf(w, "_Static_assert(%s == %s, \"%s\");\n", enum.Value, name, enum.Name)
fmt.Fprintln(w, "#endif")
}

for _, def := range src.TypeDefs {
Expand Down
2 changes: 1 addition & 1 deletion cmd/genaesmodes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func main() {
if gopackage := os.Getenv("GOPACKAGE"); gopackage != "" {
pkg = gopackage
}
fmt.Fprint(&b, "//go:build cgo && !cmd_go_bootstrap\n\n")
fmt.Fprint(&b, "//go:build !cmd_go_bootstrap\n\n")
fmt.Fprintf(&b, "package %s\n\n", pkg)
fmt.Fprint(&b, `import "crypto/cipher"`+"\n\n")

Expand Down
Loading
Loading