AesBlock::inc: use bswap64 for x64 and armv8
GitOrigin-RevId: 5842d5d9fd4a865bc0c786e31e3f62f1257d1d4d
This commit is contained in:
parent
4c288d9398
commit
1a33df9d52
@ -47,6 +47,11 @@ inline uint64 lower_bit64(uint64 x) {
|
||||
return x & bits_negate64(x);
|
||||
}
|
||||
|
||||
inline uint64 native_vs_bigendian64(uint64 x) {
|
||||
// NB: works only for litte endian systems
|
||||
return bswap64(x);
|
||||
}
|
||||
|
||||
//TODO: optimize
|
||||
inline int32 count_leading_zeroes_non_zero32(uint32 x) {
|
||||
DCHECK(x != 0);
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "td/utils/Slice-decl.h"
|
||||
#include "td/utils/as.h"
|
||||
#include "td/utils/BigNum.h"
|
||||
#include "td/utils/bits.h"
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/logging.h"
|
||||
#include "td/utils/misc.h"
|
||||
@ -79,6 +80,16 @@ struct AesBlock {
|
||||
}
|
||||
|
||||
AesBlock inc() const {
|
||||
#if __aarch64__ || __x86_64__
|
||||
AesBlock res;
|
||||
res.lo = native_vs_bigendian64(native_vs_bigendian64(lo) + 1);
|
||||
if (res.lo == 0) {
|
||||
res.hi = native_vs_bigendian64(native_vs_bigendian64(hi) + 1);
|
||||
} else {
|
||||
res.hi = hi;
|
||||
}
|
||||
return res;
|
||||
#else
|
||||
AesBlock res = *this;
|
||||
auto ptr = res.raw();
|
||||
if (++ptr[15] == 0) {
|
||||
@ -89,8 +100,9 @@ struct AesBlock {
|
||||
}
|
||||
}
|
||||
return res;
|
||||
#endif
|
||||
}
|
||||
};
|
||||
}; // namespace td
|
||||
static_assert(sizeof(AesBlock) == 16, "");
|
||||
static_assert(sizeof(AesBlock) == AES_BLOCK_SIZE, "");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user