Skip to content

Commit

Permalink
Update PQ fuzz tests (aws#2309)
Browse files Browse the repository at this point in the history
* Update PQ decapsulation fuzz tests to call recv_ciphertext
* Add PQ fuzz tests for recv_public_key
* Update PQ fuzz test corpus files
* Update CodeBuild config files for new PQ fuzz tests
* Reduce FUZZ_TIMEOUT_SEC to 90 to be consistent with other fuzz targets
  • Loading branch information
bbutch authored Sep 26, 2020
1 parent c1bf3f1 commit 240da76
Show file tree
Hide file tree
Showing 244 changed files with 545 additions and 369 deletions.
2 changes: 1 addition & 1 deletion codebuild/codebuild.config
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ stack_name: s2nCodeBuildTests
# Fuzzers
[CodeBuild:s2nfuzzerOpenSSL111Coverage]
snippet: UbuntuBoilerplate2XL
env: S2N_LIBCRYPTO=openssl-1.1.1 LATEST_CLANG=true TESTS=fuzz FUZZ_TIMEOUT_SEC=120 FUZZ_COVERAGE=true CODECOV_IO_UPLOAD=true
env: S2N_LIBCRYPTO=openssl-1.1.1 LATEST_CLANG=true TESTS=fuzz FUZZ_TIMEOUT_SEC=60 FUZZ_COVERAGE=true CODECOV_IO_UPLOAD=true

[CodeBuild:s2nfuzzerOpenSSL102FIPS]
snippet: UbuntuBoilerplate2XL
Expand Down
46 changes: 38 additions & 8 deletions codebuild/fuzz_codebuild.config
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,25 @@ artifact_secondary_identifiers: logs
artifact_s3_bucket: s2n-build-artifacts
env: TESTS=fuzz FUZZ_TIMEOUT_SEC=28000

[CloudWatchEvent:s2n_bike_r1_fuzz_test]
[CloudWatchEvent:s2n_bike_r1_recv_ciphertext_fuzz_test]
start_time: 05:00
build_job_name: s2nFuzzScheduled
input: {"environmentVariablesOverride": [{"name": "FUZZ_TESTS","value": "s2n_bike_r1_fuzz_test"}]}
input: {"environmentVariablesOverride": [{"name": "FUZZ_TESTS","value": "s2n_bike_r1_recv_ciphertext_fuzz_test"}]}

[CloudWatchEvent:s2n_bike_r2_fuzz_test]
[CloudWatchEvent:s2n_bike_r1_recv_public_key_fuzz_test]
start_time: 05:00
build_job_name: s2nFuzzScheduled
input: {"environmentVariablesOverride": [{"name": "FUZZ_TESTS","value": "s2n_bike_r2_fuzz_test"}]}
input: {"environmentVariablesOverride": [{"name": "FUZZ_TESTS","value": "s2n_bike_r1_recv_public_key_fuzz_test"}]}

[CloudWatchEvent:s2n_bike_r2_recv_ciphertext_fuzz_test]
start_time: 05:00
build_job_name: s2nFuzzScheduled
input: {"environmentVariablesOverride": [{"name": "FUZZ_TESTS","value": "s2n_bike_r2_recv_ciphertext_fuzz_test"}]}

[CloudWatchEvent:s2n_bike_r2_recv_public_key_fuzz_test]
start_time: 05:00
build_job_name: s2nFuzzScheduled
input: {"environmentVariablesOverride": [{"name": "FUZZ_TESTS","value": "s2n_bike_r2_recv_public_key_fuzz_test"}]}

[CloudWatchEvent:s2n_certificate_extensions_parse_test]
start_time: 05:00
Expand Down Expand Up @@ -111,6 +121,16 @@ start_time: 05:00
build_job_name: s2nFuzzScheduled
input: {"environmentVariablesOverride": [{"name": "FUZZ_TESTS","value": "s2n_hybrid_ecdhe_sike_r2_fuzz_test"}]}

[CloudWatchEvent:s2n_kyber_r2_recv_ciphertext_fuzz_test]
start_time: 05:00
build_job_name: s2nFuzzScheduled
input: {"environmentVariablesOverride": [{"name": "FUZZ_TESTS","value": "s2n_kyber_r2_recv_ciphertext_fuzz_test"}]}

[CloudWatchEvent:s2n_kyber_r2_recv_public_key_fuzz_test]
start_time: 05:00
build_job_name: s2nFuzzScheduled
input: {"environmentVariablesOverride": [{"name": "FUZZ_TESTS","value": "s2n_kyber_r2_recv_public_key_fuzz_test"}]}

[CloudWatchEvent:s2n_openssl_diff_pem_parsing_test]
start_time: 05:00
build_job_name: s2nFuzzScheduled
Expand Down Expand Up @@ -146,15 +166,25 @@ start_time: 05:00
build_job_name: s2nFuzzScheduled
input: {"environmentVariablesOverride": [{"name": "FUZZ_TESTS","value": "s2n_server_hello_recv_test"}]}

[CloudWatchEvent:s2n_sike_r1_fuzz_test]
[CloudWatchEvent:s2n_sike_r1_recv_ciphertext_fuzz_test]
start_time: 05:00
build_job_name: s2nFuzzScheduled
input: {"environmentVariablesOverride": [{"name": "FUZZ_TESTS","value": "s2n_sike_r1_recv_ciphertext_fuzz_test"}]}

[CloudWatchEvent:s2n_sike_r1_recv_public_key_fuzz_test]
start_time: 05:00
build_job_name: s2nFuzzScheduled
input: {"environmentVariablesOverride": [{"name": "FUZZ_TESTS","value": "s2n_sike_r1_recv_public_key_fuzz_test"}]}

[CloudWatchEvent:s2n_sike_r2_recv_ciphertext_fuzz_test]
start_time: 05:00
build_job_name: s2nFuzzScheduled
input: {"environmentVariablesOverride": [{"name": "FUZZ_TESTS","value": "s2n_sike_r1_fuzz_test"}]}
input: {"environmentVariablesOverride": [{"name": "FUZZ_TESTS","value": "s2n_sike_r2_recv_ciphertext_fuzz_test"}]}

[CloudWatchEvent:s2n_sike_r2_fuzz_test]
[CloudWatchEvent:s2n_sike_r2_recv_public_key_fuzz_test]
start_time: 05:00
build_job_name: s2nFuzzScheduled
input: {"environmentVariablesOverride": [{"name": "FUZZ_TESTS","value": "s2n_sike_r2_fuzz_test"}]}
input: {"environmentVariablesOverride": [{"name": "FUZZ_TESTS","value": "s2n_sike_r2_recv_public_key_fuzz_test"}]}

[CloudWatchEvent:s2n_stuffer_pem_fuzz_test]
start_time: 05:00
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
����]9B<P���ʳk�BM�[�2Y�oa���W��ɑ��_\�6�׎�҉�,GR?;���#=I?X?G�V��)} =��NXFnK"�~ba�ụ�ۀ�F��R��*����zP0[� D�S��u:�M���f}c��~4������N0Ȯ��7ۡ�p[}�p�S]��=oZ?�b{��q� ������T�lp�N1C�!����Y���
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
����]9B<P��A ����]�������
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
��&D��1V~��R�µ9�(kmh��MP��=���&5Y�D����T�$U�-e���tj�r��i�� ��&D��1V~��R�µ9�(kmh��MP��=���&5Y�D����T�$U�-e���tj�r��i��D���}-Q�q�m�^��J�Dv
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
o(
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
B�
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
;�
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
��
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
z ���_������Z5��G��.K�g\�L�,��i)5���7~�~yНW���P�&�5
 #��m� `}n��c���%�m�0��B�ge��Y^�.
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
z ��m0��B�ge��Y^�.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
z ���_������Z0��G��.K�g\�L�,��i)5���7~�~yНW�X(�����M0�=/v��)��'�V�D�:Cxr�8��nHr>/�F��d�-�|{������a����D@�u@L�.7��#LQ;� �_��S5|���oS�eȸ��P�&�5
 9J�;�>v_���U��ь������oC�f��\#��m� `}n��c���%���:���̕�P��I���_���~�ƒ�m�f������9 H'�g-~�8"�����8�M4��~�d�v�eA?}�:v-i�r��W<�Ƀ�6-Y�n7pK��V7�k����f�L!�<�Yd��Oo�s��c��C,cum�0��B�ge��Y^�.
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
��
Binary file not shown.
Binary file not shown.
71 changes: 0 additions & 71 deletions tests/fuzz/s2n_bike_r1_fuzz_test.c

This file was deleted.

59 changes: 59 additions & 0 deletions tests/fuzz/s2n_bike_r1_recv_ciphertext_fuzz_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. 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.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file 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.
*/

/* Target Functions: s2n_kem_recv_ciphertext s2n_kem_decapsulate BIKE1_L1_R1_crypto_kem_dec */

#include "tests/s2n_test.h"
#include "tests/testlib/s2n_testlib.h"
#include "tls/s2n_kem.h"
#include "utils/s2n_safety.h"
#include "pq-crypto/bike_r1/bike_r1_kem.h"

#define KAT_FILE_NAME "../unit/kats/bike_r1.kat"

/* This fuzz test uses the first private key (count = 0) from tests/unit/kats/bike_r1.kat.
* A valid ciphertext to provide to s2n_kem_recv_ciphertext (as it would have appeared on
* the wire) was generated by taking the corresponding KAT ciphertext (count = 0) and
* prepending BIKE1_L1_R1_CIPHERTEXT_BYTES as two hex-encoded bytes. */
static struct s2n_kem_params kem_params = { .kem = &s2n_bike1_l1_r1 };

int s2n_fuzz_init(int *argc, char **argv[]) {
GUARD(s2n_kem_recv_ciphertext_fuzz_test_init(KAT_FILE_NAME, &kem_params));
return S2N_SUCCESS;
}

int s2n_fuzz_test(const uint8_t *buf, size_t len) {
struct s2n_stuffer ciphertext = { 0 };
GUARD(s2n_stuffer_growable_alloc(&ciphertext, 8192));
GUARD(s2n_stuffer_write_bytes(&ciphertext, buf, len));

/* We do not GUARD s2n_kem_recv_ciphertext; it will likely fail. */
s2n_kem_recv_ciphertext(&ciphertext, &kem_params);

/* We do not GUARD decapsulate for BIKE1_L1_R1; there is a non-zero
* chance the decoding may fail if the inputs are not valid. */
uint8_t ss_buf[BIKE1_L1_R1_SHARED_SECRET_BYTES] = { 0 };
kem_params.kem->decapsulate(ss_buf, ciphertext.blob.data, kem_params.private_key.data);

/* Clean up */
GUARD(s2n_stuffer_free(&ciphertext));
if (kem_params.shared_secret.allocated) {
GUARD(s2n_free(&kem_params.shared_secret));
}

return S2N_SUCCESS;
}

S2N_FUZZ_TARGET(s2n_fuzz_init, s2n_fuzz_test, NULL)
33 changes: 33 additions & 0 deletions tests/fuzz/s2n_bike_r1_recv_public_key_fuzz_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. 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.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file 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.
*/

/* Target Functions: s2n_kem_recv_public_key s2n_kem_encapsulate BIKE1_L1_R1_crypto_kem_enc */

#include "tests/s2n_test.h"
#include "tests/testlib/s2n_testlib.h"
#include "tls/s2n_kem.h"
#include "utils/s2n_safety.h"

/* The valid_public_key in the corpus directory was generated by taking the first public
* key (count = 0) from bike_r1.kat and prepending BIKE1_L1_R1_PUBLIC_KEY_BYTES as two
* hex-encoded bytes. This is how we would expect it to appear on the wire. */
static struct s2n_kem_params kem_params = { .kem = &s2n_bike1_l1_r1 };

int s2n_fuzz_test(const uint8_t *buf, size_t len) {
GUARD(s2n_kem_recv_public_key_fuzz_test(buf, len, &kem_params));
return S2N_SUCCESS;
}

S2N_FUZZ_TARGET(NULL, s2n_fuzz_test, NULL)
71 changes: 0 additions & 71 deletions tests/fuzz/s2n_bike_r2_fuzz_test.c

This file was deleted.

Loading

0 comments on commit 240da76

Please sign in to comment.