From d2653aa9c6933014dc657b9b42ee3d1fc682e340 Mon Sep 17 00:00:00 2001 From: jsing Date: Wed, 15 Dec 2021 17:30:20 +0000 Subject: [PATCH] Provide CBS_get_u64(). This will be used in the libcrypto certificate transparency code. ok tb@ --- lib/libssl/bs_cbs.c | 19 ++++++++++++++++++- lib/libssl/bytestring.h | 8 +++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/libssl/bs_cbs.c b/lib/libssl/bs_cbs.c index 627c609bb9e..97b0163f3fb 100644 --- a/lib/libssl/bs_cbs.c +++ b/lib/libssl/bs_cbs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bs_cbs.c,v 1.22 2021/12/15 17:23:34 jsing Exp $ */ +/* $OpenBSD: bs_cbs.c,v 1.23 2021/12/15 17:30:20 jsing Exp $ */ /* * Copyright (c) 2014, Google Inc. * @@ -190,6 +190,23 @@ CBS_get_u32(CBS *cbs, uint32_t *out) return cbs_get_u(cbs, out, 4); } +int +CBS_get_u64(CBS *cbs, uint64_t *out) +{ + uint32_t a, b; + + if (cbs->len < 8) + return 0; + + if (!CBS_get_u32(cbs, &a)) + return 0; + if (!CBS_get_u32(cbs, &b)) + return 0; + + *out = (uint64_t)a << 32 | b; + return 1; +} + int CBS_get_last_u8(CBS *cbs, uint8_t *out) { diff --git a/lib/libssl/bytestring.h b/lib/libssl/bytestring.h index 4ab2828d09f..fa5e05fa27b 100644 --- a/lib/libssl/bytestring.h +++ b/lib/libssl/bytestring.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bytestring.h,v 1.20 2021/12/15 17:23:34 jsing Exp $ */ +/* $OpenBSD: bytestring.h,v 1.21 2021/12/15 17:30:20 jsing Exp $ */ /* * Copyright (c) 2014, Google Inc. * @@ -133,6 +133,12 @@ int CBS_get_u24(CBS *cbs, uint32_t *out); */ int CBS_get_u32(CBS *cbs, uint32_t *out); +/* + * CBS_get_u64 sets |*out| to the next, big-endian uint64_t value from |cbs| + * and advances |cbs|. It returns one on success and zero on error. + */ +int CBS_get_u64(CBS *cbs, uint64_t *out); + /* * CBS_get_last_u8 sets |*out| to the last uint8_t from |cbs| and shortens * |cbs|. It returns one on success and zero on error. -- 2.20.1