Last active
October 23, 2023 14:51
-
-
Save viswanathkgp12/1ec14e76781eec09170bae4c6a1e1841 to your computer and use it in GitHub Desktop.
Ed25519 Sign Verification using libsodium
This file contains 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 "sodium.h" | |
int main(void) | |
{ | |
sodium_init(); | |
crypto_sign_state st; | |
unsigned char sig[64]; | |
unsigned long long siglen; | |
// Signature, message and Public Key from RFC-8037 | |
char sig_hex[129] = "\x63\xc3\x0c\xe0\x78\xf0\xc8\x4d\xc5\x9a\x52\x49\xd1\x4f\x37\xd1\xad\xb3\x45\x17\x0f\x1a\x04\xcd\x96\x67\x72\xf5\xee\x79\x32\x63\x1b\x8f\xb1\xb5\x2c\x2b\x9b\xee\x3a\x3c\x2f\x12\x02\xba\xf2\x69\x79\x55\x32\x36\x34\xb3\x3e\x68\x7f\x2e\x45\x2b\xf4\xe1\x17\x07"; | |
const char *m = "\xb6\x33\x37\xd1\xea\x4c\xf5\x3b\xd0\xa8\x07\x56\x36\x19\x2c\x1e\x40\x09\x8f\x01\x13\xa8\xd1\xfc\xed\xd2\x97\x1e\xb9\x34\x0d\x28"; | |
const unsigned char pk[32] = "\x23\x65\xfb\x69\x44\x94\xf1\x20\x97\xb9\x52\x47\xdc\x89\x01\x6b\x63\x70\xf1\xc4\xdd\x3a\xe1\xd8\xd6\x31\x3b\x98\x9b\x4f\x5d\x2c"; | |
unsigned long long mlen = 32; | |
crypto_sign_ed25519ph_init(&st); | |
crypto_sign_ed25519ph_update(&st, (const unsigned char *)m, mlen); | |
int verified = crypto_sign_ed25519ph_final_verify(&st, sig_hex, pk); | |
printf("Signature verified: %d\n", verified); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
gcc test.c -lsodium -o test.o
./test.o