Skip to content

Commit

Permalink
Merge pull request #473 from atsign-foundation/uuid-pers
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierChanth authored Dec 12, 2024
2 parents db240ad + 6feea2e commit 70d8b46
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 8 additions & 0 deletions packages/atchops/include/atchops/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ extern "C" {
#endif

#include <atchops/platform.h> // IWYU pragma: keep

// Only define this if it isn't defined
// Consumers of the SDK should be able to override it so their personalization
// isn't open source
// TODO: later provide more intentional ways of forcing consumers of the SDK
// to override this
#ifndef ATCHOPS_RNG_PERSONALIZATION
#define ATCHOPS_RNG_PERSONALIZATION "@atchops12345"
#endif

#ifdef __cplusplus
}
Expand Down
7 changes: 3 additions & 4 deletions packages/atchops/src/uuid.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "atchops/uuid.h"
#include "atchops/constants.h"
#include <atchops/platform.h>
#include <atlogger/atlogger.h>
#include <stddef.h>
Expand Down Expand Up @@ -105,16 +106,14 @@ static int uuid4_init(void) {
mbedtls_ctr_drbg_context ctr_drbg;
mbedtls_entropy_context entropy;

// TODO replace this string
const unsigned char pers[13] = {"Arduino_Seed"};

size_t off = sizeof(uint64_t) / sizeof(unsigned char);
size_t n = off * 2;
unsigned char pointer[n]; // create char pointer to long number
mbedtls_ctr_drbg_init(&ctr_drbg);
mbedtls_entropy_init(&entropy);

ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, pers, sizeof(pers));
ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, (unsigned char *)ATCHOPS_RNG_PERSONALIZATION,
sizeof(ATCHOPS_RNG_PERSONALIZATION));
if (ret != 0) {
mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy);
Expand Down

0 comments on commit 70d8b46

Please sign in to comment.