(claude) generated some general crypto headers I was too lazy to do myself

This commit is contained in:
2026-11-26 20:25:43 +01:00
parent aafd55c2ef
commit e84550d746
12 changed files with 423 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
// x25519.c
#include "crypto/x25519.h"
#include <assert.h>
#include <sodium.h>
static_assert(crypto_scalarmult_BYTES == BRAVAIS_X25519_KEY_LENGTH, "X25519 shared secret size");
static_assert(crypto_scalarmult_SCALARBYTES == BRAVAIS_X25519_KEY_LENGTH, "X25519 private key size");
void bravais_x25519_keypair(uint8_t* outPrivateKey, uint8_t* outPublicKey) {
randombytes_buf(outPrivateKey, BRAVAIS_X25519_KEY_LENGTH);
crypto_scalarmult_base(outPublicKey, outPrivateKey);
}
void bravais_x25519_public_key(const uint8_t* privateKey, uint8_t* outPublicKey) {
crypto_scalarmult_base(outPublicKey, privateKey);
}
bravais_result_t bravais_x25519_dh(const uint8_t* privateKey, const uint8_t* publicKey, uint8_t* outShared) {
// libsodium returns -1 when the output is all zeros, i.e. the peer sent a low-order point
if (crypto_scalarmult(outShared, privateKey, publicKey) != 0) {
return BRAVAIS_ERR_AUTH;
}
return BRAVAIS_OK;
}