Function secure_fill

Summary

#include "breeze/algorithm/secure_fill.hpp"

(1) template <typename ForwardIterator, typename T>
    void secure_fill(ForwardIterator begin, ForwardIterator end, T const &value)

(2) template <typename T, std::ptrdiff_t n>
    void secure_fill(T(&arr)[n], T const &value=T())

Function overload

Synopsis

#include "breeze/algorithm/secure_fill.hpp"

template <typename ForwardIterator, typename T>
void secure_fill(ForwardIterator begin, ForwardIterator end, T const &value)

Description

Like std::fill(), but guarantees that the range is written to.

This is completely analogous to the std::fill() algorithm, except that it guarantees that the range is written to, even if its elements are never touched after the secure_fill() call (in other words: it ensures that the compiler will not optimize away the call); unless, of course, the provided range is empty. Useful for zeroing passwords and other sensitive data (see

https://devblogs.microsoft.com/oldnewthing/20130529-00/?p=4223

for some insights on this).

Note that a convenience overload for built-in arrays is provided.

For technical reasons, secure_fill() requires a range, or an array, whose elements are of a built-in type.

Warning
Note that algorithm names are usually verb-based. However, in the expression "secure fill", "fill" is actually a noun. I don't like this inconsistency, but couldn't find a better, verb-based name (some native speakers told me that "securely_fill" would sound weird); if you have one, please send me a mail.

Source

Lines 119-126 in breeze/algorithm/secure_fill.hpp.

template< typename ForwardIterator, typename T >
void
secure_fill( ForwardIterator begin, ForwardIterator end, T const & value )
{
    for ( ; begin != end ; ++ begin ) {
        breeze::volatilize( *begin ) = value ;
    }
}

Synopsis

#include "breeze/algorithm/secure_fill.hpp"

template <typename T, std::ptrdiff_t n>
void secure_fill(T(&arr)[n], T const &value=T())

Description

Version for built-in arrays.

Source

Lines 133-141 in breeze/algorithm/secure_fill.hpp.

template< typename T, std::ptrdiff_t n >
void
secure_fill( T ( &arr )[ n ], T const & value = T() )
{
    //      Intentionally renouncing to using our begin()/end(), to
    //      reduce dependencies.
    // -----------------------------------------------------------------------
    breeze::secure_fill( arr, arr + n , value ) ;
}