> diff --git a/c/src/lib/libbsp/shared/getentropy-cpucounter-based.c > b/c/src/lib/libbsp/shared/getentropy-cpucounter-based.c > new file mode 100644 > index 0000000000..137fdfbb6c > --- /dev/null > +++ b/c/src/lib/libbsp/shared/getentropy-cpucounter-based.c > @@ -0,0 +1,46 @@ > +/* > + * Copyright (c) 2017 embedded brains GmbH. All rights reserved. > + * > + * embedded brains GmbH > + * Dornierstr. 4 > + * 82178 Puchheim > + * Germany > + * <rt...@embedded-brains.de> > + * > + * The license and distribution terms for this file may be > + * found in the file LICENSE in this distribution or at > + * http://www.rtems.org/license/LICENSE. > + */ > + > +#include <unistd.h> > +#include <string.h> > +#include <rtems/sysinit.h> > +#include <rtems/counter.h> > + > +int getentropy(void *ptr, size_t n) > +{ > + uint8_t *dest = ptr; > + > + while (n > 0) { > + rtems_counter_ticks ticks; > + > + ticks = rtems_counter_read(); > + > + if (n >= sizeof(ticks)) { > + memcpy(dest, &ticks, sizeof(ticks)); > + n -= sizeof(ticks); > + dest += sizeof(ticks); > + } else { > + /* > + * Fill the remaining bytes with only the least > + * significant byte of the time. That is the byte with > + * the most changes. > + */ > + *dest = ticks & 0xFF; > + --n; > + ++dest; > + } > + } > + > + return 0; > +}
I don't believe this is a good source of entropy--the passage of time is not random. Should this be documented as such? _______________________________________________ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel