BeRTOS
entropy.h
Go to the documentation of this file.
00001 
00038 #ifndef SEC_ENTROPY_H
00039 #define SEC_ENTROPY_H
00040 
00041 #include <cfg/compiler.h>
00042 #include <cfg/debug.h>
00043 
00050 #define CONFIG_ENTROPY_NUM_SOURCES   8
00051 
00052 typedef struct EntropyPool
00053 {
00054     void (*add_entropy)(struct EntropyPool *ctx, int source_idx,
00055                         const uint8_t *data, size_t len,
00056                         int entropy);
00057     bool (*seeding_ready)(struct EntropyPool *ctx);
00058     void (*make_seed)(struct EntropyPool *ctx, uint8_t *out, size_t len);
00059 
00060 } EntropyPool;
00061 
00062 
00069 INLINE void entropy_add(EntropyPool *e, int source_idx,
00070                  const uint8_t *data, size_t len,
00071                  int entropy)
00072 {
00073     ASSERT(e->add_entropy);
00074     e->add_entropy(e, source_idx, data, len, entropy);
00075 }
00076 
00080 INLINE bool entropy_seeding_ready(EntropyPool *ctx)
00081 {
00082     ASSERT(ctx->seeding_ready);
00083     return ctx->seeding_ready(ctx);
00084 }
00085 
00092 INLINE void entropy_make_seed(EntropyPool *ctx, uint8_t *out, size_t len)
00093 {
00094     ASSERT(ctx->make_seed);
00095     ctx->make_seed(ctx, out, len);
00096 }
00097 
00098 #endif /* SEC_ENTROPY_H */