Coverage for /pythoncovmergedfiles/medio/medio/src/fuzz_aead.py: 62%
39 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-08 07:26 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-08 07:26 +0000
1###### Coverage stub
2import atexit
3import coverage
4cov = coverage.coverage(data_file='.coverage', cover_pylib=True)
5cov.start()
6# Register an exist handler that will print coverage
7def exit_handler():
8 cov.stop()
9 cov.save()
10atexit.register(exit_handler)
11####### End of coverage stub
12#!/usr/bin/python3
14# Copyright 2022 Google LLC
15#
16# Licensed under the Apache License, Version 2.0 (the "License");
17# you may not use this file except in compliance with the License.
18# You may obtain a copy of the License at
19#
20# http://www.apache.org/licenses/LICENSE-2.0
21#
22# Unless required by applicable law or agreed to in writing, software
23# distributed under the License is distributed on an "AS IS" BASIS,
24# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25# See the License for the specific language governing permissions and
26# limitations under the License.
27import sys
28import atheris
29with atheris.instrument_imports():
30 import cryptography.hazmat.primitives.ciphers.aead as aead
32def TestInput(input_bytes):
33 if len(input_bytes) < 12:
34 return
36 fdp = atheris.FuzzedDataProvider(input_bytes)
38 choice = fdp.ConsumeIntInRange(1,4)
40 if choice == 1:
41 cipher = aead.ChaCha20Poly1305(aead.ChaCha20Poly1305.generate_key())
42 if choice == 2:
43 cipher = aead.AESGCM(aead.AESGCM.generate_key(bit_length=128))
44 if choice == 3:
45 cipher = aead.AESOCB3(aead.AESOCB3.generate_key(bit_length=128))
46 if choice == 4:
47 cipher = aead.AESCCM(aead.AESCCM.generate_key(bit_length=128))
49 msg = fdp.ConsumeBytes(32)
50 authentext = fdp.ConsumeBytes(32)
51 nonce = fdp.ConsumeBytes(12)
53 if len(nonce) < 12:
54 return
56 ciphertext = cipher.encrypt(nonce, msg, authentext)
57 plaintext = cipher.decrypt(nonce, ciphertext, authentext)
59 assert (plaintext == msg), "Encryption/Decrption error!"
61def main():
62 atheris.Setup(sys.argv, TestInput, enable_python_coverage=False)
63 atheris.instrument_all()
64 atheris.Fuzz()
66if __name__ == "__main__":
67 main()