Line | Count | Source |
1 | | // Copyright 2026 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 <stddef.h> |
16 | | #include <stdint.h> |
17 | | #include <string.h> |
18 | | |
19 | | #include <sodium.h> |
20 | | |
21 | 29 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
22 | 29 | if (sodium_init() == -1) { |
23 | 0 | return 0; |
24 | 0 | } |
25 | | |
26 | 29 | if (size < crypto_kx_SEEDBYTES + crypto_kx_PUBLICKEYBYTES) { |
27 | 11 | return 0; |
28 | 11 | } |
29 | | |
30 | 18 | unsigned char pk[crypto_kx_PUBLICKEYBYTES]; |
31 | 18 | unsigned char sk[crypto_kx_SECRETKEYBYTES]; |
32 | 18 | unsigned char seed[crypto_kx_SEEDBYTES]; |
33 | | |
34 | 18 | memcpy(seed, data, crypto_kx_SEEDBYTES); |
35 | | |
36 | | // Test keypair generation from seed |
37 | 18 | crypto_kx_seed_keypair(pk, sk, seed); |
38 | | |
39 | 18 | unsigned char client_pk[crypto_kx_PUBLICKEYBYTES]; |
40 | 18 | unsigned char client_sk[crypto_kx_SECRETKEYBYTES]; |
41 | 18 | unsigned char server_pk[crypto_kx_PUBLICKEYBYTES]; |
42 | 18 | unsigned char server_sk[crypto_kx_SECRETKEYBYTES]; |
43 | | |
44 | | // Use data to simulate other party's public key |
45 | 18 | memcpy(server_pk, data + size - crypto_kx_PUBLICKEYBYTES, crypto_kx_PUBLICKEYBYTES); |
46 | | |
47 | 18 | unsigned char rx[crypto_kx_SESSIONKEYBYTES]; |
48 | 18 | unsigned char tx[crypto_kx_SESSIONKEYBYTES]; |
49 | | |
50 | | // Test client session keys |
51 | 18 | crypto_kx_client_session_keys(rx, tx, pk, sk, server_pk); |
52 | | |
53 | | // Test server session keys |
54 | | // We'll use the same 'pk' and 'sk' as server keys now |
55 | 18 | memcpy(client_pk, data + size - crypto_kx_PUBLICKEYBYTES, crypto_kx_PUBLICKEYBYTES); |
56 | 18 | crypto_kx_server_session_keys(rx, tx, pk, sk, client_pk); |
57 | | |
58 | 18 | return 0; |
59 | 29 | } |