-
Notifications
You must be signed in to change notification settings - Fork 3
Algorithm Lucidity #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,41 +21,57 @@ static const size_t signature_len = crypto_sign_BYTES; | |
|
|
||
|
|
||
| bool paseto_v2_public_load_public_key_hex( | ||
| uint8_t key[paseto_v2_PUBLIC_PUBLICKEYBYTES], | ||
| struct paseto_v2_public_pk *key, | ||
| const char *key_hex) { | ||
| return key_load_hex(key, paseto_v2_PUBLIC_PUBLICKEYBYTES, key_hex); | ||
| struct paseto_v2_public_pk tmp; | ||
| *key = &tmp; | ||
| key->header = V2_PUBLIC; | ||
| return key_load_hex(key->key_bytes, paseto_v2_PUBLIC_PUBLICKEYBYTES, key_hex); | ||
| } | ||
|
|
||
|
|
||
| bool paseto_v2_public_load_public_key_base64( | ||
| uint8_t key[paseto_v2_PUBLIC_PUBLICKEYBYTES], | ||
| struct paseto_v2_public_pk *key, | ||
| const char *key_base64) { | ||
| return key_load_base64(key, paseto_v2_PUBLIC_PUBLICKEYBYTES, key_base64); | ||
| struct paseto_v2_public_pk tmp; | ||
| *key = &tmp; | ||
| key->header = V2_PUBLIC; | ||
| return key_load_base64(key->key_bytes, paseto_v2_PUBLIC_PUBLICKEYBYTES, key_base64); | ||
| } | ||
|
|
||
|
|
||
| bool paseto_v2_public_load_secret_key_hex( | ||
| uint8_t key[paseto_v2_PUBLIC_SECRETKEYBYTES], | ||
| struct paseto_v2_public_sk key, | ||
| const char *key_hex) { | ||
| return key_load_hex(key, paseto_v2_PUBLIC_SECRETKEYBYTES, key_hex); | ||
| struct paseto_v2_public_sk tmp; | ||
| *key = &tmp; | ||
| key->header = V2_PUBLIC; | ||
| return key_load_hex(key->key_bytes, paseto_v2_PUBLIC_SECRETKEYBYTES, key_hex); | ||
| } | ||
|
|
||
|
|
||
| bool paseto_v2_public_load_secret_key_base64( | ||
| uint8_t key[paseto_v2_PUBLIC_SECRETKEYBYTES], | ||
| v2_public_sk key, | ||
| const char *key_base64) { | ||
| return key_load_base64(key, paseto_v2_PUBLIC_SECRETKEYBYTES, key_base64); | ||
| struct paseto_v2_public_sk tmp; | ||
| *key = &tmp; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no point in doing this, since tmp does not get initialized in C, you can just drop it. Also the |
||
| key->header = V2_PUBLIC; | ||
| return key_load_base64(key->key_bytes, paseto_v2_PUBLIC_SECRETKEYBYTES, key_base64); | ||
| } | ||
|
|
||
|
|
||
| char *paseto_v2_public_sign( | ||
| const uint8_t *message, size_t message_len, | ||
| const uint8_t key[paseto_v2_PUBLIC_SECRETKEYBYTES], | ||
| struct paseto_v2_public_sk *key, | ||
| const uint8_t *footer, size_t footer_len) { | ||
| if (!message || !key) { | ||
| errno = EINVAL; | ||
| return NULL; | ||
| } | ||
| if (key->header != V2_PUBLIC) { | ||
| errno = EINVAL; | ||
| return NULL; | ||
| } | ||
| if (!footer) footer_len = 0; | ||
| if (!footer_len) footer = NULL; | ||
|
|
||
|
|
@@ -79,7 +95,7 @@ char *paseto_v2_public_sign( | |
| size_t pre_auth_len = pa.current - pa.base; | ||
|
|
||
| uint8_t *ct = to_encode + message_len; | ||
| crypto_sign_detached(ct, NULL, pa.base, pre_auth_len, key); | ||
| crypto_sign_detached(ct, NULL, pa.base, pre_auth_len, key->key_bytes); | ||
|
|
||
| free(pa.base); | ||
|
|
||
|
|
@@ -124,12 +140,16 @@ char *paseto_v2_public_sign( | |
|
|
||
| uint8_t *paseto_v2_public_verify( | ||
| const char *encoded, size_t *message_len, | ||
| const uint8_t key[paseto_v2_PUBLIC_PUBLICKEYBYTES], | ||
| const struct paseto_v2_public_pk *key, | ||
| uint8_t **footer, size_t *footer_len) { | ||
| if (!encoded || !message_len || !key) { | ||
| errno = EINVAL; | ||
| return NULL; | ||
| } | ||
| if (key->header != V2_PUBLIC) { | ||
| errno = EINVAL; | ||
| return NULL; | ||
| } | ||
|
|
||
| if (strlen(encoded) < header_len + sodium_base64_ENCODED_LEN( | ||
| signature_len, sodium_base64_VARIANT_URLSAFE_NO_PADDING) - 1 | ||
|
|
@@ -215,7 +235,7 @@ uint8_t *paseto_v2_public_verify( | |
| return NULL; | ||
| } | ||
| if (crypto_sign_verify_detached( | ||
| signature, pa.base, pre_auth_len, key) != 0) { | ||
| signature, pa.base, pre_auth_len, key->key_bytes) != 0) { | ||
| free(decoded); | ||
| free(decoded_footer); | ||
| free(pa.base); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything in the header should be namespaced/prefixed so it doesn't potentially collide with other libraries or code. Enums aren't namespaced in C(++).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood. We don't normally do C development and was hoping the CI pipeline would catch these bugs.