Skip to content

Commit

Permalink
Fix blobstorage crypto module build for aarch64 (ydb-platform#11840)
Browse files Browse the repository at this point in the history
  • Loading branch information
SammyVimes authored and dahbka-lis committed Nov 25, 2024
1 parent 8f1b8b6 commit 7a30252
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
11 changes: 4 additions & 7 deletions ydb/core/blobstorage/crypto/crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,14 @@ const bool TStreamCypher::HasAVX512 = NX86::HaveAVX512F();
Y_FORCE_INLINE void TStreamCypher::Encipher(const ui8* plaintext, ui8* ciphertext, size_t len) {
std::visit([&](auto&& chacha) {
chacha.Encipher(plaintext, ciphertext, len);
}, *Cypher);
}, Cypher);
}

Y_FORCE_INLINE void TStreamCypher::SetKeyAndIV(const ui64 blockIdx) {
std::visit([&](auto&& chacha) {
chacha.SetKey((ui8*)&Key[0], sizeof(Key));
chacha.SetIV((ui8*)&Nonce, (ui8*)&blockIdx);
}, *Cypher);
}, Cypher);
}

TStreamCypher::TStreamCypher()
Expand All @@ -189,15 +189,12 @@ TStreamCypher::TStreamCypher()
{
#if ENABLE_ENCRYPTION
memset(Key, 0, sizeof(Key));

auto* chacha = new std::variant<ChaChaVec, ChaCha512>;

if (HasAVX512) {
chacha->emplace<ChaCha512>(CYPHER_ROUNDS);
Cypher.emplace<ChaCha512>(CYPHER_ROUNDS);
} else {
chacha->emplace<ChaChaVec>(CYPHER_ROUNDS);
Cypher.emplace<ChaChaVec>(CYPHER_ROUNDS);
}
Cypher.reset(chacha);
#else
Y_UNUSED(Leftover);
Y_UNUSED(Key);
Expand Down
8 changes: 4 additions & 4 deletions ydb/core/blobstorage/crypto/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
#if (defined(_win_) || defined(_arm64_))
#include <ydb/core/blobstorage/crypto/chacha.h>
#include <ydb/core/blobstorage/crypto/poly1305.h>
#define ChaChaVec ChaCha
#define ChaCha512 ChaCha
#define Poly1305Vec Poly1305
#define CHACHA_BPI 1
using ChaChaVec = ChaCha;
using Poly1305Vec = Poly1305;
class ChaCha512 : public ChaCha {};
#else
#include <ydb/core/blobstorage/crypto/chacha_vec.h>
#include <ydb/core/blobstorage/crypto/chacha_512/chacha_512.h>
Expand Down Expand Up @@ -104,7 +104,7 @@ class TStreamCypher {
alignas(16) ui8 Leftover[BLOCK_BYTES];
alignas(16) ui64 Key[4];
alignas(16) i64 Nonce;
std::unique_ptr<std::variant<ChaChaVec, ChaCha512>> Cypher;
std::variant<ChaChaVec, ChaCha512> Cypher;
ui32 UnusedBytes;
public:
TStreamCypher();
Expand Down

0 comments on commit 7a30252

Please sign in to comment.