mirror of https://github.com/google/oss-fuzz.git
29 lines
756 B
C++
29 lines
756 B
C++
|
#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;
|
||
|
}
|