1017 const char* szFunc =
"OTSymmetricKey::SerializeFrom";
1023 uint16_t n_is_generated = 0;
1025 if (0 == (nRead = theInput.OTfread(
1026 reinterpret_cast<uint8_t*>(&n_is_generated),
1027 static_cast<uint32_t>(
sizeof(n_is_generated))))) {
1028 otErr << szFunc <<
": Error reading n_is_generated.\n";
1034 uint16_t host_is_generated =
1035 static_cast<uint16_t
>(ntohs(static_cast<uint16_t>(n_is_generated)));
1037 if (1 == host_is_generated)
1038 m_bIsGenerated =
true;
1039 else if (0 == host_is_generated)
1040 m_bIsGenerated =
false;
1042 otErr << szFunc <<
": Error: host_is_generated, Bad value: "
1043 <<
static_cast<int32_t
>(host_is_generated)
1044 <<
". (Expected 0 or 1.)\n";
1049 <<
": is_generated: " <<
static_cast<int32_t
>(host_is_generated)
1054 uint16_t n_key_size_bits = 0;
1056 if (0 == (nRead = theInput.OTfread(
1057 reinterpret_cast<uint8_t*>(&n_key_size_bits),
1058 static_cast<uint32_t>(
sizeof(n_key_size_bits))))) {
1059 otErr << szFunc <<
": Error reading n_key_size_bits.\n";
1065 m_nKeySize =
static_cast<uint16_t
>(ntohs(n_key_size_bits));
1068 <<
": key_size_bits: " <<
static_cast<int32_t
>(m_nKeySize) <<
" \n";
1072 uint32_t n_iteration_count = 0;
1074 if (0 == (nRead = theInput.OTfread(
1075 reinterpret_cast<uint8_t*>(&n_iteration_count),
1076 static_cast<uint32_t>(
sizeof(n_iteration_count))))) {
1077 otErr << szFunc <<
": Error reading n_iteration_count.\n";
1080 OT_ASSERT(nRead == static_cast<uint32_t>(
sizeof(n_iteration_count)));
1084 m_uIterationCount =
static_cast<uint32_t
>(ntohl(n_iteration_count));
1087 <<
": iteration_count: " <<
static_cast<int64_t
>(m_uIterationCount)
1092 uint32_t n_salt_size = 0;
1094 if (0 == (nRead = theInput.OTfread(
1095 reinterpret_cast<uint8_t*>(&n_salt_size),
1096 static_cast<uint32_t>(
sizeof(n_salt_size))))) {
1097 otErr << szFunc <<
": Error reading n_salt_size.\n";
1100 OT_ASSERT(nRead == static_cast<uint32_t>(
sizeof(n_salt_size)));
1104 const uint32_t lSaltSize =
1105 static_cast<uint32_t
>(ntohl(static_cast<uint32_t>(n_salt_size)));
1108 <<
": salt_size value: " <<
static_cast<int64_t
>(lSaltSize) <<
" \n";
1114 if (0 == (nRead = theInput.OTfread(static_cast<uint8_t*>(const_cast<void*>(
1116 static_cast<uint32_t
>(lSaltSize)))) {
1117 otErr << szFunc <<
": Error reading salt for symmetric key.\n";
1121 <<
": salt length actually read: " <<
static_cast<int64_t
>(nRead)
1123 OT_ASSERT(nRead == static_cast<uint32_t>(lSaltSize));
1127 uint32_t n_iv_size = 0;
1130 (nRead = theInput.OTfread(reinterpret_cast<uint8_t*>(&n_iv_size),
1131 static_cast<uint32_t>(
sizeof(n_iv_size))))) {
1132 otErr << szFunc <<
": Error reading n_iv_size.\n";
1136 OT_ASSERT(nRead == static_cast<uint32_t>(
sizeof(n_iv_size)));
1140 const uint32_t lIVSize = ntohl(n_iv_size);
1143 <<
": iv_size value: " <<
static_cast<int64_t
>(lIVSize) <<
" \n";
1149 if (0 == (nRead = theInput.OTfread(static_cast<uint8_t*>(const_cast<void*>(
1151 static_cast<uint32_t
>(lIVSize)))) {
1152 otErr << szFunc <<
": Error reading IV for symmetric key.\n";
1157 <<
": iv length actually read: " <<
static_cast<int64_t
>(nRead)
1160 OT_ASSERT(nRead == static_cast<uint32_t>(lIVSize));
1164 uint32_t n_enc_key_size = 0;
1166 if (0 == (nRead = theInput.OTfread(
1167 reinterpret_cast<uint8_t*>(&n_enc_key_size),
1168 static_cast<uint32_t>(
sizeof(n_enc_key_size))))) {
1169 otErr << szFunc <<
": Error reading n_enc_key_size.\n";
1172 OT_ASSERT(nRead == static_cast<uint32_t>(
sizeof(n_enc_key_size)));
1176 const uint32_t lEncKeySize = ntohl(n_enc_key_size);
1179 <<
": enc_key_size value: " <<
static_cast<int64_t
>(lEncKeySize)
1187 (nRead = theInput.OTfread(static_cast<uint8_t*>(const_cast<void*>(
1189 static_cast<uint32_t
>(lEncKeySize)))) {
1190 otErr << szFunc <<
": Error reading encrypted symmetric key.\n";
1194 otLog5 << __FUNCTION__ <<
": encrypted key length actually read: "
1195 <<
static_cast<int64_t
>(nRead) <<
" \n";
1197 OT_ASSERT(nRead == static_cast<uint32_t>(lEncKeySize));
1201 uint32_t n_hash_check_size = 0;
1203 if (0 == (nRead = theInput.OTfread(
1204 reinterpret_cast<uint8_t*>(&n_hash_check_size),
1205 static_cast<uint32_t>(
sizeof(n_hash_check_size))))) {
1206 otErr << szFunc <<
": Error reading n_hash_check_size.\n";
1209 <<
": Looks like we don't have a hash check yet! (will make one)\n";
1210 m_bHasHashCheck =
false;
1213 OT_ASSERT(nRead == static_cast<uint32_t>(
sizeof(n_hash_check_size)));
1217 const uint32_t lHashCheckSize = ntohl(n_hash_check_size);
1219 otLog5 << __FUNCTION__ <<
": hash_check_size value: "
1220 <<
static_cast<int64_t
>(lHashCheckSize) <<
" \n";
1227 (nRead = theInput.OTfread(static_cast<uint8_t*>(const_cast<void*>(
1229 static_cast<uint32_t
>(lHashCheckSize)))) {
1230 otErr << szFunc <<
": Error reading hash check data.\n";
1235 <<
": hash check data actually read: " <<
static_cast<int64_t
>(nRead)
1238 OT_ASSERT(nRead == static_cast<uint32_t>(lHashCheckSize));
1240 m_bHasHashCheck = !m_dataHashCheck.
IsEmpty();
EXPORT void SetPayloadSize(uint32_t lNewSize)
EXPORT const void * GetPayloadPointer() const
OTLOG_IMPORT OTLogStream otErr
EXPORT bool IsEmpty() const
OTLOG_IMPORT OTLogStream otLog5