2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Krzysztof Jackiewicz <k.jackiewicz@samsung.com>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License
23 #include <openssl/crypto.h>
24 #include <openssl/evp.h>
25 #include <openssl/rand.h>
27 #include <yaca/crypto.h>
28 #include <yaca/error.h>
32 API int yaca_init(void)
36 OpenSSL_add_all_digests();
37 OpenSSL_add_all_ciphers();
40 We should prepare for multithreading. Either we or the user should setup static locks.
41 We should also decide on Openssl config.
42 Here's a good tutorial for initalization and cleanup: https://wiki.openssl.org/index.php/Library_Initialization
43 We should also initialize the entropy for random number generator: https://wiki.openssl.org/index.php/Random_Numbers#Initialization
48 API void yaca_exit(void)
51 CRYPTO_cleanup_all_ex_data();
54 API void *yaca_malloc(size_t size)
56 return OPENSSL_malloc(size);
59 API void *yaca_realloc(void *addr, size_t size)
61 return OPENSSL_realloc(addr, size);
64 API void yaca_free(void *ptr)
69 API int yaca_rand_bytes(char *data, size_t data_len)
73 if (data == NULL || data_len == 0)
74 return YACA_ERROR_INVALID_ARGUMENT;
76 ret = RAND_bytes((unsigned char *)data, data_len);
78 return YACA_ERROR_NOT_SUPPORTED;
82 return YACA_ERROR_OPENSSL_FAILURE;
85 API int yaca_ctx_set_param(yaca_ctx_h ctx, yaca_ex_param_e param,
86 const void *value, size_t value_len)
88 return YACA_ERROR_NOT_IMPLEMENTED;
91 API int yaca_ctx_get_param(const yaca_ctx_h ctx, yaca_ex_param_e param,
92 void **value, size_t *value_len)
94 return YACA_ERROR_NOT_IMPLEMENTED;
97 API void yaca_ctx_free(yaca_ctx_h ctx)
100 /* TODO: What about digest context? This should free specific contexts as well. */
103 API int yaca_get_output_length(const yaca_ctx_h ctx, size_t input_len)
105 if (ctx == YACA_CTX_NULL)
106 return YACA_ERROR_INVALID_ARGUMENT;
108 return ctx->get_output_length(ctx, input_len);
111 API int yaca_get_iv_length(yaca_enc_algo_e algo,
112 yaca_block_cipher_mode_e bcm,
115 return YACA_ERROR_NOT_IMPLEMENTED;