add CBS_get_u48 The latest MTC draft uses uint48 values. Change-Id: Ide5e405de82e1bdd6b6229d8f959973348bbc360 Bug: 452983502 Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/95747 Reviewed-by: David Benjamin <davidben@google.com> Commit-Queue: Matt Mueller <mattm@google.com>
diff --git a/crypto/bytestring/bytestring_test.cc b/crypto/bytestring/bytestring_test.cc index 0e36a2e..e0c200d 100644 --- a/crypto/bytestring/bytestring_test.cc +++ b/crypto/bytestring/bytestring_test.cc
@@ -59,7 +59,8 @@ TEST(CBSTest, GetUint) { static const uint8_t kData[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, - 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}; + 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + 21, 22, 23, 24, 25, 26}; uint8_t u8; uint16_t u16; uint32_t u32; @@ -75,12 +76,14 @@ EXPECT_EQ(0x40506u, u32); ASSERT_TRUE(CBS_get_u32(&data, &u32)); EXPECT_EQ(0x708090au, u32); + ASSERT_TRUE(CBS_get_u48(&data, &u64)); + EXPECT_EQ(0xb0c0d0e0f10u, u64); ASSERT_TRUE(CBS_get_u64(&data, &u64)); - EXPECT_EQ(0xb0c0d0e0f101112u, u64); + EXPECT_EQ(0x1112131415161718u, u64); ASSERT_TRUE(CBS_get_last_u8(&data, &u8)); - EXPECT_EQ(0x14u, u8); + EXPECT_EQ(0x1au, u8); ASSERT_TRUE(CBS_get_last_u8(&data, &u8)); - EXPECT_EQ(0x13u, u8); + EXPECT_EQ(0x19u, u8); EXPECT_FALSE(CBS_get_u8(&data, &u8)); EXPECT_FALSE(CBS_get_last_u8(&data, &u8));
diff --git a/crypto/bytestring/cbs.cc b/crypto/bytestring/cbs.cc index dbaa3e8..f9011e3 100644 --- a/crypto/bytestring/cbs.cc +++ b/crypto/bytestring/cbs.cc
@@ -146,6 +146,8 @@ return 1; } +int CBS_get_u48(CBS *cbs, uint64_t *out) { return cbs_get_u(cbs, out, 6); } + int CBS_get_u64(CBS *cbs, uint64_t *out) { return cbs_get_u(cbs, out, 8); } int CBS_get_u64le(CBS *cbs, uint64_t *out) {
diff --git a/include/openssl/bytestring.h b/include/openssl/bytestring.h index 3e1cfe5..50263cb 100644 --- a/include/openssl/bytestring.h +++ b/include/openssl/bytestring.h
@@ -121,6 +121,10 @@ // |cbs| and advances |cbs|. It returns one on success and zero on error. OPENSSL_EXPORT int CBS_get_u32le(CBS *cbs, uint32_t *out); +// CBS_get_u48 sets |*out| to the next, big-endian 48-bit value from |cbs| and +// advances |cbs|. It returns one on success and zero on error. +OPENSSL_EXPORT int CBS_get_u48(CBS *cbs, uint64_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. OPENSSL_EXPORT int CBS_get_u64(CBS *cbs, uint64_t *out);
diff --git a/include/openssl/prefix_symbols.h b/include/openssl/prefix_symbols.h index c25242d..4d970a3 100644 --- a/include/openssl/prefix_symbols.h +++ b/include/openssl/prefix_symbols.h
@@ -568,6 +568,7 @@ #pragma redefine_extname CBS_get_u24_length_prefixed BORINGSSL_ADD_USER_LABEL_AND_PREFIX(CBS_get_u24_length_prefixed) #pragma redefine_extname CBS_get_u32 BORINGSSL_ADD_USER_LABEL_AND_PREFIX(CBS_get_u32) #pragma redefine_extname CBS_get_u32le BORINGSSL_ADD_USER_LABEL_AND_PREFIX(CBS_get_u32le) +#pragma redefine_extname CBS_get_u48 BORINGSSL_ADD_USER_LABEL_AND_PREFIX(CBS_get_u48) #pragma redefine_extname CBS_get_u64 BORINGSSL_ADD_USER_LABEL_AND_PREFIX(CBS_get_u64) #pragma redefine_extname CBS_get_u64_decimal BORINGSSL_ADD_USER_LABEL_AND_PREFIX(CBS_get_u64_decimal) #pragma redefine_extname CBS_get_u64le BORINGSSL_ADD_USER_LABEL_AND_PREFIX(CBS_get_u64le) @@ -3682,6 +3683,7 @@ #define CBS_get_u24_length_prefixed BORINGSSL_ADD_PREFIX(CBS_get_u24_length_prefixed) #define CBS_get_u32 BORINGSSL_ADD_PREFIX(CBS_get_u32) #define CBS_get_u32le BORINGSSL_ADD_PREFIX(CBS_get_u32le) +#define CBS_get_u48 BORINGSSL_ADD_PREFIX(CBS_get_u48) #define CBS_get_u64 BORINGSSL_ADD_PREFIX(CBS_get_u64) #define CBS_get_u64_decimal BORINGSSL_ADD_PREFIX(CBS_get_u64_decimal) #define CBS_get_u64le BORINGSSL_ADD_PREFIX(CBS_get_u64le)