~ubuntu-branches/ubuntu/hardy/trousers/hardy-proposed

« back to all changes in this revision

Viewing changes to src/tspi/rpc/tcstp/rpc_random.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2008-01-23 22:03:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080123220300-fhtqja3c0oq0gp6z
Tags: 0.3.1-4
* Added patch from Aaron M. Ucko <ucko@debian.org> to allow trousers to
  build successfully on amd64, and presumably also other 64-bit
  architectures (Closes: #457400).
* Including udev rule for /dev/tpm from William Lima
  <wlima.amadeus@gmail.com> as suggested by David Smith <dds@google.com>
  (Closes: #459682).
* Added lintian overrides.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*
 
3
 * Licensed Materials - Property of IBM
 
4
 *
 
5
 * trousers - An open source TCG Software Stack
 
6
 *
 
7
 * (C) Copyright International Business Machines Corp. 2004-2006
 
8
 *
 
9
 */
 
10
 
 
11
#include <stdlib.h>
 
12
#include <stdio.h>
 
13
#include <string.h>
 
14
#include <assert.h>
 
15
 
 
16
#include "trousers/tss.h"
 
17
#include "trousers/trousers.h"
 
18
#include "trousers_types.h"
 
19
#include "spi_utils.h"
 
20
#include "capabilities.h"
 
21
#include "tsplog.h"
 
22
#include "hosttable.h"
 
23
#include "tcsd_wrap.h"
 
24
#include "obj.h"
 
25
#include "rpc_tcstp_tsp.h"
 
26
 
 
27
 
 
28
TSS_RESULT
 
29
RPC_GetRandom_TP(struct host_table_entry *hte,
 
30
                  UINT32 bytesRequested,        /* in */
 
31
                  BYTE ** randomBytes)  /* out */
 
32
{
 
33
        TSS_RESULT result;
 
34
 
 
35
        initData(&hte->comm, 2);
 
36
        hte->comm.hdr.u.ordinal = TCSD_ORD_GETRANDOM;
 
37
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
38
 
 
39
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
40
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
41
        if (setData(TCSD_PACKET_TYPE_UINT32, 1, &bytesRequested, 0, &hte->comm))
 
42
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
43
 
 
44
        result = sendTCSDPacket(hte);
 
45
 
 
46
        if (result == TSS_SUCCESS)
 
47
                result = hte->comm.hdr.u.result;
 
48
 
 
49
        if (result == TSS_SUCCESS) {
 
50
                if (getData(TCSD_PACKET_TYPE_UINT32, 0, &bytesRequested, 0, &hte->comm)) {
 
51
                        result = TSPERR(TSS_E_INTERNAL_ERROR);
 
52
                        goto done;
 
53
                }
 
54
                *randomBytes = (BYTE *) malloc(bytesRequested);
 
55
                if (*randomBytes == NULL) {
 
56
                        LogError("malloc of %u bytes failed.", bytesRequested);
 
57
                        result = TSPERR(TSS_E_OUTOFMEMORY);
 
58
                        goto done;
 
59
                }
 
60
                if (getData(TCSD_PACKET_TYPE_PBYTE, 1, *randomBytes, bytesRequested, &hte->comm)) {
 
61
                        free(*randomBytes);
 
62
                        result = TSPERR(TSS_E_INTERNAL_ERROR);
 
63
                }
 
64
        }
 
65
 
 
66
done:
 
67
        return result;
 
68
}
 
69
 
 
70
TSS_RESULT
 
71
RPC_StirRandom_TP(struct host_table_entry *hte,
 
72
                   UINT32 inDataSize,   /* in */
 
73
                   BYTE * inData)       /* in */
 
74
{
 
75
        TSS_RESULT result;
 
76
 
 
77
        initData(&hte->comm, 3);
 
78
        hte->comm.hdr.u.ordinal = TCSD_ORD_STIRRANDOM;
 
79
        LogDebugFn("TCS Context: 0x%x", hte->tcsContext);
 
80
 
 
81
        if (setData(TCSD_PACKET_TYPE_UINT32, 0, &hte->tcsContext, 0, &hte->comm))
 
82
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
83
        if (setData(TCSD_PACKET_TYPE_UINT32, 1, &inDataSize, 0, &hte->comm))
 
84
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
85
        if (setData(TCSD_PACKET_TYPE_PBYTE, 2, inData, inDataSize, &hte->comm))
 
86
                return TSPERR(TSS_E_INTERNAL_ERROR);
 
87
 
 
88
        result = sendTCSDPacket(hte);
 
89
 
 
90
        if (result == TSS_SUCCESS)
 
91
                result = hte->comm.hdr.u.result;
 
92
 
 
93
        return result;
 
94
}