TAAFT
Free mode
100% free
Freemium
Free Trial
Deals

jedisct1 / ipcrypt-elixir

IPCrypt implementation in Elixir

6 0 Language: Elixir License: MIT Updated: 6mo ago

README

IPCrypt Elixir Implementation

This is an Elixir implementation of the IPCrypt specification for IP address encryption and obfuscation.

Features

  • ipcrypt-deterministic: Deterministic encryption using AES-128
  • ipcrypt-pfx: Prefix-preserving encryption using dual AES-128
  • ipcrypt-nd: Non-deterministic encryption using KIASU-BC with 8-byte tweaks
  • ipcrypt-ndx: Non-deterministic encryption using AES-XTS with 16-byte tweaks

Installation

Add ipcrypt to your list of dependencies in mix.exs:

def deps do
  [
    {:ipcrypt, "~> 0.2.0"}
  ]
end

Usage

# Deterministic encryption
key16 = <<1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16>>
ip = "192.0.2.1"
encrypted_ip = IPCrypt.Deterministic.encrypt(ip, key16)
decrypted_ip = IPCrypt.Deterministic.decrypt(encrypted_ip, key16)

# Prefix-preserving encryption
key32 = <<1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32>>
encrypted_ip_pfx = IPCrypt.Pfx.encrypt(ip, key32)
decrypted_ip_pfx = IPCrypt.Pfx.decrypt(encrypted_ip_pfx, key32)

# Non-deterministic encryption with KIASU-BC
encrypted_data_nd = IPCrypt.Nd.encrypt(ip, key16)
decrypted_ip_nd = IPCrypt.Nd.decrypt(encrypted_data_nd, key16)

# Non-deterministic encryption with AES-XTS
encrypted_data_ndx = IPCrypt.Ndx.encrypt(ip, key32)
decrypted_ip_ndx = IPCrypt.Ndx.decrypt(encrypted_data_ndx, key32)

You can also use the main module for a unified interface:

# Using the main IPCrypt module
encrypted_ip = IPCrypt.encrypt(ip, key32, :pfx)
decrypted_ip = IPCrypt.decrypt(encrypted_ip, key32, :pfx)

Testing

To run the tests:

mix test

The tests verify the implementation against the official test vectors from the IPCrypt specification.

License

This implementation is released under the MIT license.

0 AIs selected
Clear selection
#
Name
Task