Skip to content

Commit

Permalink
Merge branch 'master' into bson-rust-fix-build
Browse files Browse the repository at this point in the history
  • Loading branch information
manunio authored Jan 9, 2025
2 parents e95b6cc + 879cb18 commit 3742453
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
1 change: 1 addition & 0 deletions projects/golang/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ COPY build.sh text_fuzzer.go \
unicode_fuzzer.go \
x509_fuzzer.go \
ecdsa_fuzzer.go \
dsa_fuzzer.go \
aes_fuzzer.go \
h2c_fuzzer.go \
fuzz_x_h2c.options \
Expand Down
5 changes: 5 additions & 0 deletions projects/golang/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ function setup_golang_fuzzers() {
mkdir -p $SRC/golang/crypto/ecdsa
cp $SRC/ecdsa_fuzzer.go ./crypto/ecdsa/

mkdir -p $SRC/golang/crypto/dsa
cp $SRC/dsa_fuzzer.go ./crypto/dsa/

mkdir -p $SRC/golang/crypto/aes
cp $SRC/aes_fuzzer.go ./crypto/aes/

Expand Down Expand Up @@ -82,6 +85,8 @@ function compile_fuzzers() {
then
compile_go_fuzzer $FUZZ_ROOT/crypto/ecdsa FuzzEcdsaSign FuzzEcdsaSign$version
compile_native_go_fuzzer $FUZZ_ROOT/crypto/ecdsa FuzzEcdsaVerify FuzzEcdsaVerify$version
compile_native_go_fuzzer $FUZZ_ROOT/crypto/dsa FuzzDsaSign FuzzDsaSign$version
compile_native_go_fuzzer $FUZZ_ROOT/crypto/dsa FuzzDsaVerify FuzzDsaVerify$version
fi
compile_go_fuzzer $FUZZ_ROOT/crypto/x509 FuzzParseCert fuzz_parse_cert$version
compile_go_fuzzer $FUZZ_ROOT/crypto/x509 FuzzPemDecrypt fuzz_pem_decrypt$version
Expand Down
72 changes: 72 additions & 0 deletions projects/golang/dsa_fuzzer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright 2025 Google LLC
//
// 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 dsa

import (
"bytes"
"crypto/dsa"
"math/big"
"testing"
)

func FuzzDsaVerify(f *testing.F) {
f.Fuzz(func(t *testing.T, data1, data2, data3 []byte, s1, s2 string, s uint8) {
bi1, ok := new(big.Int).SetString(s1, 16)
bi2, ok2 := new(big.Int).SetString(s2, 16)
if !ok && !ok2 {
return
}
var priv dsa.PrivateKey
params := &priv.Parameters
sizes := []dsa.ParameterSizes{
dsa.L1024N160,
dsa.L2048N224,
dsa.L2048N256,
dsa.L3072N256,
}
err := dsa.GenerateParameters(params, bytes.NewReader(data1), sizes[int(s)%len(sizes)])
if err != nil {
return
}
err = dsa.GenerateKey(&priv, bytes.NewReader(data2))
if err != nil {
return
}
dsa.Verify(&priv.PublicKey, data3, bi1, bi2)
})
}

func FuzzDsaSign(f *testing.F) {
f.Fuzz(func(t *testing.T, data1, data2, data3, data4 []byte, s uint8) {
var priv dsa.PrivateKey
params := &priv.Parameters
sizes := []dsa.ParameterSizes{
dsa.L1024N160,
dsa.L2048N224,
dsa.L2048N256,
dsa.L3072N256,
}
err := dsa.GenerateParameters(params, bytes.NewReader(data1), sizes[int(s)%len(sizes)])
if err != nil {
return
}
err = dsa.GenerateKey(&priv, bytes.NewReader(data2))
if err != nil {
return
}
dsa.Sign(bytes.NewReader(data3), &priv, data4)
})
}

0 comments on commit 3742453

Please sign in to comment.