### Link X448 Library in CMake Project Source: https://context7.com/hydra-acn/x448/llms.txt Example CMakeLists.txt configuration to link the X448 static library into your application. This setup includes adding the library's subdirectory and specifying include paths. ```cmake cmake_minimum_required(VERSION 2.8) project(MySecureApp) # Add the X448 library directory add_subdirectory(x448) # Create your executable add_executable(my_app main.c) # Link against the x448 library target_link_libraries(my_app x448) # Include headers target_include_directories(my_app PRIVATE x448/include x448/include/openssl x448/include/arch_32 ) ``` -------------------------------- ### Curve448 Point Operations Example Source: https://context7.com/hydra-acn/x448/llms.txt Demonstrates various operations on curve448 points, including initialization, validation, equality testing, doubling, and scalar multiplication. Remember to securely destroy point data when no longer needed. ```c #include "point_448.h" #include int main() { curve448_point_t point_a, point_b, doubled; curve448_scalar_t scalar; // Initialize with identity point curve448_point_copy(point_a, curve448_point_identity); // Validate a point (useful after deserialization) c448_bool_t is_valid = curve448_point_valid(point_a); if (is_valid == C448_TRUE) { // Point is on the curve } // Test point equality curve448_point_copy(point_b, point_a); c448_bool_t are_equal = curve448_point_eq(point_a, point_b); if (are_equal == C448_TRUE) { // Points are equal } // Double a point: doubled = 2 * point_a curve448_point_double(doubled, point_a); // Scalar multiplication with precomputed base point unsigned char scalar_bytes[C448_SCALAR_BYTES] = {0}; scalar_bytes[0] = 7; // Example scalar curve448_scalar_decode(scalar, scalar_bytes); curve448_point_t result; curve448_precomputed_scalarmul(result, curve448_precomputed_base, scalar); // Securely destroy points when done curve448_point_destroy(point_a); curve448_point_destroy(point_b); curve448_point_destroy(doubled); curve448_point_destroy(result); curve448_scalar_destroy(scalar); return 0; } ``` -------------------------------- ### Standalone Build Instructions Source: https://github.com/hydra-acn/x448/blob/master/README.md Instructions for building the standalone cryptographic library. ```APIDOC ## Stand-alone Build ### Description Instructions to compile the project from source. ### Steps 1. Create a build directory: ```bash mkdir build ``` 2. Change into the build directory: ```bash cd build ``` 3. Configure the build with CMake, specifying the release build type: ```bash cmake -DCMAKE_BUILD_TYPE=Release .. ``` 4. Compile the project: ```bash make ``` ``` -------------------------------- ### Build X448 Static Library with CMake Source: https://context7.com/hydra-acn/x448/llms.txt Instructions for building the X448 library as a static archive using CMake. Ensure you are in the project's root directory before running these commands. ```bash # Create build directory mkdir build cd build # Configure with CMake cmake -DCMAKE_BUILD_TYPE=Release .. # Build the library make # The static library 'libx448.a' will be created in the build directory # Install to system (optional) # sudo make install ``` -------------------------------- ### Build Standalone Project Source: https://github.com/hydra-acn/x448/blob/master/README.md Steps to build the project from source using CMake and Make. Ensure you are in the project's root directory. ```bash mkdir build cd build cmake -DCMAKE_BUILD_TYPE=Release .. make ``` -------------------------------- ### x448 ECDH Key Generation and Exchange Source: https://github.com/hydra-acn/x448/blob/master/README.md Workflow for Alice using x448 to derive a public key and compute a shared secret with Bob. Remember to clean up memory after use by overwriting keys and freeing memory. ```c uint8_t* sk = generate_56_random_bytes(); uint8_t* pk = allocate_56_bytes(); x448_derive_public_key(pk, sk); send_pk_to_bob(pk); uint8_t* bob_pk = receive_56_bytes_from_bob(); uint8_t* shared_secret = allocate_56_bytes(); x448_int(shared_secret, bob_pk, sk); // important: cleanup your memory after use (overwrite keys with 0, free/delete)! ``` -------------------------------- ### x448 ECDH Functions Source: https://github.com/hydra-acn/x448/blob/master/README.md Documentation for the x448 ECDH functions, including key derivation and shared secret computation. ```APIDOC ## x448 ECDH Functions ### Description Provides functions for Elliptic Curve Diffie-Hellman (ECDH) key exchange using the x448 curve. ### Functions #### `c448_error_t x448_int(uint8_t* out, const uint8_t* base, const uint8_t* scalar);` Computes the shared secret using the base point and scalar. #### `void x448_derive_public_key(uint8_t* out, const uint8_t* scalar);` Derives the public key from a given private scalar. ### Workflow for Alice 1. Generate a private scalar (`sk`). 2. Allocate memory for the public key (`pk`). 3. Derive the public key using `x448_derive_public_key(pk, sk)`. 4. Send the public key (`pk`) to Bob. 5. Receive Bob's public key (`bob_pk`). 6. Allocate memory for the shared secret (`shared_secret`). 7. Compute the shared secret using `x448_int(shared_secret, bob_pk, sk)`. 8. **Important**: Clean up memory by overwriting keys with zeros and freeing allocated memory. ``` -------------------------------- ### Derive X448 Public Key Source: https://context7.com/hydra-acn/x448/llms.txt Derives a 56-byte X448 public key from a given private key. The resulting public key can be safely shared. ```c #include "point_448.h" #include int main() { // 56-byte private key (must be random in production) uint8_t private_key[X448_PRIVATE_BYTES] = { 0x9a, 0x8f, 0x49, 0x25, 0xd1, 0x51, 0x9f, 0x57, 0x75, 0xcf, 0x46, 0xb0, 0x4b, 0x58, 0x00, 0xd4, 0xee, 0x9e, 0xe8, 0xba, 0xe8, 0xbc, 0x55, 0x65, 0xd4, 0x98, 0xc2, 0x8d, 0xd9, 0xc9, 0xba, 0xf5, 0x74, 0xa9, 0x41, 0x97, 0x44, 0x89, 0x73, 0x91, 0x00, 0x63, 0x82, 0xa6, 0xf1, 0x27, 0xab, 0x1d, 0x9a, 0xc2, 0xd8, 0xc0, 0xa5, 0x98, 0x72, 0x6b }; // Output buffer for 56-byte public key uint8_t public_key[X448_PUBLIC_BYTES]; // Derive public key from private key x448_derive_public_key(public_key, private_key); // public_key now contains the X448 public key // This can be safely shared with communication partners return 0; } ``` -------------------------------- ### x448 Function Signatures Source: https://github.com/hydra-acn/x448/blob/master/README.md Signatures for the two primary x448 ECDH functions: key exchange and public key derivation. These are defined in `include/point_448.h`. ```c c448_error_t x448_int(uint8_t* out, const uint8_t* base, const uint8_t* scalar); ``` ```c void x448_derive_public_key(uint8_t* out, const uint8_t* scalar); ``` -------------------------------- ### Perform X448 ECDH Key Exchange Source: https://context7.com/hydra-acn/x448/llms.txt Computes the X448 shared secret using a public key and a private key. Ensure sensitive key material is securely cleared after use. ```c #include "point_448.h" #include #include // Generate a random 56-byte private key (use a CSPRNG in production) void generate_private_key(uint8_t private_key[56]) { // In production, use a cryptographically secure random number generator // For example: RAND_bytes(private_key, 56); for (int i = 0; i < 56; i++) { private_key[i] = (uint8_t)(rand() & 0xFF); } } int main() { // Alice's key pair uint8_t alice_private[56]; uint8_t alice_public[56]; // Bob's key pair uint8_t bob_private[56]; uint8_t bob_public[56]; // Shared secrets uint8_t alice_shared[56]; uint8_t bob_shared[56]; // Generate private keys generate_private_key(alice_private); generate_private_key(bob_private); // Derive public keys from private keys x448_derive_public_key(alice_public, alice_private); x448_derive_public_key(bob_public, bob_private); // Alice computes shared secret using Bob's public key c448_error_t alice_result = x448_int(alice_shared, bob_public, alice_private); // Bob computes shared secret using Alice's public key c448_error_t bob_result = x448_int(bob_shared, alice_public, bob_private); if (alice_result == C448_SUCCESS && bob_result == C448_SUCCESS) { // alice_shared and bob_shared should be identical printf("X448 key exchange successful\n"); } // IMPORTANT: Securely clear sensitive key material after use memset(alice_private, 0, 56); memset(bob_private, 0, 56); memset(alice_shared, 0, 56); memset(bob_shared, 0, 56); return 0; } ``` -------------------------------- ### x25519 ECDH Functions Source: https://github.com/hydra-acn/x448/blob/master/README.md Documentation for the x25519 ECDH functions, including key derivation and shared secret computation. ```APIDOC ## x25519 ECDH Functions ### Description Provides functions for Elliptic Curve Diffie-Hellman (ECDH) key exchange using the x25519 curve. ### Functions #### `int X25519(uint8_t out_shared_key[32], const uint8_t private_key[32], const uint8_t peer_public_value[32]);` Computes the shared secret key. #### `void X25519_public_from_private(uint8_t out_public_value[32], const uint8_t private_key[32]);` Derives the public key from a private key. ### Workflow The workflow is analogous to `x448`, but operates with 32-byte keys. ``` -------------------------------- ### Curve448 Scalar Operations Source: https://context7.com/hydra-acn/x448/llms.txt Provides low-level scalar arithmetic operations for curve448. Supports encoding, decoding, addition, subtraction, multiplication, and halving. Ensure scalars are securely destroyed after use. ```c #include "point_448.h" #include #include int main() { // 56-byte serialized scalar unsigned char scalar_bytes[C448_SCALAR_BYTES] = {0}; scalar_bytes[0] = 42; // Simple scalar value for demonstration curve448_scalar_t scalar_a, scalar_b, result; // Decode scalar from bytes c448_error_t decode_result = curve448_scalar_decode(scalar_a, scalar_bytes); if (decode_result != C448_SUCCESS) { // Scalar was larger than modulus and was reduced } // Copy scalar curve448_scalar_copy(scalar_b, scalar_a); // Scalar addition: result = scalar_a + scalar_b curve448_scalar_add(result, scalar_a, scalar_b); // Scalar multiplication: result = scalar_a * scalar_b curve448_scalar_mul(result, scalar_a, scalar_b); // Scalar subtraction: result = scalar_a - scalar_b curve448_scalar_sub(result, scalar_a, scalar_b); // Scalar halving: result = scalar_a / 2 curve448_scalar_halve(result, scalar_a); // Encode scalar back to bytes unsigned char output_bytes[C448_SCALAR_BYTES]; curve448_scalar_encode(output_bytes, result); // Securely destroy scalar values when done curve448_scalar_destroy(scalar_a); curve448_scalar_destroy(scalar_b); curve448_scalar_destroy(result); return 0; } ``` -------------------------------- ### X25519 Public Key Derivation Source: https://context7.com/hydra-acn/x448/llms.txt Derives an X25519 public key from a 32-byte private key. The private key should be random in production environments. The function clamps the private key as per RFC 7748. ```c #include "curve25519.h" #include int main() { // 32-byte private key (should be random in production) uint8_t private_key[32] = { 0xa5, 0x46, 0xe3, 0x6b, 0xf0, 0x52, 0x7c, 0x9d, 0x3b, 0x16, 0x15, 0x4b, 0x82, 0x46, 0x5e, 0xdd, 0x62, 0x14, 0x4c, 0x0a, 0xc1, 0xfc, 0x5a, 0x18, 0x50, 0x6a, 0x22, 0x44, 0xba, 0x44, 0x9a, 0xc4 }; // Output buffer for 32-byte public key uint8_t public_key[32]; // Derive public key X25519_public_from_private(public_key, private_key); // public_key now contains the X25519 public key // ready for distribution to communication partners return 0; } ``` -------------------------------- ### x25519 Function Signatures Source: https://github.com/hydra-acn/x448/blob/master/README.md Signatures for the two primary x25519 ECDH functions: key exchange and public key derivation. These are defined in `include/curve25519.h`. ```c int X25519(uint8_t out_shared_key[32], const uint8_t private_key[32], const uint8_t peer_public_value[32]); ``` ```c void X25519_public_from_private(uint8_t out_public_value[32], const uint8_t private_key[32]); ``` -------------------------------- ### X25519 ECDH Key Exchange Source: https://context7.com/hydra-acn/x448/llms.txt Performs X25519 Elliptic Curve Diffie-Hellman key exchange using 32-byte keys. Ensure keys are valid and the shared secret is not all zeros to prevent small subgroup attacks. ```c #include "curve25519.h" #include #include int main() { // Alice's key pair (32 bytes each) uint8_t alice_private[32] = { 0x77, 0x07, 0x6d, 0x0a, 0x73, 0x18, 0xa5, 0x7d, 0x3c, 0x16, 0xc1, 0x72, 0x51, 0xb2, 0x66, 0x45, 0xdf, 0x4c, 0x2f, 0x87, 0xeb, 0xc0, 0x99, 0x2a, 0xb1, 0x77, 0xfb, 0xa5, 0x1d, 0xb9, 0x2c, 0x2a }; uint8_t alice_public[32]; // Bob's key pair (32 bytes each) uint8_t bob_private[32] = { 0x5d, 0xab, 0x08, 0x7e, 0x62, 0x4a, 0x8a, 0x4b, 0x79, 0xe1, 0x7f, 0x8b, 0x83, 0x80, 0x0e, 0xe6, 0x6f, 0x3b, 0xb1, 0x29, 0x26, 0x18, 0xb6, 0xfd, 0x1c, 0x2f, 0x8b, 0x27, 0xff, 0x88, 0xe0, 0xeb }; uint8_t bob_public[32]; // Shared secrets uint8_t alice_shared[32]; uint8_t bob_shared[32]; // Derive public keys X25519_public_from_private(alice_public, alice_private); X25519_public_from_private(bob_public, bob_private); // Compute shared secrets int alice_success = X25519(alice_shared, alice_private, bob_public); int bob_success = X25519(bob_shared, bob_private, alice_public); if (alice_success && bob_success) { // Verify both parties computed the same shared secret int match = 1; for (int i = 0; i < 32; i++) { if (alice_shared[i] != bob_shared[i]) { match = 0; break; } } if (match) { printf("X25519 key exchange successful - shared secrets match\n"); } } else { printf("X25519 key exchange failed\n"); } return 0; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.