From 840b9ce3647722a668b38d09c74a6e91aa475721 Mon Sep 17 00:00:00 2001 From: Francisco Paisana Date: Mon, 21 Jan 2019 14:16:21 +0000 Subject: [PATCH] fixed octstring to_number() endianess --- lib/src/asn1/asn1_utils.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/asn1/asn1_utils.cc b/lib/src/asn1/asn1_utils.cc index a7f407cb2..4a8f6fd02 100644 --- a/lib/src/asn1/asn1_utils.cc +++ b/lib/src/asn1/asn1_utils.cc @@ -622,7 +622,7 @@ uint64_t octstring_to_number(const uint8_t* ptr, uint32_t nbytes) } uint64_t val = 0; for (uint32_t i = 0; i < nbytes; ++i) { - val += ptr[i] << (i * 8); + val += ((uint64_t)ptr[nbytes - 1 - i]) << (uint64_t)(i * 8); } return val; } @@ -634,7 +634,7 @@ void number_to_octstring(uint8_t* ptr, uint64_t number, uint32_t nbytes) return; } for (uint32_t i = 0; i < nbytes; ++i) { - ptr[i] = (number >> (i * 8)) & 0xFF; + ptr[nbytes - 1 - i] = (number >> (uint64_t)(i * 8u)) & 0xFF; } }