Botan 3.0.0-alpha0
Crypto and TLS for C&
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

◆ microseconds32

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

Definition at line 61 of file roughtime.h.

◆ microseconds64

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

Definition at line 62 of file roughtime.h.

◆ sys_microseconds64

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

◆ from_bits()

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

Definition at line 178 of file roughtime.cpp.

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

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

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

◆ utc_midpoint()

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

Definition at line 69 of file roughtime.h.

69{ return m_utc_midpoint; }

◆ utc_radius()

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

Definition at line 71 of file roughtime.h.

71{ return m_utc_radius; }

◆ validate()

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

Definition at line 229 of file roughtime.cpp.

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

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


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