Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2020 Google LLC |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | #include "AES.c" |
16 | | #include "common.h" |
17 | | #include <fuzzer/FuzzedDataProvider.h> |
18 | | |
19 | 148 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
20 | | |
21 | 148 | if (!size) |
22 | 0 | return 0; |
23 | | |
24 | 148 | enum KeySize { AES128 = 16, AES192 = 24, AES256 = 32, kMaxValue = AES256 }; |
25 | | |
26 | 148 | FuzzedDataProvider stream(data, size); |
27 | 148 | const KeySize keySize = stream.ConsumeEnum<KeySize>(); |
28 | 148 | if (stream.remaining_bytes() < keySize) |
29 | 8 | return 0; |
30 | | |
31 | 140 | std::vector<uint8_t> keyBuf = stream.ConsumeBytes<uint8_t>(keySize); |
32 | 140 | const uint8_t *key = keyBuf.data(); |
33 | | |
34 | 140 | BlockBase *state; |
35 | 140 | if (AES_start_operation(key, keySize, reinterpret_cast<AES_State **>(&state))) |
36 | 67 | return 0; |
37 | | |
38 | 73 | uint8_t outEnc[size]; |
39 | 73 | uint8_t outDec[size]; |
40 | | |
41 | 73 | AES_encrypt(reinterpret_cast<BlockBase *>(state), data, outEnc, size); |
42 | 73 | AES_decrypt(reinterpret_cast<BlockBase *>(state), data, outDec, size); |
43 | | |
44 | 73 | AES_stop_operation(reinterpret_cast<BlockBase *>(state)); |
45 | | |
46 | 73 | return 0; |
47 | 140 | } |