Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ctidh compatibility build tags #16

Merged
merged 26 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
580470a
ctidh: don't build it on windows
david415 May 17, 2024
dda2218
nike: hybrid ctidh also optional
david415 May 17, 2024
5b02e0c
Merge branch 'main' into fix_ctidh.1
david415 May 18, 2024
5eb387a
add TestHybridSchemeInitialization
amitbasuri May 23, 2024
d8da448
refactor TestHybridSchemeInitialization
amitbasuri May 23, 2024
fa7b7e6
add multiple ci run platform
amitbasuri May 23, 2024
b1fee83
WIP
david415 May 23, 2024
6eee3ed
sign: remove TestHybridSchemeInitialization
david415 May 26, 2024
b16db41
Merge branch 'hybrid_scheme_init.1' into fix_ctidh.1
david415 May 26, 2024
e484e39
ctidh: try to fix build tags for windows/darwin/linux
david415 May 26, 2024
ee43fbd
sign: disable sphincsplus on windows
david415 May 26, 2024
6168858
github CI: try to make it build on windows
david415 May 26, 2024
7c209aa
sign: fix compat
david415 May 26, 2024
2d2f568
sign: add hybrid compat
david415 May 26, 2024
939eb6b
WIP
david415 May 26, 2024
7fa356b
nike/dh: make unmarshal key size error more precise
david415 May 26, 2024
5eef2b6
kem/schemes: fix compat
david415 May 26, 2024
de31b6d
kem/schemes: make it work
david415 May 26, 2024
512409c
WIP
david415 May 26, 2024
4fb86d0
kem/schemes: remove superfluous composite kems
david415 May 26, 2024
c9c6781
kem/adapter: FromNIKE returns a kem.Scheme
david415 May 26, 2024
0949103
try to fix ci testing on mac
david415 May 26, 2024
bb9d715
fix ci configs matrix
david415 May 26, 2024
4d8462f
try to fix tests on darwin
david415 May 26, 2024
b9197e1
try to use highctidh cross compile golang ci configs
david415 May 26, 2024
f3f4c8a
kem/adapter: add more error checking
david415 May 26, 2024
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
14 changes: 8 additions & 6 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
arch: [amd64, arm64]
go-version: ["1.21.x", "1.22.0"]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand All @@ -16,8 +22,4 @@ jobs:
go-version-file: go.mod
check-latest: true
- name: Run tests
run: go test ./...
- name: Run tests (short + race)
run: go test -short -race ./...
- name: KEM Benchmark tests
run: cd kem/schemes && go test -v -bench=. -run Benchmark
run: go test -v ./...
47 changes: 47 additions & 0 deletions .github/workflows/macos-golang-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: MacOS Golang build and test

on: [push]

jobs:
build:
runs-on: ${{ matrix.OS }}
strategy:
matrix:
OS: ["macos-14"]
go-version: ["1.21.x", "1.22.0"]
fail-fast: false

steps:
- uses: actions/checkout@v4

- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

- name: Display Go version
shell: bash
run: go version

- name: Install golang dependencies
shell: bash
run: |
export HIGHCTIDH_PORTABLE=1
export CGO_ENABLED=1
go get -v ./...

- name: Build golang
shell: bash
run: |
export HIGHCTIDH_PORTABLE=1
export CGO_ENABLED=1
go build -v ./...

- name: Golang test
shell: bash
run: |
export HIGHCTIDH_PORTABLE=1
export CGO_ENABLED=1
go test -v ./...


35 changes: 35 additions & 0 deletions .github/workflows/ubuntu-golang-cross-compile-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Go cross compile

on:
push:
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
CC: ["clang"]
ARCH: ["amd64", "arm32v5", "arm32v6", "arm32v7", "i386", "arm64", "mips64", "mips64le", "mips", "mipsle", "ppc64", "ppc64le", "riscv64", "s390x"]
go-version: [ '1.19', '1.20', '1.21.x' ]
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Display Go version
run: go version

- name: Install Golang deps
run: sudo ./misc/install-debian-go-deps-by-arch.sh ${{ matrix.ARCH }}

- name: Install Go (from go.mod)
uses: actions/setup-go@v4
with:
go-version-file: go.mod
check-latest: true
- name: Run tests
run: go test -v ./...
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Windows Msys2 64bit (cygwin,msvcrt,ucrt) gcc golang build and test

on: [push]

jobs:
windows-build-and-test-golang:
runs-on: ${{ matrix.os }}
strategy:
matrix:
OS: ["windows-2019", "windows-2022"]
CC: ["gcc"]
ENVIRONMENT: ["UCRT64", "MINGW64"] # https://www.msys2.org/docs/environments/
go-version: [ "1.21.x", "1.22.x"]
fail-fast: false
steps:
- uses: actions/checkout@v4

- name: Set up Msys2
uses: msys2/setup-msys2@v2
with:
msystem: ${{ matrix.ENVIRONMENT }}
install: >-
base-devel
mingw-w64-x86_64-toolchain
mingw-w64-x86_64-pkg-config
mingw-w64-x86_64-gcc
mingw-w64-ucrt-x86_64-gcc
mingw-w64-x86_64-go
mingw-w64-ucrt-x86_64-go
make
git
gcc

- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

- name: Gather runtime environment
shell: msys2 {0}
run: |
echo ${{ matrix.ENVIRONMENT }}
uname -a
bash --version
${{ matrix.CC }} -v
go version

- name: Install golang dependencies
shell: bash
run: |
export HIGHCTIDH_PORTABLE=1
export CGO_ENABLED=1
go get -v ./...

- name: Build golang
shell: msys2 {0}
run: |
export HIGHCTIDH_PORTABLE=1
export CGO_ENABLED=1
export GOEXPERIMENT=cgocheck2
export GODEBUG=cgocheck=1
go build -v ./...

- name: Golang test
shell: msys2 {0}
run: |
export HIGHCTIDH_PORTABLE=1
export CGO_ENABLED=1
export GOEXPERIMENT=cgocheck2
export GODEBUG=cgocheck=1
export CGO_LDFLAGS="-Wl,--no-as-needed -Wl,-allow-multiple-definition"
go test -v ./...
11 changes: 10 additions & 1 deletion kem/adapter/kem.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ var _ kem.PrivateKey = (*PrivateKey)(nil)

// FromNIKE creates a new KEM adapter Scheme
// using the given NIKE Scheme.
func FromNIKE(nike nike.Scheme) *Scheme {
func FromNIKE(nike nike.Scheme) kem.Scheme {
if nike == nil {
return nil
}
return &Scheme{
nike: nike,
}
Expand Down Expand Up @@ -185,6 +188,9 @@ func (a *Scheme) Decapsulate(myPrivkey kem.PrivateKey, ct []byte) ([]byte, error

// Unmarshals a PublicKey from the provided buffer.
func (a *Scheme) UnmarshalBinaryPublicKey(b []byte) (kem.PublicKey, error) {
if len(b) != a.PublicKeySize() {
return nil, fmt.Errorf("UnmarshalBinaryPublicKey: wrong key size %d != %d", len(b), a.PublicKeySize())
}
pubkey, err := a.nike.UnmarshalBinaryPublicKey(b)
if err != nil {
return nil, err
Expand All @@ -197,6 +203,9 @@ func (a *Scheme) UnmarshalBinaryPublicKey(b []byte) (kem.PublicKey, error) {

// Unmarshals a PrivateKey from the provided buffer.
func (a *Scheme) UnmarshalBinaryPrivateKey(b []byte) (kem.PrivateKey, error) {
if len(b) != a.PrivateKeySize() {
return nil, fmt.Errorf("UnmarshalBinaryPrivateKey: wrong key size %d != %d", len(b), a.PrivateKeySize())
}
privkey, err := a.nike.UnmarshalBinaryPrivateKey(b)
if err != nil {
return nil, err
Expand Down
119 changes: 23 additions & 96 deletions kem/schemes/schemes.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,17 @@ import (
"github.com/katzenpost/hpqc/rand"
)

var allSchemes = [...]kem.Scheme{
var potentialSchemes = [...]kem.Scheme{

// post quantum KEM schemes

adapter.FromNIKE(ctidh511.Scheme()),
adapter.FromNIKE(ctidh512.Scheme()),
adapter.FromNIKE(ctidh1024.Scheme()),
adapter.FromNIKE(ctidh2048.Scheme()),
}

var allSchemes = []kem.Scheme{

// classical KEM schemes (converted from NIKE via hashed elgamal construction)
adapter.FromNIKE(diffiehellman.Scheme()),
Expand All @@ -45,11 +55,15 @@ var allSchemes = [...]kem.Scheme{
// post quantum KEM schemes

mlkem768.Scheme(),

sntrup.Scheme(),

kyber512.Scheme(),
kyber768.Scheme(),
kyber1024.Scheme(),

frodo640shake.Scheme(),

mceliece348864.Scheme(),
mceliece348864f.Scheme(),
mceliece460896.Scheme(),
Expand All @@ -61,13 +75,6 @@ var allSchemes = [...]kem.Scheme{
mceliece8192128.Scheme(),
mceliece8192128f.Scheme(),

// post quantum KEM schemes
// (converted from NIKE via hashed ElGamal construction)
adapter.FromNIKE(ctidh511.Scheme()),
adapter.FromNIKE(ctidh512.Scheme()),
adapter.FromNIKE(ctidh1024.Scheme()),
adapter.FromNIKE(ctidh2048.Scheme()),

// hybrid KEM schemes

xwing.Scheme(),
Expand All @@ -80,6 +87,7 @@ var allSchemes = [...]kem.Scheme{
kyber768.Scheme(),
),

// An alternative to Xwing using a generic and secure KEM combiner.
combiner.New(
"MLKEM768-X25519",
[]kem.Scheme{
Expand All @@ -88,107 +96,26 @@ var allSchemes = [...]kem.Scheme{
},
),

/* doesn't work on arm64 for some reason
combiner.New(
"DH4096_RFC3526-MLKEM768",
[]kem.Scheme{
adapter.FromNIKE(diffiehellman.Scheme()),
mlkem768.Scheme(),
},
),

combiner.New(
"x25519-mceliece8192128f-ctidh512",
[]kem.Scheme{
adapter.FromNIKE(x25519.Scheme(rand.Reader)),
mceliece8192128f.Scheme(),
adapter.FromNIKE(ctidh512.Scheme()),
},
),

combiner.New(
"x448-mceliece8192128f-mlkem768",
[]kem.Scheme{
adapter.FromNIKE(x448.Scheme(rand.Reader)),
mceliece8192128f.Scheme(),
mlkem768.Scheme(),
},
),

combiner.New(
"x448-mceliece8192128f-ctidh512",
[]kem.Scheme{
adapter.FromNIKE(x448.Scheme(rand.Reader)),
mceliece8192128f.Scheme(),
adapter.FromNIKE(ctidh512.Scheme()),
},
),

combiner.New(
"sntrup4591761-X25519",
[]kem.Scheme{
adapter.FromNIKE(x25519.Scheme(rand.Reader)),
sntrup.Scheme(),
},
),

combiner.New(
"ctidh512-X25519",
[]kem.Scheme{
adapter.FromNIKE(x25519.Scheme(rand.Reader)),
adapter.FromNIKE(ctidh512.Scheme()),
},
),

combiner.New(
"ctidh1024-X25519",
[]kem.Scheme{
adapter.FromNIKE(x25519.Scheme(rand.Reader)),
adapter.FromNIKE(ctidh1024.Scheme()),
},
),

combiner.New(
"ctidh2048-X25519",
[]kem.Scheme{
adapter.FromNIKE(x25519.Scheme(rand.Reader)),
adapter.FromNIKE(ctidh2048.Scheme()),
},
),

// hybrid KEM schemes with two post quantum KEMs

combiner.New(
"X25519-mlkem768-sntrup4591761",
[]kem.Scheme{
adapter.FromNIKE(x25519.Scheme(rand.Reader)),
mlkem768.Scheme(),
sntrup.Scheme(),
},
),

combiner.New(
"X25519-mlkem768-ctidh512",
[]kem.Scheme{
adapter.FromNIKE(x25519.Scheme(rand.Reader)),
mlkem768.Scheme(),
adapter.FromNIKE(ctidh512.Scheme()),
},
),

combiner.New(
"X25519-mlkem768-ctidh1024",
[]kem.Scheme{
adapter.FromNIKE(x25519.Scheme(rand.Reader)),
mlkem768.Scheme(),
adapter.FromNIKE(ctidh1024.Scheme()),
},
),
*/
}

var allSchemeNames map[string]kem.Scheme

func init() {
allSchemeNames = make(map[string]kem.Scheme)
for _, scheme := range potentialSchemes {
if scheme != nil {
allSchemes = append(allSchemes, scheme)
}
}
for _, scheme := range allSchemes {
allSchemeNames[strings.ToLower(scheme.Name())] = scheme
}
Expand Down
Loading
Loading