aboutsummaryrefslogtreecommitdiff
path: root/projects/libsodium/secretbox_easy_fuzzer.cc
diff options
context:
space:
mode:
authorChris Wolfe <chriswwolfe@gmail.com>2018-01-17 10:13:47 -0600
committerjonathanmetzman <31354670+jonathanmetzman@users.noreply.github.com>2018-01-17 08:13:47 -0800
commit2a4963cffbe28f25e82a83ad8a9404e6980622ec (patch)
treeac865b13223f19afabd341cd726ac62da2338894 /projects/libsodium/secretbox_easy_fuzzer.cc
parentc8fa1013305e3c30eeec93d08ed7012ff34d7863 (diff)
downloadoss-fuzz-2a4963cffbe28f25e82a83ad8a9404e6980622ec.tar.gz
Projects: Include libsodium (#1051)
Add libsodium fuzzers. Add secret_key_auth_fuzzer and secretbox_easy_fuzzer targets from libsodium.
Diffstat (limited to 'projects/libsodium/secretbox_easy_fuzzer.cc')
-rw-r--r--projects/libsodium/secretbox_easy_fuzzer.cc28
1 files changed, 28 insertions, 0 deletions
diff --git a/projects/libsodium/secretbox_easy_fuzzer.cc b/projects/libsodium/secretbox_easy_fuzzer.cc
new file mode 100644
index 000000000..4e25bcc7a
--- /dev/null
+++ b/projects/libsodium/secretbox_easy_fuzzer.cc
@@ -0,0 +1,28 @@
+#include <assert.h>
+#include <sodium.h>
+
+#include "fake_random.h"
+
+extern "C" int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size) {
+ int initialized = sodium_init();
+ assert(initialized >= 0);
+
+ setup_fake_random(data, size);
+
+ unsigned char key[crypto_secretbox_KEYBYTES];
+ unsigned char nonce[crypto_secretbox_NONCEBYTES];
+
+ // these use a deterministic generator
+ crypto_secretbox_keygen(key);
+ randombytes_buf(nonce, sizeof nonce);
+
+ size_t ciphertext_len = crypto_secretbox_MACBYTES + size;
+ unsigned char ciphertext[ciphertext_len];
+
+ crypto_secretbox_easy(ciphertext, data, size, nonce, key);
+
+ unsigned char decrypted[size];
+ crypto_secretbox_open_easy(decrypted, ciphertext, ciphertext_len, nonce, key);
+
+ return 0;
+}