From c1ff2263450145d9bb9cfbb87684f75a9981ec66 Mon Sep 17 00:00:00 2001 From: Mike Hibler Date: Thu, 29 Mar 2012 13:38:44 -0600 Subject: [PATCH] Fix nonce calculation. Well, isn't that special. We had the arguments to memcpy backward (probably dating from the time when we use bcopy instead). So instead of copying bytes of goodness into the zeroed nonce buffer, we were copying bytes out. Net result: a nonce of zeros. --- clientside/lib/tmcd/tpm.c | 8 ++++---- tmcd/tmcd.c | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/clientside/lib/tmcd/tpm.c b/clientside/lib/tmcd/tpm.c index 747f70c3c..93b399d51 100644 --- a/clientside/lib/tmcd/tpm.c +++ b/clientside/lib/tmcd/tpm.c @@ -146,7 +146,7 @@ tmcd_tpm_generate_nonce(unsigned char *nonce) pid_t pid; int byte_count = 0; - memset(nonce,0,TPM_NONCE_BYTES); + memset(nonce, 0, TPM_NONCE_BYTES); /* * Nonce must be 160 bits (20 bytes) long, and we must be quite sure that @@ -167,7 +167,7 @@ tmcd_tpm_generate_nonce(unsigned char *nonce) if (sizeof(time) + byte_count > TPM_NONCE_BYTES) { return -1; } - memcpy(&time, nonce, sizeof(time)); + memcpy(nonce, &time, sizeof(time)); byte_count += sizeof(time); // pid @@ -175,14 +175,14 @@ tmcd_tpm_generate_nonce(unsigned char *nonce) if (sizeof(pid) + byte_count > TPM_NONCE_BYTES) { return -1; } - memcpy(&pid, nonce + byte_count, sizeof(pid)); + memcpy(nonce + byte_count, &pid, sizeof(pid)); byte_count += sizeof(pid); // counter if (sizeof(nonce_counter) + byte_count > TPM_NONCE_BYTES) { return -1; } - memcpy(&nonce_counter, nonce + byte_count, sizeof(nonce_counter)); + memcpy(nonce + byte_count, &nonce_counter, sizeof(nonce_counter)); byte_count += sizeof(nonce_counter); nonce_counter++; diff --git a/tmcd/tmcd.c b/tmcd/tmcd.c index a91677fdc..8ae4e1325 100644 --- a/tmcd/tmcd.c +++ b/tmcd/tmcd.c @@ -5484,8 +5484,9 @@ COMMAND_PROTOTYPE(doquoteprep) sprintf(nonce_hex + (i*2),"%.02x",nonce[i]); } nonce_hex[TPM_NONCE_BYTES*2] = '\0'; - // XXX - info("NONCE: %s\n", nonce_hex); + + if (debug) + info("%s: NONCE %s\n", reqp->nodeid, nonce_hex); // Store the nonce in the database. It expires in one minute, and we // overwrite any existing nonces for this node/state combo -- GitLab