Search code examples
c++botan

How do I use Botan::MemoryRegion?


Does anyone know how to create an object of type Botan::MemoryRegion for use in this method?

BigInt BOTAN_DLL fe1_encrypt(const BigInt& n, const BigInt& X,
                         const SymmetricKey& key,
                         const MemoryRegion<byte>& tweak);

Solution

  • Both MemoryVector and SecureVector inherit from MemoryRegion and can be used quite similar to std::vector.

    BYTE tweakData[tweakDataLen] = { ... };
    MemoryVector<byte> myTweak(tweakData, tweakDataLen);
    

    SecureVector takes some precautions to prevent the data from spreading around (e.g. overwrite-before-delete and supresses some swap-to-disk scenarios)