/**
* @brief NULL value for the crypto context.
+ *
+ * @since_tizen 3.0
*/
#define YACA_CTX_NULL ((yaca_ctx_h) NULL)
/**
* @brief Initializes the library. Must be called before any other crypto function.
*
+ * @since_tizen 3.0
+ *
* @return 0 on success, negative on error.
* @see yaca_exit()
*/
/**
* @brief Closes the library. Must be called before exiting the application.
*
+ * @since_tizen 3.0
+ *
* @see yaca_init()
*/
void yaca_exit(void);
/**
* @brief Allocates the memory.
*
+ * @since_tizen 3.0
+ *
* @param[in] size Size of the allocation (bytes).
*
* @return NULL on failure, pointer to allocated memory otherwise.
/**
* @brief Allocates the zeroed memory.
*
+ * @since_tizen 3.0
+ *
* @param[in] size Size of the allocation (bytes).
*
* @return NULL on failure, pointer to allocated and zeroed memory otherwise.
/**
* @brief Re-allocates the memory.
*
+ * @since_tizen 3.0
+ *
* @param[in] addr Address of the memory to be reallocated.
* @param[in] size Size of the new allocation (bytes).
*
* @brief Frees the memory allocated by yaca_malloc(), yaca_zalloc(),
* yaca_realloc() or one of the cryptographic operations.
*
+ * @since_tizen 3.0
+ *
* @param[in] ptr Pointer to the memory to be freed.
* @see yaca_malloc(), yaca_zalloc(), yaca_realloc()
*
/**
* @brief Generates random data.
*
+ * @since_tizen 3.0
+ *
* @param[in,out] data Pointer to the memory to be randomized.
* @param[in] data_len Length of the memory to be randomized.
*
* @brief Sets the extended context parameters. Can only be called on an
* initialized context.
*
+ * @since_tizen 3.0
+ *
* @param[in,out] ctx Previously initialized crypto context.
* @param[in] param Parameter to be set.
* @param[in] value Parameter value.
* @brief Returns the extended context parameters. Can only be called on an
* initialized context.
*
+ * @since_tizen 3.0
+ *
* @param[in] ctx Previously initialized crypto context.
* @param[in] param Parameter to be read.
* @param[out] value Copy of the parameter value (must be freed with yaca_free()).
* @brief Destroys the crypto context. Must be called on all contexts that are
* no longer used. Passing YACA_CTX_NULL is allowed.
*
+ * @since_tizen 3.0
+ *
* @param[in,out] ctx Crypto context.
* @see #yaca_ctx_h
*
* @brief Returns the output length for a given algorithm. Can only be called
* on an initialized context.
*
+ * @since_tizen 3.0
+ *
* @param[in] ctx Previously initialized crypto context.
* @param[in] input_len Length of the input data to be processed.
* @param[in] output_len Required length of the output.
/**
* @brief Wrapper - returns the length of the digest (for a given context).
+ *
+ * @since_tizen 3.0
*/
#define yaca_get_digest_length(ctxa, output_len) yaca_get_output_length((ctxa), 0, (output_len))
/**
* @brief Wrapper - returns the length of the signature (for a given context).
+ *
+ * @since_tizen 3.0
*/
#define yaca_get_sign_length(ctxa, output_len) yaca_get_output_length((ctxa), 0, (output_len))
/**
* @brief Wrapper - returns the length of the block (for a given context).
+ *
+ * @since_tizen 3.0
*/
#define yaca_get_block_length(ctxa, output_len) yaca_get_output_length((ctxa), 0, (output_len))
/**
* @brief Safely compares first @b len bytes of two buffers.
*
+ * @since_tizen 3.0
+ *
* @param[in] first Pointer to the first buffer.
* @param[in] second Pointer to the second buffer.
* @param[in] len Length to compare.
/**
* @brief Initializes a digest context.
*
+ * @since_tizen 3.0
+ *
* @param[out] ctx Newly created context (must be freed with yaca_ctx_free()).
* @param[in] algo Digest algorithm that will be used.
*
/**
* @brief Feeds the data into the message digest algorithm.
*
+ * @since_tizen 3.0
+ *
* @param[in,out] ctx Context created by yaca_digest_init().
* @param[in] data Data from which the digest is to be calculated.
* @param[in] data_len Length of the data.
/**
* @brief Calculates the final digest.
*
+ * @since_tizen 3.0
+ *
* @param[in,out] ctx A valid digest context.
* @param[out] digest Buffer for the message digest (must be allocated by client,
* see yaca_get_digest_length()).
/**
* @brief Initializes an encryption context.
*
+ * @since_tizen 3.0
+ *
* @param[out] ctx Newly created context (must be freed with yaca_ctx_free()).
* @param[in] algo Encryption algorithm that will be used.
* @param[in] bcm Chaining mode that will be used.
/**
* @brief Encrypts chunk of the data.
*
+ * @since_tizen 3.0
+ *
* @param[in,out] ctx Context created by yaca_encrypt_init().
* @param[in] plain Plain text to be encrypted.
* @param[in] plain_len Length of the plain text.
/**
* @brief Encrypts the final chunk of the data.
*
+ * @since_tizen 3.0
+ *
* @param[in,out] ctx A valid encrypt context.
* @param[out] cipher Final piece of the encrypted data (must be allocated by client, see
* yaca_get_block_length()).
/**
* @brief Initializes an decryption context.
*
+ * @since_tizen 3.0
+ *
* @param[out] ctx Newly created context (must be freed with yaca_ctx_free()).
* @param[in] algo Encryption algorithm that was used to encrypt the data.
* @param[in] bcm Chaining mode that was used to encrypt the data.
/**
* @brief Decrypts chunk of the data.
*
+ * @since_tizen 3.0
+ *
* @param[in,out] ctx Context created by yaca_decrypt_init().
* @param[in] cipher Cipher text to be decrypted.
* @param[in] cipher_len Length of the cipher text.
/**
* @brief Decrypts the final chunk of the data.
*
+ * @since_tizen 3.0
+ *
* @param[in,out] ctx A valid decrypt context.
* @param[out] plain Final piece of the decrypted data (must be allocated by client, see
* yaca_get_block_length()).
/**
* @brief Returns the recomended/default length of the IV for a given encryption configuration.
*
- * If returned iv_bits equals 0 that means that for this
- * specific algorithm and its parameters IV is not used.
+ * @since_tizen 3.0
+ *
+ * @remarks If returned iv_bits equals 0 that means that for this
+ * specific algorithm and its parameters IV is not used.
*
* @param[in] algo Encryption algorithm.
* @param[in] bcm Chain mode.
#ifndef YACA_ERROR_H
#define YACA_ERROR_H
+#include <tizen.h>
+
#ifdef __cplusplus
extern "C" {
#endif
+
+#define TIZEN_ERROR_YACA -0x01E30000
+
/**
* @defgroup Error Yet another Crypto API - error enums.
*
*/
/**
- * @brief Error enums
+ * @brief Error enums
+ *
+ * @since_tizen 3.0
*/
enum __yaca_error_code {
- YACA_ERROR_NONE = 0,
- YACA_ERROR_INVALID_ARGUMENT = -1,
- YACA_ERROR_NOT_IMPLEMENTED = -2,
- YACA_ERROR_INTERNAL = -3,
- YACA_ERROR_TOO_BIG_ARGUMENT = -4,
- YACA_ERROR_OUT_OF_MEMORY = -5,
- YACA_ERROR_DATA_MISMATCH = -6,
- YACA_ERROR_PASSWORD_INVALID = -7
+ YACA_ERROR_NONE = TIZEN_ERROR_NONE,
+ YACA_ERROR_INVALID_ARGUMENT = TIZEN_ERROR_INVALID_PARAMETER,
+
+ YACA_ERROR_NOT_IMPLEMENTED = TIZEN_ERROR_YACA | 0x01,
+ YACA_ERROR_INTERNAL = TIZEN_ERROR_YACA | 0x02,
+ YACA_ERROR_TOO_BIG_ARGUMENT = TIZEN_ERROR_YACA | 0x03,
+ YACA_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_YACA | 0x04,
+ YACA_ERROR_DATA_MISMATCH = TIZEN_ERROR_YACA | 0x05,
+ YACA_ERROR_PASSWORD_INVALID = TIZEN_ERROR_YACA | 0x06
};
/**@}*/
/**
* @brief Get key's type.
*
+ * @since_tizen 3.0
+ *
* @param[in] key Key which type we return.
* @param[out] key_type Key type.
*
/**
* @brief Get key's length (in bits).
*
+ * @since_tizen 3.0
+ *
* @param[in] key Key which length we return.
* @param[out] key_bits Key length in bits.
*
/**
* @brief Imports a key.
*
- * This function imports a key trying to match it to the key_type specified.
- * It should autodetect both, key format and file format.
+ * @since_tizen 3.0
*
- * For symmetric, IV and DES keys RAW binary format and BASE64 encoded
- * binary format are supported.
- * For asymmetric keys PEM and DER file formats are supported.
+ * @remarks This function imports a key trying to match it to the key_type specified.
+ * It should autodetect both, key format and file format.
*
- * Asymmetric keys can be in PKCS#1 or SSleay key formats (for RSA and
- * DSA respectively). Asymmetric private keys can also be in PKCS#8
- * format. Additionally it is possible to import public RSA key from
- * X509 certificate.
+ * For symmetric, IV and DES keys RAW binary format and BASE64 encoded
+ * binary format are supported.
+ * For asymmetric keys PEM and DER file formats are supported.
*
- * If the key is encrypted the algorithm will be autodetected and password
- * used. If it's not known if the key is encrypted one should pass NULL as
- * password and check for the YACA_ERROR_PASSWORD_INVALID return code.
+ * Asymmetric keys can be in PKCS#1 or SSleay key formats (for RSA and
+ * DSA respectively). Asymmetric private keys can also be in PKCS#8
+ * format. Additionally it is possible to import public RSA key from
+ * X509 certificate.
+ *
+ * If the key is encrypted the algorithm will be autodetected and password
+ * used. If it's not known if the key is encrypted one should pass NULL as
+ * password and check for the YACA_ERROR_PASSWORD_INVALID return code.
*
* @param[out] key Returned key (must be freed with yaca_key_free()).
* @param[in] key_type Type of the key.
/**
* @brief Exports a key to arbitrary format. Export may fail if key is HW-based.
*
- * This function exports the key to an arbitrary key format and key file format.
+ * @since_tizen 3.0
+ *
+ * @remarks This function exports the key to an arbitrary key format and key file format.
*
- * For key formats two values are allowed:
- * - #YACA_KEY_FORMAT_DEFAULT: this is the only option possible in case of symmetric keys (or IV),
- * for asymmetric keys it will choose PKCS#1 for RSA and SSLeay for DSA.
- * - #YACA_KEY_FORMAT_PKCS8: this will only work for private asymmetric keys.
+ * For key formats two values are allowed:
+ * - #YACA_KEY_FORMAT_DEFAULT: this is the only option possible in case of symmetric keys (or IV),
+ * for asymmetric keys it will choose PKCS#1 for RSA and SSLeay for DSA.
+ * - #YACA_KEY_FORMAT_PKCS8: this will only work for private asymmetric keys.
*
- * The following file formats are supported:
- * - #YACA_KEY_FILE_FORMAT_RAW: used only for symmetric, raw binary format
- * - #YACA_KEY_FILE_FORMAT_BASE64: used only for symmetric, BASE64 encoded binary form
- * - #YACA_KEY_FILE_FORMAT_PEM: used only for asymmetric, PEM file format
- * - #YACA_KEY_FILE_FORMAT_DER: used only for asymmetric, DER file format
+ * The following file formats are supported:
+ * - #YACA_KEY_FILE_FORMAT_RAW: used only for symmetric, raw binary format
+ * - #YACA_KEY_FILE_FORMAT_BASE64: used only for symmetric, BASE64 encoded binary form
+ * - #YACA_KEY_FILE_FORMAT_PEM: used only for asymmetric, PEM file format
+ * - #YACA_KEY_FILE_FORMAT_DER: used only for asymmetric, DER file format
*
- * If no password is provided the exported key will be unencrypted. Only private
- * RSA/DSA exported as PEM can be encrypted.
+ * If no password is provided the exported key will be unencrypted. Only private
+ * RSA/DSA exported as PEM can be encrypted.
*
- * TODO: document the default encryption algorithm (AES256 for FORMAT_DEFAULT,
- * unknown yet for the FORMAT_PKCS8)
+ * TODO:document the default encryption algorithm (AES256 for FORMAT_DEFAULT,
+ * unknown yet for the FORMAT_PKCS8).
*
* @param[in] key Key to be exported.
* @param[in] key_fmt Format of the key.
/**
* @brief Generates a secure key (or an initialization vector).
*
- * This function is used to generate symmetric and private asymmetric keys.
+ * @since_tizen 3.0
+ *
+ * @remarks This function is used to generate symmetric and private asymmetric keys.
*
* @param[out] key Newly generated key (must be freed with yaca_key_free()).
* @param[in] key_type Type of the key to be generated.
/**
* @brief Extracts public key from a private one.
*
+ * @since_tizen 3.0
+ *
* @param[in] prv_key Private key to extract the public one from.
* @param[out] pub_key Extracted public key (must be freed with yaca_key_free()).
*
/**
* @brief Frees the key created by the library. Passing YACA_KEY_NULL is allowed.
*
+ * @since_tizen 3.0
+ *
* @param key Key to be freed.
* @see yaca_key_import(), yaca_key_export(), yaca_key_gen()
*
/**
* @brief Derives a key from user password (PKCS #5 a.k.a. pbkdf2 algorithm).
*
+ * @since_tizen 3.0
+ *
* @param[in] password User password as a NULL-terminated string.
* @param[in] salt Salt, should be non-zero.
* @param[in] salt_len Length of the salt.
/**
* @brief Initializes an asymmetric encryption context.
*
+ * @since_tizen 3.0
+ *
* @param[out] ctx Newly created context (must be freed with yaca_ctx_free()).
* @param[in] pub_key Public key of the peer that will receive the encrypted data.
* @param[in] algo Symmetric algorithm that will be used.
/**
* @brief Encrypts piece of the data.
*
+ * @since_tizen 3.0
+ *
* @param[in,out] ctx Context created by yaca_seal_init().
* @param[in] plain Plain text to be encrypted.
* @param[in] plain_len Length of the plain text.
/**
* @brief Encrypts the final piece of the data.
*
+ * @since_tizen 3.0
+ *
* @param[in,out] ctx A valid seal context.
* @param[out] cipher Final piece of the encrypted data (must be allocated by client, see
* yaca_get_block_length()).
/**
* @brief Initializes an asymmetric decryption context.
*
+ * @since_tizen 3.0
+ *
* @param[out] ctx Newly created context. Must be freed by yaca_ctx_free().
* @param[in] prv_key Private key, part of the pair that was used for the encryption.
* @param[in] algo Symmetric algorithm that was used for the encryption.
/**
* @brief Decrypts piece of the data.
*
+ * @since_tizen 3.0
+ *
* @param[in,out] ctx Context created by yaca_open_init().
* @param[in] cipher Cipher text to be decrypted.
* @param[in] cipher_len Length of the cipher text.
/**
* @brief Decrypts last chunk of sealed message.
*
+ * @since_tizen 3.0
+ *
* @param[in,out] ctx A valid open context.
* @param[out] plain Final piece of the decrypted data (must be allocated by client, see
* yaca_get_block_length()).
/**
* @brief Initializes a signature context for asymmetric signatures.
*
- * For verification use yaca_verify_init(), yaca_verify_update() and
- * yaca_verify_final() functions with matching public key.
+ * @since_tizen 3.0
+ *
+ * @remarks For verification use yaca_verify_init(), yaca_verify_update() and
+ * yaca_verify_final() functions with matching public key.
*
* @param[out] ctx Newly created context (must be freed with yaca_ctx_free()).
* @param[in] algo Digest algorithm that will be used.
/**
* @brief Initializes a signature context for HMAC.
*
- * For verification, calculate message HMAC and compare with received MAC using
- * yaca_memcmp().
+ * @since_tizen 3.0
+ *
+ * @remarks For verification, calculate message HMAC and compare with received MAC using
+ * yaca_memcmp().
*
* @param[out] ctx Newly created context (must be freed with yaca_ctx_free()).
* @param[in] algo Digest algorithm that will be used.
/**
* @brief Initializes a signature context for CMAC.
*
- * For verification, calculate message CMAC and compare with received MAC using
- * yaca_memcmp().
+ * @since_tizen 3.0
+ *
+ * @remarks For verification, calculate message CMAC and compare with received MAC using
+ * yaca_memcmp().
*
* @param[out] ctx Newly created context (must be freed with yaca_ctx_free()).
* @param[in] algo Encryption algorithm that will be used.
/**
* @brief Feeds the data into the digital signature or MAC algorithm.
*
+ * @since_tizen 3.0
+ *
* @param[in,out] ctx Context created by yaca_sign_init(),
* yaca_sign_hmac_init() or yaca_sign_cmac_init().
* @param[in] data Data to be signed.
/**
* @brief Calculates the final signature or MAC.
*
+ * @since_tizen 3.0
+ *
* @param[in,out] ctx A valid sign context.
* @param[out] signature Buffer for the MAC or the signature,
* (must be allocated by client, see yaca_get_sign_length()).
/**
* @brief Initializes a signature verification context for asymmetric signatures
*
+ * @since_tizen 3.0
+ *
* @param[out] ctx Newly created context (must be freed with yaca_ctx_free()).
* @param[in] algo Digest algorithm that will be used.
* @param[in] key Public key that will be used. Algorithm is deduced based on
/**
* @brief Feeds the data into the digital signature verification algorithm.
*
+ * @since_tizen 3.0
+ *
* @param[in,out] ctx Context created by yaca_verify_init().
* @param[in] data Data to be verified.
* @param[in] data_len Length of the data.
/**
* @brief Performs the verification.
*
+ * @since_tizen 3.0
+ *
* @param[in,out] ctx A valid verify context.
* @param[in] signature Input signature (returned by yaca_sign_final()).
* @param[in] signature_len Size of the signature.
/**
* @brief Calculate a digest of a buffer.
*
+ * @since_tizen 3.0
+ *
* @param[in] algo Digest algorithm (select #YACA_DIGEST_SHA256 if unsure).
* @param[in] data Data from which the digest is to be calculated.
* @param[in] data_len Length of the data.
/**
* @brief Encrypt data using a symmetric cipher.
*
+ * @since_tizen 3.0
+ *
* @param[in] algo Encryption algorithm (select #YACA_ENC_AES if unsure).
* @param[in] bcm Chaining mode (select #YACA_BCM_CBC if unsure).
* @param[in] sym_key Symmetric encryption key (see key.h for key generation functions).
/**
* @brief Decrypt data using a symmetric cipher.
*
+ * @since_tizen 3.0
+ *
* @param[in] algo Decryption algorithm that was used to encrypt the data.
* @param[in] bcm Chaining mode that was used to encrypt the data.
* @param[in] sym_key Symmetric encryption key that was used to encrypt the data.
/**
* @brief Create a signature using asymmetric private key.
*
+ * @since_tizen 3.0
+ *
* @param[in] algo Digest algorithm that will be used.
* @param[in] key Private key that will be used. Algorithm is
* deduced based on key type. Supported key types:
/**
* @brief Verify a signature using asymmetric public key.
*
+ * @since_tizen 3.0
+ *
* @param[in] algo Digest algorithm that will be used.
* @param[in] key Public key that will be used. Algorithm is
* deduced based on key type. Supported key types:
/**
* @brief Calculate a HMAC of given message using symmetric key.
*
- * For verification, calculate message HMAC and compare with received MAC using
- * yaca_memcmp().
+ * @since_tizen 3.0
+ *
+ * @remarks For verification, calculate message HMAC and compare with received MAC using
+ * yaca_memcmp().
*
* @param[in] algo Digest algorithm that will be used.
* @param[in] key Key that will be used. Supported key types:
/**
* @brief Calculate a CMAC of given message using symmetric key.
*
- * For verification, calculate message CMAC and compare with received MAC using
- * yaca_memcmp().
+ * @since_tizen 3.0
+ *
+ * @remarks For verification, calculate message CMAC and compare with received MAC using
+ * yaca_memcmp().
*
* @param[in] algo Encryption algorithm that will be used.
* @param[in] key Key that will be used. Supported key types:
/**
* @brief Context
+ *
+ * @since_tizen 3.0
*/
typedef struct yaca_ctx_s *yaca_ctx_h;
/**
* @brief Key
+ *
+ * @since_tizen 3.0
*/
typedef struct yaca_key_s *yaca_key_h;
/**
* @brief Key formats
+ *
+ * @since_tizen 3.0
*/
typedef enum {
YACA_KEY_FORMAT_DEFAULT, /**< key is either PKCS#1 for RSA or SSLeay for DSA, also use this option for symmetric */
/**
* @brief Key file formats
+ *
+ * @since_tizen 3.0
*/
typedef enum {
YACA_KEY_FILE_FORMAT_RAW, /**< key file is in raw binary format, used for symmetric keys */
/**
* @brief Key types, IV is considered as key
+ *
+ * @since_tizen 3.0
*/
typedef enum {
YACA_KEY_TYPE_SYMMETRIC, /**< Generic symmetric cipher KEY */
/**
* @brief Key length, It is possible to use arbitrary integer instead, this enums are placed here to avoid magic numbers.
+ *
+ * @since_tizen 3.0
*/
typedef enum {
YACA_KEY_IV_UNSAFE_24BIT = 24, /**< 24-bit IV */
/**
* @brief Message digest algorithms.
+ *
+ * @since_tizen 3.0
*/
typedef enum {
YACA_DIGEST_MD5, /**< Message digest algorithm MD5 */
/**
* @brief Symmetric encryption algorithms
+ *
+ * @since_tizen 3.0
*/
typedef enum {
/**
/**
* @brief Chaining modes for block ciphers
+ *
+ * @since_tizen 3.0
*/
typedef enum {
/**
/**
* @brief Non-standard parameters for algorithms
+ *
+ * @since_tizen 3.0
*/
typedef enum {
YACA_PARAM_PADDING, /**< Padding */
/**
* @brief Paddings supported by Yet Another Crypto API
+ *
+ * @since_tizen 3.0
*/
typedef enum {
YACA_PADDING_NONE = 0, /**< total number of data MUST multiple of block size, Default */
Group: Security/Other
Summary: Yet Another Crypto API
BuildRequires: cmake
+BuildRequires: pkgconfig(capi-base-common)
BuildRequires: pkgconfig(openssl)
Requires(post): /sbin/ldconfig
Requires(postun): /sbin/ldconfig
VERSION ${_LIB_VERSION_})
## Link libraries ##############################################################
-PKG_CHECK_MODULES(YACA_DEPS REQUIRED openssl)
+PKG_CHECK_MODULES(YACA_DEPS REQUIRED openssl capi-base-common)
INCLUDE_DIRECTORIES(${API_FOLDER})
INCLUDE_DIRECTORIES(SYSTEM ${YACA_DEPS_INCLUDE_DIRS})