Created
November 7, 2017 14:21
-
-
Save mimoo/20e35148e811db1c8052e0081a067aec to your computer and use it in GitHub Desktop.
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> | |
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
int main(void) | |
{ | |
if (sodium_init() < 0) { | |
printf("can't init libsodium"); | |
return 1; | |
} | |
char ed25519_private_hex[] = "28e9e1d48cb0e52e437080e4a180058d7a42a07abcd05ea2ec4e6122cded8f6a0d2a6b9fd1878fd76ab20caecab666916ac3cc772fc57f8fa6e8dc3227bb8497"; | |
char ed25519_public_hex[] = "8fbe438aab6c40dc2ebc839ba27530ca1bf23d4efd36958a3365406efe52ccd1"; | |
unsigned char ed25519_private[64]; | |
size_t ed25519_private_len; | |
sodium_hex2bin(ed25519_private, sizeof ed25519_private, ed25519_private_hex, strlen(ed25519_private_hex), NULL, &ed25519_private_len, NULL); | |
unsigned char ed25519_public[32]; | |
size_t ed25519_public_len; | |
sodium_hex2bin(ed25519_public, sizeof ed25519_public, ed25519_public_hex, strlen(ed25519_public_hex), NULL, &ed25519_public_len, NULL); | |
unsigned char message[] = "hello"; | |
unsigned char signed_message[crypto_sign_BYTES + 5]; | |
unsigned long long signed_message_len; | |
crypto_sign(signed_message, &signed_message_len, message, 5, ed25519_private); | |
unsigned char unsigned_message[5]; | |
unsigned long long unsigned_message_len; | |
if (crypto_sign_open(unsigned_message, &unsigned_message_len, | |
signed_message, signed_message_len, ed25519_public) != 0) { | |
printf("signature incorrect\n"); | |
} | |
else { | |
printf("signature correcte\n"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment