encrypted_value.hHeader

This header file defines the encrypted_value class template for securely storing and managing encrypted values. More...

Defines

TypeName
ANTISPY_ENCRYPTED_VALUE

Detailed Description

The encrypted_value.h file is part of the antispy SDK library, which provides tools and utilities for enhancing security and protecting sensitive data in C++ applications. This specific file focuses on the secure storage of data through encryption. It defines the encrypted_value class template, which allows developers to securely store a value by encrypting it with a specified key and unique identifier. The value remains encrypted when stored and is only decrypted when accessed, thus ensuring that sensitive information is protected against unauthorized access or tampering.

Key Features:

  • Secure Storage : Values are stored in an encrypted form, making it difficult for attackers to access raw data.

  • Automatic Encryption and Decryption : The class handles the encryption when a value is stored and decryption when it is accessed.

  • Compile-time and Runtime Support : The encrypted_value class supports both compile-time encryption (for constant values) and runtime encryption, providing flexibility for various use cases.

  • Macro Support : The file also includes macros for conveniently creating encrypted values, reducing the likelihood of errors in manual encryption processes.

Example Use Cases:

  • Storing Sensitive Information : Securely store passwords, API keys, or other sensitive data within an application.

  • Data Integrity : Ensure that values stored in memory or passed through functions are not tampered with by encrypting them.

  • Obfuscation : Obfuscate data at rest to protect against reverse engineering or memory dump attacks.

Structure of the File:

  • **Namespace libantispy ** : Contains the main encrypted_value class template.

  • Macros : Provides utility macros for creating encrypted values easily.

  • Test Support : Conditional compilation for testing, allowing developers to verify the encryption and decryption processes.

This file is typically included as part of a broader security framework within a C++ application, where the protection of sensitive data is crucial. It should be used in conjunction with other security best practices, such as secure coding guidelines and data protection strategies.

Defines

ANTISPY_ENCRYPTED_VALUE

Macro for creating an encrypted value.

Detailed Description

The ANTISPY_ENCRYPTED_VALUE macro provides a convenient way to create an instance of the encrypted_value class, which securely stores a value of type T by encrypting it using a predefined encryption key and seed.

Parameters

  • T: The type of the value to be encrypted.

  • n: The name of the variable that will store the encrypted value.

  • v: The value to be encrypted.

The macro does the following:

  • It suppresses potential compiler warnings about overflow using SUPRESS_OVERFLOW_WARN .

  • It defines a variable n of type encrypted_value<T, ANTISPY_ENCRYPTION_SEED, ANTISPY_ENCRYPTION_SEED % (sizeof(T) * CHAR_BIT)> .

  • T is the type of the value.

  • n is the name of the variable.

  • v is the value to be encrypted.

  • The macro initializes the variable n by passing the value v to the constructor of the encrypted_value class.

  • The encryption is performed using a key derived from ANTISPY_ENCRYPTION_SEED , which is a predefined encryption seed.

  • The ANTISPY_ENCRYPTION_SEED % (sizeof(T) * CHAR_BIT) ensures the encryption process uses a modulus based on the size of the type T to avoid overflow issues during encryption.

The SUPRESS_OVERFLOW_WARN directive is used to suppress warnings about potential overflow during encryption, which may occur due to the nature of the mathematical operations performed.

Example

#include <antispy/libantispy.h>

int main() {
   // Example usage of the macro to create an encrypted integer value
   ANTISPY_ENCRYPTED_VALUE(int, myEncryptedValue, 42);
   // This creates an `encrypted_value<int, ...>` instance named `myEncryptedValue` that stores the encrypted form of 42.
}