-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathhmac_session_impl.cc
59 lines (47 loc) · 1.89 KB
/
hmac_session_impl.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2015 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "trunks/hmac_session_impl.h"
#include <string>
#include <base/logging.h>
#include <base/macros.h>
#include <base/stl_util.h>
#include <openssl/rand.h>
namespace trunks {
HmacSessionImpl::HmacSessionImpl(const TrunksFactory& factory)
: factory_(factory) {
session_manager_ = factory_.GetSessionManager();
}
HmacSessionImpl::~HmacSessionImpl() {
session_manager_->CloseSession();
}
AuthorizationDelegate* HmacSessionImpl::GetDelegate() {
if (session_manager_->GetSessionHandle() == kUninitializedHandle) {
return nullptr;
}
return &hmac_delegate_;
}
TPM_RC HmacSessionImpl::StartBoundSession(
TPMI_DH_ENTITY bind_entity,
const std::string& bind_authorization_value,
bool salted,
bool enable_encryption) {
return session_manager_->StartSession(TPM_SE_HMAC, bind_entity,
bind_authorization_value, salted,
enable_encryption, &hmac_delegate_);
}
TPM_RC HmacSessionImpl::StartUnboundSession(bool salted,
bool enable_encryption) {
// Starting an unbound session is the same as starting a session bound to
// TPM_RH_NULL. In this case, the authorization is the zero length buffer.
// We can therefore simply call StartBoundSession with TPM_RH_NULL as the
// binding entity, and the empty string as the authorization.
return StartBoundSession(TPM_RH_NULL, "", salted, enable_encryption);
}
void HmacSessionImpl::SetEntityAuthorizationValue(const std::string& value) {
hmac_delegate_.set_entity_authorization_value(value);
}
void HmacSessionImpl::SetFutureAuthorizationValue(const std::string& value) {
hmac_delegate_.set_future_authorization_value(value);
}
} // namespace trunks