1
0
mirror of https://github.com/CPunch/Laika.git synced 2025-10-09 01:10:14 +00:00

Key exchange refactoring!

- LAIKAPKT_HANDSHAKE_REQ now only sends the bot's pub key
	a shared key is generated using the other peer's pub key,
	allowing for fully encrypted packet bodies, (packet ID is
	left in plain-text)
- laikaS_startOutPacket(), laikaS_endOutPacket(),
	laikaS_startInPacket() & laikaS_endInPacket() have been
	added.
- laikaS_setSecure() has been added to turn on/off encrypted packets.
- genKey now generates kx keypairs
- major refactoring for relevant packet handlers
- variadic packets have been temporarily disabled
This commit is contained in:
2022-02-03 16:25:49 -06:00
parent 310a751a07
commit dd173ee422
12 changed files with 162 additions and 97 deletions

View File

@@ -4,39 +4,22 @@
#include "lerror.h"
#include "lrsa.h"
#define DATA "Encryption/Decryption test passed!\n"
#define DATALEN 36
#define CIPHERLEN crypto_box_SEALBYTES + DATALEN
int main(int argv, char **argc) {
unsigned char priv[crypto_box_SECRETKEYBYTES], pub[crypto_box_PUBLICKEYBYTES];
unsigned char priv[crypto_kx_SECRETKEYBYTES], pub[crypto_kx_PUBLICKEYBYTES];
char buf[256];
unsigned char enc[CIPHERLEN];
unsigned char dec[DATALEN];
if (sodium_init() < 0) {
printf("Libsodium failed to init!\n");
return 1;
}
crypto_box_keypair(pub, priv);
crypto_kx_keypair(pub, priv);
printf("[~] Generated keypair!\n");
sodium_bin2hex(buf, 256, pub, crypto_box_PUBLICKEYBYTES);
sodium_bin2hex(buf, 256, pub, crypto_kx_PUBLICKEYBYTES);
printf("[~] public key: %s\n", buf);
sodium_bin2hex(buf, 256, priv, crypto_box_SECRETKEYBYTES);
sodium_bin2hex(buf, 256, priv, crypto_kx_SECRETKEYBYTES);
printf("[~] private key: %s\n\n", buf);
if (crypto_box_seal(enc, DATA, DATALEN, pub) != 0) {
printf("Failed to encrypt!\n");
return 1;
}
if (crypto_box_seal_open(dec, enc, CIPHERLEN, pub, priv) != 0) {
printf("Failed to decrypt!\n");
return 1;
}
printf("%s", dec);
return 0;
}