summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2021-12-15 17:30:20 +0000
committerjsing <>2021-12-15 17:30:20 +0000
commitc65b7fde1b92fc7227e530fe38647376938edebd (patch)
treed08eff21ae5dbf5ea173d6a4a6d63881bd7be7cb
parent4d85c2eaad13fb1a929709a9c386d1179d1f4ac1 (diff)
downloadopenbsd-c65b7fde1b92fc7227e530fe38647376938edebd.tar.gz
openbsd-c65b7fde1b92fc7227e530fe38647376938edebd.tar.bz2
openbsd-c65b7fde1b92fc7227e530fe38647376938edebd.zip
Provide CBS_get_u64().
This will be used in the libcrypto certificate transparency code. ok tb@
-rw-r--r--src/lib/libssl/bs_cbs.c19
-rw-r--r--src/lib/libssl/bytestring.h8
2 files changed, 25 insertions, 2 deletions
diff --git a/src/lib/libssl/bs_cbs.c b/src/lib/libssl/bs_cbs.c
index 627c609bb9..97b0163f3f 100644
--- a/src/lib/libssl/bs_cbs.c
+++ b/src/lib/libssl/bs_cbs.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bs_cbs.c,v 1.22 2021/12/15 17:23:34 jsing Exp $ */ 1/* $OpenBSD: bs_cbs.c,v 1.23 2021/12/15 17:30:20 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2014, Google Inc. 3 * Copyright (c) 2014, Google Inc.
4 * 4 *
@@ -191,6 +191,23 @@ CBS_get_u32(CBS *cbs, uint32_t *out)
191} 191}
192 192
193int 193int
194CBS_get_u64(CBS *cbs, uint64_t *out)
195{
196 uint32_t a, b;
197
198 if (cbs->len < 8)
199 return 0;
200
201 if (!CBS_get_u32(cbs, &a))
202 return 0;
203 if (!CBS_get_u32(cbs, &b))
204 return 0;
205
206 *out = (uint64_t)a << 32 | b;
207 return 1;
208}
209
210int
194CBS_get_last_u8(CBS *cbs, uint8_t *out) 211CBS_get_last_u8(CBS *cbs, uint8_t *out)
195{ 212{
196 if (cbs->len == 0) 213 if (cbs->len == 0)
diff --git a/src/lib/libssl/bytestring.h b/src/lib/libssl/bytestring.h
index 4ab2828d09..fa5e05fa27 100644
--- a/src/lib/libssl/bytestring.h
+++ b/src/lib/libssl/bytestring.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: bytestring.h,v 1.20 2021/12/15 17:23:34 jsing Exp $ */ 1/* $OpenBSD: bytestring.h,v 1.21 2021/12/15 17:30:20 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2014, Google Inc. 3 * Copyright (c) 2014, Google Inc.
4 * 4 *
@@ -134,6 +134,12 @@ int CBS_get_u24(CBS *cbs, uint32_t *out);
134int CBS_get_u32(CBS *cbs, uint32_t *out); 134int CBS_get_u32(CBS *cbs, uint32_t *out);
135 135
136/* 136/*
137 * CBS_get_u64 sets |*out| to the next, big-endian uint64_t value from |cbs|
138 * and advances |cbs|. It returns one on success and zero on error.
139 */
140int CBS_get_u64(CBS *cbs, uint64_t *out);
141
142/*
137 * CBS_get_last_u8 sets |*out| to the last uint8_t from |cbs| and shortens 143 * CBS_get_last_u8 sets |*out| to the last uint8_t from |cbs| and shortens
138 * |cbs|. It returns one on success and zero on error. 144 * |cbs|. It returns one on success and zero on error.
139 */ 145 */