I try to repeat the example instruction like this: https://developer.nuki.io/page/nuki-smart-lock-api-220/2#heading--command-usage-examples
I took an official C library of NaCI: tweetnacl
As I understood I need to use my secret key and obtained public key as arguments in kdf1 method.
kdf1 method is crypto_stream_salsa20_tweet in tweetnacl.
My secret key: 8CAA54672307BFFDF5EA183FC607158D2011D008ECA6A1088614FF0853A5AA07
Obtained public key : 2FE57DA347CD62431528DAAC5FBB290730FFF684AFC4CFC2ED90995F58CB3B74
I wrote very simple arduino sketch for esp8266.
#include <Arduino.h>
#include <tweetnacl.h>
void setup() {
Serial.begin(115200);
Serial.flush();
Serial.println("Test");
pinMode(LED_BUILTIN, OUTPUT);
char * t1 = new char[64];
unsigned long long t2 = 32;
const char * t3 = "8CAA54672307BFFDF5EA183FC607158D2011D008ECA6A1088614FF0853A5AA07";
const char * t4 = "2FE57DA347CD62431528DAAC5FBB290730FFF684AFC4CFC2ED90995F58CB3B74";
Serial.println("=========");
Serial.println();
crypto_stream_salsa20_tweet((unsigned char *)t1, t2, (unsigned char *)t3, (unsigned char *)t4);
int lenReceived = strlen((const char*)t1);
for (int i = 0; i < lenReceived; i++) {
char str[3];
sprintf(str, "%02X", (int)t1[i]);
Serial.print(str);
}
Serial.println();
Serial.println("=========");
free(t1);
}
void loop() {
}
Result is:
Test
B0FAA155DE753CC48E9FA1082A0421F4B4B88675168EC67B950A85A8E7BAE5EB
But we must see:
217FCB0F18CAF284E9BDEA0B94B83B8D10867ED706BFDEDBD2381F4CB3B8F730
I have the same situation with Swift.
Do anybody know why it happens? What I do wrong?
Also, I tried to do it with method crypto_core_salsa20 like this:
char * t1 = new char[64]; const char * t3 = "8CAA54672307BFFDF5EA183FC607158D2011D008ECA6A1088614FF0853A5AA07"; const char * t4 = "2FE57DA347CD62431528DAAC5FBB290730FFF684AFC4CFC2ED90995F58CB3B74"; const char *sigma = "expand 32-byte k"; Serial.println("========="); Serial.println(); crypto_core_salsa20((unsigned char *)t1, (unsigned char *)t3, (unsigned char *)t3, (unsigned char *)sigma);
But anywhere I received wrong result: