Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Commit

Permalink
Go Fuzz (#12)
Browse files Browse the repository at this point in the history
* Fuzz tests

* Export test vectors

* Initial corpus

* more corpus
  • Loading branch information
gdbelvin authored Jun 22, 2020
1 parent b1b8083 commit 595588e
Show file tree
Hide file tree
Showing 63 changed files with 295 additions and 15 deletions.
1 change: 1 addition & 0 deletions go/vrf/corpus/0153960749b22dd090b29a1ed299d6e4c378f507-2
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
Expand Down
2 changes: 2 additions & 0 deletions go/vrf/corpus/0cfacfa8474bc1285de5ed5bd04620d98559b691-1
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�,��[R M�īc
|Tg J�K����T��⺠�test
Binary file not shown.
1 change: 1 addition & 0 deletions go/vrf/corpus/1a93ecbf3f67798d43927b8793270f2d9eb68831-4
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��ç�i���nqu�ym�o�esvqxXle
Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions go/vrf/corpus/1f81e16cf35206a10b314797f076795c666ca59c-3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
,�AA�{$̌;��? *l諹}�I�P�����;:��<hU��)Q~��i��"�o�f�^���AZh6�051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156f1ef451fd46b503f28494847�?lyn6{/Fp^јdExe of ECDSA with aand SHA-256
Expand Down
2 changes: 2 additions & 0 deletions go/vrf/corpus/20ecb8756c2209f5ddb2fc4fd9614be7f5a5cc82-1
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
2 changes: 2 additions & 0 deletions go/vrf/corpus/23aeb1476bf43c32220ee4cccc49db5e5ea95978-5
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 M�īc
|Tg J�K����T��⺠� X�H���nq_�yme�sample
Binary file not shown.
1 change: 1 addition & 0 deletions go/vrf/corpus/2f364b21dde5a477baa99b2f4ade92705f7367b3-1
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
Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions go/vrf/corpus/3f2c672cd2bd8271bdca23da851c8d3efb24d607-2
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
Expand Down
1 change: 1 addition & 0 deletions go/vrf/corpus/4876685b79005644f45003e0db00f50df5396733-2
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"ӣ>�ſ�+� ^јdExe of ECDSA witIh aand SHA-256
Expand Down
1 change: 1 addition & 0 deletions go/vrf/corpus/492ca4b13febdc3fdc2d4cd8ba6d9c745c740995-2
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
1 change: 1 addition & 0 deletions go/vrf/corpus/4e7ae0faa3acb6cef49313ce44eb288143547949-2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
,�AA�{$̌;��? *l諹}�I�P�����;:��<hU��)Q~��i��"�o�f�^���AZh6��?lyn654253189979148500{/Fp&IY��K�q���W"ӣ>�@��+� ^јdExp256r1 and SHA-256
Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions go/vrf/corpus/5c844731e287c03232c3c75843eca856991650f3-5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
,�AA�{$̌;��? *l諹}�I�P�����;:��<hU��)Q~��i��"�o�f�^���AZh6�051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918e�1819e156f1ef451fd46b503f28494847�?lyn6{/Fp^јdExe of ECDSA with aand SHA-256
Expand Down
1 change: 1 addition & 0 deletions go/vrf/corpus/6a9490ee55aa4f88b8cc4ff8acbc9e769b2ee927-1
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
Expand Down
1 change: 1 addition & 0 deletions go/vrf/corpus/6f61f0ef1ee2cfc530a9c7a68a41a54c93171127-1
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
Expand Down
Binary file not shown.
2 changes: 2 additions & 0 deletions go/vrf/corpus/73a62219ebbe900819e5541a866043ef6be70ca1-2
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 M�īc
|Tg J�K����T��⺠� X�H��ça���nqu�yme�sample
1 change: 1 addition & 0 deletions go/vrf/corpus/82ddcaa2de47cff8959df05960dee3d8691f6c83-2
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
Expand Down
2 changes: 2 additions & 0 deletions go/vrf/corpus/83439e43dc8ffccb81dccc47abe9c868c27c8f82-3
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 M�īc
|Tg J�K����T��⺠� X�H���nqu�yme�sample
1 change: 1 addition & 0 deletions go/vrf/corpus/84866899625e0d9872798c5b98ed07da58a87c55-1
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"ӣ>�ſ�+� ^јdExe of ECDSA with aand SHA-256
Expand Down
1 change: 1 addition & 0 deletions go/vrf/corpus/84dffe7051943af2df313f6b6e7e65b621c33b5f-1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ɯ��E�uk\!Wg�֓NP��15966757596650410�{�b+g!�ܤ�9�}���/��i �fY����~��V���W�$4�l͇�>�����������H$ X�H��ç�a���nqu�yme�sample
Expand Down
2 changes: 2 additions & 0 deletions go/vrf/corpus/8d5201895646c103624b9e04ace6ad8613904655-4
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�,��[R M�īc
|Tg J�K����T��d���test
1 change: 1 addition & 0 deletions go/vrf/corpus/8e7714df0c42a95030fbeea03607ae365c81d965-3
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
Expand Down
1 change: 1 addition & 0 deletions go/vrf/corpus/98b07087b48059b544fa89840af47aa9a1cc2448-2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
,�AA�{$̌;��? Rl諹}�I�P����;:��<hU��)Q~��i��"�o�f�^���AZh6��?:��<withU��)Q~��i��"�o�f�^���AZh6��?lyn6{/Fp&IY��K�q��W"ӣ>�ſ�+� ^јdExmplelyn6{/p&IY��K�q���W"ӣ>�ſ�+� ^јdxample f ECD
Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions go/vrf/corpus/P256SHA523TAI-0
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
Expand Down
2 changes: 2 additions & 0 deletions go/vrf/corpus/P256SHA523TAI-1
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 M�īc
|Tg J�K����T��⺠�test
1 change: 1 addition & 0 deletions go/vrf/corpus/P256SHA523TAI-2
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"ӣ>�ſ�+� ^јdExample of ECDSA with ansip256r1 and SHA-256
Expand Down
Binary file not shown.
2 changes: 2 additions & 0 deletions go/vrf/corpus/abfc84dc214938eb2fe84e684f296f8cc1243522-1
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 M�īc
|Tg J�K����T��⺠�test
1 change: 1 addition & 0 deletions go/vrf/corpus/b8f5f53af43fe9d51490d9b04a3dd6bb4ccef3ac-3
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
Expand Down
Binary file not shown.
2 changes: 2 additions & 0 deletions go/vrf/corpus/bd0fccda78d0a5cdd48cb7d9c98ff2ef15ccf4f0-1
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�,��[R M�īc
|Tg J�K����T��⺠�test
1 change: 1 addition & 0 deletions go/vrf/corpus/bdeca72d7377d74ef6a5e156945081b89e6f205c-1
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
Expand Down
1 change: 1 addition & 0 deletions go/vrf/corpus/c59a6773d73b68a8ba9d1a7556a5f164e61c37ca-2
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
Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions go/vrf/corpus/cab75eb03121f955dff836ebffbb2a6c33a30c38-1
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"ӣ>�ſ�+� ^јdExample of ECDS2SHA-256
Expand Down
2 changes: 2 additions & 0 deletions go/vrf/corpus/ce41843cdb9e41bd55403c654ebc7ef745950ea4-2
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�,��[R M�īc
|Tg J�K����T��d���test
2 changes: 2 additions & 0 deletions go/vrf/corpus/ceaadbf6afa2bcdd2cb1a041a895219343fe4caa-1
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
2 changes: 2 additions & 0 deletions go/vrf/corpus/d1e3b214e102a9a7a93a3d6f36e9d16dbe6b99bc-1
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�,��[R M�īc
|Tg J�K����T��⺠�test
Binary file not shown.
1 change: 1 addition & 0 deletions go/vrf/corpus/d4864723d13dffc65a97d1f81ceca45d25e8704c-1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
,�AA�{$̌;��? *l諹}�I�P����;:��<hU��)Q~��i��"�o�f�^���AZh6��?:��<withU��)Q~��i��"�o�f�^���AZh6��?lyn6{/Fp&IY��K�q��W"ӣ>�ſ�+� ^јdExmplelyn6{/p&IY��K�q���W"ӣ>�ſ�+� ^јdxample f ECD
Expand Down
1 change: 1 addition & 0 deletions go/vrf/corpus/d7ed4580e6b98ff5b575b5a23ba651053c4f49cd-1
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
Expand Down
1 change: 1 addition & 0 deletions go/vrf/corpus/d911985df9133508b10542af7bc379d46c7a7963-3
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
Expand Down
1 change: 1 addition & 0 deletions go/vrf/corpus/d92c3f0f17d35cd736990ad46af959123f01d203-2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
,�AA�{$̌;��? *l諹}�I�P�����;:��<hU��)�AZh6�051953eb9618e12da7259e156193951ec7e937b1652c352d3bb1bf073573dff1ef1fd46b503f284948407�?lyn6{/Fp�K�q���W"ӣ>�ſ�+� ^јdExe of ECDSA with aand SHA-256
Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions go/vrf/corpus/e5640306be9dfd98768458fa7dfd6fbeea8ac65d-1
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
Expand Down
1 change: 1 addition & 0 deletions go/vrf/corpus/e7b4f19d5ba953d549e0657306828a9d8e93ed62-2
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
2 changes: 2 additions & 0 deletions go/vrf/corpus/ecb5234c58908454bee6ad250a9550256c84f21f-1
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�,��[R M�īc
|Tg J�K����T��⺠�tes
1 change: 1 addition & 0 deletions go/vrf/corpus/ee7ba63a3b8e8ba02f9ebb12786c410bf5cb8c04-1
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
Expand Down
1 change: 1 addition & 0 deletions go/vrf/corpus/f014c1d979440ffa0d379d639d8919007b92a0aa-6
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
,�AA�{$̌;��? *l諹}�I�P�����;:��<hU��)Q~��i��"�o�f�^���AZh6�055953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918e�1819e156f1ef451fd46b503f28494847�?lyn6{/Fp^јdExe of ECDSA with aand SHA-256
Expand Down
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions go/vrf/corpus/fa6f1ac65d0c7a660e481a0595864739a174c484-2
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
Expand Down
1 change: 1 addition & 0 deletions go/vrf/corpus/ff5127d3606215ad4320cadc8da5103a653f4ac1-2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
,�AA�{$̌;��? *l諹}�I�P����;:��<hU��11579208921035624876267446949407573529999275760342422259061h aand S4369)Q~��i��"�o�f�^���AZh6��?lyn6{/Fp&IY��K�q���W"ӣ>�ſ�+� ^јdExe of ECDSA with aand
Expand Down
1 change: 1 addition & 0 deletions go/vrf/corpus/ffa12530fbac9a15c79672cf1eed8051bc7ac1ef-1
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
Expand Down
129 changes: 129 additions & 0 deletions go/vrf/ecvrf_p256_sha256_tai_fuzz.go
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
}
83 changes: 83 additions & 0 deletions go/vrf/ecvrf_p256_sha256_tai_fuzz_test.go
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)
}

}
})
}
}
Loading

0 comments on commit 595588e

Please sign in to comment.