mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-20 10:24:12 +00:00
A pass that adds random noops to X86 binaries to introduce diversity with the goal of increasing security against most return-oriented programming attacks. Command line options: -noop-insertion // Enable noop insertion. -noop-insertion-percentage=X // X% of assembly instructions will have a noop prepended (default: 50%, requires -noop-insertion) -max-noops-per-instruction=X // Randomly generate X noops per instruction. ie. roll the dice X times with probability set above (default: 1). This doesn't guarantee X noop instructions. In addition, the following 'quick switch' in clang enables basic diversity using default settings (currently: noop insertion and schedule randomization; it is intended to be extended in the future). -fdiversify This is the llvm part of the patch. clang part: D3393 http://reviews.llvm.org/D3392 Patch by Stephen Crane (@rinon) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225908 91177308-0d34-0410-b5e6-96231b3b80d8
73 lines
2.3 KiB
C++
73 lines
2.3 KiB
C++
//==- llvm/Support/RandomNumberGenerator.h - RNG for diversity ---*- C++ -*-==//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file defines an abstraction for deterministic random number
|
|
// generation (RNG). Note that the current implementation is not
|
|
// cryptographically secure as it uses the C++11 <random> facilities.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_SUPPORT_RANDOMNUMBERGENERATOR_H_
|
|
#define LLVM_SUPPORT_RANDOMNUMBERGENERATOR_H_
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
#include "llvm/Support/Compiler.h"
|
|
#include "llvm/Support/DataTypes.h" // Needed for uint64_t on Windows.
|
|
#include <random>
|
|
|
|
namespace llvm {
|
|
|
|
/// A random number generator.
|
|
///
|
|
/// Instances of this class should not be shared across threads. The
|
|
/// seed should be set by passing the -rng-seed=<uint64> option. Use
|
|
/// Module::createRNG to create a new RNG instance for use with that
|
|
/// module.
|
|
class RandomNumberGenerator {
|
|
public:
|
|
typedef std::mt19937_64 RNG;
|
|
typedef RNG::result_type result_type;
|
|
|
|
/// Returns a random number in the range [0, Max).
|
|
result_type operator()();
|
|
|
|
// Must define min and max to be compatible with URNG as used by
|
|
// std::uniform_*_distribution
|
|
static LLVM_CONSTEXPR result_type min() {
|
|
return RNG::min();
|
|
}
|
|
static LLVM_CONSTEXPR result_type max() {
|
|
return RNG::max();
|
|
}
|
|
|
|
private:
|
|
/// Seeds and salts the underlying RNG engine.
|
|
///
|
|
/// This constructor should not be used directly. Instead use
|
|
/// Module::createRNG to create a new RNG salted with the Module ID.
|
|
RandomNumberGenerator(StringRef Salt);
|
|
|
|
// 64-bit Mersenne Twister by Matsumoto and Nishimura, 2000
|
|
// http://en.cppreference.com/w/cpp/numeric/random/mersenne_twister_engine
|
|
// This RNG is deterministically portable across C++11
|
|
// implementations.
|
|
RNG Generator;
|
|
|
|
// Noncopyable.
|
|
RandomNumberGenerator(const RandomNumberGenerator &other)
|
|
LLVM_DELETED_FUNCTION;
|
|
RandomNumberGenerator &
|
|
operator=(const RandomNumberGenerator &other) LLVM_DELETED_FUNCTION;
|
|
|
|
friend class Module;
|
|
};
|
|
}
|
|
|
|
#endif
|