This repository has been archived by the owner on Dec 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fuzz tests * Export test vectors * Initial corpus * more corpus
- Loading branch information
Showing
63 changed files
with
295 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ɯ��E�uk\!Wg�֓NP��6�{�b+g!��9�}���/�����~��V���W�$� �fY����~��V���P�$4�l͇�>�����������H$X�H��ç�a�4�nqu�yme�sample | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ɯ��E�uk\!Wg�֓NP��6�{�E+g!�:�,���f�k�{V����g�@�rV��K�T���ҳ���O�,��[RM�īc | ||
|Tg J�K����T��⺠�test |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ɯ��E�uk\!Wg�֓NP��6�{�b+g!�:,���f�k�{V����g�@�rV��K�T���ҳ���O�,��[R�īc | ||
|Tg J�K����T��⺠�test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ɯ��E�uk\!Wg�֓NP��6� {�b+g!�:�,���f�k�{V����g�@�rV��K�T���ҳ���O�,��[RM�īc | ||
|Tg J�K����T��⺠�X�H���nq_�yme�sample |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ɯ��E�uk\!Wg�֓NP��6�{�b+g!�ܤ�9�}���/�����~��V���W�$4�l͇�>�����������H$X�H�ç�a���nqu�yme�s | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ɯ��E�uk\!Wg�֓NP��1596675759�{�b+g!�ܤ�9�}���/��i �fY����~��V���W�$4�l͇�>�����������H$X�H��ç�a���nqu�yme�sample | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
,�AA�uk\!Wg�֓NP��6�{�b+g!��9�}���/�����~��Vo�f�^���AZh147121735�?lyn6{/Fp&IY��K�q���W"ӣ>�ſ�+�^јdE-256 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ɯ��E�uk\!Wg�֓NP��b+g!�ܤ�9�}���/�����~��V���W�$4�l͇�>�����������H$X�H��ç�a���nqu�yme�sample | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
,�AA�{$̌;��? *l諹}�I�P�����;:��<hU��)Q~��i��"�o�f�^���AZh6��?lyn6{/Fp&IY��K�q���W"ӣ>�ſ�+�^јdE-256 | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ɯ��E�uk\!Wg�֓NP��6�{�b+g!�:�,���f�k�{V����g�@�rV��K�T���ҳ���O�,��[RM�īc | ||
|Tg J�K����T��⺠�X�H��ça���nqu�yme�sample |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ɯ��E�uk\!Wg�֓P�6�{�b�g!�ܤ�9�}���/�+���~��V���W�$4�l͇�>�����������H$X�E��ç�a���nqu�yme�sample | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ɯ��E�uk\!Wg�֓NP��6�{�b+g!�:�,���f�k�{V����g�@�rV��K�T���ҳ���O�,��[RM�īc | ||
|Tg J�K����T��⺠�X�H���nqu�yme�sample |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ɯ��E�uk\!Wg�֓NP�īc|TE+g!�:�,���f�k�{V����g�@�rV��K�T���ҳ���O�,��[RM�īc | ||
|Tg J�K����T��d���test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ɯ��E�u�!Wg�q�NP��1596675759�{�b+g!�ܤ�9�}���/��i �fY����~��V���W�$4�l͇�>�����������H$X�H��ç�a���nqu�yme�sample | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ɯ��E�uk\!Wg�֓NP��6�{�b+g!�ܤ�9�}���/�����~��V���W�$4�l͇�>�����������H$X�H��ç�a���nqu�yme�sample | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ɯ��E�uk\!Wg�֓NP��6�{�b+g!�:�,���f�k�{V����g�@�rV��K�T���ҳ���O�,��[RM�īc | ||
|Tg J�K����T��⺠�test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
����E�uk\!Wg�֓NP��6�{�b+g!�:�,���f�k�{V����g�@�rV��K�T���ҳ���O�,��[RM�īc | ||
|Tg J�K����T��⺠�test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
,�AA�{$̌;��? *l諹}�I�P����;:�~�i��"�o�f�^���AZh6��?lyn6{/Fp&IY��K�q���W"ӣ>�ſ�+�^јdExe of ECDSA with aand | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ɯ��E�uk\!Wg�֓NP���{�b+g!�:�,���f�k�{V����g�@�rV��K�T���ҳ���O�,��[RM�īc | ||
|Tg J�K����T��⺠�test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ɯ��E�g�֓NP��6�{�b+g!�ܤ�9�}���/�����~��V���W�$4�l͇�>�����������H$X�H��ç�a���nqu�yme�sample | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ɯ��E�g�֓NP��6�{�b+g!�Ҥ�9�}���/�����~��V���W�$4�l͇�>�����������HX�H��ç�a���nqu�yme�sample | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ɯ��E�uk\!Wg�֓NP��6�{�E+g!�:�,���f�k�{V����g�@�rV��K�T���ҳ���O�,��[RM�īc | ||
|Tg J�K����T��d���test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ɯ��E�uk\!Wg�֓NP��1�{��+�b+gg!�:�,���f�k�{V����g�@�rV��K�T���ҳ���O�,��[R`�īc | ||
|Tg JA�K����T���b��tPst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ɯ�E�u\!Wg�֓NP��6�{�b+!�:�,���f�k�{V����g�@�rV��K�T���ҳ���O�,��[RM�īc | ||
|Tg J�K����T��⺠�test |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ɯ��E�uk\!Wg�֓NP��6�{�b+g!��9�}���/�����~��V���W�$4�l͇�>�����������H$X�H��ç�a���nqu�yme�sa | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ɯ��E�uk\!Wg�q�NP��1596675759�{�b+g!�ܤ�9�}���/��i �fY����~��V���W�$4�l͇�>�����������H$X�H��ç�a���nqu�yme�sample | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
,�AA�{$̌;��? *l諹}�I�P�����;:��<hU��)Q~��i��"�o�f�^���AZh6��?lyn6{/Fp&IY��K�q���W"ӣ>�ſ�+�^јdExp256r1 and SHA-256 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
,�AA�{$̌;��?���;:��<hU��)Q~��i��"�o�f�^���AZh6��?lyn6IY��K�q���W"ӣ>�ſ�+�^јdExample of ECDSA with ansip256r1 an� SHA-256 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ɯ�E�k\!Wg�֓NP��6�{�b+g!�:�,���f�k�{V����g�@�rV��K�T���ҳ���O�,��[RM�īc | ||
|Tg J�K����T��⺠�tes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ɯ��E�uk\!Wg�֓NP��6�{�bg!�ܤ�9�}���/�����~��V���W�$4�l͇�>�����������H$X�H��ç�a���nqu�yme�sample | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ɯ��E�uk\!Wg�֓.P��6�{�b+g!�ܤ�9�}���/�������W�$4�~��V���W�$4�l͇�>�����������H$X�H��ç�a���e�saY | ||
mple | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ɯ��E�uk\!Wg�֓NP��6�{�b+g!��9�}���/�����~��V���W�$4�l͇�>�����������H$X�H��ç�����nqu�yme�sa | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
// Copyright 2020 Google Inc. 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. | ||
|
||
// +build gofuzz | ||
|
||
package vrf | ||
|
||
import ( | ||
"bytes" | ||
"encoding/binary" | ||
"fmt" | ||
) | ||
|
||
// To run the fuzzer: | ||
// $ go get -u github.com/dvyukov/go-fuzz/go-fuzz github.com/dvyukov/go-fuzz/go-fuzz-build | ||
// $ cd go/vrf | ||
// $ go-fuzz-build | ||
// $ go-fuzz | ||
|
||
const ( | ||
skLen = 32 | ||
piLen = 33 + 16 + 32 // ptLen + fieldLen/2 + qLen | ||
) | ||
|
||
type Input struct { | ||
SK [skLen]byte | ||
PI [piLen]byte | ||
Alpha []byte | ||
} | ||
|
||
func NewInput(sk, pi, alpha []byte) (Input, error) { | ||
if got := len(sk); got != skLen { | ||
return Input{}, fmt.Errorf("len(sk): %v, want %v", got, skLen) | ||
} | ||
if got := len(pi); got != piLen { | ||
return Input{}, fmt.Errorf("len(pi): %v, want %v", got, piLen) | ||
} | ||
|
||
var i Input | ||
copy(i.SK[:], sk) | ||
copy(i.PI[:], pi) | ||
i.Alpha = alpha | ||
return i, nil | ||
} | ||
|
||
func (i Input) MarshalBinary() ([]byte, error) { | ||
b := new(bytes.Buffer) | ||
if err := binary.Write(b, binary.BigEndian, i.SK); err != nil { | ||
return nil, err | ||
} | ||
if err := binary.Write(b, binary.BigEndian, i.PI); err != nil { | ||
return nil, err | ||
} | ||
if err := binary.Write(b, binary.BigEndian, i.Alpha); err != nil { | ||
return nil, err | ||
} | ||
return b.Bytes(), nil | ||
} | ||
|
||
func (i *Input) UnmarshalBinary(data []byte) error { | ||
b := bytes.NewBuffer(data) | ||
if err := binary.Read(b, binary.BigEndian, &i.SK); err != nil { | ||
return err | ||
} | ||
if err := binary.Read(b, binary.BigEndian, &i.PI); err != nil { | ||
return err | ||
} | ||
a := new(bytes.Buffer) | ||
if _, err := a.ReadFrom(b); err != nil { | ||
return err | ||
} | ||
i.Alpha = a.Bytes() | ||
return nil | ||
} | ||
|
||
// Fuzz returns 1 if the fuzzer should increase the priority of the input, | ||
// -1 if the input must not be added to the corpus, and 0 otherwise. | ||
func FuzzVerify(data []byte) int { | ||
var i Input | ||
if err := i.UnmarshalBinary(data); err != nil { | ||
return -1 | ||
} | ||
|
||
v := ECVRFP256SHA256TAI() | ||
sk := NewKey(v.Params().ec, i.SK[:]) | ||
_, err := v.Verify(sk.Public(), i.PI[:], i.Alpha) | ||
if err != nil { | ||
return 0 | ||
} | ||
return 1 | ||
} | ||
|
||
func FuzzProve(data []byte) int { | ||
var i Input | ||
if err := i.UnmarshalBinary(data); err != nil { | ||
return -1 | ||
} | ||
|
||
v := ECVRFP256SHA256TAI() | ||
sk := NewKey(v.Params().ec, i.SK[:]) | ||
|
||
// i.PI is unused, we generate it from SK and Alpha. | ||
pi := v.Prove(sk, i.Alpha) | ||
beta1, err := v.ProofToHash(pi) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
beta2, err := v.Verify(sk.Public(), pi, i.Alpha) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
if !bytes.Equal(beta1, beta2) { | ||
panic("beta1 != beta2") | ||
} | ||
return 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright 2020 Google Inc. 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. | ||
|
||
// +build gofuzz | ||
|
||
package vrf | ||
|
||
import ( | ||
"bytes" | ||
"flag" | ||
"fmt" | ||
"io/ioutil" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
var writeCorpus = flag.Bool("writecorpus", false, "Write initial corpus from test vectors") | ||
|
||
func TestInputMarshal(t *testing.T) { | ||
for _, i := range []Input{ | ||
{SK: [skLen]byte{1, 1, 1, 1}, PI: [piLen]byte{2, 2, 2, 2}, Alpha: []byte{3, 3, 3, 3}}, | ||
} { | ||
enc, err := i.MarshalBinary() | ||
if err != nil { | ||
t.Fatalf("MarshalBinary(): %v", err) | ||
} | ||
t.Logf("MarshalBinary(): %x", enc) | ||
var j Input | ||
if err := j.UnmarshalBinary(enc); err != nil { | ||
t.Fatalf("UnmarshalBinary(): %v", err) | ||
} | ||
if !reflect.DeepEqual(i, j) { | ||
t.Errorf("Unmarshal: %#v, want %#v", j, i) | ||
} | ||
} | ||
} | ||
|
||
// go test ./vrf/ -tags gofuzz --writecorpus | ||
func TestInitialCorpus(t *testing.T) { | ||
for i, tc := range P256SHA256TAITestVectors(t) { | ||
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { | ||
v := ECVRFP256SHA256TAI() | ||
sk := NewKey(v.Params().ec, tc.SK) | ||
|
||
pi := v.Prove(sk, tc.alpha) | ||
if !bytes.Equal(pi, tc.pi) { | ||
t.Errorf("Prove(%s): %x, want %x", tc.alpha, pi, tc.pi) | ||
} | ||
|
||
if _, err := v.Verify(sk.Public(), pi, tc.alpha); err != nil { | ||
t.Errorf("Verify(): %v", err) | ||
} | ||
|
||
t.Logf("Fuzz test vector: %x%x%x", tc.SK, tc.pi, tc.alpha) | ||
|
||
if *writeCorpus { | ||
input, err := NewInput(tc.SK, pi, tc.alpha) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
b, err := input.MarshalBinary() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if err := ioutil.WriteFile(fmt.Sprintf("./corpus/P256SHA523TAI-%0d", i), b, 0644); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.