|
Csilk 0.2.1
A lightweight, high-performance C HTTP web framework
|
Default cipher driver implementation (OpenSSL-backed). More...
#include "csilk/drivers/cipher.h"#include <openssl/err.h>#include <openssl/evp.h>#include <openssl/pem.h>#include <openssl/rsa.h>#include <openssl/sha.h>#include <stdint.h>#include <string.h>
Macros | |
| #define | RSA_PSS_SALTLEN_DIGEST -1 |
Functions | |
| static int | default_symmetric_encrypt (const uint8_t *key, size_t key_len, const uint8_t *plaintext, size_t plaintext_len, const uint8_t *iv, size_t iv_len, uint8_t *ciphertext, size_t *ciphertext_len, uint8_t *tag, size_t tag_len) |
| AES-256-GCM symmetric encryption. | |
| static int | default_symmetric_decrypt (const uint8_t *key, size_t key_len, const uint8_t *ciphertext, size_t ciphertext_len, const uint8_t *iv, size_t iv_len, const uint8_t *tag, size_t tag_len, uint8_t *plaintext, size_t *plaintext_len) |
| AES-256-GCM symmetric decryption with authentication tag verification. | |
| static int | default_generate_keypair (char *public_key, size_t *pub_len, char *private_key, size_t *priv_len) |
| Generate an RSA keypair and return PEM-encoded public and private keys. | |
| static EVP_PKEY * | pem_to_pkey (const char *pem, size_t len) |
| Internal: parse a PEM-encoded public key into an EVP_PKEY handle. | |
| static EVP_PKEY * | pem_to_privkey (const char *pem, size_t len) |
| Internal: parse a PEM-encoded private key into an EVP_PKEY handle. | |
| static int | default_asymmetric_encrypt (const char *public_key, size_t pub_len, const uint8_t *plaintext, size_t plaintext_len, uint8_t *ciphertext, size_t *ciphertext_len) |
| RSA-OAEP asymmetric encryption. | |
| static int | default_asymmetric_decrypt (const char *private_key, size_t priv_len, const uint8_t *ciphertext, size_t ciphertext_len, uint8_t *plaintext, size_t *plaintext_len) |
| RSA-OAEP asymmetric decryption. | |
| static int | default_sign (const char *private_key, size_t priv_len, const uint8_t *data, size_t data_len, uint8_t *signature, size_t *sig_len) |
| RSA-PSS digital signature generation. | |
| static int | default_verify (const char *public_key, size_t pub_len, const uint8_t *data, size_t data_len, const uint8_t *signature, size_t sig_len) |
| RSA-PSS digital signature verification. | |
Variables | |
| csilk_cipher_driver_t | csilk_default_cipher_driver |
| Default cipher driver vtable mapping all operations to the OpenSSL-backed implementations above. | |
Default cipher driver implementation (OpenSSL-backed).
Architecture: Provides a concrete implementation of the abstract csilk_cipher_driver_t interface using OpenSSL EVP primitives. This module is the default driver installed by the cipher subsystem. All functions are stateless and thread-safe (OpenSSL is expected to have been configured with locking callbacks at process start).
Supported operations:
| #define RSA_PSS_SALTLEN_DIGEST -1 |
|
static |
RSA-OAEP asymmetric decryption.
Algorithm:
| private_key | PEM-encoded RSA private key. |
| priv_len | Length of private_key string. |
| ciphertext | Input ciphertext (must equal RSA key size). |
| ciphertext_len | Length of ciphertext. |
| plaintext | [out] Output buffer for decrypted data. |
| plaintext_len | [in/out] Input: buffer capacity. Output: plaintext len. |
|
static |
RSA-OAEP asymmetric encryption.
Algorithm:
| public_key | PEM-encoded RSA public key. |
| pub_len | Length of public_key string. |
| plaintext | Input plaintext (max ~190 bytes for 2048-bit RSA). |
| plaintext_len | Length of plaintext. |
| ciphertext | [out] Output buffer for encrypted data. |
| ciphertext_len | [in/out] Input: buffer capacity. Output: ciphertext len. |
|
static |
Generate an RSA keypair and return PEM-encoded public and private keys.
Algorithm:
| public_key | [out] Buffer for PEM-encoded public key. |
| pub_len | [in/out] Input: buffer capacity. Output: actual key length including null terminator. |
| private_key | [out] Buffer for PEM-encoded private key. |
| priv_len | [in/out] Input: buffer capacity. Output: actual key length including null terminator. |
|
static |
RSA-PSS digital signature generation.
Algorithm:
| private_key | PEM-encoded RSA private key. |
| priv_len | Length of private_key string. |
| data | Input data to sign. |
| data_len | Length of data. |
| signature | [out] Output buffer for the signature. |
| sig_len | [in/out] Input: buffer capacity. Output: signature len. |
|
static |
AES-256-GCM symmetric decryption with authentication tag verification.
Algorithm:
| key | 256-bit AES key (must be 32 bytes). |
| key_len | Must be 32. |
| ciphertext | Input encrypted data. |
| ciphertext_len | Length of ciphertext. |
| iv | 96-bit IV (must be 12 bytes). |
| iv_len | Must be 12. |
| tag | 128-bit authentication tag to verify (16 bytes). |
| tag_len | Must be 16. |
| plaintext | [out] Output buffer for decrypted data. |
| plaintext_len | [out] Receives the plaintext length. |
|
static |
AES-256-GCM symmetric encryption.
Algorithm:
| key | 256-bit (32-byte) AES key. |
| key_len | Must be 32. |
| plaintext | Input plaintext. |
| plaintext_len | Length of plaintext. |
| iv | 96-bit (12-byte) initialization vector. |
| iv_len | Must be 12. |
| ciphertext | [out] Output buffer for encrypted data (must be at least plaintext_len + 16 bytes). |
| ciphertext_len | [out] Receives the ciphertext length. |
| tag | [out] 128-bit (16-byte) authentication tag. |
| tag_len | Must be 16. |
|
static |
RSA-PSS digital signature verification.
Algorithm:
| public_key | PEM-encoded RSA public key. |
| pub_len | Length of public_key string. |
| data | Original signed data. |
| data_len | Length of data. |
| signature | Signature to verify. |
| sig_len | Length of signature. |
|
static |
Internal: parse a PEM-encoded public key into an EVP_PKEY handle.
| pem | PEM string buffer. |
| len | Length of the PEM string. |
|
static |
Internal: parse a PEM-encoded private key into an EVP_PKEY handle.
| pem | PEM string buffer. |
| len | Length of the PEM string. |
| csilk_cipher_driver_t csilk_default_cipher_driver |
Default cipher driver vtable mapping all operations to the OpenSSL-backed implementations above.
Installed by the cipher subsystem as the default driver. Callers can override individual operations by building a custom driver struct with different function pointers for specific needs (e.g., hardware-backed keys).