* '''Symmetric Key Algorithms''': Includes AES, DES, and Camellia. * '''Hash Functions''': Includes SHA-1, SHA-256, SHA-512, MD5, and others. * '''Public Key Algorithms''': Includes RSA, DSA, and ECDSA. * '''Message Authentication Codes (MACs)''': Includes HMAC and CMAC. * '''Random Number Generation''': Provides cryptographically secure random number generation.
* '''Performance''': Optimized for performance, suitable for use in high-throughput applications. * '''Flexibility''': Offers a wide range of cryptographic primitives that can be combined in various ways. * '''Portability''': Designed to be portable across different operating systems and architectures. * '''Interoperability''': Compatible with other cryptographic libraries and standards.
```c #include#include
void aes_encrypt_example() { struct aes_ctx ctx; uint8_t key[16] = "mysecretkey12345"; // 128-bit key uint8_t plaintext[16] = "exampleplaintext"; uint8_t ciphertext[16];
// Initialize AES context with the key aes_set_encrypt_key(&ctx, sizeof(key), key);
// Encrypt the plaintext aes_encrypt(&ctx, sizeof(plaintext), ciphertext, plaintext);
// Print the ciphertext for (int i = 0; i < sizeof(ciphertext); i++) { printf("%02x", ciphertext[i]); } printf("\n"); }
int main() { aes_encrypt_example(); return 0; } ```
```python import ctypes import ctypes.util
# Load the Nettle library nettle = ctypes.CDLL(ctypes.util.find_library('nettle'))
# Define the SHA-256 context structure class Sha256Ctx(ctypes.Structure): _fields_ = [("state", ctypes.c_uint32 * 8), ("count", ctypes.c_uint64), ("block", ctypes.c_uint8 * 64), ("index", ctypes.c_size_t)]
# Initialize the SHA-256 context ctx = Sha256Ctx() nettle.nettle_sha256_init(ctypes.byref(ctx))
# Update the context with the input data data = b"hello world" nettle.nettle_sha256_update(ctypes.byref(ctx), ctypes.c_size_t(len(data)), data)
# Finalize the hash and retrieve the output digest = (ctypes.c_uint8 * 32)() nettle.nettle_sha256_digest(ctypes.byref(ctx), ctypes.c_size_t(len(digest)), digest)
# Print the SHA-256 hash print("SHA-256:", "".join("{:02x}".format(b) for b in digest)) ```