You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.1 KiB
C
63 lines
1.1 KiB
C
![]()
6 years ago
|
/*
|
||
|
* Copyright (C) 2017 Freie Universität Berlin
|
||
|
*
|
||
|
* This file is subject to the terms and conditions of the GNU Lesser
|
||
|
* General Public License v2.1. See the file LICENSE in the top level
|
||
|
* directory for more details.
|
||
|
*/
|
||
|
|
||
|
/**
|
||
![]()
6 years ago
|
* @ingroup sys_luid
|
||
![]()
6 years ago
|
* @{
|
||
|
*
|
||
|
* @file
|
||
![]()
6 years ago
|
* @brief LUID module implementation
|
||
![]()
6 years ago
|
*
|
||
|
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
||
|
*
|
||
|
* @}
|
||
|
*/
|
||
|
|
||
|
#include <stdint.h>
|
||
|
#include <string.h>
|
||
|
|
||
|
#include "assert.h"
|
||
|
#include "periph/cpuid.h"
|
||
|
|
||
![]()
6 years ago
|
#include "luid.h"
|
||
![]()
6 years ago
|
|
||
|
static uint8_t lastused = 1;
|
||
|
|
||
![]()
6 years ago
|
void luid_get(void *buf, size_t len)
|
||
![]()
6 years ago
|
{
|
||
![]()
6 years ago
|
luid_base(buf, len);
|
||
![]()
6 years ago
|
|
||
|
((uint8_t *)buf)[0] ^= lastused++;
|
||
|
}
|
||
|
|
||
![]()
6 years ago
|
void luid_custom(void *buf, size_t len, int gen)
|
||
![]()
6 years ago
|
{
|
||
![]()
6 years ago
|
luid_base(buf, len);
|
||
![]()
6 years ago
|
|
||
![]()
6 years ago
|
for (size_t i = 0; i < sizeof(gen); i++) {
|
||
![]()
6 years ago
|
((uint8_t *)buf)[i % len] ^= ((gen >> (i * 8)) & 0xff);
|
||
|
}
|
||
|
}
|
||
|
|
||
![]()
6 years ago
|
void luid_base(void *buf, size_t len)
|
||
![]()
6 years ago
|
{
|
||
|
assert(buf && (len > 0));
|
||
|
|
||
![]()
6 years ago
|
memset(buf, LUID_BACKUP_SEED, len);
|
||
![]()
6 years ago
|
|
||
|
#if CPUID_LEN
|
||
|
uint8_t *out = (uint8_t *)buf;
|
||
|
uint8_t cid[CPUID_LEN];
|
||
|
|
||
|
cpuid_get(cid);
|
||
|
for (size_t i = 0; i < CPUID_LEN; i++) {
|
||
|
out[i % len] ^= cid[i];
|
||
|
}
|
||
|
#endif
|
||
|
}
|