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
24 #ifndef YACA_INTERNAL_H
25 #define YACA_INTERNAL_H
29 #include <openssl/ossl_typ.h>
30 #include <openssl/err.h>
32 #include <yaca_types.h>
34 #define API __attribute__ ((visibility("default")))
35 #define UNUSED __attribute__((unused))
37 enum yaca_ctx_type_e {
45 /* Base structure for crypto contexts - to be inherited */
46 struct yaca_context_s {
47 enum yaca_ctx_type_e type;
49 void (*ctx_destroy)(const yaca_context_h ctx);
50 int (*get_output_length)(const yaca_context_h ctx, size_t input_len, size_t *output_len);
51 int (*set_param)(yaca_context_h ctx, yaca_property_e param,
52 const void *value, size_t value_len);
53 int (*get_param)(const yaca_context_h ctx, yaca_property_e param,
54 void **value, size_t *value_len);
58 /* Base structure for crypto keys - to be inherited */
65 * - YACA_KEY_TYPE_SYMMETRIC
69 struct yaca_key_simple_s {
70 struct yaca_key_s key;
78 * - YACA_KEY_TYPE_RSA_PUB
79 * - YACA_KEY_TYPE_RSA_PRIV
80 * - YACA_KEY_TYPE_DSA_PUB
81 * - YACA_KEY_TYPE_DSA_PRIV
84 struct yaca_key_evp_s {
85 struct yaca_key_s key;
90 int digest_get_algorithm(yaca_digest_algorithm_e algo, const EVP_MD **md);
92 int encrypt_get_algorithm(yaca_encrypt_algorithm_e algo,
93 yaca_block_cipher_mode_e bcm,
95 const EVP_CIPHER **cipher);
97 struct yaca_key_simple_s *key_get_simple(const yaca_key_h key);
98 struct yaca_key_evp_s *key_get_evp(const yaca_key_h key);
100 void error_dump(const char *file, int line, const char *function, int code);
101 #define ERROR_DUMP(code) error_dump(__FILE__, __LINE__, __func__, (code))
102 #define ERROR_CLEAR() ERR_clear_error()
105 * Function responsible for translating the openssl error to yaca error and
106 * clearing/dumping the openssl error queue. Use only after openssl function
109 * The function checks only first error in the queue. If the function doesn't
110 * find any error in openssl queue or is not able to translate it, it will
111 * return YACA_ERROR_INTERNAL and dump openssl errors if any. If the
112 * translation succeeds the function will clear the error queue and return the
113 * result of translation.
115 int error_handle(const char *file, int line, const char *function);
116 #define ERROR_HANDLE() error_handle(__FILE__, __LINE__, __func__)
118 #endif /* YACA_INTERNAL_H */