Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1334)

Side by Side Diff: src/tcs/tcsi_random.c

Issue 3581012: Upgrade from trousers 0.3.3 to 0.3.6 and from testsuite 0.2 to 0.3. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/trousers.git
Patch Set: git cl push Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/tcs/tcsi_own.c ('k') | src/tcsd/Makefile.am » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Licensed Materials - Property of IBM 3 * Licensed Materials - Property of IBM
4 * 4 *
5 * trousers - An open source TCG Software Stack 5 * trousers - An open source TCG Software Stack
6 * 6 *
7 * (C) Copyright International Business Machines Corp. 2004 7 * (C) Copyright International Business Machines Corp. 2004
8 * 8 *
9 */ 9 */
10 10
(...skipping 22 matching lines...) Expand all
33 * According to the TPM compliance work posted here: http://www.prosec.rub.de/tp mcompliance.html, 33 * According to the TPM compliance work posted here: http://www.prosec.rub.de/tp mcompliance.html,
34 * some TPMs return as little as 132 bytes per query, which would require about 30 loops to get 4K. 34 * some TPMs return as little as 132 bytes per query, which would require about 30 loops to get 4K.
35 * We'll be extremely conservative here and loop 50 times, since it won't affect performance on 35 * We'll be extremely conservative here and loop 50 times, since it won't affect performance on
36 * TPMs that return more bytes. 36 * TPMs that return more bytes.
37 */ 37 */
38 TSS_RESULT 38 TSS_RESULT
39 TCSP_GetRandom_Internal(TCS_CONTEXT_HANDLE hContext, /* in */ 39 TCSP_GetRandom_Internal(TCS_CONTEXT_HANDLE hContext, /* in */
40 UINT32 * bytesRequested, /* in, out */ 40 UINT32 * bytesRequested, /* in, out */
41 BYTE ** randomBytes) /* out */ 41 BYTE ** randomBytes) /* out */
42 { 42 {
43 » UINT64 offset = 0; 43 » UINT64 offset;
44 TSS_RESULT result; 44 TSS_RESULT result;
45 UINT32 paramSize, totalReturned = 0, bytesReturned, retries = 50; 45 UINT32 paramSize, totalReturned = 0, bytesReturned, retries = 50;
46 » BYTE txBlob[TSS_TPM_TXBLOB_SIZE], *rnd_tmp = NULL; 46 » BYTE txBlob[TSS_TPM_TXBLOB_SIZE], *rnd_tmp = NULL, *rnd_tmp2 = NULL;
47 47
48 LogDebugFn("%u bytes", *bytesRequested); 48 LogDebugFn("%u bytes", *bytesRequested);
49 49
50 if ((result = ctx_verify_context(hContext))) 50 if ((result = ctx_verify_context(hContext)))
51 return result; 51 return result;
52 52
53 do { 53 do {
54 offset = 0;
54 if ((result = tpm_rqu_build(TPM_ORD_GetRandom, &offset, txBlob, 55 if ((result = tpm_rqu_build(TPM_ORD_GetRandom, &offset, txBlob,
55 *bytesRequested - totalReturned, NUL L))) 56 *bytesRequested - totalReturned, NUL L)))
56 break; 57 break;
57 58
58 if ((result = req_mgr_submit_req(txBlob))) 59 if ((result = req_mgr_submit_req(txBlob)))
59 break;; 60 break;;
60 61
61 result = UnloadBlob_Header(txBlob, &paramSize); 62 result = UnloadBlob_Header(txBlob, &paramSize);
62 if (!result) { 63 if (!result) {
63 #if 0 64 #if 0
64 offset = 10; 65 offset = 10;
65 UnloadBlob_UINT32(&offset, &bytesReturned, txBlob); 66 UnloadBlob_UINT32(&offset, &bytesReturned, txBlob);
66 67
67 LogDebugFn("received %u bytes from the TPM", bytesReturn ed); 68 LogDebugFn("received %u bytes from the TPM", bytesReturn ed);
68 69
69 rnd_tmp = realloc(rnd_tmp, totalReturned + bytesReturned ); 70 rnd_tmp = realloc(rnd_tmp, totalReturned + bytesReturned );
70 if (rnd_tmp == NULL) { 71 if (rnd_tmp == NULL) {
71 LogError("malloc of %u bytes failed.", bytesRetu rned); 72 LogError("malloc of %u bytes failed.", bytesRetu rned);
72 return TCSERR(TSS_E_OUTOFMEMORY); 73 return TCSERR(TSS_E_OUTOFMEMORY);
73 } 74 }
74 UnloadBlob(&offset, bytesReturned, txBlob, &rnd_tmp[tota lReturned]); 75 UnloadBlob(&offset, bytesReturned, txBlob, &rnd_tmp[tota lReturned]);
75 #else 76 #else
76 /* XXX */ 77 /* XXX */
77 if ((result = tpm_rsp_parse(TPM_ORD_GetRandom, txBlob, p aramSize, 78 if ((result = tpm_rsp_parse(TPM_ORD_GetRandom, txBlob, p aramSize,
78 &bytesReturned, &rnd_tmp, NU LL, NULL))) 79 &bytesReturned, &rnd_tmp, NU LL, NULL)))
79 break; 80 break;
80 81
81 » » » *randomBytes = realloc(*randomBytes, totalReturned + byt esReturned); 82 » » » rnd_tmp2 = realloc(*randomBytes, totalReturned + bytesRe turned);
82 » » » if (*randomBytes == NULL) { 83 » » » if (rnd_tmp2 == NULL) {
83 free(rnd_tmp); 84 free(rnd_tmp);
84 rnd_tmp = NULL; 85 rnd_tmp = NULL;
85 LogError("malloc of %u bytes failed.", bytesRetu rned); 86 LogError("malloc of %u bytes failed.", bytesRetu rned);
86 result = TCSERR(TSS_E_OUTOFMEMORY); 87 result = TCSERR(TSS_E_OUTOFMEMORY);
87 break; 88 break;
88 } 89 }
89 » » » memcpy(*randomBytes, rnd_tmp, bytesReturned); 90 » » » *randomBytes = rnd_tmp2;
91 » » » memcpy(*randomBytes + totalReturned, rnd_tmp, bytesRetur ned);
90 free(rnd_tmp); 92 free(rnd_tmp);
91 rnd_tmp = NULL; 93 rnd_tmp = NULL;
92 #endif 94 #endif
93 totalReturned += bytesReturned; 95 totalReturned += bytesReturned;
94 } else { 96 } else {
95 free(rnd_tmp); 97 free(rnd_tmp);
96 return result; 98 return result;
97 } 99 }
98 } while (totalReturned < *bytesRequested && retries--); 100 } while (totalReturned < *bytesRequested && retries--);
99 101
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 return result; 138 return result;
137 139
138 if ((result = req_mgr_submit_req(txBlob))) 140 if ((result = req_mgr_submit_req(txBlob)))
139 return result; 141 return result;
140 142
141 result = UnloadBlob_Header(txBlob, &paramSize); 143 result = UnloadBlob_Header(txBlob, &paramSize);
142 LogResult("Stir random", result); 144 LogResult("Stir random", result);
143 return result; 145 return result;
144 } 146 }
145 147
OLDNEW
« no previous file with comments | « src/tcs/tcsi_own.c ('k') | src/tcsd/Makefile.am » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698