feat: Add SE050 hardware RNG integration
- Added system RNG fallback using /dev/urandom - Created se050_wireguard_se050_rng.c for SE050 TRNG integration - WireGuard can now use SE050's built-in hardware random number generator - Improved test coverage: 28 passing tests Usage for SE050 RNG: For standalone (no SE050):
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* @file se050_wireguard_se050_rng.c
|
||||
* @brief WireGuard with SE050 Hardware RNG Integration
|
||||
*
|
||||
* This file provides an alternative key generation function that uses
|
||||
* the SE050 hardware TRNG instead of the system RNG.
|
||||
*
|
||||
* Usage: Link with se050_rng.c and se050_session.c
|
||||
*/
|
||||
|
||||
#include "se050_wireguard.h"
|
||||
#include "se050_x25519_sw.h"
|
||||
#include "se050_rng.h"
|
||||
#include "se050_session.h"
|
||||
|
||||
/* SE050 RNG wrapper for x25519 keypair generation */
|
||||
static int se050_rng_wrapper(uint8_t *out, size_t len, void *ctx)
|
||||
{
|
||||
se050_rng_ctx_t *rng = (se050_rng_ctx_t *)ctx;
|
||||
|
||||
if (!rng || !out) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
se050_status_t ret = se050_rng_generate(rng, out, len);
|
||||
return (ret == SE050_OK) ? 0 : -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Generate WireGuard keypair using SE050 hardware RNG
|
||||
*
|
||||
* @param session SE050 session context (must be initialized)
|
||||
* @param private_key Output: private key (32 bytes)
|
||||
* @param public_key Output: public key (32 bytes)
|
||||
* @return 0 on success, -1 on error
|
||||
*/
|
||||
int se050_wireguard_generate_keypair_se050(se050_session_ctx_t *session,
|
||||
uint8_t *private_key,
|
||||
uint8_t *public_key)
|
||||
{
|
||||
if (!session || !private_key || !public_key) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Initialize SE050 RNG */
|
||||
se050_rng_ctx_t *rng;
|
||||
se050_status_t ret = se050_rng_init(&rng, session);
|
||||
if (ret != SE050_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Generate keypair using SE050 RNG */
|
||||
se050_x25519_sw_keypair_t keypair;
|
||||
ret = se050_x25519_sw_generate_keypair(&keypair, se050_rng_wrapper, rng);
|
||||
|
||||
/* Cleanup RNG context */
|
||||
se050_rng_free(rng);
|
||||
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(private_key, keypair.private_key, 32);
|
||||
memcpy(public_key, keypair.public_key, 32);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user