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

Side by Side Diff: tpm/tpm_crypto.c

Issue 660204: Upgrade to tpm-emulator version 0.7. (Closed)
Patch Set: Created 10 years, 9 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
« no previous file with comments | « tpm/tpm_credentials.c ('k') | tpm/tpm_daa.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Software-Based Trusted Platform Module (TPM) Emulator for Linux 1 /* Software-based Trusted Platform Module (TPM) Emulator
2 * Copyright (C) 2004 Mario Strasser <mast@gmx.net>, 2 * Copyright (C) 2004-2010 Mario Strasser <mast@gmx.net>
3 * Swiss Federal Institute of Technology (ETH) Zurich
4 * 3 *
5 * This module is free software; you can redistribute it and/or modify 4 * This module is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published 5 * it under the terms of the GNU General Public License as published
7 * by the Free Software Foundation; either version 2 of the License, 6 * by the Free Software Foundation; either version 2 of the License,
8 * or (at your option) any later version. 7 * or (at your option) any later version.
9 * 8 *
10 * This module is distributed in the hope that it will be useful, 9 * This module is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 12 * GNU General Public License for more details.
14 * 13 *
15 * $Id$ 14 * $Id: tpm_crypto.c 368 2010-02-15 09:26:37Z mast $
16 */ 15 */
17 16
18 #include "tpm_emulator.h" 17 #include "tpm_emulator.h"
19 #include "tpm_commands.h" 18 #include "tpm_commands.h"
20 #include "tpm_data.h" 19 #include "tpm_data.h"
21 #include "tpm_handles.h" 20 #include "tpm_handles.h"
22 #include "crypto/sha1.h" 21 #include "crypto/sha1.h"
23 #include "crypto/hmac.h" 22 #include "crypto/hmac.h"
24 #include "crypto/rc4.h" 23 #include "crypto/rc4.h"
25 #include "tpm_marshalling.h" 24 #include "tpm_marshalling.h"
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 if (res != TPM_SUCCESS) return res; 193 if (res != TPM_SUCCESS) return res;
195 } 194 }
196 if (key->keyUsage != TPM_KEY_SIGNING && key->keyUsage != TPM_KEY_LEGACY) 195 if (key->keyUsage != TPM_KEY_SIGNING && key->keyUsage != TPM_KEY_LEGACY)
197 return TPM_INVALID_KEYUSAGE; 196 return TPM_INVALID_KEYUSAGE;
198 /* sign data */ 197 /* sign data */
199 return tpm_sign(key, auth1, FALSE, areaToSign, areaToSignSize, sig, sigSize); 198 return tpm_sign(key, auth1, FALSE, areaToSign, areaToSignSize, sig, sigSize);
200 } 199 }
201 200
202 void tpm_get_random_bytes(void *buf, size_t nbytes) 201 void tpm_get_random_bytes(void *buf, size_t nbytes)
203 { 202 {
204 #ifdef TPM_USE_INTERNAL_PRNG 203 if (tpmConf & TPM_CONF_USE_INTERNAL_PRNG) {
205 tpm_rc4_ctx_t ctx; 204 tpm_rc4_ctx_t ctx;
206 tpm_rc4_init(&ctx, tpmData.permanent.data.rngState, 205 tpm_rc4_init(&ctx, tpmData.permanent.data.rngState,
207 sizeof(tpmData.permanent.data.rngState)); 206 sizeof(tpmData.permanent.data.rngState));
208 tpm_rc4_crypt(&ctx, buf, buf, nbytes); 207 tpm_rc4_crypt(&ctx, buf, buf, nbytes);
209 tpm_rc4_crypt(&ctx, tpmData.permanent.data.rngState, 208 tpm_rc4_crypt(&ctx, tpmData.permanent.data.rngState,
210 tpmData.permanent.data.rngState, sizeof(tpmData.permanent.data.rngState)); 209 tpmData.permanent.data.rngState, sizeof(tpmData.permanent.data.rngState));
211 #else 210 } else {
212 tpm_get_extern_random_bytes(buf, nbytes); 211 tpm_get_extern_random_bytes(buf, nbytes);
213 #endif 212 }
214 } 213 }
215 214
216 TPM_RESULT TPM_GetRandom(UINT32 bytesRequested, UINT32 *randomBytesSize, 215 TPM_RESULT TPM_GetRandom(UINT32 bytesRequested, UINT32 *randomBytesSize,
217 BYTE **randomBytes) 216 BYTE **randomBytes)
218 { 217 {
219 info("TPM_GetRandom()"); 218 info("TPM_GetRandom()");
220 *randomBytesSize = (bytesRequested < 2048) ? bytesRequested : 2048; 219 *randomBytesSize = (bytesRequested < 2048) ? bytesRequested : 2048;
221 *randomBytes = tpm_malloc(*randomBytesSize); 220 *randomBytes = tpm_malloc(*randomBytesSize);
222 if (*randomBytes == NULL) return TPM_SIZE; 221 if (*randomBytes == NULL) return TPM_SIZE;
223 tpm_get_random_bytes(*randomBytes, *randomBytesSize); 222 tpm_get_random_bytes(*randomBytes, *randomBytesSize);
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 tpm_sha1_final(&sha1_ctx, buf); 477 tpm_sha1_final(&sha1_ctx, buf);
479 res = tpm_sign(cert, auth1, FALSE, buf, SHA1_DIGEST_LENGTH, outData, outDataSi ze); 478 res = tpm_sign(cert, auth1, FALSE, buf, SHA1_DIGEST_LENGTH, outData, outDataSi ze);
480 tpm_free(buf); 479 tpm_free(buf);
481 if (res != TPM_SUCCESS) { 480 if (res != TPM_SUCCESS) {
482 free_TPM_KEY_PARMS(certifyInfo->algorithmParms); 481 free_TPM_KEY_PARMS(certifyInfo->algorithmParms);
483 return res; 482 return res;
484 } 483 }
485 return TPM_SUCCESS; 484 return TPM_SUCCESS;
486 } 485 }
487 486
OLDNEW
« no previous file with comments | « tpm/tpm_credentials.c ('k') | tpm/tpm_daa.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698