Cerberus/x25519_handshake.cpp
wheelchairy 118875234a upd
2025-01-28 22:33:54 +03:00

26 lines
743 B
C++

#include "x25519_handshake.hpp"
#include <cstdio>
#include <cstring>
#include <iostream>
extern "C" {
#include "monocypher.h"
}
void x25519GenerateEphemeral(AppConfig &config){
FILE* f=fopen("/dev/urandom","rb");
if(!f)return;
fread(config.ephemeralSec,1,32,f);
fclose(f);
crypto_x25519_public_key(config.ephemeralPub,config.ephemeralSec);
std::memset(config.sharedSecret,0,32);
config.haveSharedSecret=false;
}
void x25519ComputeShared(AppConfig &config,const uint8_t otherPub[32]){
uint8_t shared[32];
crypto_x25519(shared,config.ephemeralSec,otherPub);
std::memcpy(config.sharedSecret,shared,32);
config.haveSharedSecret=true;
std::cout<<CLR_GREEN<<"[x25519] key computed!\n"<<CLR_RESET;
}