CMAKE_MINIMUM_REQUIRED (VERSION 2.6.2)
-PROJECT(owl)
+PROJECT(yaca)
SET(VERSION "0.0.1")
## pkgconfig ###################################################################
IF (( "${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" AND NOT (CMAKE_C_COMPILER_VERSION VERSION_LESS 4.9))
OR ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" ))
- IF (OWL_BUILD_FORCE_COMPILER_COLORS)
+ IF (YACA_BUILD_FORCE_COMPILER_COLORS)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fdiagnostics-color=always")
ENDIF()
ENDIF()
+++ /dev/null
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Contact: Krzysztof Jackiewicz <k.jackiewicz@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License
- */
-
-/**
- * @file types.h
- * @brief
- */
-
-#ifndef TYPES_H
-#define TYPES_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @defgroup Crypto-Types Enumerations for CryptoAPI
- *
- * TODO: extended description.
- *
- * @{
- */
-
-/**
- * @brief Context
- */
-typedef struct owl_ctx_s *owl_ctx_h;
-
-/**
- * @brief Key
- */
-typedef struct owl_key_s *owl_key_h;
-
-/**
- * @brief Key formats
- */
-typedef enum {
- OWL_KEY_FORMAT_RAW, /**< key is in clear format */
- OWL_KEY_FORMAT_BASE64, /**< key is encoded in ASCII-base64 */
- OWL_KEY_FORMAT_PEM, /**< key is in PEM file format */
- OWL_KEY_FORMAT_DER /**< key is in DER file format */
-} owl_key_fmt_e;
-
-/**
- * @brief Key types, IV is considered as key
- */
-typedef enum {
- OWL_KEY_TYPE_SYMMETRIC, /**< Generic symmetric cipher KEY */
- OWL_KEY_TYPE_DES, /**< DES* key - must be handled differently because of parity bits */
- OWL_KEY_TYPE_IV, /**< IV for symmetric algorithms */
-
- OWL_KEY_TYPE_RSA_PUB, /**< RSA public key */
- OWL_KEY_TYPE_RSA_PRIV, /**< RSA private key */
-
- OWL_KEY_TYPE_DSA_PUB, /**< DSA public key */
- OWL_KEY_TYPE_DSA_PRIV, /**< DSA private key */
-
- OWL_KEY_TYPE_DH_PUB, /**< Diffie-Hellman public key */
- OWL_KEY_TYPE_DH_PRIV, /**< Diffie-Hellman private key */
-
- OWL_KEY_TYPE_ECC_PUB, /**< ECC public key */
- OWL_KEY_TYPE_ECC_PRIV, /**< ECC private key */
-
- OWL_KEY_TYPE_PAIR_RSA, /**< Pair of RSA keys */
- OWL_KEY_TYPE_PAIR_DSA, /**< Pair of DSA keys */
- OWL_KEY_TYPE_PAIR_DH, /**< Pair of Diffie-Hellman keys */
- OWL_KEY_TYPE_PAIR_ECC /**< Pair of ECC keys */
-} owl_key_type_e;
-
-/**
- * @brief Key length, It is possible to use arbitrary integer instead, this enums are placed here to avoid magic numbers.
- */
-typedef enum {
- OWL_KEY_IV_UNSAFE_24BIT = 24, /**< 24-bit IV */
- OWL_KEY_IV_64BIT = 64, /**< 64-bit IV */
- OWL_KEY_IV_128BIT = 128, /**< 128-bit IV */
- OWL_KEY_IV_256BIT = 256, /**< 256-bit IV */
- OWL_KEY_CURVE_P192 = 192, /**< ECC: P192 curve */
- OWL_KEY_CURVE_P256 = 256, /**< ECC: P-256 curve */
- OWL_KEY_CURVE_P384 = 384, /**< ECC: SECP-384 curve */
- OWL_KEY_UNSAFE_40BIT = 40,
- OWL_KEY_UNSAFE_56BIT = 56,
- OWL_KEY_UNSAFE_80BIT = 80,
- OWL_KEY_UNSAFE_112BIT = 112,
- OWL_KEY_UNSAFE_128BIT = 128,
- OWL_KEY_192BIT = 192,
- OWL_KEY_256BIT = 256,
- OWL_KEY_512BIT = 512,
- OWL_KEY_1024BIT = 1024,
- OWL_KEY_2048BIT = 2048,
- OWL_KEY_3072BIT = 3072,
- OWL_KEY_4096BIT = 4096
-} owl_key_len_e;
-
-/**
- * @brief Message digest algorithms. CMAC is included to simplify API
- */
-typedef enum {
- OWL_DIGEST_MD5, /**< Message digest algorithm MD5 */
- OWL_DIGEST_SHA1, /**< Message digest algorithm SHA1 */
- OWL_DIGEST_SHA224, /**< Message digest algorithm SHA2, 224bit */
- OWL_DIGEST_SHA256, /**< Message digest algorithm SHA2, 256bit */
- OWL_DIGEST_SHA384, /**< Message digest algorithm SHA2, 384bit */
- OWL_DIGEST_SHA512, /**< Message digest algorithm SHA2, 512bit */
- OWL_DIGEST_CMAC /**< TODO: perhaps CMAC should be handled differently */
-} owl_digest_algo_e;
-
-/**
- * @brief Symmetric encryption algorithms
- */
-typedef enum {
- OWL_ENC_AES = 0, /**< AES encryption.
- - see #owl_block_cipher_mode_e for details on additional parameters (mandatory)
- Supported key lengths: @c 128, @c 192 and @c 256 */
-
- OWL_ENC_UNSAFE_DES, /**< DES encryption.
- - see #owl_block_cipher_mode_e for details on additional parameters (mandatory)
- Supported key lengths: @c 56 */
-
- OWL_ENC_UNSAFE_3DES_2TDEA, /**< 3DES 2-key encryption.
- - see #owl_block_cipher_mode_e for details on additional parameters (mandatory)
- Use double DES keys to perform corresponding 2-key 3DES encryption. Supported key lengths: @c 112 */
-
- OWL_ENC_3DES_3TDEA, /**< 3DES 3-key encryption.
- - see #owl_block_cipher_mode_e for details on additional parameters (mandatory)
- Use triple DES keys to perform corresponding 3-key 3DES encryption. Supported key lengths: @c 168 */
-
- OWL_ENC_UNSAFE_RC2, /**< RC2 encryption.
- - see #owl_block_cipher_mode_e for details on additional parameters (mandatory)
- The key length is extracted from the key buffer. Supported key lengths: 8-1024 bits in steps of 8 bits. */
-
- OWL_ENC_UNSAFE_RC4, /**< RC4 encryption.
- The key length is extracted from the key buffer. Supported key lengths: 40–2048 bits in steps of 8 bits */
-
- OWL_ENC_CAST5, /**< CAST5 encryption.
- - see #owl_block_cipher_mode_e for details on additional parameters (mandatory)
- The key length is extracted from the key buffer. Supported key lengths: 40-128 bits in steps of 8 bits */
-
- OWL_ENC_UNSAFE_SKIPJACK /**< SKIPJACK algorithm
- - see #owl_block_cipher_mode_e for details on additional parameters (mandatory)
- Supported key length: 80 bits */
-} owl_enc_algo_e;
-
-/**
- * @brief Chaining modes for block ciphers
- */
-typedef enum {
- OWL_BCM_ECB, /**< ECB block cipher mode. Encrypts 64 bit at a time. No IV is used. */
-
- OWL_BCM_CTR, /**< CTR block cipher mode. 16-byte initialization vector is mandatory.
- Supported parameters:
- - OWL_PARAM_CTR_CNT = length of counter block in bits
- (optional, only 128b is supported at the moment) */
-
- OWL_BCM_CBC, /**< CBC block cipher mode. 16-byte initialization vector is mandatory. */
-
- OWL_BCM_GCM, /**< GCM block cipher mode. IV is needed.
- Supported parameters:
- - OWL_PARAM_TAG = GCM tag
- - OWL_PARAM_AAD = additional authentication data(optional) */
-
- OWL_BCM_CFB, /**< CFB block cipher mode. 16-byte initialization vector is mandatory. */
-
- OWL_BCM_OFB, /**< OFB block cipher mode. 16-byte initialization vector is mandatory. */
-
- OWL_BCM_OCB, /**< Offest Codebook Mode (AES) */
-
- OWL_BCM_CCM /**< CBC-MAC Mode (AES) */
-
-} owl_block_cipher_mode_e;
-
-
-/**
- * @brief Non-standard parameters for algorithms
- */
-typedef enum {
- OWL_PARAM_PADDING, /**< Padding */
-
- OWL_PARAM_CTR_CNT, /**< CTR Counter bits */
-
- OWL_PARAM_GCM_AAD, /**< GCM Additional Authentication Data */
- OWL_PARAM_GCM_TAG, /**< GCM Tag bits */
- OWL_PARAM_GCM_TAG_LEN, /**< GCM Tag length */
-
- OWL_PARAM_CCM_AAD, /**< CCM Additional Authentication Data */
- OWL_PARAM_CCM_TAG, /**< CCM Tag bits */
- OWL_PARAM_CCM_TAG_LEN, /**< CCM Tag length */
-} owl_ex_param_e;
-
-/**
- * @brief Paddings supported by CryptoAPI
- */
-typedef enum {
- OWL_PADDING_NONE = 0, /**< total number of data MUST multiple of block size, Default */
- OWL_PADDING_ZEROS, /**< pad with zeros */
- OWL_PADDING_ISO10126, /**< ISO 10126 */
- OWL_PADDING_ANSIX923, /**< ANSI X.923 padding*/
- OWL_PADDING_ANSIX931, /**< ANSI X.931 padding*/
- OWL_PADDING_PKCS1, /**< RSA signature creation */
- OWL_PADDING_PKCS7 /**< Byte padding for symetric algos (RFC 5652), (PKCS5 padding is the same) */
-} owl_padding_e;
-
-/**@}*/
-
-#ifdef __cplusplus
-} /* extern */
-#endif
-
-#endif /* TYPES_H */
#define CRYPTO_H
#include <stddef.h>
-#include <owl/types.h>
+#include <yaca/types.h>
#ifdef __cplusplus
extern "C" {
*/
/**
- * @brief OWL_CTX_NULL NULL value for the crypto context.
+ * @brief YACA_CTX_NULL NULL value for the crypto context.
*/
-#define OWL_CTX_NULL ((owl_ctx_h) NULL)
+#define YACA_CTX_NULL ((yaca_ctx_h) NULL)
/**
- * @brief owl_init Initializes the library. Must be called before any other crypto function.
+ * @brief yaca_init Initializes the library. Must be called before any other crypto function.
*
* @return 0 on success, negative on error (@see error.h).
*/
-int owl_init(void);
+int yaca_init(void);
/**
- * @brief owl_exit Closes the library. Must be called before exiting the application.
+ * @brief yaca_exit Closes the library. Must be called before exiting the application.
*
*/
-void owl_exit(void);
+void yaca_exit(void);
/**
- * @brief owl_malloc Allocates the memory.
+ * @brief yaca_malloc Allocates the memory.
*
* @param[in] size Size of the allocation (bytes).
*
* @return NULL on failure, pointer to allocated memory otherwise.
*/
// TODO: this should be a macro to CRYPTO_*
-void *owl_malloc(size_t size);
+void *yaca_malloc(size_t size);
/**
- * @brief owl_realloc Re-allocates the memory.
+ * @brief yaca_realloc Re-allocates the memory.
*
* @param[in] addr Address of the memory to be reallocated.
* @param[in] size Size of the new allocation (bytes).
* @return NULL on failure, pointer to allocated memory otherwise.
*/
// TODO: this should be a macro to CRYPTO_*
-void *owl_realloc(void *addr, size_t size);
+void *yaca_realloc(void *addr, size_t size);
/**
- * @brief owl_free Frees the memory allocated by @see owl_malloc
- * or one of the cryptographics operations.
+ * @brief yaca_free Frees the memory allocated by @see yaca_malloc
+ * or one of the cryptographics operations.
*
* @param[in] ptr Pointer to the memory to be freed.
*
*/
// TODO: this should be a macro to CRYPTO_*
-void owl_free(void *ptr);
+void yaca_free(void *ptr);
/**
- * @brief owl_rand_bytes Generates random data.
+ * @brief yaca_rand_bytes Generates random data.
*
* @param[in,out] data Pointer to the memory to be randomized.
* @param[in] data_len Length of the memory to be randomized.
*
* @return 0 on success, negative on error (@see error.h).
*/
-int owl_rand_bytes(char *data, size_t data_len);
+int yaca_rand_bytes(char *data, size_t data_len);
/**
- * @brief owl_ctx_set_param Sets the extended context parameters.
- * Can only be called on an initialized context.
+ * @brief yaca_ctx_set_param Sets the extended context parameters.
+ * Can only be called on an initialized context.
*
* @param[in,out] ctx Previously initialized crypto context.
* @param[in] param Parameter to be set.
*
* @return 0 on success, negative on error (@see error.h).
*/
-int owl_ctx_set_param(owl_ctx_h ctx, owl_ex_param_e param,
- const void *value, size_t value_len);
+int yaca_ctx_set_param(yaca_ctx_h ctx, yaca_ex_param_e param,
+ const void *value, size_t value_len);
/**
- * @brief owl_ctx_get_param Returns the extended context parameters.
- * Can only be called on an initialized context.
+ * @brief yaca_ctx_get_param Returns the extended context parameters.
+ * Can only be called on an initialized context.
*
* @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 @see owl_free).
+ * @param[out] value Copy of the parameter value (must be freed with @see yaca_free).
* @param[out] value_len Length of the parameter value will be returned here.
*
* @return 0 on success, negative on error (@see error.h).
*/
-int owl_ctx_get_param(const owl_ctx_h ctx, owl_ex_param_e param,
- void **value, size_t *value_len);
+int yaca_ctx_get_param(const yaca_ctx_h ctx, yaca_ex_param_e param,
+ void **value, size_t *value_len);
/**
- * @brief owl_ctx_free Destroys the crypto context. Must be called
- * on all contexts that are no longer used.
- * Passing OWL_CTX_NULL is allowed.
+ * @brief yaca_ctx_free Destroys the crypto context. Must be called
+ * on all contexts that are no longer used.
+ * Passing YACA_CTX_NULL is allowed.
*
* @param[in,out] ctx Crypto context.
*
*/
-void owl_ctx_free(owl_ctx_h ctx);
+void yaca_ctx_free(yaca_ctx_h ctx);
/**
- * @brief owl_get_output_length Returns the output length for a given algorithm.
- * Can only be called on an initialized context.
+ * @brief yaca_get_output_length Returns the output length for a given algorithm.
+ * Can only be called on an initialized context.
*
* @param[in] ctx Previously initialized crypto context.
* @param[in] input_len Length of the input data to be processed.
*
* @return negative on error (@see error.h) or length of output.
*/
-int owl_get_output_length(const owl_ctx_h ctx, size_t input_len);
+int yaca_get_output_length(const yaca_ctx_h ctx, size_t input_len);
/**
- * @brief owl_get_digest_length Wrapper - returns the length of the digest (for a given context).
+ * @brief yaca_get_digest_length Wrapper - returns the length of the digest (for a given context).
*/
-#define owl_get_digest_length(ctxa) owl_get_output_length((ctxa), 0)
+#define yaca_get_digest_length(ctxa) yaca_get_output_length((ctxa), 0)
/**
- * @brief owl_get_sign_length Wrapper - returns the length of the signature (for a given context).
+ * @brief yaca_get_sign_length Wrapper - returns the length of the signature (for a given context).
*/
-#define owl_get_sign_length(ctxa) owl_get_output_length((ctxa), 0)
+#define yaca_get_sign_length(ctxa) yaca_get_output_length((ctxa), 0)
/**
- * @brief owl_get_block_length Wrapper - returns the length of the block (for a given context).
+ * @brief yaca_get_block_length Wrapper - returns the length of the block (for a given context).
*/
-#define owl_get_block_length(ctxa) owl_get_output_length((ctxa), 0)
+#define yaca_get_block_length(ctxa) yaca_get_output_length((ctxa), 0)
/**
- * @brief owl_get_iv_length Returns the recomended/default length of the IV for a given encryption configuration.
+ * @brief yaca_get_iv_length Returns the recomended/default length of the IV for a given encryption configuration.
*
* @param[in] algo Encryption algorithm.
* @param[in] bcm Chain mode.
*
* @return negative on error (@see error.h) or the IV length.
*/
-int owl_get_iv_length(owl_enc_algo_e algo,
- owl_block_cipher_mode_e bcm,
- size_t key_len);
+int yaca_get_iv_length(yaca_enc_algo_e algo,
+ yaca_block_cipher_mode_e bcm,
+ size_t key_len);
/**@}*/
#define DIGEST_H
#include <stddef.h>
-#include <owl/types.h>
+#include <yaca/types.h>
#ifdef __cplusplus
extern "C" {
*/
/**
- * @brief owl_digest_init Initializes a digest context.
+ * @brief yaca_digest_init Initializes a digest context.
*
- * @param[out] ctx Newly created context (must be freed with @see owl_ctx_free).
+ * @param[out] ctx Newly created context (must be freed with @see yaca_ctx_free).
* @param[in] algo Digest algorithm that will be used.
*
* @return 0 on success, negative on error (@see error.h).
*/
-int owl_digest_init(owl_ctx_h *ctx, owl_digest_algo_e algo);
+int yaca_digest_init(yaca_ctx_h *ctx, yaca_digest_algo_e algo);
/**
- * @brief owl_digest_update Feeds the data into the message digest algorithm.
+ * @brief yaca_digest_update Feeds the data into the message digest algorithm.
*
- * @param[in,out] ctx Context created by @see owl_digest_init.
+ * @param[in,out] ctx Context created by @see yaca_digest_init.
* @param[in] data Data from which the digest is to be calculated.
* @param[in] data_len Length of the data.
*
* @return 0 on success, negative on error (@see error.h).
*/
-int owl_digest_update(owl_ctx_h ctx, const char *data, size_t data_len);
+int yaca_digest_update(yaca_ctx_h ctx, const char *data, size_t data_len);
/**
- * @brief owl_digest_final Calculates the final digest.
+ * @brief yaca_digest_final Calculates the final digest.
*
* @param[in,out] ctx A valid digest context.
- * @param[out] digest Buffer for the message digest (must be allocated by client, @see owl_get_digest_length).
+ * @param[out] digest Buffer for the message digest (must be allocated by client, @see yaca_get_digest_length).
* @param[out] digest_len Length of the digest, actual number of bytes written will be returned here.
*
* @return 0 on success, negative on error (@see error.h).
*/
-int owl_digest_final(owl_ctx_h ctx, char *digest, size_t *digest_len);
+int yaca_digest_final(yaca_ctx_h ctx, char *digest, size_t *digest_len);
/**@}*/
#define ENCRYPT_H
#include <stddef.h>
-#include <owl/types.h>
+#include <yaca/types.h>
#ifdef __cplusplus
extern "C" {
*/
/**
- * @brief owl_encrypt_init Initializes an encryption context.
+ * @brief yaca_encrypt_init Initializes an encryption context.
*
- * @param[out] ctx Newly created context (must be freed with @see owl_ctx_free).
+ * @param[out] ctx Newly created context (must be freed with @see yaca_ctx_free).
* @param[in] algo Encryption algorithm that will be used.
* @param[in] bcm Chaining mode that will be used.
* @param[in] sym_key Symmetric key that will be used.
*
* @return 0 on success, negative on error (@see error.h).
*/
-int owl_encrypt_init(owl_ctx_h *ctx,
- owl_enc_algo_e algo,
- owl_block_cipher_mode_e bcm,
- const owl_key_h sym_key,
- const owl_key_h iv);
+int yaca_encrypt_init(yaca_ctx_h *ctx,
+ yaca_enc_algo_e algo,
+ yaca_block_cipher_mode_e bcm,
+ const yaca_key_h sym_key,
+ const yaca_key_h iv);
/**
- * @brief owl_encrypt_update Encrypts chunk of the data.
+ * @brief yaca_encrypt_update Encrypts chunk of the data.
*
- * @param[in,out] ctx Context created by @see owl_encrypt_init.
+ * @param[in,out] ctx Context created by @see yaca_encrypt_init.
* @param[in] plain Plain text to be encrypted.
* @param[in] plain_len Length of the plain text.
- * @param[out] cipher Buffer for the encrypted data (must be allocated by client, @see owl_get_output_length).
+ * @param[out] cipher Buffer for the encrypted data (must be allocated by client, @see yaca_get_output_length).
* @param[out] cipher_len Length of the encrypted data, actual number of bytes written will be returned here.
*
* @return 0 on success, negative on error (@see error.h).
*/
-int owl_encrypt_update(owl_ctx_h ctx,
- const char *plain,
- size_t plain_len,
- char *cipher,
- size_t *cipher_len);
+int yaca_encrypt_update(yaca_ctx_h ctx,
+ const char *plain,
+ size_t plain_len,
+ char *cipher,
+ size_t *cipher_len);
/**
- * @brief owl_encrypt_final Encrypts the final chunk of the data.
+ * @brief yaca_encrypt_final Encrypts the final chunk of the data.
*
* @param[in,out] ctx A valid encrypt context.
- * @param[out] cipher Final piece of the encrypted data (must be allocated by client, @see owl_get_block_length).
+ * @param[out] cipher Final piece of the encrypted data (must be allocated by client, @see yaca_get_block_length).
* @param[out] cipher_len Length of the final piece, actual number of bytes written will be returned here.
*
* @return 0 on success, negative on error (@see error.h).
*/
-int owl_encrypt_final(owl_ctx_h ctx,
- char *cipher,
- size_t *cipher_len);
+int yaca_encrypt_final(yaca_ctx_h ctx,
+ char *cipher,
+ size_t *cipher_len);
/**
- * @brief owl_decrypt_init Initializes an decryption context.
+ * @brief yaca_decrypt_init Initializes an decryption context.
*
- * @param[out] ctx Newly created context (must be freed with @see owl_ctx_free).
+ * @param[out] ctx Newly created context (must be freed with @see 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.
* @param[in] sym_key Symmetric key that was used to encrypt the data.
*
* @return 0 on success, negative on error (@see error.h).
*/
-int owl_decrypt_init(owl_ctx_h *ctx,
- owl_enc_algo_e algo,
- owl_block_cipher_mode_e bcm,
- const owl_key_h sym_key,
- const owl_key_h iv);
+int yaca_decrypt_init(yaca_ctx_h *ctx,
+ yaca_enc_algo_e algo,
+ yaca_block_cipher_mode_e bcm,
+ const yaca_key_h sym_key,
+ const yaca_key_h iv);
/**
- * @brief owl_decrypt_update Decrypts chunk of the data.
+ * @brief yaca_decrypt_update Decrypts chunk of the data.
*
- * @param[in,out] ctx Context created by @see owl_decrypt_init.
+ * @param[in,out] ctx Context created by @see yaca_decrypt_init.
* @param[in] cipher Cipher text to be decrypted.
* @param[in] cipher_len Length of the cipher text.
- * @param[out] plain Buffer for the decrypted data (must be allocated by client, @see owl_get_output_length).
+ * @param[out] plain Buffer for the decrypted data (must be allocated by client, @see yaca_get_output_length).
* @param[out] plain_len Length of the decrypted data, actual number of bytes written will be returned here.
*
* @return 0 on success, negative on error (@see error.h).
*/
-int owl_decrypt_update(owl_ctx_h ctx,
- const char *cipher,
- size_t cipher_len,
- char *plain,
- size_t *plain_len);
+int yaca_decrypt_update(yaca_ctx_h ctx,
+ const char *cipher,
+ size_t cipher_len,
+ char *plain,
+ size_t *plain_len);
/**
- * @brief owl_decrypt_final Decrypts the final chunk of the data.
+ * @brief yaca_decrypt_final Decrypts the final chunk of the data.
*
* @param[in,out] ctx A valid decrypt context.
- * @param[out] plain Final piece of the decrypted data (must be allocated by client, @see owl_get_block_length).
+ * @param[out] plain Final piece of the decrypted data (must be allocated by client, @see yaca_get_block_length).
* @param[out] plain_len Length of the final piece, actual number of bytes written will be returned here.
*
* @return 0 on success, negative on error (@see error.h).
*/
-int owl_decrypt_final(owl_ctx_h ctx,
- char *plain,
- size_t *plain_len);
+int yaca_decrypt_final(yaca_ctx_h ctx,
+ char *plain,
+ size_t *plain_len);
/**@}*/
*/
/**
- * @brief owl_seal_init Initializes an asymmetric encryption context.
+ * @brief yaca_seal_init Initializes an asymmetric encryption context.
*
- * @param[out] ctx Newly created context (must be freed with @see owl_ctx_free).
+ * @param[out] ctx Newly created context (must be freed with @see 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.
* @param[in] bcm Block chaining mode for the symmetric algorithm.
*
* @return 0 on success, negative on error (@see error.h).
*/
-int owl_seal_init(owl_ctx_h *ctx,
- const owl_key_h pub_key,
- owl_enc_algo_e algo,
- owl_block_cipher_mode_e bcm,
- owl_key_h *sym_key,
- owl_key_h *iv);
+int yaca_seal_init(yaca_ctx_h *ctx,
+ const yaca_key_h pub_key,
+ yaca_enc_algo_e algo,
+ yaca_block_cipher_mode_e bcm,
+ yaca_key_h *sym_key,
+ yaca_key_h *iv);
/**
- * @brief owl_seal_update Encrypts piece of the data.
+ * @brief yaca_seal_update Encrypts piece of the data.
*
- * @param[in,out] ctx Context created by @see owl_seal_init.
+ * @param[in,out] ctx Context created by @see yaca_seal_init.
* @param[in] plain Plain text to be encrypted.
* @param[in] plain_len Length of the plain text.
- * @param[out] cipher Buffer for the encrypted data (must be allocated by client, @see owl_get_output_length).
+ * @param[out] cipher Buffer for the encrypted data (must be allocated by client, @see yaca_get_output_length).
* @param[out] cipher_len Length of the encrypted data, actual number of bytes written will be returned here.
*
* @return 0 on success, negative on error (@see error.h).
*/
-int owl_seal_update(owl_ctx_h ctx,
- const char *plain,
- size_t plain_len,
- char *cipher,
- size_t *cipher_len);
+int yaca_seal_update(yaca_ctx_h ctx,
+ const char *plain,
+ size_t plain_len,
+ char *cipher,
+ size_t *cipher_len);
/**
- * @brief owl_seal_final Encrypts the final piece of the data.
+ * @brief yaca_seal_final Encrypts the final piece of the data.
*
* @param[in,out] ctx A valid seal context.
- * @param[out] cipher Final piece of the encrypted data (must be allocated by client, @see owl_get_block_length).
+ * @param[out] cipher Final piece of the encrypted data (must be allocated by client, @see yaca_get_block_length).
* @param[out] cipher_len Length of the final piece, actual number of bytes written will be returned here.
*
* @return 0 on success, negative on error (@see error.h).
*/
-int owl_seal_final(owl_ctx_h ctx,
- char *cipher,
- size_t *cipher_len);
+int yaca_seal_final(yaca_ctx_h ctx,
+ char *cipher,
+ size_t *cipher_len);
/**
- * @brief owl_open_init Initializes an asymmetric decryption context.
+ * @brief yaca_open_init Initializes an asymmetric decryption context.
*
- * @param[out] ctx Newly created context. Must be freed by @see owl_ctx_free.
+ * @param[out] ctx Newly created context. Must be freed by @see 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.
* @param[in] bcm Block chaining mode for the symmetric algorithm.
*
* @return 0 on success, negative on error (@see error.h).
*/
-int owl_open_init(owl_ctx_h *ctx,
- const owl_key_h prv_key,
- owl_enc_algo_e algo,
- owl_block_cipher_mode_e bcm,
- const owl_key_h sym_key,
- const owl_key_h iv);
+int yaca_open_init(yaca_ctx_h *ctx,
+ const yaca_key_h prv_key,
+ yaca_enc_algo_e algo,
+ yaca_block_cipher_mode_e bcm,
+ const yaca_key_h sym_key,
+ const yaca_key_h iv);
/**
- * @brief owl_open_update Decrypts piece of the data.
+ * @brief yaca_open_update Decrypts piece of the data.
*
- * @param[in,out] ctx Context created by @see owl_open_init.
+ * @param[in,out] ctx Context created by @see yaca_open_init.
* @param[in] cipher Cipher text to be decrypted.
* @param[in] cipher_len Length of the cipher text.
- * @param[out] plain Buffer for the decrypted data (must be allocated by client, @see owl_get_output_length).
+ * @param[out] plain Buffer for the decrypted data (must be allocated by client, @see yaca_get_output_length).
* @param[out] plain_len Length of the decrypted data, actual number of bytes written will be returned here.
*
* @return 0 on success, negative on error (@see error.h).
*/
-int owl_open_update(owl_ctx_h ctx,
- const char *cipher,
- size_t cipher_len,
- char *plain,
- size_t *plain_len);
+int yaca_open_update(yaca_ctx_h ctx,
+ const char *cipher,
+ size_t cipher_len,
+ char *plain,
+ size_t *plain_len);
/**
- * @brief owl_open_final Decrypts last chunk of sealed message.
+ * @brief yaca_open_final Decrypts last chunk of sealed message.
*
* @param[in,out] ctx A valid open context.
- * @param[out] plain Final piece of the decrypted data (must be allocated by client, @see owl_get_block_length).
+ * @param[out] plain Final piece of the decrypted data (must be allocated by client, @see yaca_get_block_length).
* @param[out] plain_len Length of the final piece, actual number of bytes written will be returned here.
*
* @return 0 on success, negative on error (@see error.h).
*/
-int owl_open_final(owl_ctx_h ctx,
- char *plain,
- size_t *plain_len);
+int yaca_open_final(yaca_ctx_h ctx,
+ char *plain,
+ size_t *plain_len);
/**@}*/
extern "C" {
#endif
-enum __owl_error_code {
- OWL_ERROR_INVALID_ARGUMENT = -1,
- OWL_ERROR_NOT_IMPLEMENTED= -2,
- OWL_ERROR_OPENSSL_FAILURE = -3,
- OWL_ERROR_NOT_SUPPORTED = -4,
- OWL_ERROR_TOO_BIG_ARGUMENT = -5,
- OWL_ERROR_OUT_OF_MEMORY = -6
+enum __yaca_error_code {
+ YACA_ERROR_INVALID_ARGUMENT = -1,
+ YACA_ERROR_NOT_IMPLEMENTED= -2,
+ YACA_ERROR_OPENSSL_FAILURE = -3,
+ YACA_ERROR_NOT_SUPPORTED = -4,
+ YACA_ERROR_TOO_BIG_ARGUMENT = -5,
+ YACA_ERROR_OUT_OF_MEMORY = -6
};
#ifdef __cplusplus
#define KEY_H
#include <stddef.h>
-#include <owl/types.h>
+#include <yaca/types.h>
#ifdef __cplusplus
extern "C" {
* @{
*/
-#define OWL_KEY_NULL ((owl_key_h) NULL)
+#define YACA_KEY_NULL ((yaca_key_h) NULL)
-// TODO: We need a way to import keys encrypted with hw (or other) keys. New function like owl_key_load or sth??
+// TODO: We need a way to import keys encrypted with hw (or other) keys. New function like yaca_key_load or sth??
/**
- * @brief owl_key_get_length Get key's length.
+ * @brief yaca_key_get_length Get key's length.
*
* @param[in] key Key which length we return.
*
* @return negative on error (@see error.h) or key length.
*/
-int owl_key_get_length(const owl_key_h key);
+int yaca_key_get_length(const yaca_key_h key);
/**
- * @brief owl_key_import Imports a key from the arbitrary format.
+ * @brief yaca_key_import Imports a key from the arbitrary format.
*
- * @param[out] key Returned key (must be freed with @see owl_key_free).
+ * @param[out] key Returned key (must be freed with @see yaca_key_free).
* @param[in] key_fmt Format of the key.
* @param[in] key_type Type of the key.
* @param[in] data Blob containing the key.
*
* @return 0 on success, negative on error (@see error.h).
*/
-int owl_key_import(owl_key_h *key,
- owl_key_fmt_e key_fmt,
- owl_key_type_e key_type,
- const char *data,
- size_t data_len);
+int yaca_key_import(yaca_key_h *key,
+ yaca_key_fmt_e key_fmt,
+ yaca_key_type_e key_type,
+ const char *data,
+ size_t data_len);
/**
- * @brief owl_key_export Exports a key to arbitrary format. Export may fail if key is HW-based.
+ * @brief yaca_key_export Exports a key to arbitrary format. Export may fail if key is HW-based.
*
* @param[in] key Key to be exported.
* @param[in] key_fmt Format of the key.
- * @param[out] data Data, allocated by the library, containing exported key (must be freed with @see owl_free).
+ * @param[out] data Data, allocated by the library, containing exported key (must be freed with @see yaca_free).
* @param[out] data_len Size of the output data.
*
* @return 0 on success, negative on error (@see error.h).
*/
-int owl_key_export(const owl_key_h key,
- owl_key_fmt_e key_fmt,
- char **data,
- size_t *data_len);
+int yaca_key_export(const yaca_key_h key,
+ yaca_key_fmt_e key_fmt,
+ char **data,
+ size_t *data_len);
// TODO: still a matter of ordering, should the key in key_gen functions be first or last?
/**
- * @brief owl_key_gen Generates a secure symmetric key (or an initialization vector).
+ * @brief yaca_key_gen Generates a secure symmetric key (or an initialization vector).
*
- * @param[out] sym_key Newly generated key (must be freed with @see owl_key_free).
+ * @param[out] sym_key Newly generated key (must be freed with @see yaca_key_free).
* @param[in] key_type Type of the key to be generated.
* @param[in] key_len Length of the key to be generated.
*
* @return 0 on success, negative on error (@see error.h).
*/
-int owl_key_gen(owl_key_h *sym_key,
- owl_key_type_e key_type,
- size_t key_len);
+int yaca_key_gen(yaca_key_h *sym_key,
+ yaca_key_type_e key_type,
+ size_t key_len);
/**
- * @brief owl_key_gen_pair Generates a new key pair.
+ * @brief yaca_key_gen_pair Generates a new key pair.
*
- * @param[out] prv_key Newly generated private key (must be freed with @see owl_key_free).
- * @param[out] pub_key Newly generated public key (must be freed with @see owl_key_free).
- * @param[in] key_type Type of the key to be generated (must be OWL_KEY_TYPE_PAIR*).
+ * @param[out] prv_key Newly generated private key (must be freed with @see yaca_key_free).
+ * @param[out] pub_key Newly generated public key (must be freed with @see yaca_key_free).
+ * @param[in] key_type Type of the key to be generated (must be YACA_KEY_TYPE_PAIR*).
* @param[in] key_len Length of the key to be generated.
*
* @return 0 on success, negative on error (@see error.h).
*/
-int owl_key_gen_pair(owl_key_h *prv_key,
- owl_key_h *pub_key,
- owl_key_type_e key_type,
- size_t key_len);
+int yaca_key_gen_pair(yaca_key_h *prv_key,
+ yaca_key_h *pub_key,
+ yaca_key_type_e key_type,
+ size_t key_len);
/**
- * @brief owl_key_free Frees the key created by the library.
- * Passing OWL_KEY_NULL is allowed.
+ * @brief yaca_key_free Frees the key created by the library.
+ * Passing YACA_KEY_NULL is allowed.
*
* @param key Key to be freed.
*
*/
-void owl_key_free(owl_key_h key);
+void yaca_key_free(yaca_key_h key);
/**@}*/
*/
/**
- * @brief owl_key_derive_dh Derives a key using Diffie-Helmann or EC Diffie-Helmann key exchange protocol.
+ * @brief yaca_key_derive_dh Derives a key using Diffie-Helmann or EC Diffie-Helmann key exchange protocol.
*
* @param[in] prv_key Our private key.
* @param[in] pub_key Peer public key.
- * @param[out] sym_key Shared secret, that can be used as a symmetric key (must be freed with @see owl_key_free).
+ * @param[out] sym_key Shared secret, that can be used as a symmetric key (must be freed with @see yaca_key_free).
*
* @return 0 on success, negative on error (@see error.h).
*/
-int owl_key_derive_dh(const owl_key_h prv_key,
- const owl_key_h pub_key,
- owl_key_h *sym_key);
+int yaca_key_derive_dh(const yaca_key_h prv_key,
+ const yaca_key_h pub_key,
+ yaca_key_h *sym_key);
/**
- * @brief owl_key_derive_kea Derives a key using KEA key exchange protocol.
+ * @brief yaca_key_derive_kea Derives a key using KEA key exchange protocol.
*
* @param[in] prv_key Our DH private component.
* @param[in] pub_key Peers' DH public component.
* DH public component sent to peer to verify our identity.
* @param[in] pub_key_auth Peers' public key used for signature verification
* of pub_key from peer (peer authentication).
- * @param[out] sym_key Shared secret, that can be used as a symmetric key (must be freed with @see owl_key_free).
+ * @param[out] sym_key Shared secret, that can be used as a symmetric key (must be freed with @see yaca_key_free).
*
* @return 0 on success, negative on error (@see error.h).
*/
-int owl_key_derive_kea(const owl_key_h prv_key,
- const owl_key_h pub_key,
- const owl_key_h prv_key_auth,
- const owl_key_h pub_key_auth,
- owl_key_h *sym_key);
+int yaca_key_derive_kea(const yaca_key_h prv_key,
+ const yaca_key_h pub_key,
+ const yaca_key_h prv_key_auth,
+ const yaca_key_h pub_key_auth,
+ yaca_key_h *sym_key);
/**
- * @brief owl_key_derive_pbkdf2 Derives a key from user password (PKCS #5 a.k.a. pbkdf2 algorithm).
+ * @brief yaca_key_derive_pbkdf2 Derives a key from user password (PKCS #5 a.k.a. pbkdf2 algorithm).
*
* @param[in] password User password as a NULL-terminated string.
* @param[in] salt Salt, should be non-zero.
* @param[in] iter Number of iterations. (TODO: add enum to proposed number of iterations, pick sane defaults).
* @param[in] algo Digest algorithm that should be used in key generation. (TODO: sane defaults).
* @param[in] key_len Length of a key to be generated.
- * @param[out] key Newly generated key (must be freed with @see owl_key_free).
+ * @param[out] key Newly generated key (must be freed with @see yaca_key_free).
*
* @return 0 on success, negative on error (@see error.h).
*/
-int owl_key_derive_pbkdf2(const char *password,
- const char *salt,
- size_t salt_len,
- int iter,
- owl_digest_algo_e algo,
- owl_key_len_e key_len,
- owl_key_h *key);
+int yaca_key_derive_pbkdf2(const char *password,
+ const char *salt,
+ size_t salt_len,
+ int iter,
+ yaca_digest_algo_e algo,
+ yaca_key_len_e key_len,
+ yaca_key_h *key);
// TODO: specify
-//int owl_key_wrap(owl_key_h key, ??);
-//int owl_key_unwrap(owl_key_h key, ??);
+//int yaca_key_wrap(yaca_key_h key, ??);
+//int yaca_key_unwrap(yaca_key_h key, ??);
/**@}*/
#define SIGN_H
#include <stddef.h>
-#include <owl/types.h>
+#include <yaca/types.h>
#ifdef __cplusplus
extern "C" {
*/
/**
- * @brief owl_sign_init Initializes a signature context.
+ * @brief yaca_sign_init Initializes a signature context.
*
- * @param[out] ctx Newly created context (must be freed with @see owl_ctx_free).
+ * @param[out] ctx Newly created context (must be freed with @see yaca_ctx_free).
* @param[in] algo Digest algorithm that will be used.
* @param[in] key Private or symmetric key that will be used (algorithm is deduced based on key type).
*
* @return 0 on success, negative on error (@see error.h).
*/
-int owl_sign_init(owl_ctx_h *ctx,
- owl_digest_algo_e algo,
- const owl_key_h key);
+int yaca_sign_init(yaca_ctx_h *ctx,
+ yaca_digest_algo_e algo,
+ const yaca_key_h key);
/**
- * @brief owl_sign_update Feeds the data into the digital signature algorithm.
+ * @brief yaca_sign_update Feeds the data into the digital signature algorithm.
*
- * @param[in,out] ctx Context created by @see owl_sign_init.
+ * @param[in,out] ctx Context created by @see yaca_sign_init.
* @param[in] data Data to be signed.
* @param[in] data_len Length of the data.
*
* @return 0 on success, negative on error (@see error.h).
*/
-int owl_sign_update(owl_ctx_h ctx,
- const char *data,
- size_t data_len);
+int yaca_sign_update(yaca_ctx_h ctx,
+ const char *data,
+ size_t data_len);
/**
- * @brief owl_sign_final Calculates the final signature.
+ * @brief yaca_sign_final Calculates the final signature.
*
* @param[in,out] ctx A valid sign context.
- * @param[out] mac Buffer for the MAC or the signature (must be allocated by client, @see owl_get_sign_length).
+ * @param[out] mac Buffer for the MAC or the signature (must be allocated by client, @see yaca_get_sign_length).
* @param[out] mac_len Length of the MAC or the signature, actual number of bytes written will be returned here.
*
* @return 0 on success, negative on error (@see error.h).
*/
-int owl_sign_final(owl_ctx_h ctx,
- char *mac,
- size_t *mac_len);
+int yaca_sign_final(yaca_ctx_h ctx,
+ char *mac,
+ size_t *mac_len);
/**
- * @brief owl_verify_init Initializes a signature verification context.
+ * @brief yaca_verify_init Initializes a signature verification context.
*
- * @param[out] ctx Newly created context (must be freed with @see owl_ctx_free).
+ * @param[out] ctx Newly created context (must be freed with @see yaca_ctx_free).
* @param[in] algo Digest algorithm that will be used.
* @param[in] key Private or symmetric key that will be used (algorithm is deduced based on key type).
*
* @return 0 on success, negative on error (@see error.h).
*/
-int owl_verify_init(owl_ctx_h *ctx,
- owl_digest_algo_e algo,
- const owl_key_h key);
+int yaca_verify_init(yaca_ctx_h *ctx,
+ yaca_digest_algo_e algo,
+ const yaca_key_h key);
/**
- * @brief owl_verify_update Feeds the data into the digital signature verification algorithm.
+ * @brief yaca_verify_update Feeds the data into the digital signature verification algorithm.
*
- * @param[in,out] ctx Context created by @see owl_verify_init.
+ * @param[in,out] ctx Context created by @see yaca_verify_init.
* @param[in] data Data to be verified.
* @param[in] data_len Length of the data.
*
* @return 0 on success, negative on error (@see error.h).
*/
-int owl_verify_update(owl_ctx_h ctx,
- const char *data,
- size_t data_len);
+int yaca_verify_update(yaca_ctx_h ctx,
+ const char *data,
+ size_t data_len);
/**
- * @brief owl_verify_final Performs the verification.
+ * @brief yaca_verify_final Performs the verification.
*
* @param[in,out] ctx A valid verify context.
- * @param[in] mac Input MAC or signature (returned by @see owl_sign_final).
+ * @param[in] mac Input MAC or signature (returned by @see yaca_sign_final).
* @param[in] mac_len Size of the MAC or the signature.
*
* @return 0 on success, negative on error (@see error.h).
* TODO: CRYTPO_ERROR_SIGNATURE_INVALID when verification fails.
*/
-int owl_verify_final(owl_ctx_h ctx,
- const char *mac,
- size_t mac_len);
+int yaca_verify_final(yaca_ctx_h ctx,
+ const char *mac,
+ size_t mac_len);
/**@}*/
#define SIMPLE_H
#include <stddef.h>
-#include <owl/types.h>
+#include <yaca/types.h>
#ifdef __cplusplus
extern "C" {
*/
/**
- * @brief owl_digest_calc Calculate a digest of a buffer.
+ * @brief yaca_digest_calc Calculate a digest of a buffer.
*
- * @param[in] algo Digest algorithm (select @see OWL_DIGEST_SHA256 if unsure).
+ * @param[in] algo Digest algorithm (select @see 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.
- * @param[out] digest Message digest, will be allocated by the library (should be freed with @see owl_free).
+ * @param[out] digest Message digest, will be allocated by the library (should be freed with @see yaca_free).
* @param[out] digest_len Length of message digest (depends on algorithm).
*
* @return 0 on success, negative on error (@see error.h).
*/
-int owl_digest_calc(owl_digest_algo_e algo,
- const char *data,
- size_t data_len,
- char **digest,
- size_t *digest_len);
+int yaca_digest_calc(yaca_digest_algo_e algo,
+ const char *data,
+ size_t data_len,
+ char **digest,
+ size_t *digest_len);
/**
- * @brief owl_encrypt Encrypt data using a symmetric cipher.
+ * @brief yaca_encrypt Encrypt data using a symmetric cipher.
*
- * @param[in] algo Encryption algorithm (select @see OWL_ENC_AES if unsure).
- * @param[in] bcm Chaining mode (select @see OWL_BCM_CBC if unsure).
+ * @param[in] algo Encryption algorithm (select @see YACA_ENC_AES if unsure).
+ * @param[in] bcm Chaining mode (select @see YACA_BCM_CBC if unsure).
* @param[in] sym_key Symmetric encryption key (@see key.h for key generation functions).
* @param[in] iv Initialization vector.
* @param[in] plain Plain text to be encrypted.
* @param[in] plain_len Length of the plain text.
- * @param[out] cipher Encrypted data, will be allocated by the library (should be freed with @see owl_free).
+ * @param[out] cipher Encrypted data, will be allocated by the library (should be freed with @see yaca_free).
* @param[out] cipher_len Length of the encrypted data (may be larger than decrypted).
*
* @return 0 on success, negative on error (@see error.h).
*/
-int owl_encrypt(owl_enc_algo_e algo,
- owl_block_cipher_mode_e bcm,
- const owl_key_h sym_key,
- const owl_key_h iv,
- const char *plain,
- size_t plain_len,
- char **cipher,
- size_t *cipher_len);
+int yaca_encrypt(yaca_enc_algo_e algo,
+ yaca_block_cipher_mode_e bcm,
+ const yaca_key_h sym_key,
+ const yaca_key_h iv,
+ const char *plain,
+ size_t plain_len,
+ char **cipher,
+ size_t *cipher_len);
/**
- * @brief owl_decrypt Decrypta data using a symmetric cipher.
+ * @brief yaca_decrypt Decrypta data using a symmetric cipher.
*
* @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] iv Initialization vector that was used to encrypt the data.
* @param[in] cipher Cipher text to be decrypted.
* @param[in] cipher_len Length of cipher text.
- * @param[out] plain Decrypted data, will be allocated by the library (should be freed with @see owl_free).
+ * @param[out] plain Decrypted data, will be allocated by the library (should be freed with @see yaca_free).
* @param[out] plain_len Length of the decrypted data.
*
* @return 0 on success, negative on error (@see error.h).
*/
-int owl_decrypt(owl_enc_algo_e algo,
- owl_block_cipher_mode_e bcm,
- const owl_key_h sym_key,
- const owl_key_h iv,
- const char *cipher,
- size_t cipher_len,
- char **plain,
- size_t * plain_len);
+int yaca_decrypt(yaca_enc_algo_e algo,
+ yaca_block_cipher_mode_e bcm,
+ const yaca_key_h sym_key,
+ const yaca_key_h iv,
+ const char *cipher,
+ size_t cipher_len,
+ char **plain,
+ size_t * plain_len);
// TODO: sign/verify
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Krzysztof Jackiewicz <k.jackiewicz@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+/**
+ * @file types.h
+ * @brief
+ */
+
+#ifndef TYPES_H
+#define TYPES_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @defgroup Crypto-Types Enumerations for CryptoAPI
+ *
+ * TODO: extended description.
+ *
+ * @{
+ */
+
+/**
+ * @brief Context
+ */
+typedef struct yaca_ctx_s *yaca_ctx_h;
+
+/**
+ * @brief Key
+ */
+typedef struct yaca_key_s *yaca_key_h;
+
+/**
+ * @brief Key formats
+ */
+typedef enum {
+ YACA_KEY_FORMAT_RAW, /**< key is in clear format */
+ YACA_KEY_FORMAT_BASE64, /**< key is encoded in ASCII-base64 */
+ YACA_KEY_FORMAT_PEM, /**< key is in PEM file format */
+ YACA_KEY_FORMAT_DER /**< key is in DER file format */
+} yaca_key_fmt_e;
+
+/**
+ * @brief Key types, IV is considered as key
+ */
+typedef enum {
+ YACA_KEY_TYPE_SYMMETRIC, /**< Generic symmetric cipher KEY */
+ YACA_KEY_TYPE_DES, /**< DES* key - must be handled differently because of parity bits */
+ YACA_KEY_TYPE_IV, /**< IV for symmetric algorithms */
+
+ YACA_KEY_TYPE_RSA_PUB, /**< RSA public key */
+ YACA_KEY_TYPE_RSA_PRIV, /**< RSA private key */
+
+ YACA_KEY_TYPE_DSA_PUB, /**< DSA public key */
+ YACA_KEY_TYPE_DSA_PRIV, /**< DSA private key */
+
+ YACA_KEY_TYPE_DH_PUB, /**< Diffie-Hellman public key */
+ YACA_KEY_TYPE_DH_PRIV, /**< Diffie-Hellman private key */
+
+ YACA_KEY_TYPE_ECC_PUB, /**< ECC public key */
+ YACA_KEY_TYPE_ECC_PRIV, /**< ECC private key */
+
+ YACA_KEY_TYPE_PAIR_RSA, /**< Pair of RSA keys */
+ YACA_KEY_TYPE_PAIR_DSA, /**< Pair of DSA keys */
+ YACA_KEY_TYPE_PAIR_DH, /**< Pair of Diffie-Hellman keys */
+ YACA_KEY_TYPE_PAIR_ECC /**< Pair of ECC keys */
+} yaca_key_type_e;
+
+/**
+ * @brief Key length, It is possible to use arbitrary integer instead, this enums are placed here to avoid magic numbers.
+ */
+typedef enum {
+ YACA_KEY_IV_UNSAFE_24BIT = 24, /**< 24-bit IV */
+ YACA_KEY_IV_64BIT = 64, /**< 64-bit IV */
+ YACA_KEY_IV_128BIT = 128, /**< 128-bit IV */
+ YACA_KEY_IV_256BIT = 256, /**< 256-bit IV */
+ YACA_KEY_CURVE_P192 = 192, /**< ECC: P192 curve */
+ YACA_KEY_CURVE_P256 = 256, /**< ECC: P-256 curve */
+ YACA_KEY_CURVE_P384 = 384, /**< ECC: SECP-384 curve */
+ YACA_KEY_UNSAFE_40BIT = 40,
+ YACA_KEY_UNSAFE_56BIT = 56,
+ YACA_KEY_UNSAFE_80BIT = 80,
+ YACA_KEY_UNSAFE_112BIT = 112,
+ YACA_KEY_UNSAFE_128BIT = 128,
+ YACA_KEY_192BIT = 192,
+ YACA_KEY_256BIT = 256,
+ YACA_KEY_512BIT = 512,
+ YACA_KEY_1024BIT = 1024,
+ YACA_KEY_2048BIT = 2048,
+ YACA_KEY_3072BIT = 3072,
+ YACA_KEY_4096BIT = 4096
+} yaca_key_len_e;
+
+/**
+ * @brief Message digest algorithms. CMAC is included to simplify API
+ */
+typedef enum {
+ YACA_DIGEST_MD5, /**< Message digest algorithm MD5 */
+ YACA_DIGEST_SHA1, /**< Message digest algorithm SHA1 */
+ YACA_DIGEST_SHA224, /**< Message digest algorithm SHA2, 224bit */
+ YACA_DIGEST_SHA256, /**< Message digest algorithm SHA2, 256bit */
+ YACA_DIGEST_SHA384, /**< Message digest algorithm SHA2, 384bit */
+ YACA_DIGEST_SHA512, /**< Message digest algorithm SHA2, 512bit */
+ YACA_DIGEST_CMAC /**< TODO: perhaps CMAC should be handled differently */
+} yaca_digest_algo_e;
+
+/**
+ * @brief Symmetric encryption algorithms
+ */
+typedef enum {
+ YACA_ENC_AES = 0, /**< AES encryption.
+ - see #yaca_block_cipher_mode_e for details on additional parameters (mandatory)
+ Supported key lengths: @c 128, @c 192 and @c 256 */
+
+ YACA_ENC_UNSAFE_DES, /**< DES encryption.
+ - see #yaca_block_cipher_mode_e for details on additional parameters (mandatory)
+ Supported key lengths: @c 56 */
+
+ YACA_ENC_UNSAFE_3DES_2TDEA, /**< 3DES 2-key encryption.
+ - see #yaca_block_cipher_mode_e for details on additional parameters (mandatory)
+ Use double DES keys to perform corresponding 2-key 3DES encryption. Supported key lengths: @c 112 */
+
+ YACA_ENC_3DES_3TDEA, /**< 3DES 3-key encryption.
+ - see #yaca_block_cipher_mode_e for details on additional parameters (mandatory)
+ Use triple DES keys to perform corresponding 3-key 3DES encryption. Supported key lengths: @c 168 */
+
+ YACA_ENC_UNSAFE_RC2, /**< RC2 encryption.
+ - see #yaca_block_cipher_mode_e for details on additional parameters (mandatory)
+ The key length is extracted from the key buffer. Supported key lengths: 8-1024 bits in steps of 8 bits. */
+
+ YACA_ENC_UNSAFE_RC4, /**< RC4 encryption.
+ The key length is extracted from the key buffer. Supported key lengths: 40–2048 bits in steps of 8 bits */
+
+ YACA_ENC_CAST5, /**< CAST5 encryption.
+ - see #yaca_block_cipher_mode_e for details on additional parameters (mandatory)
+ The key length is extracted from the key buffer. Supported key lengths: 40-128 bits in steps of 8 bits */
+
+ YACA_ENC_UNSAFE_SKIPJACK /**< SKIPJACK algorithm
+ - see #yaca_block_cipher_mode_e for details on additional parameters (mandatory)
+ Supported key length: 80 bits */
+} yaca_enc_algo_e;
+
+/**
+ * @brief Chaining modes for block ciphers
+ */
+typedef enum {
+ YACA_BCM_ECB, /**< ECB block cipher mode. Encrypts 64 bit at a time. No IV is used. */
+
+ YACA_BCM_CTR, /**< CTR block cipher mode. 16-byte initialization vector is mandatory.
+ Supported parameters:
+ - YACA_PARAM_CTR_CNT = length of counter block in bits
+ (optional, only 128b is supported at the moment) */
+
+ YACA_BCM_CBC, /**< CBC block cipher mode. 16-byte initialization vector is mandatory. */
+
+ YACA_BCM_GCM, /**< GCM block cipher mode. IV is needed.
+ Supported parameters:
+ - YACA_PARAM_TAG = GCM tag
+ - YACA_PARAM_AAD = additional authentication data(optional) */
+
+ YACA_BCM_CFB, /**< CFB block cipher mode. 16-byte initialization vector is mandatory. */
+
+ YACA_BCM_OFB, /**< OFB block cipher mode. 16-byte initialization vector is mandatory. */
+
+ YACA_BCM_OCB, /**< Offest Codebook Mode (AES) */
+
+ YACA_BCM_CCM /**< CBC-MAC Mode (AES) */
+
+} yaca_block_cipher_mode_e;
+
+
+/**
+ * @brief Non-standard parameters for algorithms
+ */
+typedef enum {
+ YACA_PARAM_PADDING, /**< Padding */
+
+ YACA_PARAM_CTR_CNT, /**< CTR Counter bits */
+
+ YACA_PARAM_GCM_AAD, /**< GCM Additional Authentication Data */
+ YACA_PARAM_GCM_TAG, /**< GCM Tag bits */
+ YACA_PARAM_GCM_TAG_LEN, /**< GCM Tag length */
+
+ YACA_PARAM_CCM_AAD, /**< CCM Additional Authentication Data */
+ YACA_PARAM_CCM_TAG, /**< CCM Tag bits */
+ YACA_PARAM_CCM_TAG_LEN, /**< CCM Tag length */
+} yaca_ex_param_e;
+
+/**
+ * @brief Paddings supported by CryptoAPI
+ */
+typedef enum {
+ YACA_PADDING_NONE = 0, /**< total number of data MUST multiple of block size, Default */
+ YACA_PADDING_ZEROS, /**< pad with zeros */
+ YACA_PADDING_ISO10126, /**< ISO 10126 */
+ YACA_PADDING_ANSIX923, /**< ANSI X.923 padding*/
+ YACA_PADDING_ANSIX931, /**< ANSI X.931 padding*/
+ YACA_PADDING_PKCS1, /**< RSA signature creation */
+ YACA_PADDING_PKCS7 /**< Byte padding for symetric algos (RFC 5652), (PKCS5 padding is the same) */
+} yaca_padding_e;
+
+/**@}*/
+
+#ifdef __cplusplus
+} /* extern */
+#endif
+
+#endif /* TYPES_H */
# title of most generated pages and in a few other places.
# The default value is: My Project.
-PROJECT_NAME = "Openssl wrapper layer"
+PROJECT_NAME = "Yet Another Crypto API"
# The PROJECT_NUMBER tag can be used to enter a project or revision number. This
# could be handy for archiving the generated documentation or if some version
)
ENDFUNCTION(BUILD_EXAMPLE)
-BUILD_EXAMPLE("owl-example-digest" digest.c)
-BUILD_EXAMPLE("owl-example-encrypt" encrypt.c)
-BUILD_EXAMPLE("owl-example-encrypt-gcm" encrypt_aes_gcm.c)
-BUILD_EXAMPLE("owl-example-sign" sign.c)
-BUILD_EXAMPLE("owl-example-key-exchange" key_exchange.c)
-BUILD_EXAMPLE("owl-example-test" test.c)
\ No newline at end of file
+BUILD_EXAMPLE("yaca-example-digest" digest.c)
+BUILD_EXAMPLE("yaca-example-encrypt" encrypt.c)
+BUILD_EXAMPLE("yaca-example-encrypt-gcm" encrypt_aes_gcm.c)
+BUILD_EXAMPLE("yaca-example-sign" sign.c)
+BUILD_EXAMPLE("yaca-example-key-exchange" key_exchange.c)
+BUILD_EXAMPLE("yaca-example-test" test.c)
*/
#include <stdio.h>
-#include <owl/crypto.h>
-#include <owl/digest.h>
-#include <owl/simple.h>
+#include <yaca/crypto.h>
+#include <yaca/digest.h>
+#include <yaca/simple.h>
#include "lorem.h"
#include "misc.h"
char *digest;
size_t digest_len;
- ret = owl_digest_calc(OWL_DIGEST_SHA256,
- lorem1024,
- 1024, &digest, &digest_len);
+ ret = yaca_digest_calc(YACA_DIGEST_SHA256,
+ lorem1024,
+ 1024, &digest, &digest_len);
if (ret < 0)
return;
dump_hex(digest, digest_len, "Message digest: ");
- owl_free(digest);
+ yaca_free(digest);
}
void digest_advanced(void)
{
int ret = 0;
- owl_ctx_h ctx;
+ yaca_ctx_h ctx;
- ret = owl_digest_init(&ctx, OWL_DIGEST_SHA256);
+ ret = yaca_digest_init(&ctx, YACA_DIGEST_SHA256);
if (ret < 0)
return;
- ret = owl_digest_update(ctx, lorem1024, 1024);
+ ret = yaca_digest_update(ctx, lorem1024, 1024);
if (ret < 0)
goto exit_ctx;
- // TODO: rename to owl_digest_get_length??
+ // TODO: rename to yaca_digest_get_length??
size_t digest_len;
- digest_len = owl_get_digest_length(ctx);
+ digest_len = yaca_get_digest_length(ctx);
if (digest_len <= 0)
goto exit_ctx;
{
char digest[digest_len];
- ret = owl_digest_final(ctx, digest, &digest_len);
+ ret = yaca_digest_final(ctx, digest, &digest_len);
if (ret < 0)
goto exit_ctx;
}
exit_ctx:
- owl_ctx_free(ctx);
+ yaca_ctx_free(ctx);
}
int main()
{
- int ret = owl_init();
+ int ret = yaca_init();
if (ret < 0)
return ret;
digest_advanced();
- owl_exit(); // TODO: what about handing of return value from exit??
+ yaca_exit(); // TODO: what about handing of return value from exit??
return ret;
}
#include <stdio.h>
-#include <owl/crypto.h>
-#include <owl/encrypt.h>
-#include <owl/simple.h>
-#include <owl/key.h>
+#include <yaca/crypto.h>
+#include <yaca/encrypt.h>
+#include <yaca/simple.h>
+#include <yaca/key.h>
#include "lorem.h"
#include "misc.h"
void encrypt_simple(void)
{
int ret;
- owl_key_h key = OWL_KEY_NULL;
- owl_key_h iv = OWL_KEY_NULL;
+ yaca_key_h key = YACA_KEY_NULL;
+ yaca_key_h iv = YACA_KEY_NULL;
char *enc_data = NULL;
char *dec_data = NULL;
size_t enc_len;
printf("Plain data (16 of %zu bytes): %.16s\n", (size_t)1024, lorem1024);
- ret = owl_key_derive_pbkdf2("foo bar", "123456789", 10,
- 1000, OWL_DIGEST_SHA256,
- OWL_KEY_256BIT, &key);
+ ret = yaca_key_derive_pbkdf2("foo bar", "123456789", 10,
+ 1000, YACA_DIGEST_SHA256,
+ YACA_KEY_256BIT, &key);
if (ret)
return;
- ret = owl_key_gen(&iv, OWL_KEY_TYPE_IV, OWL_KEY_IV_256BIT);
+ ret = yaca_key_gen(&iv, YACA_KEY_TYPE_IV, YACA_KEY_IV_256BIT);
if (ret)
goto exit;
- ret = owl_encrypt(OWL_ENC_AES, OWL_BCM_CBC,
- key, iv, lorem1024, 1024, &enc_data, &enc_len);
+ ret = yaca_encrypt(YACA_ENC_AES, YACA_BCM_CBC,
+ key, iv, lorem1024, 1024, &enc_data, &enc_len);
if (ret)
goto exit;
dump_hex(enc_data, 16, "Encrypted data (16 of %zu bytes): ", enc_len);
- ret = owl_decrypt(OWL_ENC_AES, OWL_BCM_CBC,
- key, iv,
- enc_data, enc_len,
- &dec_data, &dec_len);
+ ret = yaca_decrypt(YACA_ENC_AES, YACA_BCM_CBC,
+ key, iv,
+ enc_data, enc_len,
+ &dec_data, &dec_len);
if (ret < 0)
goto exit;
printf("Decrypted data (16 of %zu bytes): %.16s\n", dec_len, dec_data);
exit:
if (enc_data)
- owl_free(enc_data);
+ yaca_free(enc_data);
if (dec_data)
- owl_free(dec_data);
- if (iv != OWL_KEY_NULL)
- owl_key_free(iv);
- owl_key_free(key);
+ yaca_free(dec_data);
+ if (iv != YACA_KEY_NULL)
+ yaca_key_free(iv);
+ yaca_key_free(key);
}
// Symmetric encryption using advanced API
void encrypt_advanced(void)
{
int ret;
- owl_ctx_h ctx;
- owl_key_h key = OWL_KEY_NULL;
- owl_key_h iv = OWL_KEY_NULL;
+ yaca_ctx_h ctx;
+ yaca_key_h key = YACA_KEY_NULL;
+ yaca_key_h iv = YACA_KEY_NULL;
char *enc = NULL;
char *dec = NULL;
size_t enc_size;
/// Key generation
- ret = owl_key_derive_pbkdf2("foo bar", "123456789", 10,
- 1000, OWL_DIGEST_SHA256,
- OWL_KEY_256BIT, &key);
+ ret = yaca_key_derive_pbkdf2("foo bar", "123456789", 10,
+ 1000, YACA_DIGEST_SHA256,
+ YACA_KEY_256BIT, &key);
if (ret)
return;
- ret = owl_key_gen(&iv, OWL_KEY_IV_256BIT, OWL_KEY_TYPE_SYMMETRIC);
+ ret = yaca_key_gen(&iv, YACA_KEY_IV_256BIT, YACA_KEY_TYPE_SYMMETRIC);
if (ret)
goto ex_key;
/// Encryption
{
- ret = owl_encrypt_init(&ctx, OWL_ENC_AES, OWL_BCM_CBC,
- key, iv);
+ ret = yaca_encrypt_init(&ctx, YACA_ENC_AES, YACA_BCM_CBC,
+ key, iv);
if (ret)
goto ex_iv;
- ret = owl_encrypt_update(ctx, lorem4096, 4096, NULL, &enc_size);
+ ret = yaca_encrypt_update(ctx, lorem4096, 4096, NULL, &enc_size);
if (ret != 42)
goto ex_ctx;// TODO: what error code?
- ret = owl_get_block_length(ctx);
+ ret = yaca_get_block_length(ctx);
if (ret < 0)
goto ex_ctx;
enc_size += ret ; // Add block size for finalize
- enc = owl_malloc(enc_size);
+ enc = yaca_malloc(enc_size);
if (enc == NULL)
goto ex_ctx;
size_t out_size = enc_size;
- ret = owl_encrypt_update(ctx, lorem4096, 4096, enc, &out_size);
+ ret = yaca_encrypt_update(ctx, lorem4096, 4096, enc, &out_size);
if (ret < 0)
goto ex_of;
size_t rem = enc_size - out_size;
- ret = owl_encrypt_final(ctx, enc + out_size, &rem);
+ ret = yaca_encrypt_final(ctx, enc + out_size, &rem);
if (ret < 0)
goto ex_of;
dump_hex(enc, 16, "Encrypted data (16 of %zu bytes): ", enc_size);
- owl_ctx_free(ctx); // TODO: perhaps it should not return value
+ yaca_ctx_free(ctx); // TODO: perhaps it should not return value
}
/// Decryption
{
- ret = owl_decrypt_init(&ctx, OWL_ENC_AES, OWL_BCM_CBC,
- key, iv);
+ ret = yaca_decrypt_init(&ctx, YACA_ENC_AES, YACA_BCM_CBC,
+ key, iv);
if (ret < 0) {
- owl_free(enc);
+ yaca_free(enc);
goto ex_iv;
}
- ret = owl_decrypt_update(ctx, enc, enc_size, NULL, &dec_size);
+ ret = yaca_decrypt_update(ctx, enc, enc_size, NULL, &dec_size);
if (ret != 42)
goto ex_of; // TODO: what error code?
- ret = owl_get_block_length(ctx);
+ ret = yaca_get_block_length(ctx);
if (ret < 0)
goto ex_of;
dec_size += ret; // Add block size for finalize
- dec = owl_malloc(dec_size);
+ dec = yaca_malloc(dec_size);
if (dec == NULL)
goto ex_of;
size_t out_size = dec_size;
- ret = owl_decrypt_update(ctx, enc, enc_size, dec, &out_size);
+ ret = yaca_decrypt_update(ctx, enc, enc_size, dec, &out_size);
if (ret < 0)
goto ex_in;
size_t rem = dec_size - out_size;
- ret = owl_encrypt_final(ctx, dec + out_size, &rem);
+ ret = yaca_encrypt_final(ctx, dec + out_size, &rem);
if (ret < 0)
goto ex_in;
}
ex_in:
- owl_free(dec);
+ yaca_free(dec);
ex_of:
- owl_free(enc);
+ yaca_free(enc);
ex_ctx:
- owl_ctx_free(ctx);
+ yaca_ctx_free(ctx);
ex_iv:
- owl_key_free(iv);
+ yaca_key_free(iv);
ex_key:
- owl_key_free(key);
+ yaca_key_free(key);
}
void encrypt_seal(void)
{
int ret;
- owl_ctx_h ctx = OWL_CTX_NULL;
- owl_key_h key_pub = OWL_KEY_NULL;
- owl_key_h key_priv = OWL_KEY_NULL;
- owl_key_h aes_key = OWL_KEY_NULL;
- owl_key_h iv = OWL_KEY_NULL;
+ yaca_ctx_h ctx = YACA_CTX_NULL;
+ yaca_key_h key_pub = YACA_KEY_NULL;
+ yaca_key_h key_priv = YACA_KEY_NULL;
+ yaca_key_h aes_key = YACA_KEY_NULL;
+ yaca_key_h iv = YACA_KEY_NULL;
char *enc = NULL;
char *dec = NULL;
printf("Plain data (16 of %zu bytes): %.16s\n", (size_t)4096, lorem1024);
/// Generate key pair
- ret = owl_key_gen_pair(&key_priv, &key_pub,
- OWL_KEY_2048BIT, OWL_KEY_TYPE_PAIR_RSA);
+ ret = yaca_key_gen_pair(&key_priv, &key_pub,
+ YACA_KEY_2048BIT, YACA_KEY_TYPE_PAIR_RSA);
if (ret) return;
/// Encrypt a.k.a. seal
{
- ret = owl_seal_init(&ctx, key_pub,
- OWL_ENC_AES, OWL_BCM_CBC,
- &aes_key, &iv);
+ ret = yaca_seal_init(&ctx, key_pub,
+ YACA_ENC_AES, YACA_BCM_CBC,
+ &aes_key, &iv);
if (ret < 0)
goto ex_pk;
- ret = owl_seal_update(ctx, lorem4096, 4096, NULL, &enc_size);
+ ret = yaca_seal_update(ctx, lorem4096, 4096, NULL, &enc_size);
if (ret < 0)
goto ex_ak;
- ret = owl_get_block_length(ctx);
+ ret = yaca_get_block_length(ctx);
if (ret < 0)
goto ex_ak;
enc_size = enc_size + ret;
- enc = owl_malloc(enc_size);
+ enc = yaca_malloc(enc_size);
if (enc == NULL)
goto ex_ak;
// Seal and finalize
size_t out_size = enc_size;
- ret = owl_seal_update(ctx, lorem4096, 4096, enc, &out_size);
+ ret = yaca_seal_update(ctx, lorem4096, 4096, enc, &out_size);
if (ret < 0)
goto ex_of;
size_t rem = enc_size - out_size;
- ret = owl_seal_final(ctx, enc + out_size, &rem);
+ ret = yaca_seal_final(ctx, enc + out_size, &rem);
if (ret < 0)
goto ex_of;
dump_hex(enc, 16, "Encrypted data (16 of %zu bytes): ", enc_size);
- owl_ctx_free(ctx); // TODO: perhaps it should not return value
+ yaca_ctx_free(ctx); // TODO: perhaps it should not return value
}
/// Decrypt a.k.a. open
{
- ret = owl_open_init(&ctx, key_priv,
- OWL_ENC_AES, OWL_BCM_CBC,
- aes_key, iv);
+ ret = yaca_open_init(&ctx, key_priv,
+ YACA_ENC_AES, YACA_BCM_CBC,
+ aes_key, iv);
if (ret < 0) {
- owl_free(enc);
+ yaca_free(enc);
goto ex_ak;
}
- ret = owl_open_update(ctx, enc, enc_size, NULL, &dec_size);
+ ret = yaca_open_update(ctx, enc, enc_size, NULL, &dec_size);
if (ret < 0)
goto ex_of;
- ret = owl_get_block_length(ctx);
+ ret = yaca_get_block_length(ctx);
if (ret < 0)
goto ex_of;
dec_size = dec_size + ret;
- dec = owl_malloc(dec_size);
+ dec = yaca_malloc(dec_size);
if (dec == NULL)
goto ex_of;
// Seal and finalize
size_t out_size = enc_size;
- ret = owl_open_update(ctx, enc, enc_size, dec, &out_size);
+ ret = yaca_open_update(ctx, enc, enc_size, dec, &out_size);
if (ret < 0)
goto ex_in;
size_t rem = dec_size - out_size;
- ret = owl_open_final(ctx, dec + out_size, &rem);
+ ret = yaca_open_final(ctx, dec + out_size, &rem);
if (ret < 0)
goto ex_in;
printf("Decrypted data (16 of %zu bytes): %.16s\n", (size_t)dec_size, dec);
- owl_ctx_free(ctx); // TODO: perhaps it should not return value
+ yaca_ctx_free(ctx); // TODO: perhaps it should not return value
}
ex_in:
- owl_free(dec);
+ yaca_free(dec);
ex_of:
- owl_free(enc);
+ yaca_free(enc);
ex_ak:
- owl_key_free(aes_key);
- owl_key_free(iv);
+ yaca_key_free(aes_key);
+ yaca_key_free(iv);
ex_pk:
- owl_key_free(key_pub);
- owl_key_free(key_priv);
+ yaca_key_free(key_pub);
+ yaca_key_free(key_priv);
}
int main()
{
- int ret = owl_init();
+ int ret = yaca_init();
if (ret < 0)
return ret;
encrypt_seal();
- owl_exit(); // TODO: what about handing of return value from exit??
+ yaca_exit(); // TODO: what about handing of return value from exit??
return ret;
}
#include <stdio.h>
-#include <owl/crypto.h>
-#include <owl/encrypt.h>
-#include <owl/key.h>
-#include <owl/types.h>
+#include <yaca/crypto.h>
+#include <yaca/encrypt.h>
+#include <yaca/key.h>
+#include <yaca/types.h>
#include "lorem.h"
#include "misc.h"
{
int ret;
- owl_ctx_h ctx;
+ yaca_ctx_h ctx;
- owl_key_h key = OWL_KEY_NULL;
- owl_key_h iv = OWL_KEY_NULL;
- owl_key_h aad_key = OWL_KEY_NULL; // add OWL_OWL_KEY_TYPE_AAD ?
+ yaca_key_h key = YACA_KEY_NULL;
+ yaca_key_h iv = YACA_KEY_NULL;
+ yaca_key_h aad_key = YACA_KEY_NULL; // add YACA_YACA_KEY_TYPE_AAD ?
char *plaintext = NULL;
char *ciphertext = NULL;
/// Key generation
- ret = owl_key_gen(&key, OWL_KEY_256BIT, OWL_KEY_TYPE_SYMMETRIC); // key_type, key_len, *key ? looks imo much better
+ ret = yaca_key_gen(&key, YACA_KEY_256BIT, YACA_KEY_TYPE_SYMMETRIC); // key_type, key_len, *key ? looks imo much better
if (ret < 0)
goto clean;
- // use OWL_KEY_IV_128BIT & OWL_KEY_TYPE_IV or maybe OWL_KEY_128BIT & OWL_KEY_TYPE_SYMMETRIC ?
- ret = owl_key_gen(&iv, OWL_KEY_IV_128BIT, OWL_KEY_TYPE_IV);
+ // use YACA_KEY_IV_128BIT & YACA_KEY_TYPE_IV or maybe YACA_KEY_128BIT & YACA_KEY_TYPE_SYMMETRIC ?
+ ret = yaca_key_gen(&iv, YACA_KEY_IV_128BIT, YACA_KEY_TYPE_IV);
if (ret < 0)
goto clean;
- // use OWL_KEY_128BIT & OWL_KEY_TYPE_SYMMETRIC or maybe add OWL_KEY_AAD_128BIT & OWL_KEY_TYPE_AAD ?
- ret = owl_key_gen(&aad_key, OWL_KEY_UNSAFE_128BIT, OWL_KEY_TYPE_SYMMETRIC);
+ // use YACA_KEY_128BIT & YACA_KEY_TYPE_SYMMETRIC or maybe add YACA_KEY_AAD_128BIT & YACA_KEY_TYPE_AAD ?
+ ret = yaca_key_gen(&aad_key, YACA_KEY_UNSAFE_128BIT, YACA_KEY_TYPE_SYMMETRIC);
if (ret < 0)
goto clean;
// generate and export aad?
- ret = owl_key_export(aad_key, OWL_KEY_FORMAT_RAW, &aad, &aad_len);
+ ret = yaca_key_export(aad_key, YACA_KEY_FORMAT_RAW, &aad, &aad_len);
if (ret < 0)
goto clean;
/// Encryption
{
- ret = owl_encrypt_init(&ctx, OWL_ENC_AES, OWL_BCM_GCM, key, iv);
+ ret = yaca_encrypt_init(&ctx, YACA_ENC_AES, YACA_BCM_GCM, key, iv);
if (ret < 0)
goto clean;
- ret = owl_ctx_set_param(ctx, OWL_PARAM_GCM_AAD, aad, aad_len);
+ ret = yaca_ctx_set_param(ctx, YACA_PARAM_GCM_AAD, aad, aad_len);
if (ret < 0)
goto clean;
- ret = owl_encrypt_update(ctx, lorem4096, 4096, NULL, &ciphertext_len);
+ ret = yaca_encrypt_update(ctx, lorem4096, 4096, NULL, &ciphertext_len);
if (ret != 42)
goto clean;// TODO: what error code?
- ret = owl_get_block_length(ctx);
+ ret = yaca_get_block_length(ctx);
if (ret < 0)
goto clean;
ciphertext_len += ret ; // Add block size for finalize
- ciphertext = owl_malloc(ciphertext_len);
+ ciphertext = yaca_malloc(ciphertext_len);
if (ciphertext == NULL)
goto clean;
size_t len;
- ret = owl_encrypt_update(ctx, lorem4096, 4096, ciphertext, &len);
+ ret = yaca_encrypt_update(ctx, lorem4096, 4096, ciphertext, &len);
if (ret < 0)
goto clean;
ciphertext_len = len;
- ret = owl_encrypt_final(ctx, ciphertext + len, &len);
+ ret = yaca_encrypt_final(ctx, ciphertext + len, &len);
if (ret < 0)
goto clean;
ciphertext_len += len;
- ret = owl_ctx_get_param(ctx, OWL_PARAM_GCM_TAG, (void*)&tag, &tag_len);
+ ret = yaca_ctx_get_param(ctx, YACA_PARAM_GCM_TAG, (void*)&tag, &tag_len);
if (ret < 0)
goto clean;
dump_hex(ciphertext, 16, "Encrypted data (16 of %zu bytes): ", ciphertext_len);
- owl_ctx_free(ctx); // TODO: perhaps it should not return value
+ yaca_ctx_free(ctx); // TODO: perhaps it should not return value
}
/// Decryption
{
size_t len;
- ret = owl_decrypt_init(&ctx, OWL_ENC_AES, OWL_BCM_GCM, key, iv);
+ ret = yaca_decrypt_init(&ctx, YACA_ENC_AES, YACA_BCM_GCM, key, iv);
if (ret < 0)
goto clean;
- ret = owl_ctx_set_param(ctx, OWL_PARAM_GCM_AAD, aad, aad_len);
+ ret = yaca_ctx_set_param(ctx, YACA_PARAM_GCM_AAD, aad, aad_len);
if (ret < 0)
goto clean;
- ret = owl_decrypt_update(ctx, ciphertext, ciphertext_len, NULL, &plaintext_len);
+ ret = yaca_decrypt_update(ctx, ciphertext, ciphertext_len, NULL, &plaintext_len);
if (ret != 42)
goto clean; // TODO: what error code?
- ret = owl_get_block_length(ctx);
+ ret = yaca_get_block_length(ctx);
if (ret < 0)
goto clean;
plaintext_len += ret; // Add block size for finalize
- plaintext = owl_malloc(plaintext_len);
+ plaintext = yaca_malloc(plaintext_len);
if (plaintext == NULL)
goto clean;
- ret = owl_decrypt_update(ctx, ciphertext, ciphertext_len, plaintext, &len);
+ ret = yaca_decrypt_update(ctx, ciphertext, ciphertext_len, plaintext, &len);
if (ret < 0)
goto clean;
plaintext_len = len;
- ret = owl_ctx_set_param(ctx, OWL_PARAM_GCM_TAG, tag, tag_len);
+ ret = yaca_ctx_set_param(ctx, YACA_PARAM_GCM_TAG, tag, tag_len);
if (ret < 0)
goto clean;
- ret = owl_encrypt_final(ctx, plaintext + len, &len);
+ ret = yaca_encrypt_final(ctx, plaintext + len, &len);
if (ret < 0)
goto clean;
printf("Decrypted data (16 of %zu bytes): %.16s\n", plaintext_len, plaintext);
- owl_ctx_free(ctx);
+ yaca_ctx_free(ctx);
}
clean:
- owl_free(plaintext);
- owl_free(ciphertext);
- owl_free(tag);
- owl_free(aad);
- owl_ctx_free(ctx);
- owl_key_free(aad_key);
- owl_key_free(iv);
- owl_key_free(key);
+ yaca_free(plaintext);
+ yaca_free(ciphertext);
+ yaca_free(tag);
+ yaca_free(aad);
+ yaca_ctx_free(ctx);
+ yaca_key_free(aad_key);
+ yaca_key_free(iv);
+ yaca_key_free(key);
}
int main()
{
- int ret = owl_init();
+ int ret = yaca_init();
if (ret < 0)
return ret;
encrypt_decrypt_aes_gcm();
- owl_exit(); // TODO: what about handing of return value from exit??
+ yaca_exit(); // TODO: what about handing of return value from exit??
return ret;
}
*/
#include <stdio.h>
-#include <owl/crypto.h>
-#include <owl/encrypt.h>
-#include <owl/key.h>
-#include <owl/types.h>
+#include <yaca/crypto.h>
+#include <yaca/encrypt.h>
+#include <yaca/key.h>
+#include <yaca/types.h>
void key_exchange_dh(void)
{
int ret;
- owl_key_h private_key = OWL_KEY_NULL;
- owl_key_h public_key = OWL_KEY_NULL;
- owl_key_h peer_key = OWL_KEY_NULL;
- owl_key_h secret = OWL_KEY_NULL;
+ yaca_key_h private_key = YACA_KEY_NULL;
+ yaca_key_h public_key = YACA_KEY_NULL;
+ yaca_key_h peer_key = YACA_KEY_NULL;
+ yaca_key_h secret = YACA_KEY_NULL;
// generate private, public key
// add KEY_TYPE_PAIR_DH or use KEY_TYPE_PAIR_ECC and proper len?
// imo add KEY_TYPE_PAIR_DH
- ret = owl_key_gen_pair(&private_key, &public_key, OWL_KEY_2048BIT, OWL_KEY_TYPE_PAIR_DH);
+ ret = yaca_key_gen_pair(&private_key, &public_key, YACA_KEY_2048BIT, YACA_KEY_TYPE_PAIR_DH);
if (ret < 0)
goto clean;
rewind(fp);
/* allocate memory for entire content */
- buffer = owl_malloc(size+1);
+ buffer = yaca_malloc(size+1);
if (buffer == NULL)
goto clean;
if (1 != fread(buffer, size, 1, fp))
goto clean;
- ret = owl_key_import(&peer_key,
- OWL_KEY_FORMAT_RAW, OWL_KEY_TYPE_DH_PUB,
- buffer, size);
+ ret = yaca_key_import(&peer_key,
+ YACA_KEY_FORMAT_RAW, YACA_KEY_TYPE_DH_PUB,
+ buffer, size);
if (ret < 0)
goto clean;
// derive secret
- ret = owl_key_derive_dh(private_key, peer_key, &secret);
+ ret = yaca_key_derive_dh(private_key, peer_key, &secret);
if (ret < 0)
goto clean;
clean:
- owl_key_free(private_key);
- owl_key_free(public_key);
- owl_key_free(peer_key);
- owl_key_free(secret);
+ yaca_key_free(private_key);
+ yaca_key_free(public_key);
+ yaca_key_free(peer_key);
+ yaca_key_free(secret);
fclose(fp);
- owl_free(buffer);
+ yaca_free(buffer);
}
void key_exchange_ecdh(void)
{
int ret;
- owl_key_h private_key = OWL_KEY_NULL;
- owl_key_h public_key = OWL_KEY_NULL;
- owl_key_h peer_key = OWL_KEY_NULL;
- owl_key_h secret = OWL_KEY_NULL;
+ yaca_key_h private_key = YACA_KEY_NULL;
+ yaca_key_h public_key = YACA_KEY_NULL;
+ yaca_key_h peer_key = YACA_KEY_NULL;
+ yaca_key_h secret = YACA_KEY_NULL;
// generate private, public key
- ret = owl_key_gen_pair(&private_key, &public_key, OWL_KEY_CURVE_P256, OWL_KEY_TYPE_PAIR_ECC);
+ ret = yaca_key_gen_pair(&private_key, &public_key, YACA_KEY_CURVE_P256, YACA_KEY_TYPE_PAIR_ECC);
if (ret < 0)
goto clean;
rewind(fp);
/* allocate memory for entire content */
- buffer = owl_malloc(size+1);
+ buffer = yaca_malloc(size+1);
if (buffer == NULL)
goto clean;
if (1 != fread(buffer, size, 1, fp))
goto clean;
- ret = owl_key_import(&peer_key, OWL_KEY_FORMAT_RAW, OWL_KEY_TYPE_ECC_PUB, buffer, size);
+ ret = yaca_key_import(&peer_key, YACA_KEY_FORMAT_RAW, YACA_KEY_TYPE_ECC_PUB, buffer, size);
if (ret < 0)
goto clean;
// derive secret
- ret = owl_key_derive_dh(private_key, peer_key, &secret);
+ ret = yaca_key_derive_dh(private_key, peer_key, &secret);
if (ret < 0)
goto clean;
clean:
- owl_key_free(private_key);
- owl_key_free(public_key);
- owl_key_free(peer_key);
- owl_key_free(secret);
+ yaca_key_free(private_key);
+ yaca_key_free(public_key);
+ yaca_key_free(peer_key);
+ yaca_key_free(secret);
fclose(fp);
- owl_free(buffer);
+ yaca_free(buffer);
}
int main()
{
- int ret = owl_init();
+ int ret = yaca_init();
if (ret < 0)
return ret;
key_exchange_dh();
key_exchange_ecdh();
- owl_exit();
+ yaca_exit();
return ret;
}
*/
#include <stdio.h>
-#include <owl/crypto.h>
-#include <owl/sign.h>
-#include <owl/key.h>
+#include <yaca/crypto.h>
+#include <yaca/sign.h>
+#include <yaca/key.h>
#include "misc.h"
size_t IDX = 0;
return i;
}
-int sign(owl_ctx_h ctx, char** signature, size_t* signature_len)
+int sign(yaca_ctx_h ctx, char** signature, size_t* signature_len)
{
char buffer[SIZE];
if (read == 0)
break;
- if (owl_sign_update(ctx, buffer, read))
+ if (yaca_sign_update(ctx, buffer, read))
return -1;
}
// TODO: is it a size in bytes or length in characters?
- *signature_len = owl_get_digest_length(ctx);
- *signature = (char*)owl_malloc(*signature_len);
+ *signature_len = yaca_get_digest_length(ctx);
+ *signature = (char*)yaca_malloc(*signature_len);
- // TODO: owl_get_digest_length() returns int but owl_sign_final accepts size_t. Use common type.
- if (owl_sign_final(ctx, *signature, signature_len))
+ // TODO: yaca_get_digest_length() returns int but yaca_sign_final accepts size_t. Use common type.
+ if (yaca_sign_final(ctx, *signature, signature_len))
return -1;
dump_hex(*signature, *signature_len, "Message signature: ");
return 0;
}
-int verify(owl_ctx_h ctx, const char* signature, size_t signature_len)
+int verify(yaca_ctx_h ctx, const char* signature, size_t signature_len)
{
char buffer[SIZE];
if (read == 0)
break;
- if (owl_verify_update(ctx, buffer, read))
+ if (yaca_verify_update(ctx, buffer, read))
return -1;
}
// TODO: use int or size_t for output sizes
- if (owl_verify_final(ctx, signature, (size_t)signature_len))
+ if (yaca_verify_final(ctx, signature, (size_t)signature_len))
return -1;
printf("Verification succeeded\n");
char* signature = NULL;
size_t signature_len;
- owl_ctx_h ctx = OWL_CTX_NULL;
- owl_key_h prv = OWL_KEY_NULL;
- owl_key_h pub = OWL_KEY_NULL;
- owl_padding_e padding = OWL_PADDING_PKCS1;
+ yaca_ctx_h ctx = YACA_CTX_NULL;
+ yaca_key_h prv = YACA_KEY_NULL;
+ yaca_key_h pub = YACA_KEY_NULL;
+ yaca_padding_e padding = YACA_PADDING_PKCS1;
// GENERATE
- if (owl_key_gen_pair(&prv, &pub, OWL_KEY_4096BIT, OWL_KEY_TYPE_PAIR_RSA))
+ if (yaca_key_gen_pair(&prv, &pub, YACA_KEY_4096BIT, YACA_KEY_TYPE_PAIR_RSA))
return;
// SIGN
- if (owl_sign_init(&ctx, OWL_DIGEST_SHA512, prv))
+ if (yaca_sign_init(&ctx, YACA_DIGEST_SHA512, prv))
goto finish;
- // TODO: owl_ctx_set_param should take void* not char*
- if (owl_ctx_set_param(ctx, OWL_PARAM_PADDING, (char*)(&padding), sizeof(padding)))
+ // TODO: yaca_ctx_set_param should take void* not char*
+ if (yaca_ctx_set_param(ctx, YACA_PARAM_PADDING, (char*)(&padding), sizeof(padding)))
goto finish;
if (sign(ctx, &signature, &signature_len))
goto finish;
// TODO: is this necessary or will next ctx init handle it?
- owl_ctx_free(ctx);
- ctx = OWL_CTX_NULL;
+ yaca_ctx_free(ctx);
+ ctx = YACA_CTX_NULL;
// VERIFY
- if (owl_verify_init(&ctx, OWL_DIGEST_SHA512, pub))
+ if (yaca_verify_init(&ctx, YACA_DIGEST_SHA512, pub))
goto finish;
- if (owl_ctx_set_param(ctx, OWL_PARAM_PADDING, (char*)(&padding), sizeof(padding)))
+ if (yaca_ctx_set_param(ctx, YACA_PARAM_PADDING, (char*)(&padding), sizeof(padding)))
goto finish;
if (verify(ctx, signature, signature_len))
goto finish;
finish:
- owl_free(signature);
- owl_key_free(prv);
- owl_key_free(pub);
- owl_ctx_free(ctx);
+ yaca_free(signature);
+ yaca_key_free(prv);
+ yaca_key_free(pub);
+ yaca_ctx_free(ctx);
}
void sign_verify_hmac(void)
char* signature = NULL;
size_t signature_len;
- owl_ctx_h ctx = OWL_CTX_NULL;
- owl_key_h key = OWL_KEY_NULL;
+ yaca_ctx_h ctx = YACA_CTX_NULL;
+ yaca_key_h key = YACA_KEY_NULL;
// GENERATE
- if (owl_key_gen(&key, OWL_KEY_256BIT, OWL_KEY_TYPE_SYMMETRIC))
+ if (yaca_key_gen(&key, YACA_KEY_256BIT, YACA_KEY_TYPE_SYMMETRIC))
return;
// SIGN
- if (owl_sign_init(&ctx, OWL_DIGEST_SHA512, key))
+ if (yaca_sign_init(&ctx, YACA_DIGEST_SHA512, key))
goto finish;
if (sign(ctx, &signature, &signature_len))
// VERIFY
- if (owl_verify_init(&ctx, OWL_DIGEST_SHA512, key))
+ if (yaca_verify_init(&ctx, YACA_DIGEST_SHA512, key))
goto finish;
if (verify(ctx, signature, signature_len))
goto finish;
finish:
- owl_free(signature);
- owl_key_free(key);
- owl_ctx_free(ctx);
+ yaca_free(signature);
+ yaca_key_free(key);
+ yaca_ctx_free(ctx);
}
void sign_verify_cmac(void)
char* signature = NULL;
size_t signature_len;
- owl_ctx_h ctx = OWL_CTX_NULL;
- owl_key_h key = OWL_KEY_NULL;
+ yaca_ctx_h ctx = YACA_CTX_NULL;
+ yaca_key_h key = YACA_KEY_NULL;
// GENERATE
- if( owl_key_gen(&key, OWL_KEY_256BIT, OWL_KEY_TYPE_SYMMETRIC))
+ if( yaca_key_gen(&key, YACA_KEY_256BIT, YACA_KEY_TYPE_SYMMETRIC))
return;
// SIGN
// TODO: CMAC must extract the key length to select the proper evp (EVP_aes_XXX_cbc()) it should be documented
- if( owl_sign_init(&ctx, OWL_DIGEST_CMAC, key))
+ if( yaca_sign_init(&ctx, YACA_DIGEST_CMAC, key))
goto finish;
if( sign(ctx, &signature, &signature_len))
// VERIFY
- if( owl_verify_init(&ctx, OWL_DIGEST_CMAC, key))
+ if( yaca_verify_init(&ctx, YACA_DIGEST_CMAC, key))
goto finish;
if( verify(ctx, signature, signature_len))
goto finish;
finish:
- owl_free(signature);
- owl_key_free(key);
- owl_ctx_free(ctx);
+ yaca_free(signature);
+ yaca_key_free(key);
+ yaca_ctx_free(ctx);
}
int main()
{
- int ret = owl_init();
+ int ret = yaca_init();
if (ret < 0)
return ret;
sign_verify_hmac();
sign_verify_cmac();
- owl_exit(); // TODO: what about handing of return value from exit??
+ yaca_exit(); // TODO: what about handing of return value from exit??
return ret;
}
*/
#include <stdio.h>
-#include <owl/crypto.h>
-#include <owl/key.h>
-#include <owl/types.h>
+#include <yaca/crypto.h>
+#include <yaca/key.h>
+#include <yaca/types.h>
#include "misc.h"
/** Simple test for development of library (before API is ready) */
int main(int argc, char* argv[])
{
- owl_key_h key;
+ yaca_key_h key;
char *k;
size_t kl;
int ret;
- ret = owl_init();
+ ret = yaca_init();
if (ret < 0)
return ret;
printf("Generating key using CryptoAPI.. ");
- ret = owl_key_gen(&key, OWL_KEY_TYPE_SYMMETRIC, OWL_KEY_UNSAFE_128BIT);
+ ret = yaca_key_gen(&key, YACA_KEY_TYPE_SYMMETRIC, YACA_KEY_UNSAFE_128BIT);
if (ret < 0)
return ret;
printf("done (%d)\n", ret);
printf("Exporting key using CryptoAPI.. ");
- ret = owl_key_export(key, OWL_KEY_FORMAT_RAW, &k, &kl);
+ ret = yaca_key_export(key, YACA_KEY_FORMAT_RAW, &k, &kl);
if (ret < 0)
return ret;
printf("done (%d)\n", ret);
dump_hex(k, kl, "%zu-bit key: \n", kl);
- owl_exit();
+ yaca_exit();
return 0;
}
-Name: owl
+Name: yaca
Version: 0.0.1
Release: 0
Source0: %{name}-%{version}.tar.gz
License: Apache-2.0
Group: Security/Other
-Summary: Openssl wrapper layer
+Summary: Yet Another Crypto API
BuildRequires: cmake
BuildRequires: pkgconfig(openssl)
Requires(post): /sbin/ldconfig
Requires(postun): /sbin/ldconfig
%description
-The package provides Openssl wrapper layer.
+The package provides Yet Another Crypto API.
%files
%defattr(644,root,root,755)
-%{_libdir}/libowl.so.0
-%attr(755,root,root) %{_libdir}/libowl.so.%{version}
+%{_libdir}/libyaca.so.0
+%attr(755,root,root) %{_libdir}/libyaca.so.%{version}
%prep
%setup -q
%clean
rm -rf %{buildroot}
-%post -n owl -p /sbin/ldconfig
+%post -n yaca -p /sbin/ldconfig
-%postun -n owl -p /sbin/ldconfig
+%postun -n yaca -p /sbin/ldconfig
## Devel Package ###############################################################
%package devel
-Summary: Development Openssl wrapper layer
+Summary: Yet Another Crypto API development files
Group: Security/Other
-Requires: owl = %{version}-%{release}
+Requires: yaca = %{version}-%{release}
%description devel
-The package provides Openssl wrapper development layer.
+The package provides Yet Another Crypto API development files.
%files devel
%defattr(644,root,root,755)
-%{_libdir}/libowl.so
-%{_includedir}/owl
-%{_libdir}/pkgconfig/owl.pc
+%{_libdir}/libyaca.so
+%{_includedir}/yaca
+%{_libdir}/pkgconfig/yaca.pc
-OWL - OpenSSL Wrapper Layer
+YACA - Yet Another Crypto API
Basic information:
test/ - tests
General design:
- - All memory allocated by API should be freed with owl_free()
- - Contexts and keys should be freed with owl_ctx_free()/owl_key_free()
- - Function names: owl_<operation/object>_<function>; Ex: owl_verify_init()
+ - All memory allocated by API should be freed with yaca_free()
+ - Contexts and keys should be freed with yaca_ctx_free()/yaca_key_free()
+ - Function names: yaca_<operation/object>_<function>; Ex: yaca_verify_init()
- Simplified/Simple functions don't have <operation/object> part
- - Enums: OWL_<concept>_<value>; Ex: OWL_KEY_256BIT
+ - Enums: YACA_<concept>_<value>; Ex: YACA_KEY_256BIT
- Objects (context, key) end with _h
- Most functions return 0 on success, negative values on error
# @author Dariusz Michaluk (d.michaluk@samsung.com)
#
-PROJECT(owl)
+PROJECT(yaca)
MESSAGE(STATUS "")
-MESSAGE(STATUS "Generating makefile for the owl...")
+MESSAGE(STATUS "Generating makefile for the yaca...")
-FILE(GLOB HEADERS ${API_FOLDER}/owl/*.h)
+FILE(GLOB HEADERS ${API_FOLDER}/yaca/*.h)
FILE(GLOB SRCS *.c *.h)
SET(_LIB_VERSION_ "${VERSION}")
)
## Link libraries ##############################################################
-PKG_CHECK_MODULES(OWL_DEPS REQUIRED openssl)
+PKG_CHECK_MODULES(YACA_DEPS REQUIRED openssl)
INCLUDE_DIRECTORIES(${API_FOLDER})
-INCLUDE_DIRECTORIES(SYSTEM ${OWL_DEPS_INCLUDE_DIRS})
-TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${OWL_DEPS_LIBRARIES})
+INCLUDE_DIRECTORIES(SYSTEM ${YACA_DEPS_INCLUDE_DIRS})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${YACA_DEPS_LIBRARIES})
## Generate the pc file ########################################################
CONFIGURE_FILE(${PC_FILE}.in ${CMAKE_CURRENT_BINARY_DIR}/${PC_FILE} @ONLY)
COMPONENT RuntimeLibraries)
INSTALL(FILES ${HEADERS}
- DESTINATION ${INCLUDE_INSTALL_DIR}/owl)
+ DESTINATION ${INCLUDE_INSTALL_DIR}/yaca)
#include <openssl/evp.h>
#include <openssl/rand.h>
-#include <owl/crypto.h>
-#include <owl/error.h>
+#include <yaca/crypto.h>
+#include <yaca/error.h>
#include "ctx_p.h"
-API int owl_init(void)
+API int yaca_init(void)
{
OPENSSL_init();
return 0;
}
-API void owl_exit(void)
+API void yaca_exit(void)
{
EVP_cleanup();
CRYPTO_cleanup_all_ex_data();
}
-API void *owl_malloc(size_t size)
+API void *yaca_malloc(size_t size)
{
return OPENSSL_malloc(size);
}
-API void *owl_realloc(void *addr, size_t size)
+API void *yaca_realloc(void *addr, size_t size)
{
return OPENSSL_realloc(addr, size);
}
-API void owl_free(void *ptr)
+API void yaca_free(void *ptr)
{
OPENSSL_free(ptr);
}
-API int owl_rand_bytes(char *data, size_t data_len)
+API int yaca_rand_bytes(char *data, size_t data_len)
{
int ret;
if (data == NULL || data_len == 0)
- return OWL_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_ARGUMENT;
ret = RAND_bytes((unsigned char *)data, data_len);
if (ret == -1)
- return OWL_ERROR_NOT_SUPPORTED;
+ return YACA_ERROR_NOT_SUPPORTED;
if (ret == 1)
return 0;
- return OWL_ERROR_OPENSSL_FAILURE;
+ return YACA_ERROR_OPENSSL_FAILURE;
}
-API int owl_ctx_set_param(owl_ctx_h ctx, owl_ex_param_e param,
- const void *value, size_t value_len)
+API int yaca_ctx_set_param(yaca_ctx_h ctx, yaca_ex_param_e param,
+ const void *value, size_t value_len)
{
- return OWL_ERROR_NOT_IMPLEMENTED;
+ return YACA_ERROR_NOT_IMPLEMENTED;
}
-API int owl_ctx_get_param(const owl_ctx_h ctx, owl_ex_param_e param,
- void **value, size_t *value_len)
+API int yaca_ctx_get_param(const yaca_ctx_h ctx, yaca_ex_param_e param,
+ void **value, size_t *value_len)
{
- return OWL_ERROR_NOT_IMPLEMENTED;
+ return YACA_ERROR_NOT_IMPLEMENTED;
}
-API void owl_ctx_free(owl_ctx_h ctx)
+API void yaca_ctx_free(yaca_ctx_h ctx)
{
- owl_free(ctx);
+ yaca_free(ctx);
/* TODO: What about digest context? This should free specific contexts as well. */
}
-API int owl_get_output_length(const owl_ctx_h ctx, size_t input_len)
+API int yaca_get_output_length(const yaca_ctx_h ctx, size_t input_len)
{
- if (ctx == OWL_CTX_NULL)
- return OWL_ERROR_INVALID_ARGUMENT;
+ if (ctx == YACA_CTX_NULL)
+ return YACA_ERROR_INVALID_ARGUMENT;
return ctx->get_output_length(ctx, input_len);
}
-API int owl_get_iv_length(owl_enc_algo_e algo,
- owl_block_cipher_mode_e bcm,
- size_t key_len)
+API int yaca_get_iv_length(yaca_enc_algo_e algo,
+ yaca_block_cipher_mode_e bcm,
+ size_t key_len)
{
- return OWL_ERROR_NOT_IMPLEMENTED;
+ return YACA_ERROR_NOT_IMPLEMENTED;
}
#define CTX_P_H
#include <stddef.h>
-#include <owl/types.h>
+#include <yaca/types.h>
-enum owl_ctx_type_e
+enum yaca_ctx_type_e
{
- OWL_CTX_INVALID = 0,
- OWL_CTX_DIGEST
+ YACA_CTX_INVALID = 0,
+ YACA_CTX_DIGEST
};
/* Base structure for crypto contexts - to be inherited */
-struct owl_ctx_s
+struct yaca_ctx_s
{
- enum owl_ctx_type_e type;
+ enum yaca_ctx_type_e type;
- int (*get_output_length)(const owl_ctx_h ctx, size_t input_len);
+ int (*get_output_length)(const yaca_ctx_h ctx, size_t input_len);
};
#endif // CTX_P_H
#include <openssl/evp.h>
#include <openssl/err.h>
-#include <owl/crypto.h>
-#include <owl/error.h>
-#include <owl/types.h>
+#include <yaca/crypto.h>
+#include <yaca/error.h>
+#include <yaca/types.h>
#include "ctx_p.h"
-struct owl_digest_ctx_s
+struct yaca_digest_ctx_s
{
- struct owl_ctx_s ctx;
+ struct yaca_ctx_s ctx;
const EVP_MD *md;
EVP_MD_CTX *mdctx;
};
-static struct owl_digest_ctx_s *get_ctx(owl_ctx_h ctx)
+static struct yaca_digest_ctx_s *get_ctx(yaca_ctx_h ctx)
{
- if (ctx == OWL_CTX_NULL)
+ if (ctx == YACA_CTX_NULL)
return NULL;
switch (ctx->type)
{
- case OWL_CTX_DIGEST:
- return (struct owl_digest_ctx_s *)ctx;
+ case YACA_CTX_DIGEST:
+ return (struct yaca_digest_ctx_s *)ctx;
default:
return NULL;
}
}
-static int get_digest_output_length(const owl_ctx_h ctx, size_t input_len)
+static int get_digest_output_length(const yaca_ctx_h ctx, size_t input_len)
{
- struct owl_digest_ctx_s *c = get_ctx(ctx);
+ struct yaca_digest_ctx_s *c = get_ctx(ctx);
if (c == NULL)
- return OWL_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_ARGUMENT;
return EVP_MD_size(c->md);
}
-API int owl_digest_init(owl_ctx_h *ctx, owl_digest_algo_e algo)
+API int yaca_digest_init(yaca_ctx_h *ctx, yaca_digest_algo_e algo)
{
- struct owl_digest_ctx_s *nc;
- int ret = OWL_ERROR_OPENSSL_FAILURE;
+ struct yaca_digest_ctx_s *nc;
+ int ret = YACA_ERROR_OPENSSL_FAILURE;
if (ctx == NULL)
- return OWL_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_ARGUMENT;
- nc = owl_malloc(sizeof(struct owl_digest_ctx_s));
+ nc = yaca_malloc(sizeof(struct yaca_digest_ctx_s));
if (nc == NULL)
- return OWL_ERROR_OUT_OF_MEMORY;
+ return YACA_ERROR_OUT_OF_MEMORY;
- nc->ctx.type = OWL_CTX_DIGEST;
+ nc->ctx.type = YACA_CTX_DIGEST;
nc->ctx.get_output_length = get_digest_output_length;
switch (algo)
{
- case OWL_DIGEST_MD5:
+ case YACA_DIGEST_MD5:
nc->md = EVP_md5();
break;
- case OWL_DIGEST_SHA1:
+ case YACA_DIGEST_SHA1:
nc->md = EVP_sha1();
break;
- case OWL_DIGEST_SHA224:
+ case YACA_DIGEST_SHA224:
nc->md = EVP_sha224();
break;
- case OWL_DIGEST_SHA256:
+ case YACA_DIGEST_SHA256:
nc->md = EVP_sha256();
break;
- case OWL_DIGEST_SHA384:
+ case YACA_DIGEST_SHA384:
nc->md = EVP_sha384();
break;
- case OWL_DIGEST_SHA512:
+ case YACA_DIGEST_SHA512:
nc->md = EVP_sha512();
break;
default:
- ret = OWL_ERROR_INVALID_ARGUMENT;
+ ret = YACA_ERROR_INVALID_ARGUMENT;
goto err;
}
ret = EVP_DigestInit(nc->mdctx, nc->md);
if (ret == 1) {
- *ctx = (owl_ctx_h)nc;
+ *ctx = (yaca_ctx_h)nc;
return 0;
}
- ret = OWL_ERROR_OPENSSL_FAILURE; // TODO: owl_get_error_code_from_openssl(ret);
+ ret = YACA_ERROR_OPENSSL_FAILURE; // TODO: yaca_get_error_code_from_openssl(ret);
EVP_MD_CTX_destroy(nc->mdctx);
err:
- owl_free(nc);
+ yaca_free(nc);
return ret;
}
-API int owl_digest_update(owl_ctx_h ctx, const char *data, size_t data_len)
+API int yaca_digest_update(yaca_ctx_h ctx, const char *data, size_t data_len)
{
- struct owl_digest_ctx_s *c = get_ctx(ctx);
+ struct yaca_digest_ctx_s *c = get_ctx(ctx);
int ret;
if (c == NULL || data == NULL || data_len == 0)
- return OWL_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_ARGUMENT;
ret = EVP_DigestUpdate(c->mdctx, data, data_len);
if (ret == 1)
return 0;
- return OWL_ERROR_OPENSSL_FAILURE; // TODO: owl_get_error_code_from_openssl(ret);
+ return YACA_ERROR_OPENSSL_FAILURE; // TODO: yaca_get_error_code_from_openssl(ret);
}
-API int owl_digest_final(owl_ctx_h ctx, char *digest, size_t *digest_len)
+API int yaca_digest_final(yaca_ctx_h ctx, char *digest, size_t *digest_len)
{
- struct owl_digest_ctx_s *c = get_ctx(ctx);
+ struct yaca_digest_ctx_s *c = get_ctx(ctx);
int ret;
unsigned len = 0;
if (c == NULL || digest == NULL || digest_len == NULL)
- return OWL_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_ARGUMENT;
if (*digest_len == 0 || *digest_len > UINT_MAX) // DigestFinal accepts uint
- return OWL_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_ARGUMENT;
ret = EVP_DigestFinal_ex(c->mdctx, (unsigned char*)digest, &len);
*digest_len = len;
if (ret == 1)
return 0;
- return OWL_ERROR_OPENSSL_FAILURE; // TODO: owl_get_error_code_from_openssl(ret);
+ return YACA_ERROR_OPENSSL_FAILURE; // TODO: yaca_get_error_code_from_openssl(ret);
}
#include <openssl/crypto.h>
#include <openssl/rand.h>
-#include <owl/crypto.h>
-#include <owl/error.h>
-
-API int owl_encrypt_init(owl_ctx_h *ctx,
- owl_enc_algo_e algo,
- owl_block_cipher_mode_e bcm,
- const owl_key_h sym_key,
- const owl_key_h iv)
+#include <yaca/crypto.h>
+#include <yaca/error.h>
+
+API int yaca_encrypt_init(yaca_ctx_h *ctx,
+ yaca_enc_algo_e algo,
+ yaca_block_cipher_mode_e bcm,
+ const yaca_key_h sym_key,
+ const yaca_key_h iv)
{
- return OWL_ERROR_NOT_IMPLEMENTED;
+ return YACA_ERROR_NOT_IMPLEMENTED;
}
-API int owl_encrypt_update(owl_ctx_h ctx,
- const char *plain,
- size_t plain_len,
+API int yaca_encrypt_update(yaca_ctx_h ctx,
+ const char *plain,
+ size_t plain_len,
+ char *cipher,
+ size_t *cipher_len)
+{
+ return YACA_ERROR_NOT_IMPLEMENTED;
+}
+
+API int yaca_encrypt_final(yaca_ctx_h ctx,
char *cipher,
size_t *cipher_len)
{
- return OWL_ERROR_NOT_IMPLEMENTED;
+ return YACA_ERROR_NOT_IMPLEMENTED;
}
-API int owl_encrypt_final(owl_ctx_h ctx,
- char *cipher,
- size_t *cipher_len)
+API int yaca_decrypt_init(yaca_ctx_h *ctx,
+ yaca_enc_algo_e algo,
+ yaca_block_cipher_mode_e bcm,
+ const yaca_key_h sym_key,
+ const yaca_key_h iv)
{
- return OWL_ERROR_NOT_IMPLEMENTED;
+ return YACA_ERROR_NOT_IMPLEMENTED;
}
-API int owl_decrypt_init(owl_ctx_h *ctx,
- owl_enc_algo_e algo,
- owl_block_cipher_mode_e bcm,
- const owl_key_h sym_key,
- const owl_key_h iv)
+API int yaca_decrypt_update(yaca_ctx_h ctx,
+ const char *cipher,
+ size_t cipher_len,
+ char *plain,
+ size_t *plain_len)
{
- return OWL_ERROR_NOT_IMPLEMENTED;
+ return YACA_ERROR_NOT_IMPLEMENTED;
}
-API int owl_decrypt_update(owl_ctx_h ctx,
- const char *cipher,
- size_t cipher_len,
+API int yaca_decrypt_final(yaca_ctx_h ctx,
char *plain,
size_t *plain_len)
{
- return OWL_ERROR_NOT_IMPLEMENTED;
+ return YACA_ERROR_NOT_IMPLEMENTED;
}
-API int owl_decrypt_final(owl_ctx_h ctx,
- char *plain,
- size_t *plain_len)
+API int yaca_seal_init(yaca_ctx_h *ctx,
+ const yaca_key_h pub_key,
+ yaca_enc_algo_e algo,
+ yaca_block_cipher_mode_e bcm,
+ yaca_key_h *sym_key,
+ yaca_key_h *iv)
{
- return OWL_ERROR_NOT_IMPLEMENTED;
+ return YACA_ERROR_NOT_IMPLEMENTED;
}
-API int owl_seal_init(owl_ctx_h *ctx,
- const owl_key_h pub_key,
- owl_enc_algo_e algo,
- owl_block_cipher_mode_e bcm,
- owl_key_h *sym_key,
- owl_key_h *iv)
+API int yaca_seal_update(yaca_ctx_h ctx,
+ const char *plain,
+ size_t plain_len,
+ char *cipher,
+ size_t *cipher_len)
{
- return OWL_ERROR_NOT_IMPLEMENTED;
+ return YACA_ERROR_NOT_IMPLEMENTED;
}
-API int owl_seal_update(owl_ctx_h ctx,
- const char *plain,
- size_t plain_len,
+API int yaca_seal_final(yaca_ctx_h ctx,
char *cipher,
size_t *cipher_len)
{
- return OWL_ERROR_NOT_IMPLEMENTED;
+ return YACA_ERROR_NOT_IMPLEMENTED;
}
-API int owl_seal_final(owl_ctx_h ctx,
- char *cipher,
- size_t *cipher_len)
+API int yaca_open_init(yaca_ctx_h *ctx,
+ const yaca_key_h prv_key,
+ yaca_enc_algo_e algo,
+ yaca_block_cipher_mode_e bcm,
+ const yaca_key_h sym_key,
+ const yaca_key_h iv)
{
- return OWL_ERROR_NOT_IMPLEMENTED;
+ return YACA_ERROR_NOT_IMPLEMENTED;
}
-API int owl_open_init(owl_ctx_h *ctx,
- const owl_key_h prv_key,
- owl_enc_algo_e algo,
- owl_block_cipher_mode_e bcm,
- const owl_key_h sym_key,
- const owl_key_h iv)
+API int yaca_open_update(yaca_ctx_h ctx,
+ const char *cipher,
+ size_t cipher_len,
+ char *plain,
+ size_t *plain_len)
{
- return OWL_ERROR_NOT_IMPLEMENTED;
+ return YACA_ERROR_NOT_IMPLEMENTED;
}
-API int owl_open_update(owl_ctx_h ctx,
- const char *cipher,
- size_t cipher_len,
+API int yaca_open_final(yaca_ctx_h ctx,
char *plain,
size_t *plain_len)
{
- return OWL_ERROR_NOT_IMPLEMENTED;
-}
-
-API int owl_open_final(owl_ctx_h ctx,
- char *plain,
- size_t *plain_len)
-{
- return OWL_ERROR_NOT_IMPLEMENTED;
+ return YACA_ERROR_NOT_IMPLEMENTED;
}
#include <string.h>
#include <stdio.h>
-#include <owl/crypto.h>
-#include <owl/error.h>
-#include <owl/key.h>
+#include <yaca/crypto.h>
+#include <yaca/error.h>
+#include <yaca/key.h>
#include "key_p.h"
-static inline void key_sanity_check(const owl_key_h key)
+static inline void key_sanity_check(const yaca_key_h key)
{
assert(key->length);
assert(key->length % 8 == 0);
}
-API int owl_key_get_length(const owl_key_h key)
+API int yaca_key_get_length(const yaca_key_h key)
{
- if (key == OWL_KEY_NULL)
- return OWL_ERROR_INVALID_ARGUMENT;
+ if (key == YACA_KEY_NULL)
+ return YACA_ERROR_INVALID_ARGUMENT;
key_sanity_check(key);
return key->length;
}
-API int owl_key_import(owl_key_h *key,
- owl_key_fmt_e key_fmt,
- owl_key_type_e key_type,
- const char *data,
- size_t data_len)
+API int yaca_key_import(yaca_key_h *key,
+ yaca_key_fmt_e key_fmt,
+ yaca_key_type_e key_type,
+ const char *data,
+ size_t data_len)
{
- owl_key_h nk = NULL;
+ yaca_key_h nk = NULL;
if (key == NULL || data == NULL || data_len == 0)
- return OWL_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_ARGUMENT;
- if (key_type != OWL_KEY_TYPE_SYMMETRIC)
- return OWL_ERROR_NOT_IMPLEMENTED;
+ if (key_type != YACA_KEY_TYPE_SYMMETRIC)
+ return YACA_ERROR_NOT_IMPLEMENTED;
- if (key_fmt != OWL_KEY_FORMAT_RAW)
- return OWL_ERROR_NOT_IMPLEMENTED;
+ if (key_fmt != YACA_KEY_FORMAT_RAW)
+ return YACA_ERROR_NOT_IMPLEMENTED;
/* TODO: Overflow on an unsigned value in an undefined behaviour, unless explicitly allowed by a compile flag. */
- if (sizeof(struct owl_key_s) + data_len < data_len)
- return OWL_ERROR_TOO_BIG_ARGUMENT;
+ if (sizeof(struct yaca_key_s) + data_len < data_len)
+ return YACA_ERROR_TOO_BIG_ARGUMENT;
- nk = owl_malloc(sizeof(struct owl_key_s) + data_len);
+ nk = yaca_malloc(sizeof(struct yaca_key_s) + data_len);
if (nk == NULL)
- return OWL_ERROR_OUT_OF_MEMORY;
+ return YACA_ERROR_OUT_OF_MEMORY;
memcpy(nk->d, data, data_len); /* TODO: CRYPTO_/OPENSSL_... */
nk->length = data_len * 8;
return 0;
}
-API int owl_key_export(const owl_key_h key,
- owl_key_fmt_e key_fmt,
- char **data,
- size_t *data_len)
+API int yaca_key_export(const yaca_key_h key,
+ yaca_key_fmt_e key_fmt,
+ char **data,
+ size_t *data_len)
{
size_t byte_len;
- if (key == OWL_KEY_NULL || data == NULL || data_len == NULL)
- return OWL_ERROR_INVALID_ARGUMENT;
+ if (key == YACA_KEY_NULL || data == NULL || data_len == NULL)
+ return YACA_ERROR_INVALID_ARGUMENT;
- if (key->type != OWL_KEY_TYPE_SYMMETRIC)
- return OWL_ERROR_NOT_IMPLEMENTED;
+ if (key->type != YACA_KEY_TYPE_SYMMETRIC)
+ return YACA_ERROR_NOT_IMPLEMENTED;
- if (key_fmt != OWL_KEY_FORMAT_RAW)
- return OWL_ERROR_NOT_IMPLEMENTED;
+ if (key_fmt != YACA_KEY_FORMAT_RAW)
+ return YACA_ERROR_NOT_IMPLEMENTED;
key_sanity_check(key);
byte_len = key->length / 8;
- *data = owl_malloc(byte_len);
+ *data = yaca_malloc(byte_len);
memcpy(*data, key->d, byte_len);
*data_len = byte_len;
return 0;
}
-API int owl_key_gen(owl_key_h *sym_key,
- owl_key_type_e key_type,
- size_t key_len)
+API int yaca_key_gen(yaca_key_h *sym_key,
+ yaca_key_type_e key_type,
+ size_t key_len)
{
int ret;
if (sym_key == NULL)
- return OWL_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_ARGUMENT;
- if (key_type != OWL_KEY_TYPE_SYMMETRIC)
- return OWL_ERROR_NOT_IMPLEMENTED;
+ if (key_type != YACA_KEY_TYPE_SYMMETRIC)
+ return YACA_ERROR_NOT_IMPLEMENTED;
- *sym_key = owl_malloc(sizeof(struct owl_key_s) + key_len);
+ *sym_key = yaca_malloc(sizeof(struct yaca_key_s) + key_len);
if (*sym_key == NULL)
- return OWL_ERROR_OUT_OF_MEMORY;
+ return YACA_ERROR_OUT_OF_MEMORY;
(*sym_key)->length = key_len;
(*sym_key)->type = key_type;
- ret = owl_rand_bytes((*sym_key)->d, key_len);
+ ret = yaca_rand_bytes((*sym_key)->d, key_len);
if (ret == 0)
return 0;
- owl_free(*sym_key);
+ yaca_free(*sym_key);
return ret;
}
-API int owl_key_gen_pair(owl_key_h *prv_key,
- owl_key_h *pub_key,
- owl_key_type_e key_type,
- size_t key_len)
+API int yaca_key_gen_pair(yaca_key_h *prv_key,
+ yaca_key_h *pub_key,
+ yaca_key_type_e key_type,
+ size_t key_len)
{
- return OWL_ERROR_NOT_IMPLEMENTED;
+ return YACA_ERROR_NOT_IMPLEMENTED;
}
-API void owl_key_free(owl_key_h key)
+API void yaca_key_free(yaca_key_h key)
{
- if (key == OWL_KEY_NULL)
+ if (key == YACA_KEY_NULL)
return;
- owl_free(key);
+ yaca_free(key);
}
-API int owl_key_derive_dh(const owl_key_h prv_key,
- const owl_key_h pub_key,
- owl_key_h *sym_key)
+API int yaca_key_derive_dh(const yaca_key_h prv_key,
+ const yaca_key_h pub_key,
+ yaca_key_h *sym_key)
{
- return OWL_ERROR_NOT_IMPLEMENTED;
+ return YACA_ERROR_NOT_IMPLEMENTED;
}
-API int owl_key_derive_kea(const owl_key_h prv_key,
- const owl_key_h pub_key,
- const owl_key_h prv_key_auth,
- const owl_key_h pub_key_auth,
- owl_key_h *sym_key)
+API int yaca_key_derive_kea(const yaca_key_h prv_key,
+ const yaca_key_h pub_key,
+ const yaca_key_h prv_key_auth,
+ const yaca_key_h pub_key_auth,
+ yaca_key_h *sym_key)
{
- return OWL_ERROR_NOT_IMPLEMENTED;
+ return YACA_ERROR_NOT_IMPLEMENTED;
}
-API int owl_key_derive_pbkdf2(const char *password,
- const char *salt,
- size_t salt_len,
- int iter,
- owl_digest_algo_e algo,
- owl_key_len_e key_len,
- owl_key_h *key)
+API int yaca_key_derive_pbkdf2(const char *password,
+ const char *salt,
+ size_t salt_len,
+ int iter,
+ yaca_digest_algo_e algo,
+ yaca_key_len_e key_len,
+ yaca_key_h *key)
{
- return OWL_ERROR_NOT_IMPLEMENTED;
+ return YACA_ERROR_NOT_IMPLEMENTED;
}
#define KEY_P_H
#include <stdlib.h>
-#include <owl/types.h>
+#include <yaca/types.h>
/**
* @file key_p.h
* @brief Private header for key.c
*/
-struct owl_key_s
+struct yaca_key_s
{
- owl_key_type_e type;
+ yaca_key_type_e type;
size_t length;
char d[0];
};
#include <openssl/crypto.h>
#include <openssl/rand.h>
-#include <owl/crypto.h>
-#include <owl/error.h>
+#include <yaca/crypto.h>
+#include <yaca/error.h>
-API int owl_sign_init(owl_ctx_h *ctx,
- owl_digest_algo_e algo,
- const owl_key_h key)
+API int yaca_sign_init(yaca_ctx_h *ctx,
+ yaca_digest_algo_e algo,
+ const yaca_key_h key)
{
- return OWL_ERROR_NOT_IMPLEMENTED;
+ return YACA_ERROR_NOT_IMPLEMENTED;
}
-API int owl_sign_update(owl_ctx_h ctx,
- const char *data,
- size_t data_len)
+API int yaca_sign_update(yaca_ctx_h ctx,
+ const char *data,
+ size_t data_len)
{
- return OWL_ERROR_NOT_IMPLEMENTED;
+ return YACA_ERROR_NOT_IMPLEMENTED;
}
-API int owl_sign_final(owl_ctx_h ctx,
- char *mac,
- size_t *mac_len)
+API int yaca_sign_final(yaca_ctx_h ctx,
+ char *mac,
+ size_t *mac_len)
{
- return OWL_ERROR_NOT_IMPLEMENTED;
+ return YACA_ERROR_NOT_IMPLEMENTED;
}
-API int owl_verify_init(owl_ctx_h *ctx,
- owl_digest_algo_e algo,
- const owl_key_h key)
+API int yaca_verify_init(yaca_ctx_h *ctx,
+ yaca_digest_algo_e algo,
+ const yaca_key_h key)
{
- return OWL_ERROR_NOT_IMPLEMENTED;
+ return YACA_ERROR_NOT_IMPLEMENTED;
}
-API int owl_verify_update(owl_ctx_h ctx,
- const char *data,
- size_t data_len)
+API int yaca_verify_update(yaca_ctx_h ctx,
+ const char *data,
+ size_t data_len)
{
- return OWL_ERROR_NOT_IMPLEMENTED;
+ return YACA_ERROR_NOT_IMPLEMENTED;
}
-API int owl_verify_final(owl_ctx_h ctx,
- const char *mac,
- size_t mac_len)
+API int yaca_verify_final(yaca_ctx_h ctx,
+ const char *mac,
+ size_t mac_len)
{
- return OWL_ERROR_NOT_IMPLEMENTED;
+ return YACA_ERROR_NOT_IMPLEMENTED;
}
#include <openssl/crypto.h>
#include <openssl/rand.h>
-#include <owl/crypto.h>
-#include <owl/error.h>
-#include <owl/encrypt.h>
-#include <owl/digest.h>
-#include <owl/key.h>
-
-API int owl_digest_calc(owl_digest_algo_e algo,
- const char *data,
- size_t data_len,
- char **digest,
- size_t *digest_len)
+#include <yaca/crypto.h>
+#include <yaca/error.h>
+#include <yaca/encrypt.h>
+#include <yaca/digest.h>
+#include <yaca/key.h>
+
+API int yaca_digest_calc(yaca_digest_algo_e algo,
+ const char *data,
+ size_t data_len,
+ char **digest,
+ size_t *digest_len)
{
- owl_ctx_h ctx;
+ yaca_ctx_h ctx;
int ret;
char *ldigest;
size_t ldigest_len;
if (data == NULL || data_len == 0 || digest == NULL || digest_len == NULL)
- return OWL_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_ARGUMENT;
- ret = owl_digest_init(&ctx, algo);
+ ret = yaca_digest_init(&ctx, algo);
if (ret < 0)
return ret;
- ret = owl_digest_update(ctx, data, data_len);
+ ret = yaca_digest_update(ctx, data, data_len);
if (ret < 0)
goto err;
- ret = owl_get_digest_length(ctx);
+ ret = yaca_get_digest_length(ctx);
if (ret < 0)
goto err;
ldigest_len = ret;
- ldigest = owl_malloc(ldigest_len);
+ ldigest = yaca_malloc(ldigest_len);
if (!ldigest)
goto err;
- ret = owl_digest_final(ctx, ldigest, &ldigest_len);
+ ret = yaca_digest_final(ctx, ldigest, &ldigest_len);
if (ret < 0)
goto err_free;
- owl_ctx_free(ctx);
+ yaca_ctx_free(ctx);
*digest_len = ldigest_len;
*digest = ldigest;
return 0;
err_free:
- owl_free(ldigest);
+ yaca_free(ldigest);
err:
- owl_ctx_free(ctx);
+ yaca_ctx_free(ctx);
return ret;
}
-API int owl_encrypt(owl_enc_algo_e algo,
- owl_block_cipher_mode_e bcm,
- const owl_key_h sym_key,
- const owl_key_h iv,
- const char *plain,
- size_t plain_len,
- char **cipher,
- size_t *cipher_len)
+API int yaca_encrypt(yaca_enc_algo_e algo,
+ yaca_block_cipher_mode_e bcm,
+ const yaca_key_h sym_key,
+ const yaca_key_h iv,
+ const char *plain,
+ size_t plain_len,
+ char **cipher,
+ size_t *cipher_len)
{
- owl_ctx_h ctx;
+ yaca_ctx_h ctx;
int ret;
char *lcipher;
size_t out_len, lcipher_len, written;
if (plain == NULL || plain_len == 0 || cipher == NULL || cipher_len == NULL ||
- sym_key == OWL_KEY_NULL || iv == OWL_KEY_NULL)
- return OWL_ERROR_INVALID_ARGUMENT;
+ sym_key == YACA_KEY_NULL || iv == YACA_KEY_NULL)
+ return YACA_ERROR_INVALID_ARGUMENT;
if (plain_len > INT_MAX) /* TODO: this is because get_output_length returns signed int - perhaps we should change that */
- return OWL_ERROR_TOO_BIG_ARGUMENT;
+ return YACA_ERROR_TOO_BIG_ARGUMENT;
- ret = owl_encrypt_init(&ctx, algo, bcm, sym_key, iv);
+ ret = yaca_encrypt_init(&ctx, algo, bcm, sym_key, iv);
if (ret < 0)
return ret;
- ret = owl_get_output_length(ctx, plain_len);
+ ret = yaca_get_output_length(ctx, plain_len);
if (ret < 0)
goto err;
lcipher_len = ret;
- lcipher = owl_malloc(lcipher_len);
+ lcipher = yaca_malloc(lcipher_len);
if (lcipher == NULL)
goto err;
out_len = lcipher_len;
- ret = owl_encrypt_update(ctx, plain, plain_len, lcipher, &out_len);
+ ret = yaca_encrypt_update(ctx, plain, plain_len, lcipher, &out_len);
if (ret < 0)
goto err_free;
written = out_len;
out_len = lcipher_len - written;
- ret = owl_encrypt_final(ctx, lcipher + written, &out_len);
+ ret = yaca_encrypt_final(ctx, lcipher + written, &out_len);
if (ret < 0)
goto err_free;
assert (out_len + written == lcipher_len);
- owl_ctx_free(ctx);
+ yaca_ctx_free(ctx);
*cipher = lcipher;
*cipher_len = lcipher_len;
return 0;
err_free:
- owl_free(lcipher);
+ yaca_free(lcipher);
err:
- owl_ctx_free(ctx);
+ yaca_ctx_free(ctx);
return ret;
}
-API int owl_decrypt(owl_enc_algo_e algo,
- owl_block_cipher_mode_e bcm,
- const owl_key_h sym_key,
- const owl_key_h iv,
- const char *cipher,
- size_t cipher_len,
- char **plain,
- size_t *plain_len)
+API int yaca_decrypt(yaca_enc_algo_e algo,
+ yaca_block_cipher_mode_e bcm,
+ const yaca_key_h sym_key,
+ const yaca_key_h iv,
+ const char *cipher,
+ size_t cipher_len,
+ char **plain,
+ size_t *plain_len)
{
- owl_ctx_h ctx;
+ yaca_ctx_h ctx;
int ret;
char *lplain;
size_t out_len, lplain_len, written;
if (cipher == NULL || cipher_len == 0 || plain == NULL || plain_len == NULL ||
- sym_key == OWL_KEY_NULL || iv == OWL_KEY_NULL)
- return OWL_ERROR_INVALID_ARGUMENT;
+ sym_key == YACA_KEY_NULL || iv == YACA_KEY_NULL)
+ return YACA_ERROR_INVALID_ARGUMENT;
if (cipher_len > INT_MAX) /* TODO: this is because get_output_length returns signed int - perhaps we should change that */
- return OWL_ERROR_TOO_BIG_ARGUMENT;
+ return YACA_ERROR_TOO_BIG_ARGUMENT;
- ret = owl_decrypt_init(&ctx, algo, bcm, sym_key, iv);
+ ret = yaca_decrypt_init(&ctx, algo, bcm, sym_key, iv);
if (ret < 0)
return ret;
- ret = owl_get_output_length(ctx, cipher_len);
+ ret = yaca_get_output_length(ctx, cipher_len);
if (ret < 0)
goto err;
lplain_len = ret;
- lplain = owl_malloc(lplain_len);
+ lplain = yaca_malloc(lplain_len);
if (!lplain)
goto err;
out_len = lplain_len;
- ret = owl_decrypt_update(ctx, cipher, cipher_len, lplain, &out_len);
+ ret = yaca_decrypt_update(ctx, cipher, cipher_len, lplain, &out_len);
if (ret < 0)
goto err_free;
written = out_len;
out_len = lplain_len - written;
- ret = owl_decrypt_final(ctx, lplain + written, &out_len);
+ ret = yaca_decrypt_final(ctx, lplain + written, &out_len);
if (ret < 0)
goto err_free;
assert(out_len + written == lplain_len);
- owl_ctx_free(ctx);
+ yaca_ctx_free(ctx);
*plain = lplain;
*plain_len = lplain_len;
return 0;
err_free:
- owl_free(lplain);
+ yaca_free(lplain);
err:
- owl_ctx_free(ctx);
+ yaca_ctx_free(ctx);
return ret;
}
libdir=@LIB_INSTALL_DIR@
includedir=@INCLUDE_INSTALL_DIR@
-Name: owl
-Description: Openssl wrapper layer
+Name: yaca
+Description: Yet Another Crypto API
Version: @_LIB_VERSION_@
Libs: -L${libdir} -l@PROJECT_NAME@
Cflags: -I${includedir}