diff options
author | EuAndreh <eu@euandre.org> | 2023-12-29 12:47:15 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2025-03-20 15:58:40 -0300 |
commit | 51437318493e6f623631a73bd7f9389708cea537 (patch) | |
tree | 903ad1612db315d69d578db50c879f767bcc0c4f /src/lib.h | |
parent | Add complete "Makefile" for standard packaging (diff) | |
download | agahu-main.tar.gz agahu-main.tar.xz |
- remove `#ifndef TWEETNACL_H` guard inside `tweetnacl.h`: as headers
shouldn't include other headers;
- remove `#define sv static void` golfing alias;
- remove `#define FOR(i,n) for (i = 0;i < n;++i)` golfing alias;
- assert that the generated `tweetnacl.o` code is identical to the
original code, available at `tests/assert-identical.sh`;
- remove all extra definitions from tweetnacl.h;
- rewrite code with the correct indentation, spacing and formatting;
- use C99 constructs over C89 (for loop variable declarations inside
the parentheses);
- use smaller types on loop variables, mostly `u8` over `int`,
`i64`, etc.;
- fix the public API;
- add fuzz targets;
Diffstat (limited to '')
-rw-r--r-- | src/lib.h | 153 |
1 files changed, 153 insertions, 0 deletions
diff --git a/src/lib.h b/src/lib.h new file mode 100644 index 0000000..16a9ebd --- /dev/null +++ b/src/lib.h @@ -0,0 +1,153 @@ +enum { + crypt_verify_BYTES = 16, + + crypt_hash_BYTES = 64, + + crypt_onetimeauth_BYTES = 16, + crypt_onetimeauth_KEYBYTES = 32, + + crypt_secretbox_KEYBYTES = 32, + crypt_secretbox_NONCEBYTES = 24, + crypt_secretbox_ZEROBYTES = 32, + crypt_secretbox_BOXZEROBYTES = 16, + + crypt_sign_BYTES = 64, + crypt_sign_PUBLICKEYBYTES = 32, + crypt_sign_SECRETKEYBYTES = 64, + + crypt_box_PUBLICKEYBYTES = 32, + crypt_box_SECRETKEYBYTES = 32, + crypt_box_BEFORENMBYTES = 32, + crypt_box_NONCEBYTES = 24, + crypt_box_ZEROBYTES = 32, + crypt_box_BOXZEROBYTES = 16, +}; + + + +int +random_init(void); + +int +random_destroy(void); + +int +tweetnacl_main(int argc, const char *const *argv); + + + +bool +crypt_verify( + const unsigned char buffer1[crypt_verify_BYTES], + const unsigned char buffer2[crypt_verify_BYTES] +); + +void +crypt_hash( + const unsigned long long length, + const unsigned char *data, + unsigned char out[crypt_hash_BYTES] +); + +void +crypt_onetimeauth( + const unsigned long long length, + const unsigned char *const data, + const unsigned char secret_key[crypt_onetimeauth_KEYBYTES], + unsigned char authenticator_out[crypt_onetimeauth_BYTES] +); + +bool +crypt_onetimeauth_verify( + const unsigned char authenticator[crypt_onetimeauth_BYTES], + const unsigned char secret_key[crypt_onetimeauth_KEYBYTES], + const unsigned long long length, + const unsigned char *const data +); + +int +crypt_secretbox( + const unsigned char secret_key[crypt_secretbox_KEYBYTES], + const unsigned long long length, + const unsigned char *const clear_data, + unsigned char *const cypher_out +); + +int +crypt_secretbox_open( + const unsigned char secret_key[crypt_secretbox_KEYBYTES], + const unsigned long long length, + const unsigned char *const cypher_data, + unsigned char *const clean_out +); + +void +crypt_sign_keypair( + unsigned char public_key_out[crypt_sign_PUBLICKEYBYTES], + unsigned char secret_key_out[crypt_sign_SECRETKEYBYTES] +); + +void +crypt_sign( + const unsigned char secret_key[crypt_sign_SECRETKEYBYTES], + const unsigned long long length, + const unsigned char *const data, + unsigned long long *const outlen, + unsigned char *const signed_out +); + +int +crypt_sign_open( + const unsigned char public_key[crypt_sign_PUBLICKEYBYTES], + const unsigned long long signed_message_length, + const unsigned char *const signed_message, + unsigned long long *const inoutlen, + unsigned char *const out +); + +void +crypt_box_keypair( + unsigned char public_key_out[crypt_box_PUBLICKEYBYTES], + unsigned char secret_key_out[crypt_box_SECRETKEYBYTES] +); + +int +crypt_box( + const unsigned char receiver_public_key[crypt_box_PUBLICKEYBYTES], + const unsigned char sender_secret_key[crypt_box_PUBLICKEYBYTES], + const unsigned long long length, + const unsigned char *const clear_data, + unsigned char *const cypher_out +); + +int +crypt_box_open( + const unsigned char sender_public_key[crypt_box_PUBLICKEYBYTES], + const unsigned char receiver_secret_key[crypt_box_SECRETKEYBYTES], + const unsigned long long length, + const unsigned char *const cypher_data, + unsigned char *const clear_out +); + +void +crypt_box_beforenm( + const unsigned char public_key[crypt_box_PUBLICKEYBYTES], + const unsigned char secret_key[crypt_box_PUBLICKEYBYTES], + unsigned char out[crypt_box_BEFORENMBYTES] +); + +void +crypt_box_afternm( + const unsigned char beforenm_intermediate[crypt_box_BEFORENMBYTES], + const unsigned long long length, + const unsigned char *const clear_data, + unsigned char *const cypher_out +); + +int +crypt_box_open_afternm( + const unsigned char beforenm_intermediate[crypt_box_BEFORENMBYTES], + const unsigned long long length, + const unsigned char *const cypher_data, + unsigned char *const clear_out +); |