2 * Copyright (c) 2016-2020 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
31 #include <openssl/ossl_typ.h>
32 #include <openssl/evp.h>
33 #include <openssl/opensslv.h>
34 #include <openssl/rand.h>
36 #include <yaca_types.h>
41 #define API __attribute__ ((visibility("default")))
42 #define UNUSED __attribute__((unused))
45 enum yaca_context_type_e {
46 YACA_CONTEXT_INVALID = 0,
52 enum encrypt_op_type_e {
59 /* Base structure for crypto contexts - to be inherited */
60 struct yaca_context_s {
61 enum yaca_context_type_e type;
63 void (*context_destroy)(const yaca_context_h ctx);
64 int (*get_output_length)(const yaca_context_h ctx, size_t input_len, size_t *output_len);
65 int (*set_property)(yaca_context_h ctx, yaca_property_e property,
66 const void *value, size_t value_len);
67 int (*get_property)(const yaca_context_h ctx, yaca_property_e property,
68 void **value, size_t *value_len);
71 enum context_state_e {
79 /* Base structure for crypto keys - to be inherited */
86 * - YACA_KEY_TYPE_SYMMETRIC
90 struct yaca_key_simple_s {
91 struct yaca_key_s key;
99 * - YACA_KEY_TYPE_RSA_PUB
100 * - YACA_KEY_TYPE_RSA_PRIV
101 * - YACA_KEY_TYPE_DSA_PUB
102 * - YACA_KEY_TYPE_DSA_PRIV
103 * - YACA_KEY_TYPE_DH_PUB
104 * - YACA_KEY_TYPE_DH_PRIV
105 * - YACA_KEY_TYPE_EC_PUB
106 * - YACA_KEY_TYPE_EC_PRIV
109 struct yaca_key_evp_s {
110 struct yaca_key_s key;
115 int digest_get_algorithm(yaca_digest_algorithm_e algo, const EVP_MD **md);
117 int encrypt_get_algorithm(yaca_encrypt_algorithm_e algo,
118 yaca_block_cipher_mode_e bcm,
120 const EVP_CIPHER **cipher);
122 int encrypt_initialize(yaca_context_h *ctx,
123 const EVP_CIPHER *cipher,
124 const yaca_key_h sym_key,
126 enum encrypt_op_type_e op_type);
128 int encrypt_update(yaca_context_h ctx,
129 const unsigned char *input, size_t input_len,
130 unsigned char *output, size_t *output_len,
131 enum encrypt_op_type_e op_type);
133 int encrypt_finalize(yaca_context_h ctx,
134 unsigned char *output, size_t *output_len,
135 enum encrypt_op_type_e op_type);
137 struct yaca_key_simple_s *key_get_simple(const yaca_key_h key);
138 struct yaca_key_evp_s *key_get_evp(const yaca_key_h key);
140 int rsa_padding2openssl(yaca_padding_e padding);
143 #endif /* YACA_INTERNAL_H */