Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Types | Public Member Functions | Static Public Member Functions | List of all members
Botan::Roughtime::Response Class Referencefinal

`#include <roughtime.h>`

## Public Types
using | microseconds32 = std::chrono::duration< uint32_t, std::micro >
using | microseconds64 = std::chrono::duration< uint64_t, std::micro >
using | sys_microseconds64 = std::chrono::time_point< std::chrono::system_clock, microseconds64 >

## Public Member Functions
sys_microseconds64 | utc_midpoint () const
microseconds32 | utc_radius () const
bool | validate (const Ed25519_PublicKey &pk) const

## Static Public Member Functions
static Response | from_bits (const std::vector< uint8_t > &response, const Nonce &nonce)

## Detailed Description

An Roughtime response.

Definition at line 58 of file roughtime.h.

## Member Typedef Documentation

using Botan::Roughtime::Response::microseconds32 = std::chrono::duration<uint32_t, std::micro>

Definition at line 61 of file roughtime.h.

using Botan::Roughtime::Response::microseconds64 = std::chrono::duration<uint64_t, std::micro>

Definition at line 62 of file roughtime.h.

using Botan::Roughtime::Response::sys_microseconds64 = std::chrono::time_point<std::chrono::system_clock, microseconds64>

Definition at line 63 of file roughtime.h.

## Member Function Documentation

Response Botan::Roughtime::Response::from_bits | ( | const std::vector< uint8_t > & | response,
|  | const Nonce & | nonce
| ) |  |
| static

Definition at line 177 of file roughtime.cpp.

References Botan::Roughtime::Nonce::get_nonce(), and Botan::typecast_copy().

Referenced by Botan::Roughtime::Chain::responses().

179 {
180 const auto response_v = unpack_roughtime_packet(response);
181 const auto cert = unpack_roughtime_packet(get_v(response_v, "CERT"));
182 const auto cert_dele = get<std::array<uint8_t, 72>>(cert, "DELE");
183 const auto cert_sig = get<std::array<uint8_t, 64>>(cert, "SIG");
184 const auto cert_dele_v = unpack_roughtime_packet(cert_dele);
185 const auto srep = get_v(response_v, "SREP");
186 const auto srep_v = unpack_roughtime_packet(srep);
187
188 const auto cert_dele_pubk = get<std::array<uint8_t, 32>>(cert_dele_v, "PUBK");
189 const auto sig = get<std::array<uint8_t, 64>>(response_v, "SIG");
190 if(!verify_signature(cert_dele_pubk, srep, sig))
191 { throw Roughtime_Error("Response signature invalid"); }
192
193 const auto indx = get<uint32_t>(response_v, "INDX");
194 const auto path = get_v(response_v, "PATH");
195 const auto srep_root = get<std::array<uint8_t, 64>>(srep_v, "ROOT");
196 const auto size = path.size();
197 const auto levels = size/64;
198
199 if(size % 64)
200 { throw Roughtime_Error("Merkle tree path size must be multiple of 64 bytes"); }
201 if(indx >= (1u << levels))
202 { throw Roughtime_Error("Merkle tree path is too short"); }
203
204 auto hash = hashLeaf(nonce.get_nonce());
205 auto index = indx;
206 auto level = 0u;
207 while(level < levels)
208 {
209 hashNode(hash, typecast_copy<std::array<uint8_t, 64>>(path.data() + level*64), index&1);
210 ++level;
211 index>>=1;
212 }
213
214 if(srep_root != hash)
215 { throw Roughtime_Error("Nonce verification failed"); }
216
217 const auto cert_dele_maxt = sys_microseconds64(get<microseconds64>(cert_dele_v, "MAXT"));
218 const auto cert_dele_mint = sys_microseconds64(get<microseconds64>(cert_dele_v, "MINT"));
219 const auto srep_midp = sys_microseconds64(get<microseconds64>(srep_v, "MIDP"));
220 const auto srep_radi = get<microseconds32>(srep_v, "RADI");
221 if(srep_midp < cert_dele_mint)
222 { throw Roughtime_Error("Midpoint earlier than delegation start"); }
223 if(srep_midp > cert_dele_maxt)
224 { throw Roughtime_Error("Midpoint later than delegation end"); }
225 return {cert_dele, cert_sig, srep_midp, srep_radi};
226 }
Botan::typecast_copy
void typecast_copy(uint8_t out[], T in[], size_t N)
Definition: mem_ops.h:144
Botan::Roughtime::Response::sys_microseconds64
std::chrono::time_point< std::chrono::system_clock, microseconds64 > sys_microseconds64
Definition: roughtime.h:63
hash
MechanismType hash
Definition: p11_mechanism.cpp:64

sys_microseconds64 Botan::Roughtime::Response::utc_midpoint | ( |  | ) | const
| inline

Definition at line 69 of file roughtime.h.

69 { return m_utc_midpoint; }

microseconds32 Botan::Roughtime::Response::utc_radius | ( |  | ) | const
| inline

Definition at line 71 of file roughtime.h.

71 { return m_utc_radius; }

bool Botan::Roughtime::Response::validate | ( | const Ed25519_PublicKey & | pk | ) | const

Definition at line 228 of file roughtime.cpp.

References Botan::cast_char_ptr_to_uint8(), Botan::PK_Verifier::check_signature(), and Botan::PK_Verifier::update().

229 {
230 const char context[] = "RoughTime v1 delegation signature--";
231 PK_Verifier verifier(pk, "Pure");
232 verifier.update(cast_char_ptr_to_uint8(context), sizeof(context)); //add context including \0
233 verifier.update(m_cert_dele.data(), m_cert_dele.size());
234 return verifier.check_signature(m_cert_sig.data(), m_cert_sig.size());
235 }
Botan::cast_char_ptr_to_uint8
const uint8_t * cast_char_ptr_to_uint8(const char *s)
Definition: mem_ops.h:189

The documentation for this class was generated from the following files:

- src/lib/misc/roughtime/roughtime.h
- src/lib/misc/roughtime/roughtime.cpp