[Prev][Next][Index][Thread]

Re: random sources interface




O.k., putting aside all pretense of actually knowing what I'm doing,
here's a naive shot in the dark:


/*
 * Definition of a general interface for reading randomness
 * from entropy sources.
 */

#ifndef _OSKIT_ENTSRC_H_
#define _OSKIT_ENTSRC_H_

#include <oskit/com.h>

/*
 * Entropy source interface (based on NetBSD <sys/rnd.h>)
 * IID <iid>
 *
 * <description>
 */
struct oskit_entsrc {
	struct oskit_entsrc_ops *ops;
};
typedef struct oskit_entsrc oskit_entsrc_t;

struct oskit_entsrc_ops {
	/* COM-specified IUnknown interface operations */
	OSKIT_COMDECL	(*query)(oskit_entsrc_t *src, const struct oskit_guid *iid,
				 void **out_ihandle);
	OSKIT_COMDECL_U	(*addref)(oskit_entsrc_t *src);
	OSKIT_COMDECL_U	(*release)(oskit_entsrc_t *src);

	/*
	 * Return the current entropy count in bits.
	 */
	OSKIT_COMDECL (*get_count)(oskit_entsrc_t *src, oskit_u32_t *out_count);

	/*
	 * Return the last event timestamp recorded.
	 */
	OSKIT_COMDECL (*get_last_time)(oskit_entsrc_t *src, oskit_u32_t *out_last_time);

	/*
	 * Return the last delta value.
	 */
	OSKIT_COMDECL (*get_delta)(oskit_entsrc_t *src, oskit_u32_t *out_delta);

	/*
	 * Return the last delta2 value.
	 */
	OSKIT_COMDECL (*get_delta2)(oskit_entsrc_t *src, oskit_u32_t *out_delta2);

	/*
	 * Return the total amount on entropy this source has
	 * generated -- this is not necessarily the same as the
	 * total entropy actually used.
	 */
	OSKIT_COMDECL (*get_total)(oskit_entsrc_t *src, oskit_u32_t *out_total);

	/*
	 * Get the entropy source type.
	 */
	OSKIT_COMDECL (*get_type)(oskit_entsrc_t *src, oskit_u32_t *out_type);
	
	/*
	 * Return the flags bits.
	 */
	OSKIT_COMDECL (*get_flags)(oskit_entsrc_t *src, oskit_u32_t *out_flags);

	/*
	 * Set the flags bits.
	 */
	OSKIT_COMDECL (*set_flags)(oskit_entsrc_t *src, oskit_u32_t flags, oskit_u32_t mask);

	/*
	 * FIXME:
	 * Do we want the "do stuff over multiple sources in one call" semantics
	 * of the IOCTLs like RNDGETSRCNUM, RNDGETSRCNAME, and RNDCTL or is that
	 * a different interface?
	 */
};

#define oskit_entsrc_query(s, iid, out_ihandle) \
	((s)->ops->query((oskit_entsrc_t *)(s), (iid), (out_ihandle)))
#define oskit_entsrc_addref(s) \
	((s)->ops->addref((oskit_entsrc_t *)(s)))
#define oskit_entsrc_release(s) \
	((s)->ops->release((oskit_entsrc_t *)(s)))
#define oskit_entsrc_get_count(s) \
	((s)->ops->get_count((oskit_entsrc_t *)(s), (out_count)))
#define oskit_entsrc_get_last_time(s) \
	((s)->ops->((oskit_entsrc_t *)(s), (out_last_time)))
#define oskit_entsrc_get_delta(s) \
	((s)->ops->((oskit_entsrc_t *)(s), (out_delta)))
#define oskit_entsrc_get_delta2(s) \
	((s)->ops->((oskit_entsrc_t *)(s), (out_delta2)))
#define oskit_entsrc_get_total(s) \
	((s)->ops->((oskit_entsrc_t *)(s), (out_total)))
#define oskit_entsrc_get_type(s) \
	((s)->ops->((oskit_entsrc_t *)(s), (out_type)))
#define oskit_entsrc_get_flags(s) \
	((s)->ops->((oskit_entsrc_t *)(s), (out_flags)))
#define oskit_entsrc_set_flags(s) \
	((s)->ops->((oskit_entsrc_t *)(s), (flags), (mask)))

/* GUID for oskit_entsrc interface */
extern const struct oskit_guid oskit_entsrc_iid;
#define OSKIT_ENTSRC_IID OSKIT_GUID(/* FIXME */)

#define	RND_FLAG_NO_ESTIMATE	0x00000100	/* don't estimate entropy */
#define	RND_FLAG_NO_COLLECT	0x00000200	/* don't collect entropy */

#define	RND_TYPE_UNKNOWN	0	/* unknown source */
#define	RND_TYPE_DISK		1	/* source is physical disk */
#define	RND_TYPE_NET		2	/* source is a network device */
#define	RND_TYPE_TAPE		3	/* source is a tape drive */
#define	RND_TYPE_TTY		4	/* source is a tty device */
#define	RND_TYPE_RNG		5	/* source is a random number generator */

#endif /* _OSKIT_ENTSRC_H_ */



Is this in the ballpark?

Thanks,
Derek

-- 

Follow-Ups: References: