### Using Deterministic IP Encryption - ipcrypt - Zig Source: https://github.com/jedisct1/zig-ipcrypt/blob/main/README.md Demonstrates how to use the deterministic ipcrypt variant. It shows initialization with a 16-byte key, converting a string IP address to the internal `Ip16` format, performing the encryption, and then decryption. Requires the `ipcrypt` library as a dependency. ```Zig const ipcrypt = @import("ipcrypt"); // Initialize with a 16-byte key const key = [_]u8{0x2b} ** 16; const deterministic = ipcrypt.Deterministic.init(key); // Convert IP address to Ip16 format const ip = try ipcrypt.Ip16.fromString("192.0.2.1"); // Encrypt const encrypted = deterministic.encrypt(ip); // Decrypt const decrypted = deterministic.decrypt(encrypted); ``` -------------------------------- ### Adding ipcrypt Dependency - build.zig.zon - Zig Source: https://github.com/jedisct1/zig-ipcrypt/blob/main/README.md Provides the configuration required to add the `zig-ipcrypt` library as a dependency in a Zig project's `build.zig.zon` file. It specifies the package name, source URL, and the required hash for caching and integrity. This is the first step in integrating the library into a Zig project. ```Zig .{ .name = "ipcrypt", .url = "https://github.com/yourusername/zig-ipcrypt/archive/refs/tags/v0.1.0.tar.gz", .hash = "1220...", } ``` -------------------------------- ### Using Non-deterministic IP Encryption (KIASU-BC) - ipcrypt - Zig Source: https://github.com/jedisct1/zig-ipcrypt/blob/main/README.md Illustrates the usage of the non-deterministic ipcrypt variant using KIASU-BC. It covers initialization with a 16-byte key, converting an IP to `Ip16`, encrypting using a randomly generated tweak, encrypting with a user-provided 8-byte tweak, and decrypting the output. Requires the `ipcrypt` library as a dependency. ```Zig const ipcrypt = @import("ipcrypt"); // Initialize with a 16-byte key const key = [_]u8{0x2b} ** 16; const nd = ipcrypt.DeterministicNd.init(key); // Convert IP address to Ip16 format const ip = try ipcrypt.Ip16.fromString("2001:db8::1"); // Encrypt with random tweak const encrypted = nd.encrypt(ip); // Encrypt with specific tweak const tweak = [_]u8{0x2b} ** 8; const encrypted_with_tweak = nd.encryptWithTweak(ip, tweak); // Decrypt const decrypted = nd.decrypt(encrypted); ``` -------------------------------- ### Integrating ipcrypt Dependency - build.zig - Zig Source: https://github.com/jedisct1/zig-ipcrypt/blob/main/README.md Shows how to integrate the `zig-ipcrypt` library dependency within a Zig project's `build.zig` file. It retrieves the dependency and adds its module to the executable, making the library's functions available for use in the project's source code. This follows adding the dependency in `build.zig.zon`. ```Zig const ipcrypt = b.dependency("ipcrypt", .{ .target = target, .optimize = optimize, }); exe.addModule("ipcrypt", ipcrypt.module("ipcrypt")); ``` -------------------------------- ### Using Non-deterministic IP Encryption (AES-XTS) - ipcrypt - Zig Source: https://github.com/jedisct1/zig-ipcrypt/blob/main/README.md Shows how to use the non-deterministic ipcrypt variant based on AES-XTS. It demonstrates initialization with a 32-byte key, converting an IP to `Ip16`, encrypting using a randomly generated tweak, encrypting with a user-provided 16-byte tweak, and decrypting the result. Requires the `ipcrypt` library as a dependency. ```Zig const ipcrypt = @import("ipcrypt"); // Initialize with a 32-byte key const key = [_]u8{0x2b} ** 32; const ndx = ipcrypt.DeterministicNdx.init(key); // Convert IP address to Ip16 format const ip = try ipcrypt.Ip16.fromString("2001:db8::1"); // Encrypt with random tweak const encrypted = ndx.encrypt(ip); // Encrypt with specific tweak const tweak = [_]u8{0x2b} ** 16; const encrypted_with_tweak = ndx.encryptWithTweak(ip, tweak); // Decrypt const decrypted = ndx.decrypt(encrypted); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.