OLD | NEW |
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, | 3 * 2005-2008 Heiko Stamer <stamer@gaos.org> |
4 * 2005, 2006 Heiko Stamer <stamer@gaos.org> | |
5 * | 4 * |
6 * This module is free software; you can redistribute it and/or modify | 5 * This module is free software; you can redistribute it and/or modify |
7 * it under the terms of the GNU General Public License as published | 6 * it under the terms of the GNU General Public License as published |
8 * by the Free Software Foundation; either version 2 of the License, | 7 * by the Free Software Foundation; either version 2 of the License, |
9 * or (at your option) any later version. | 8 * or (at your option) any later version. |
10 * | 9 * |
11 * This module is distributed in the hope that it will be useful, | 10 * This module is distributed in the hope that it will be useful, |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 * GNU General Public License for more details. | 13 * GNU General Public License for more details. |
15 * | 14 * |
16 * $Id$ | 15 * $Id: tpm_marshalling.c 372 2010-02-15 12:52:00Z mast $ |
17 */ | 16 */ |
18 | 17 |
19 #include "tpm_marshalling.h" | 18 #include "tpm_marshalling.h" |
20 #include "tpm_handles.h" | 19 #include "tpm_handles.h" |
21 #include "crypto/rsa.h" | 20 #include "crypto/rsa.h" |
22 | 21 |
23 int tpm_marshal_UINT32_ARRAY(BYTE **ptr, UINT32 *length, | 22 int tpm_marshal_UINT32_ARRAY(BYTE **ptr, UINT32 *length, |
24 UINT32 *v, UINT32 n) | 23 UINT32 *v, UINT32 n) |
25 { | 24 { |
26 UINT32 i; | 25 UINT32 i; |
(...skipping 1658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1685 for (i = 0; i < TPM_MAX_KEYS; i++) { | 1684 for (i = 0; i < TPM_MAX_KEYS; i++) { |
1686 if (tpm_unmarshal_TPM_KEY_DATA(ptr, length, &v->keys[i])) return -1; | 1685 if (tpm_unmarshal_TPM_KEY_DATA(ptr, length, &v->keys[i])) return -1; |
1687 } | 1686 } |
1688 if (tpm_unmarshal_UINT32_ARRAY(ptr, length, v->tis_timeouts, TPM_NUM_TIS_TIMEO
UTS) | 1687 if (tpm_unmarshal_UINT32_ARRAY(ptr, length, v->tis_timeouts, TPM_NUM_TIS_TIMEO
UTS) |
1689 || tpm_unmarshal_UINT32_ARRAY(ptr, length, v->cmd_durations, TPM_NUM_CMD_D
URATIONS)) return -1; | 1688 || tpm_unmarshal_UINT32_ARRAY(ptr, length, v->cmd_durations, TPM_NUM_CMD_D
URATIONS)) return -1; |
1690 return 0; | 1689 return 0; |
1691 } | 1690 } |
1692 | 1691 |
1693 int tpm_marshal_TPM_STCLEAR_DATA(BYTE **ptr, UINT32 *length, TPM_STCLEAR_DATA *v
) | 1692 int tpm_marshal_TPM_STCLEAR_DATA(BYTE **ptr, UINT32 *length, TPM_STCLEAR_DATA *v
) |
1694 { | 1693 { |
1695 UINT32 i; | |
1696 if (tpm_marshal_TPM_STRUCTURE_TAG(ptr, length, v->tag) | 1694 if (tpm_marshal_TPM_STRUCTURE_TAG(ptr, length, v->tag) |
1697 || tpm_marshal_TPM_NONCE(ptr, length, &v->contextNonceKey) | 1695 || tpm_marshal_TPM_NONCE(ptr, length, &v->contextNonceKey) |
1698 || tpm_marshal_TPM_COUNT_ID(ptr, length, v->countID) | 1696 || tpm_marshal_TPM_COUNT_ID(ptr, length, v->countID) |
1699 || tpm_marshal_UINT32(ptr, length, v->ownerReference) | 1697 || tpm_marshal_UINT32(ptr, length, v->ownerReference) |
1700 || tpm_marshal_BOOL(ptr, length, v->disableResetLock) | 1698 || tpm_marshal_BOOL(ptr, length, v->disableResetLock) |
1701 || tpm_marshal_UINT32(ptr, length, v->deferredPhysicalPresence)) return -1
; | 1699 || tpm_marshal_UINT32(ptr, length, v->deferredPhysicalPresence)) return -1
; |
1702 return 0; | 1700 return 0; |
1703 } | 1701 } |
1704 | 1702 |
1705 int tpm_unmarshal_TPM_STCLEAR_DATA(BYTE **ptr, UINT32 *length, TPM_STCLEAR_DATA
*v) | 1703 int tpm_unmarshal_TPM_STCLEAR_DATA(BYTE **ptr, UINT32 *length, TPM_STCLEAR_DATA
*v) |
1706 { | 1704 { |
1707 UINT32 i; | |
1708 if (tpm_unmarshal_TPM_STRUCTURE_TAG(ptr, length, &v->tag) | 1705 if (tpm_unmarshal_TPM_STRUCTURE_TAG(ptr, length, &v->tag) |
1709 || tpm_unmarshal_TPM_NONCE(ptr, length, &v->contextNonceKey) | 1706 || tpm_unmarshal_TPM_NONCE(ptr, length, &v->contextNonceKey) |
1710 || tpm_unmarshal_TPM_COUNT_ID(ptr, length, &v->countID) | 1707 || tpm_unmarshal_TPM_COUNT_ID(ptr, length, &v->countID) |
1711 || tpm_unmarshal_UINT32(ptr, length, &v->ownerReference) | 1708 || tpm_unmarshal_UINT32(ptr, length, &v->ownerReference) |
1712 || tpm_unmarshal_BOOL(ptr, length, &v->disableResetLock) | 1709 || tpm_unmarshal_BOOL(ptr, length, &v->disableResetLock) |
1713 || tpm_unmarshal_UINT32(ptr, length, &v->deferredPhysicalPresence)) return
-1; | 1710 || tpm_unmarshal_UINT32(ptr, length, &v->deferredPhysicalPresence)) return
-1; |
1714 return 0; | 1711 return 0; |
1715 } | 1712 } |
1716 | 1713 |
1717 int tpm_marshal_TPM_SESSION_DATA(BYTE **ptr, UINT32 *length, TPM_SESSION_DATA *v
) | 1714 int tpm_marshal_TPM_SESSION_DATA(BYTE **ptr, UINT32 *length, TPM_SESSION_DATA *v
) |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1781 if (tpm_unmarshal_TPM_SESSION_DATA(ptr, length, &v->sessions[i])) return -1; | 1778 if (tpm_unmarshal_TPM_SESSION_DATA(ptr, length, &v->sessions[i])) return -1; |
1782 } | 1779 } |
1783 for (i = 0; i < TPM_MAX_SESSIONS_DAA; i++) { | 1780 for (i = 0; i < TPM_MAX_SESSIONS_DAA; i++) { |
1784 if (tpm_unmarshal_TPM_DAA_SESSION_DATA(ptr, length, &v->sessionsDAA[i])) ret
urn -1; | 1781 if (tpm_unmarshal_TPM_DAA_SESSION_DATA(ptr, length, &v->sessionsDAA[i])) ret
urn -1; |
1785 } | 1782 } |
1786 if (tpm_unmarshal_DAAHANDLE(ptr, length, &v->currentDAA) | 1783 if (tpm_unmarshal_DAAHANDLE(ptr, length, &v->currentDAA) |
1787 || tpm_unmarshal_TPM_TRANSHANDLE(ptr, length, &v->transExclusive)) return
-1; | 1784 || tpm_unmarshal_TPM_TRANSHANDLE(ptr, length, &v->transExclusive)) return
-1; |
1788 return 0; | 1785 return 0; |
1789 } | 1786 } |
1790 | 1787 |
| 1788 int tpm_marshal_TPM_DATA(BYTE **ptr, UINT32 *length, TPM_DATA *v) |
| 1789 { |
| 1790 if (tpm_marshal_TPM_PERMANENT_FLAGS(ptr, length, &v->permanent.flags) |
| 1791 || tpm_marshal_BOOL(ptr, length, v->permanent.flags.selfTestSucceeded) |
| 1792 || tpm_marshal_BOOL(ptr, length, v->permanent.flags.owned) |
| 1793 || tpm_marshal_TPM_PERMANENT_DATA(ptr, length, &v->permanent.data) |
| 1794 || tpm_marshal_TPM_STCLEAR_FLAGS(ptr, length, &v->stclear.flags) |
| 1795 || tpm_marshal_TPM_STCLEAR_DATA(ptr, length, &v->stclear.data) |
| 1796 || tpm_marshal_TPM_STANY_DATA(ptr, length, &v->stany.data)) return -1; |
| 1797 return 0; |
| 1798 } |
| 1799 |
| 1800 int tpm_unmarshal_TPM_DATA(BYTE **ptr, UINT32 *length, TPM_DATA *v) |
| 1801 { |
| 1802 if (tpm_unmarshal_TPM_PERMANENT_FLAGS(ptr, length, &v->permanent.flags) |
| 1803 || tpm_unmarshal_BOOL(ptr, length, &v->permanent.flags.selfTestSucceeded) |
| 1804 || tpm_unmarshal_BOOL(ptr, length, &v->permanent.flags.owned) |
| 1805 || tpm_unmarshal_TPM_PERMANENT_DATA(ptr, length, &v->permanent.data) |
| 1806 || tpm_unmarshal_TPM_STCLEAR_FLAGS(ptr, length, &v->stclear.flags) |
| 1807 || tpm_unmarshal_TPM_STCLEAR_DATA(ptr, length, &v->stclear.data) |
| 1808 || tpm_unmarshal_TPM_STANY_DATA(ptr, length, &v->stany.data)) return -1; |
| 1809 return 0; |
| 1810 } |
| 1811 |
1791 int tpm_marshal_TPM_RESPONSE(BYTE **ptr, UINT32 *length, TPM_RESPONSE *v) | 1812 int tpm_marshal_TPM_RESPONSE(BYTE **ptr, UINT32 *length, TPM_RESPONSE *v) |
1792 { | 1813 { |
1793 if (tpm_marshal_TPM_TAG(ptr, length, v->tag) | 1814 if (tpm_marshal_TPM_TAG(ptr, length, v->tag) |
1794 || tpm_marshal_UINT32(ptr, length, v->size) | 1815 || tpm_marshal_UINT32(ptr, length, v->size) |
1795 || tpm_marshal_TPM_RESULT(ptr, length, v->result) | 1816 || tpm_marshal_TPM_RESULT(ptr, length, v->result) |
1796 || tpm_marshal_BLOB(ptr, length, v->param, v->paramSize)) return -1; | 1817 || tpm_marshal_BLOB(ptr, length, v->param, v->paramSize)) return -1; |
1797 if (v->tag == TPM_TAG_RSP_AUTH2_COMMAND) { | 1818 if (v->tag == TPM_TAG_RSP_AUTH2_COMMAND) { |
1798 if (tpm_marshal_TPM_AUTH(ptr, length, v->auth1) | 1819 if (tpm_marshal_TPM_AUTH(ptr, length, v->auth1) |
1799 || tpm_marshal_TPM_AUTH(ptr, length, v->auth2)) return -1; | 1820 || tpm_marshal_TPM_AUTH(ptr, length, v->auth2)) return -1; |
1800 } else if (v->tag == TPM_TAG_RSP_AUTH1_COMMAND) { | 1821 } else if (v->tag == TPM_TAG_RSP_AUTH1_COMMAND) { |
(...skipping 23 matching lines...) Expand all Loading... |
1824 if (tpm_unmarshal_BLOB(ptr, length, &v->param, v->paramSize) | 1845 if (tpm_unmarshal_BLOB(ptr, length, &v->param, v->paramSize) |
1825 || tpm_unmarshal_TPM_AUTH(ptr, length, &v->auth1)) return -1; | 1846 || tpm_unmarshal_TPM_AUTH(ptr, length, &v->auth1)) return -1; |
1826 v->auth1.ordinal = v->ordinal; | 1847 v->auth1.ordinal = v->ordinal; |
1827 v->auth2.authHandle = TPM_INVALID_HANDLE; | 1848 v->auth2.authHandle = TPM_INVALID_HANDLE; |
1828 } else { | 1849 } else { |
1829 v->auth1.authHandle = TPM_INVALID_HANDLE; | 1850 v->auth1.authHandle = TPM_INVALID_HANDLE; |
1830 v->auth2.authHandle = TPM_INVALID_HANDLE; | 1851 v->auth2.authHandle = TPM_INVALID_HANDLE; |
1831 } | 1852 } |
1832 return 0; | 1853 return 0; |
1833 } | 1854 } |
OLD | NEW |