+ return -1;
+ }
+ return 0;
+}
+
+/* tpm rng read call to kernel has 13 bytes of overhead
+ * the logic to process this involves reading to a temporary_buf
+ * and copying the no generated to buf */
+int xread_tpm(void *buf, size_t size, struct rng *ent_src)
+{
+ size_t bytes_read = 0;
+ ssize_t r;
+ int retval;
+ unsigned char *temp_buf = NULL;
+ unsigned char rng_cmd[] = {
+ 0, 193, /* TPM_TAG_RQU_COMMAND */
+ 0, 0, 0, 14, /* length */
+ 0, 0, 0, 70, /* TPM_ORD_GetRandom */
+ 0, 0, 0, 0, /* number of bytes to return */
+ };
+ char *offset;
+
+ ent_src->rng_fd = open(ent_src->rng_name, O_RDWR);
+ if (ent_src->rng_fd == -1) {
+ return -1;
+ }
+
+ temp_buf = (unsigned char *) malloc(size + TPM_GET_RNG_OVERHEAD);
+ memset(temp_buf, 0, (size+TPM_GET_RNG_OVERHEAD));
+ if (temp_buf == NULL) {
+ message(LOG_ERR|LOG_INFO,"No memory");
+ return -1;