Class ChaosOptionsBuilder

java.lang.Object
org.refcodes.security.alt.chaos.ChaosOptionsBuilder
All Implemented Interfaces:
org.refcodes.mixin.EncodedAccessor, ChaosOptions

public class ChaosOptionsBuilder extends Object implements ChaosOptions
The ChaosOptionsBuilder provides means to create a ChaosOptions instance.
  • Constructor Details

    • ChaosOptionsBuilder

      public ChaosOptionsBuilder(byte[] aEncoded)
      Instantiates the ChaosOptions by reversing the result of the ChaosOptions.getEncoded() operation where the byte array contains the values of the options. The values use a big endian representation. The byte array being passed is to be of the size as returned by ChaosOptions.getEncodedLength(). The meaning of the bits in the encoded byte are defined as in ChaosOptions.OPTIONS_BIT_MUTATE_S, ChaosOptions.OPTIONS_BIT_XOR_NEXT and ChaosOptions.OPTIONS_BIT_SALTED.
      Parameters:
      aEncoded - The encoded representation of the options.
    • ChaosOptionsBuilder

      public ChaosOptionsBuilder(boolean isMutateS, boolean isXorNext, boolean isSalted)
      Constructs the ChaosOptionsBuilder with the given values.
      Parameters:
      isMutateS - Enables or disables the isMutateS() option.
      isXorNext - Enables or disables the isXorNext() option.
      isSalted - Enables or disables the isSalted() option.
    • ChaosOptionsBuilder

      public ChaosOptionsBuilder(boolean isMutateS, boolean isXorNext, boolean isSalted, short aRndPrefixSize)
      Constructs the ChaosOptionsBuilder with the given values.
      Parameters:
      isMutateS - Enables or disables the isMutateS() option.
      isXorNext - Enables or disables the isXorNext() option.
      isSalted - Enables or disables the isSalted() option.
      aRndPrefixSize - The number of bytes to prefix with random bytes.
  • Method Details

    • isXorNext

      public boolean isXorNext()
      Determines whether an XOR obfuscation of the next byte value to be encrypted is to be applied with the previous byte value (before its encryption or zero 0 in case of the first value being processed). XOR does not seem to be too effective obfuscating similar encrypted data with the same ChaosKey, though for low capability devices it can be handy to add that little extra obfuscation to make it hard to interpolate between two similar but different messages. Disclaimer: Using this option "stand alone" in a ChaosKey not in combination with ChaosOptions.isSalted() either in this ChaosKey or in combination with another ChaosKey not completely closes the "comparison" attack vector (see "https://www.metacodes.pro/funcodes/blog/chaos-based_encryption_revisited")
      Specified by:
      isXorNext in interface ChaosOptions
      Returns:
      True in case XOR obfuscation is to be established.
    • isMutateS

      public boolean isMutateS()
      Determines whether a MUTATION operation of the ChaosKey's S value is to be applied with the previous byte value (before its encryption or zero 0 in case of the first value being processed), S then varies by +127 to -128 by each iteration: Nearly equal encrypted datasets will differ chaotically beginning with the the first occurrence of a different byte. Disclaimer: Using this option "stand alone" in a ChaosKey not in combination with ChaosOptions.isSalted() either in this ChaosKey or in combination with another ChaosKey not completely closes the "comparison" attack vector (see "https://www.metacodes.pro/funcodes/blog/chaos-based_encryption_revisited")
      Specified by:
      isMutateS in interface ChaosOptions
      Returns:
      True in case ADD obfuscation is to be established.
    • isSalted

      public boolean isSalted()
      Determines whether an additional SALTING operation with an additional salting (random) ChaosKey is to be applied: The salting ChaosKey's encoded bytes representation (as of ChaosKey.getEncoded()) is prefixed to the actual data which in a first pass is encoded with the this very salting ChaosKey. The salting ChaosKey encoded bytes representation as well as the succeeding initially encoded (salted) data then is encoded with the actual encryption ChaosKey, ensuring that the prefixed salting ChaosKey bytes are encoded. Decryption then is applied in reverse order. Currently only the ChaosEncryptionOutputStream and the ChaosDecryptionInputStream support salting! The ChaosEncrypter and ChaosDecrypter ignore this option!
      Specified by:
      isSalted in interface ChaosOptions
      Returns:
      True in case SALTING is to be established.
    • getRndPrefixSize

      public short getRndPrefixSize()
      Sets the number of random bytes to be prefixed upon a PREFIX operation of decrypted (raw) data when encrypting with the accordingly configured ChaosKey: Prefixing with random bytes will cause the same (succeeding) decrypted (raw) data to be encrypted differently even when using the same ChaosKey configuration. Valid values range from {1..256} representable by one byte as of {0x00..0xFF}. Disclaimer: Using this option "stand alone" in a ChaosKey not in combination with ChaosOptions.isSalted() either in this ChaosKey or in combination with another ChaosKey not close by any means the "comparison" attack vector (see "https://www.metacodes.pro/funcodes/blog/chaos-based_encryption_revisited")
      Specified by:
      getRndPrefixSize in interface ChaosOptions
      Returns:
      The number of bytes for establishing the PREFIX functionality, 0 if no prefixing is to be applied at all.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Returns true if all the passed object is of type ChaosOptions and all the attributes from the ChaosOptions are equal to this instance's attributes (as of ChaosOptions.isMutateS(), ChaosOptions.isXorNext() and ChaosOptions.isSalted()).
      Specified by:
      equals in interface ChaosOptions
      Overrides:
      equals in class Object
      Parameters:
      obj - the object to compare with for equality.
      Returns:
      true, if equal
    • builder

      public static ChaosOptionsBuilder.Builder builder()
      Creates builder to build ChaosOptionsBuilder.
      Returns:
      created builder