Created
December 1, 2020 22:06
-
-
Save jjromannet/bab5ce7f6d331d52904108f4a1076a8c 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
/* | |
This work is derived from: | |
https://github.com/I-Connect/nuki_ble | |
Therefore licence is: GPL v3.0 | |
requirements: | |
GCC, libsodium | |
compile: | |
gcc main.cpp -lsodium | |
run: | |
./a.out | |
*/ | |
#include <stdio.h> | |
#include <string.h> | |
#include <sodium.h> | |
typedef bool boolean; | |
#define byte uint8_t | |
unsigned char remotePublicKey[32] = {0x2F, 0xE5, 0x7D, 0xA3, 0x47, 0xCD, 0x62, 0x43, 0x15, 0x28, 0xDA, 0xAC, 0x5F, 0xBB, 0x29, 0x07, 0x30, 0xFF, 0xF6, 0x84, 0xAF, 0xC4, 0xCF, 0xC2, 0xED, 0x90, 0x99, 0x5F, 0x58, 0xCB, 0x3B, 0x74}; | |
static unsigned char myPrivateKey[32] = {0x8C, 0xAA, 0x54, 0x67, 0x23, 0x07, 0xBF, 0xFD, 0xF5, 0xEA, 0x18, 0x3F, 0xC6, 0x07, 0x15, 0x8D, 0x20, 0x11, 0xD0, 0x08, 0xEC, 0xA6, 0xA1, 0x08, 0x86, 0x14, 0xFF, 0x08, 0x53, 0xA5, 0xAA, 0x07}; | |
static unsigned char myPublicKey[32] = {0xF8, 0x81, 0x27, 0xCC, 0xF4, 0x80, 0x23, 0xB5, 0xCB, 0xE9, 0x10, 0x1D, 0x24, 0xBA, 0xA8, 0xA3, 0x68, 0xDA, 0x94, 0xE8, 0xC2, 0xE3, 0xCD, 0xE2, 0xDE, 0xD2, 0x9C, 0xE9, 0x6A, 0xB5, 0x0C, 0x15}; | |
void printBuffer(const byte* buff, const uint8_t size, const boolean asChars, const char* header) { | |
if (strlen(header) > 0) { | |
printf ("%s", header); | |
printf (": "); | |
} | |
for (int i = 0; i < size; i++) { | |
if (asChars) { | |
printf ("%c", (char)buff[i]); | |
} else { | |
printf ("%02x ", buff[i]); | |
} | |
} | |
printf("\n"); | |
} | |
int main(){ | |
unsigned char sharedKeyS[32]; | |
int i= crypto_scalarmult_curve25519(sharedKeyS, myPrivateKey, remotePublicKey); | |
printBuffer(sharedKeyS, sizeof(sharedKeyS), false, "Shared key s"); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment